prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward port 8081 on localhost and IP address 10.19.21.23 to port 3000 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8081:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cr...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 9090 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8088:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Create a service for the replication controller specified in the "node-controller.yaml" file, serving on port 7000 and connecting to the containers on port 808000.
Command: ```bash kubectl expose -f node-controller.yaml --port=7000 --target-port=808000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Retrieve the previous logs of the terminated "rocket-ranger" container from the pod "analytics-pod".
Command: ```bash kubectl logs -p -c rocket-ranger analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Create a pod disruption budget named "critical-services-pdb" that will select all pods with the "release=1.0.0" label and require a minimum of one pod being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=release=1.0.0 --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-availa...
Update the pod 'payment' with the annotation 'env' and the value 'staging', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods payment env='staging' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbi...
Import the 'max_connections' key from the 'api-config' config map into the 'order-processing-deployment' deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/api-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Partially update a node using a strategic merge patch specified in YAML
Command: ```bash kubectl patch node testing-node-11 -p $'spec:\n replicas: 3' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flag...
Import the environment variables from the 'gcp-service-account-secret' secret into the 'monitoring-stack-deployment' deployment
Command: ```bash kubectl set env --from=secret/gcp-service-account-secret deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create an ingress named 'private-ingress' that routes requests from site.com/bar to svc1:3306 with the tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="site.com/bar=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Set the custom TLS server name to "moon-cluster" for the "staging-cluster" cluster entry.
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=moon-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Forward local port 5000 to port 8000 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
List the replication controller named 'web', the service named 'backend-rc', and the pod named 'chat-app-pod'.
Command: ```bash kubectl get rc/web service/backend-rc pods/chat-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced yo...
Update the label of the pod 'log-aggregator' to have 'tier' as the label key and 'frontend' as the label value.
Command: ```bash kubectl label pods log-aggregator tier=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "u...
Create a new secret named 'docker-registry-secret' using the environment variables specified in the 'path/to/data.env' file
Command: ```bash kubectl create secret generic docker-registry-secret --from-env-file=path/to/data.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the b...
Import specific keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/namespace-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Forward local port 8088 to port 5432 in the pod named e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8088 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Remove the 'NoSchedule' taint with key 'cpu-type' from 'gpu-node-12' if it exists
Command: ```bash kubectl taint nodes gpu-node-12 cpu-type:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Create a service for the replication controller specified in "centos-controller.yaml", serving on port 9091 and connecting to the containers on port 888800.
Command: ```bash kubectl expose -f centos-controller.yaml --port=9091 --target-port=888800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Embed the certificate authority data for the kube-cluster-2 cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/cluster-beta/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Set the cluster field of a specified context to a specific cluster
Command: ```bash kubectl config set contexts.team-alpha-context.cluster on-prem-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new valu...
Run a proxy to the Kubernetes API server on port 5432, serving static content from the specified directory
Command: ```bash kubectl proxy --port=5432 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Forward local port 5000 to port 8081 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod 5000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named app-config, and specify keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a co...
Listen on port 6379 on localhost and IP 10.19.21.23, and forward the traffic to port 5432 in the pod named 'api-service-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 6379:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Listen on the local ports 5432 and 6000, and forward data to/from the ports 6379 and 6000 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward pod/security-service-pod 5432 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Listen on port 8888 locally and forward it to port 8888 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Set the 'cluster' field in the 'my-context' context to 'my-k8s-cluster' for 'client-2'
Command: ```bash kubectl config set contexts.client-2-context.cluster my-k8s-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value y...
Create a deployment named "loadbalancer" with the specified image and expose port 5000
Command: ```bash kubectl create deployment loadbalancer --image=docker.elastic.co/elasticsearch/elasticsearch --port=5000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "def...
Return the logs from the 'web-app-pod-1' container of the 'database-deployment' deployment
Command: ```bash kubectl logs deployment/database-deployment -c web-app-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "-...
List the replication controller "web", service "analytics-rc", and pod "chat-app-pod"
Command: ```bash kubectl get rc/web service/analytics-rc pods/chat-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced ...
Create a cron job named "backup-job" using the dotnet core runtime image
Command: ```bash kubectl create cronjob backup-job --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "...
Create a copy of the "security-service-pod" pod, changing the command of the "warp-drive" container to "sh".
Command: ```bash kubectl debug security-service-pod -it --copy-to=debug-image-web --container=warp-drive -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used ...
Embed the certificate authority data for the data-cluster cluster entry
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/staging-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/namespace-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Forward local port 8080 to port 5432 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 8080 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Start a nginx pod with specific configurations provided in JSON format.
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "v1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-name-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/ui-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Update the annotation 'monitoring-tool' of pod 'payment' to have the value 'Prometheus'
Command: ```bash kubectl annotate pods payment monitoring-tool=Prometheus ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arb...
Copy the ~/.config/kube directory from the 'api-server-pod-3' pod in the 'default' namespace to the '/tmp/bar' directory locally.
Command: ```bash kubectl cp default/api-server-pod-3:~/.config/kube :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Describe a specific node
Command: ```bash kubectl describe nodes edge-node-5.edge-cluster.local ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of t...
Check if you have the permission to list the "virus-scan-job" job in the "kube-dns" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/virus-scan-job -n kube-dns ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL th...
Copy the file /tmp/foo from the remote pod front-end-pod-12 to the local directory /tmp/bar.
Command: ```bash kubectl cp kubeapps/front-end-pod-12::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Forward port 9090 on localhost and IP 10.19.21.23 to port 8888 in the log-aggregator-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 9090:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Forward traffic from port 5432 on localhost and IP 10.19.21.23 to port 8000 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 5432:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Create a service for the alpine deployment with specific port configurations
Command: ```bash kubectl expose deployment alpine --port=8181 --target-port=808800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Embed the certificate authority data for the 'cluster-beta' cluster entry using the command 'kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/sun-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/sun-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Start a node pod called 'nginx' with the 'node' image, but overwrite the spec with a partial set of values parsed from the specified JSON file
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "v3.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND]...
Create a new LoadBalancer service named 'backend-lb' that forwards traffic from port 7000 to port 8089
Command: ```bash kubectl create service loadbalancer backend-lb --tcp=7000:8089 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default...
Update the deployment 'analytics-platform-deployment' by adding a new environment variable named CACHE_SIZE with the value of 64MB.
Command: ```bash kubectl set env deployment/analytics-platform-deployment CACHE_SIZE=64MB ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...
Retrieve the logs of the previously terminated Ruby container from the pod named "api-service-pod", using the command "kubectl logs -p -c ruby api-service-pod"
Command: ```bash kubectl logs -p -c ruby api-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short":...
Set a custom TLS server name for validation for the "star-cluster" cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=moon-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate...
Set the cpu and memory limits for a container in a deployment.
Command: ```bash kubectl set resources deployment jenkins -c=nginx --limits=cpu=1,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Print the result in yaml format of updating the nginx container image to ubuntu:20.04 from a local file, without making changes on the server.
Command: ```bash kubectl set image -f path/to/file.yaml ubuntu=ubuntu:20.04 --local -o yaml ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), repli...
Set the custom TLS server name "testing-cluster" to use for validation for the kube-cluster-2 cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=testing-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certif...
Forward local port 8080 to pod port 8000
Command: ```bash kubectl port-forward pod/api-service-pod 8080 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Import environment variables from a secret to a deployment called cache-cluster-deployment.
Command: ```bash kubectl set env --from=secret/gcp-service-account-secret deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Forward port 8088 on all addresses to port 5000 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8088:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sel...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/monitoring-rc pods/email-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is names...
Create a new config map named app-config using specified keys and file paths
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ma...
Forward traffic from local port 8081 to port 3000 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Set the resource limits and request for all containers in the golang deployment
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource reques...
Autoscale the replication controller "database" with a target CPU utilization of 90% and a minimum of 1 and maximum of 5 pods.
Command: ```bash kubectl autoscale rc database --max=5 --cpu-percent=90 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a new config map named app-config-prod with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Embed the certificate authority data for the 'cloud-cluster' cluster entry using the command 'kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/galaxy-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/galaxy-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Set the custom TLS server name "edge-cluster" to use for validation for the "kube-cluster-1" cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=edge-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Create a deployment named "api" running the "jenkins" image and expose port 8000
Command: ```bash kubectl create deployment api --image=jenkins --port=8000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Rename the context 'testing-context' to 'new-context' in your kubeconfig file
Command: ```bash kubectl config rename-context testing-context new-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also ...
Create a service for the hazelcast replicated controller with port 8181, which will connect to the containers on port 909200.
Command: ```bash kubectl expose rc hazelcast --port=8181 --target-port=909200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Forward the traffic from port 9090 on both localhost and IP 10.19.21.23 to port 8088 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 9090:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Start a pod named "hazelcast" using the "mongo" image with the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default"
Command: ```bash kubectl run hazelcast --image=mongo --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Import specific keys from a config map into the environment variables of a deployment named "load-balancer-deployment"
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/kube-system-config deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Execute the 'go run hello.go' command inside the proxy-service-pod and retrieve the output
Command: ```bash kubectl exec proxy-service-pod -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Start a pod named "hazelcast" using the "hazelcast/hazelcast" image and expose port 8443.
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8443 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags:...
Create a deployment named "jenkins-x" using the Ruby image and specify that the command to run is "ruby --version"
Command: ```bash kubectl create deployment jenkins-x --image=ruby -- ruby --version ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. On...
Attach to the backend-pod and get output from lunar-launcher
Command: ```bash kubectl attach backend-pod -c lunar-launcher ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Create a new secret named ssl-key-secret with the specified keys instead of names on disk
Command: ```bash kubectl create secret generic ssl-key-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret ...
Retrieve the snapshot logs from the container named 'proxy-service-deployment-1' within the 'media-stream-pod' deployment.
Command: ```bash kubectl logs deployment/proxy-service-deployment -c media-stream-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: ...
Update the annotation 'criticality' of pod 'email' with the value 'high' and overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods email criticality='high' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Create a new config map named app-config-prod using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When c...
Import the 'api_key' key from the config map 'kube-system-config' into the deployment 'search-engine-deployment'
Command: ```bash kubectl set env --keys=api_key --from=configmap/kube-system-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Forward all traffic from port 3000 on all addresses to port 8000 in the web-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 3000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Forward port 5432 on your local machine to port 8000 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 5432:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Create a job called "certificate-renewal" using the Alpine image, and install curl in the job container.
Command: ```bash kubectl create job certificate-renewal --image=alpine -- apk add curl ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output...
label pod 'payment' with release=v2.0
Command: ```bash kubectl label pods payment release=v2.0 ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "...
Create a pod named nginx with the Ruby image, using specific configuration values from a parsed JSON object.
Command: ```bash kubectl run nginx --image=ruby --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAN...
Copy the "~/.config/kube" file from the remote pod "velero/backend-pod-13" to the local directory "/tmp/bar"
Command: ```bash kubectl cp velero/backend-pod-13:~/.config/kube :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Create a new ClusterIP service named 'inventory-service-clusterip' with a mapping from port 3001 on the service to port 27017 on the backend
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=3001:27017 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "...
Update the environment of a pod using annotations in the given preferences.json file.
Command: ```bash kubectl annotate -f preferences.json env=staging ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary s...
Execute the 'wp' command in the warp-drive container of the backend-pod pod
Command: ```bash kubectl exec backend-pod -c warp-drive -- wp ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
List the supported API resources sorted by short names
Command: ```bash kubectl api-resources --sort-by=shortnames ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
List the replication controller named "web", the service named "gateway-rc", and the pod named "auth-service-pod"
Command: ```bash kubectl get rc/web service/gateway-rc pods/auth-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Display the details of the 'proxy-server-pod' pod in JSON format.
Command: ```bash kubectl get -o json pod proxy-server-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see...
Create a copy of the "frontend-pod" pod, changing the command of the "stardust-shuttle" container, and start an interactive shell session in the copied pod
Command: ```bash kubectl debug frontend-pod -it --copy-to=my-custom-dbg --container=stardust-shuttle -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by d...
Remove taints with key 'cpu-type' from node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 cpu-type- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yam...
Create a deployment named "db" with 7 replicas running the "mongo" image
Command: ```bash kubectl create deployment db --image=mongo --replicas=7 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|...
Create an ingress rule named 'api-gateway-ingress' that directs requests from testing.com/bar to svc1:3000, using the tls secret 'my-cert'
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/bar=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Add a taint with key 'dedicated' on nodes having label region=eu-west-2, and the taint value set to 'storage-node-13:PreferNoSchedule'.
Command: ```bash kubectl taint node -l region=eu-west-2 dedicated=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...