prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set up an autoscaling for the 'frontend' replication controller with a maximum of 3 pods and a target CPU utilization of 40%.
Command: ```bash kubectl autoscale rc frontend --max=3 --cpu-percent=40 ``` 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...
Add a taint with key 'cpu-type' on nodes having label 'team=devops' with the value 'gpu-node-12:PreferNoSchedule'
Command: ```bash kubectl taint node -l team=devops cpu-type=gpu-node-12: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": "", "usage": "Ou...
Roll back a daemonset to revision 3
Command: ```bash kubectl rollout undo daemonset/my-deployment --to-revision=3 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifyi...
Return the snapshot logs from the 'media-stream-pod' pod with only one container.
Command: ```bash kubectl logs media-stream-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": "-c", "de...
Forward all traffic on port 8081 to the pod with the name "chat-app-pod" on port 5000
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8081: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...
If the current size of the deployment named 'api-service-rs' is 7, scale the deployment of mysql to 7 replicas.
Command: ```bash kubectl scale --current-replicas=7 --replicas=7 deployment/api-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
View the non-namespaced resources supported by the Kubernetes API
Command: ```bash kubectl api-resources --groupspaced=false ``` 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. "
Copy the local file "/tmp/foo" to the remote pod "monitoring-agent-pod-6" in the "prometheus" namespace as "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo prometheus/monitoring-agent-pod-6::/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...
Roll back the deployment 'my-deployment' to the previous version
Command: ```bash kubectl rollout undo deployment/my-deployment ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource...
List deployments in YAML output format, using the "custom-version" version of the "extensions" API group.
Command: ```bash kubectl get deployments.custom-version.extensions -o yaml ``` 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 new secret named "password-secret" from an environment file
Command: ```bash kubectl create secret generic password-secret --from-env-file=path/to/settings.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 base...
Port forward local ports 8888 and 6000 to ports 8888 and 6000 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-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 automa...
Expose the deployment 'nginx' as a service, with the port set to 8082 and the target port set to 909000
Command: ```bash kubectl expose deployment nginx --port=8082 --target-port=909000 ``` 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 specifie...
Import the SMTP_SERVER key from the 'app-name-config' ConfigMap to the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-name-config deployment/backend-microservice-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 variab...
Listen on port 8088 locally and forward it to port 6379 in the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 8088: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 selected au...
Listen on port 8081 locally, forwarding to the targetPort of the "https" service port in a pod selected by the "search-service" service
Command: ```bash kubectl port-forward service/search-service 8081:https ``` 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 selecte...
Forward traffic from port 6379 to port 9090 in the web-app-pod, listening on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 6379: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 criteria, a pod will ...
Create a cron job named 'cron-task' with the specified schedule and command
Command: ```bash kubectl create cronjob cron-task --image=wordpress --schedule="*/1 * * * *" -- mysql --version ``` 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": "--output", "short": ...
Create a service for the centos deployment, with port 3001 on the service and port 818100 on the pods
Command: ```bash kubectl expose deployment centos --port=3001 --target-port=818100 ``` 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...
Forward local port 5000 to port 8888 inside the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000: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 au...
Update the pod called 'database' and set the label 'status' to 'unhealthy', but only if the resource version is still 1.
Command: ```bash kubectl label pods database status=unhealthy --resource-version=1 ``` 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", "def...
Forward port 6379 from the pod called "frontend-pod" to port 3000 locally
Command: ```bash kubectl port-forward pod/frontend-pod 6379: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 autom...
import the environment variables from the 'my-secret' secret and set them in the deployment named 'api-server-deployment'
Command: ```bash kubectl set env --from=secret/my-secret deployment/api-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 definitions in one or more pod temp...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/db-config deployment/frontend-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 definition...
Create a new config map named 'env-vars' by using the 'settings' file located at '/path/to/preferences/file1.txt' and the 'key2' file located at '/path/to/options/file2.txt' as the values for the keys.
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/preferences/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 c...
Create an ingress resource with a specific rule and TLS secret
Command: ```bash kubectl create ingress www-ingress --rule="website.com/input=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": "", "usage"...
Attach to the 'warp-drive' container in the 'proxy-service-pod' pod and get the output
Command: ```bash kubectl attach proxy-service-pod -c warp-drive ``` 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,...
Auto scale the replication controller "media-stream" to maintain the number of pods between 1 and 3, with a target CPU utilization of 20%.
Command: ```bash kubectl autoscale rc media-stream --max=3 --cpu-percent=20 ``` 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...
Create a service to expose the replicated Ubuntu containers on port 3000, which will connect to the containers on port 637900.
Command: ```bash kubectl expose rs ubuntu --port=3000 --target-port=637900 ``` 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 port....
List deployments in YAML format for the "v1.0.0" version of the "prod-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.prod-apps -o yaml ``` 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 ...
Open a raw terminal session inside the astro-container of the chat-app-pod.
Command: ```bash kubectl exec chat-app-pod -c astro-container -i -t -- bash -il ``` 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 omi...
Copy the contents of the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the "cache-pod-5" pod in the "default" namespace to the local "/tmp/bar" directory.
Command: ```bash kubectl cp default/cache-pod-5:/var/run/secrets/kubernetes.io/serviceaccount/ /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 na...
Forward traffic from port 5432 on all addresses to port 5000 in the backend-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 5432: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 ...
Create a job named "deployment-rollout-job" with the dotnet runtime image from Microsoft, running the "dotnet" command.
Command: ```bash kubectl create job deployment-rollout-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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", "de...
Get output from running the 'mysql' command in the 'astro-container' from the 'auth-service-pod'
Command: ```bash kubectl exec auth-service-pod -c astro-container -- mysql ``` 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,...
Switch to the raw terminal mode and attach to the monitoring pod in the code-explorer container
Command: ```bash kubectl attach monitoring-pod -c code-explorer -i -t ``` 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 om...
Forward local traffic to a pod for port 6379
Command: ```bash kubectl port-forward pod/web-app-pod 6379 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 selected automa...
Create a service for the replicated alpine using the replica set "alpine", which serves on port 5432 and connects to the containers on port 8000.
Command: ```bash kubectl expose rs alpine --port=5432 --target-port=800000 ``` 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 port....
Start port forwarding between your local machine's port 9090 and the pod's port 9090 for the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod 9090 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 criteria, a pod will be select...
Remove all the taints with the key 'hardware' from the 'kube-master-9' node
Command: ```bash kubectl taint nodes kube-master-9 hardware- ``` 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...
Copy the local ~/.config/kube file to the /tmp/bar directory in the "admin-dashboard" container of the "task-processor-pod-17" pod.
Command: ```bash kubectl cp ~/.config/kube task-processor-pod-17:/tmp/bar -c admin-dashboard ``` 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 omit...
Continuously stream the logs of the "quantum-quark" container in the "security-service-pod" pod.
Command: ```bash kubectl logs -f -c quantum-quark security-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": "--contai...
Forward port 5432 on your localhost and IP address 10.19.21.23 to port 6379 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Copy the local file '/tmp/foo' to the remote pod 'database-pod-2' at '/tmp/bar_dir' in the container 'security-scanner'
Command: ```bash kubectl cp :/tmp/foo database-pod-2:/tmp/bar_dir -c security-scanner ``` 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, us...
Create an ingress with the name 'api-ingress' that routes requests from site.com/module to the service 'svc1:8089' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress api-ingress --rule="site.com/module=svc1:8089,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": ...
Import the environment variables from the `env-vars` ConfigMap and prefix them with `MYSQL_` for the `authentication-service-deployment` deployment.
Command: ```bash kubectl set env --from=configmap/env-vars --prefix=MYSQL_ deployment/authentication-service-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...
Copy the local file /tmp/foo_dir to the remote pod image-resizer-pod-20 in the container monitoring-agent, and place it in the directory /tmp/bar_dir.
Command: ```bash kubectl cp /tmp/foo_dir image-resizer-pod-20:/tmp/bar_dir -c monitoring-agent ``` 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 om...
Create a new deployment named "scheduler" using the "ethereum/client-go" image and expose port 6379.
Command: ```bash kubectl create deployment scheduler --image=ethereum/client-go --port=6379 ``` 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 fo...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-settings deployment/database-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...
Create a new config map named 'log-config' using the specified keys and files as values
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/configurations/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 ...
Apply a taint with the key 'datacenter' and the value 'dev-node-4:PreferNoSchedule' on nodes that have the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta datacenter=dev-node-4: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": "", "usage": "...
Create a new resource quota named "pod-count-quota" with a limit of 10 pods.
Command: ```bash kubectl create quota pod-count-quota --hard=pods=10 ``` What it does: Create a resource quota with the specified name, hard limits, and optional scopes. Syntax: `kubectl create quota NAME [--hard=key1=value1,key2=value2] [--scopes=Scope1,Scope2] [--dry-run=server|client|none]` Helpful flags: "flag":...
Create a config map named kube-system-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/preferences/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...
Add a taint with key 'app' and value 'testing-node-11:PreferNoSchedule' on nodes having label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 app=testing-node-11: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": "", "...
Set the cluster field in the 'client-1-context' context to 'dev-cluster'
Command: ```bash kubectl config set contexts.client-1-context.cluster dev-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 you ...
Create a pod based on the JSON configuration file provided as input
Command: ```bash cat config.json | kubectl create -f - ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use to ...
Check if you have permission to list the specified job in the given namespace
Command: ```bash kubectl auth can-i list jobs.batch/database-indexing-job -n development ``` 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 part...
Roll back the daemonset/app-v2 to revision 5.
Command: ```bash kubectl rollout undo daemonset/app-v2 --to-revision=5 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the ...
Create a new secret named tls-certificate-secret from an env file
Command: ```bash kubectl create secret generic tls-certificate-secret --from-env-file=path/to/preferences.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 t...
Forward local port 5000 to the targetPort of the "https" service port in a pod that is selected by the scheduler-service service.
Command: ```bash kubectl port-forward service/scheduler-service 5000:https ``` 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 sele...
Attach to the auth-service-pod and switch to raw terminal mode, sending stdin to 'bash' in the nano-bot container and receiving stdout/stderr from 'bash' back to the client
Command: ```bash kubectl attach auth-service-pod -c nano-bot -i -t ``` 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 omitt...
Set the cluster for a specific context in the Kubernetes configuration to a specified value
Command: ```bash kubectl config set contexts.service-account-context.cluster star-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 va...
Start a pod named 'hazelcast' using the 'mcr.microsoft.com/dotnet/core/runtime' image, and expose port 5432.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=5432 ``` 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......
Output the modified deployment configuration in YAML format without making any changes to the actual deployment on the server.
Command: ```bash kubectl set env deployment/cache-cluster-deployment S3_BUCKET=my-s3-bucket -o yaml ``` 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 mor...
Display the environment variables defined on the 'gateway-deployment' deployment.
Command: ```bash kubectl set env deployment/gateway-deployment --list ``` 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 templates (within replic...
Start a hazelcast pod, specifying the hazelcast image to use and the port to expose
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=9091 ``` 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:...
Get the output from the running pod 'web-app-pod' and attach to it using the default container.
Command: ```bash kubectl attach web-app-pod ``` 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, use the kubectl.kub...
Remove a taint from node 'node-1' if it exists, with the key 'workload' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes node-1 workload: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: json...
Create a new ClusterIP service named 'payment-service-clusterip' that maps port 8089 on the service to port 8082 on the pods
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=8089:8082 ``` 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": "-o"...
Listen on a random port locally, forwarding to port 8000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod :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 automatic...
Set the cluster field in the my-context context to cluster-beta
Command: ```bash kubectl config set contexts.cloud-context.cluster cluster-beta ``` 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 you wa...
List the deployments in JSON output format, in the "custom-version" version of the "api-v2" API group.
Command: ```bash kubectl get deployments.custom-version.api-v2 -o json ``` 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 ...
Update the expiration-date annotation of the pod specified in the "docker-registry.yaml" file to '2024-12-31'
Command: ```bash kubectl annotate -f docker-registry.yaml expiration-date='2024-12-31' ``` 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 an...
Start streaming the logs of the 'cyber-sleuth' container in the 'auth-service-pod' pod
Command: ```bash kubectl logs -f -c cyber-sleuth auth-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",...
Update the annotation 'criticality' of the pod 'log-aggregator' with the value 'high', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods log-aggregator 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 ...
Print the supported API resources for the "rbac.authorization.k8s.io" API group
Command: ```bash kubectl api-resources --api-group=rbac.authorization.k8s.io ``` 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. "
Partially update the spec of the node "db-node-7". Set the replicas value to 3.
Command: ```bash kubectl patch node db-node-7 -p '{"spec":{"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 flags: "...
Create a copy of the analytics-pod and add a debug container to it
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-app --image=debian --set-image=api=api:v2,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Deny a Certificate Signing Request for 'csr-node-1'
Command: ```bash kubectl certificate deny csr-node-1 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kubectl ce...
Create a LoadBalancer service named cdn-service-lb to expose the application running on port 8083 and forward it to port 27017.
Command: ```bash kubectl create service loadbalancer cdn-service-lb --tcp=8083:27017 ``` 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", "de...
create a service for a replicated WordPress application, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose rc wordpress --port=3001 --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...
Get the output from running the 'redis-server' command inside the 'nano-bot' container of the 'gateway-pod'
Command: ```bash kubectl exec gateway-pod -c nano-bot -- redis-server ``` 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 ...
Check if you have permission to list deployments in the current namespace
Command: ```bash kubectl auth can-i list deployments.apps ``` 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 that starts with "/". N...
Set custom TLS server name for a cluster entry
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=galaxy-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...
Update the pod specified in the options.json file, setting the 'team' annotation to 'frontend team'
Command: ```bash kubectl annotate -f options.json team='frontend team' ``` 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 arbitr...
Copy the file '/tmp/foo' from the local machine to the '/etc/kubernetes' directory inside a specific container named 'auth-service' in the 'ingress-controller-pod-8' pod.
Command: ```bash kubectl cp :/tmp/foo ingress-controller-pod-8:/etc/kubernetes -c auth-service ``` 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 om...
Edit the 'backend-microservice-deployment' deployment in YAML format, and save the modified configuration in its annotation.
Command: ```bash kubectl edit deployment/backend-microservice-deployment -o yaml --save-config ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or ED...
Create a deployment named scheduler that runs the ethereum/client-go image and exposes port 8089
Command: ```bash kubectl create deployment scheduler --image=ethereum/client-go --port=8089 ``` 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 fo...
Create a job named 'test-job' from the 'report-generation' cron job.
Command: ```bash kubectl create job test-job --from=cronjob/report-generation ``` 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 format. ...
Import the DATABASE_URL key from the config map named namespace-config into the search-engine-deployment deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/namespace-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 de...
Update the pod 'gateway' with the annotation 'git-repo' and set the value as 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods gateway git-repo='https://github.com/example/my-app' ``` 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 labe...
Set the service account of the deployment "proxy-service-deployment" to "istio"
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment istio ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubect...
Create a debug copy of the e-commerce-pod with a debian debug container and updated container images for web and scheduler
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-1 --image=debian --set-image=web=nginx:latest,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Create a service for the replication controller specified in the "hazelcast-controller.yaml" file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8084 --target-port=808300 ``` 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 ...
Enable the Google Compute Platform auth provider for the "jane.smith" entry in your kubectl configuration
Command: ```bash kubectl config set-credentials jane.smith --auth-provider=gcp ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags: --...
Taint nodes with the label 'stack=tech-stack' with the taint 'dedicated=web-node-8:PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack dedicated=web-node-8: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": "", "usage"...
Scale the replica set 'api-service-rs' to 7 replicas.
Command: ```bash kubectl scale --replicas=7 rs/api-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is valid...
Forward local ports 5000 to 8000 to a pod selected by the deployment "authentication-service-deployment" to enable communication between them.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Create an ingress called 'rontend-ingress' that directs requests to website.com/example to service 'svc1' on port 5432, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress rontend-ingress --rule="website.com/example=svc1:5432,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": "", "...
Create a copy of the monitoring-pod and launch an interactive shell in the nano-bot container of the copied pod
Command: ```bash kubectl debug monitoring-pod -it --copy-to=my-custom-dbg --container=nano-bot -- 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 default...