prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 8081 to port 5432 in the pod "log-aggregator-pod" and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8081: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 po...
Remove the 'workload' taint with effect 'NoSchedule' from the 'db-node-7' node
Command: ```bash kubectl taint nodes db-node-7 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: j...
Create a single ingress called 'private-service-ingress' that directs requests to testing.com/input to svc1:9090 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/input=svc1:9090,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":...
Update the specified node by applying a partial patch in JSON format.
Command: ```bash kubectl patch node web-node-8 -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: ...
Import the 'secret_key' key from the 'ui-config' config map and set it as an environment variable in the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/ui-config 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...
Get the details of a single pod in JSON format.
Command: ```bash kubectl get -o json pod 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 namespaced you will only see...
Taint nodes with label 'tier=frontend' by adding a taint with key 'workload' and value 'node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l tier=frontend workload=node-1: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": "Outpu...
Create a deployment named "drupal" using the "ubuntu" image with 6 replicas.
Command: ```bash kubectl create deployment drupal --image=ubuntu --replicas=6 ``` 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: ...
Create a new secret named tls-certificate-secret and include all files inside the folder bar in the secret with keys matching the file names
Command: ```bash kubectl create secret generic tls-certificate-secret --from-file=path/to/options ``` 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 basena...
List the resource details for multiple types and names
Command: ```bash kubectl get rc/web service/backend-rc pods/security-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 single ingress called 'api-v1-ingress' that directs requests to testing.com/bar to svc1:7000 with a TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/bar=svc1:7000,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...
Create a pod named "nginx" with the image "docker.elastic.co/elasticsearch/elasticsearch", and customize the pod specification using a partial set of values parsed from the provided JSON file.
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "v1.1.1", "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] [--overri...
Auto scale the replication controller "media-stream" with a target CPU utilization of 40%
Command: ```bash kubectl autoscale rc media-stream --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...
Create an ingress named 'service-ingress' that routes requests for 'testing.com/input' to the service 'svc1' on port '8443', using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/input=svc1:8443,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": "", "us...
Roll back the daemonset "namespace-1" to revision 7.
Command: ```bash kubectl rollout undo daemonset/namespace-1 --to-revision=7 ``` 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...
Attach to a specific pod and enter the raw terminal mode to interact with the code explorer container.
Command: ```bash kubectl attach auth-service-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 ...
Copy the '~/.config/kube' local file to '/tmp/bar' in the 'admin-dashboard-pod-16' pod in the 'kube-server' namespace.
Command: ```bash kubectl cp ~/.config/kube kube-server/admin-dashboard-pod-16:/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, u...
List one or more resources by their type and names
Command: ```bash kubectl get rc/web service/chat-app-rc pods/payment-gateway-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 NodePort service named email-service-nodeport with port mapping 9090 to 8080
Command: ```bash kubectl create service nodeport email-service-nodeport --tcp=9090:8080 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default...
Create an ingress called 'app2-ingress' that directs requests from foo.com/example to the service svc1 on port 6379, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress app2-ingress --rule="foo.com/example=svc1:6379,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":...
Add a taint to node 'db-node-7' with key 'workload' and no value
Command: ```bash kubectl taint nodes db-node-7 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: js...
Set the CPU limit for the 'postgres' deployment's container named 'nginx' to 500 milli CPUs and the memory limit to 2 gigabytes
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=500m,memory=2Gi ``` 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 t...
Copy the directory located at ~/.config/kube_dir on your local machine and paste it into the /tmp/bar_dir directory of the cache-pod-5 pod in the default namespace.
Command: ```bash kubectl cp ~/.config/kube_dir cache-pod-5:/tmp/bar_dir ``` 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 kubectl....
Import specific keys from a config map and set them as environment variables for a deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/monitoring-config 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 defini...
Configure the deployment "security" to automatically scale the number of pods between 7 and 10.
Command: ```bash kubectl autoscale deployment security --min=7 --max=10 ``` 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-secrets using the files file1.txt and file2.txt from the specified paths.
Command: ```bash kubectl create configmap app-secrets --from-file=conf=/path/to/options/file1.txt --from-file=data=/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 creating a...
Output the modified deployment YAML for the 'mydeployment' deployment to set the environment variable 'PORT' to '8080', without making any changes to the deployment object on the server.
Command: ```bash kubectl set env deployment/mydeployment PORT=8080 -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 more pod templates (within r...
import the 'redis_host' key from the 'ui-config' config map and set it as an environment variable for the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/ui-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 definitions...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8888 in the backend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8088: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 criteri...
List deployments in JSON output format for a specific version of the "custom-deployments" API group.
Command: ```bash kubectl get deployments.dev-2.2.0.custom-deployments -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 namespac...
Get the output from running the 'node' command in the nebula-navigator container inside the web-app-pod.
Command: ```bash kubectl exec web-app-pod -c nebula-navigator -- node ``` 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 ...
Expose a service for the replication controller specified in the "python-controller.yaml" file, serving on port 5000 and connecting to the containers on port 808300.
Command: ```bash kubectl expose -f python-controller.yaml --port=5000 --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 the...
Create an ingress called 'api-v1-ingress' that routes requests for 'testing.com/bar' to the service 'svc1:8084' using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/bar=svc1:8084,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...
Create a new LoadBalancer service named analytics-lb that forwards traffic from port 5001 on the external IP to port 8083 on the service.
Command: ```bash kubectl create service loadbalancer analytics-lb --tcp=5001:8083 ``` 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", "defau...
Create a single ingress called 'api-gateway-ingress' that directs requests to foo.com/input to svc1:8084 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/input=svc1:8084,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": "", "us...
Create a copy of the payment-gateway-pod and change all container images to hazelcast/hazelcast
Command: ```bash kubectl debug payment-gateway-pod --copy-to=dgb-img --set-image=*=hazelcast/hazelcast ``` 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 defau...
Create an ingress called 'myapp-ingress' that directs requests to 'website.com/input' to the service 'svc1:8088' with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/input=svc1:8088,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": "", "usag...
Add a taint with the key 'hardware' on nodes that have the label app=web-app
Command: ```bash kubectl taint node -l app=web-app hardware=app-node-6: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": "Out...
Retrieve snapshot logs from the container named payment-gateway-pod-1 in the deployment named load-balancer-deployment
Command: ```bash kubectl logs deployment/load-balancer-deployment -c payment-gateway-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 flag...
Set the certificate-authority-data field on the app-cluster cluster
Command: ```bash kubectl config set clusters.app-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) ``` 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 d...
Add a taint with key 'zone' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp zone=db-node-7: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": "O...
Return the snapshot logs from the container monitoring-pod-1 of the deployment named order-processing-deployment.
Command: ```bash kubectl logs deployment/order-processing-deployment -c monitoring-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 all deployments and replication controllers (rc) with a container named 'mongo' to use the image 'mongo:5.0.2'
Command: ```bash kubectl set image deployments,rc mongo=mongo:5.0.2 --all ``` 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), replicaset (rs) Syntax...
Expose the nginx deployment on port 8888, connecting to the containers on port 808000.
Command: ```bash kubectl expose deployment nginx --port=8888 --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 specifie...
Remove the NoSchedule taint with the key 'dedicated' from the node 'dev-node-4' if one exists
Command: ```bash kubectl taint nodes dev-node-4 dedicated: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:...
Execute the 'python' command in the astro-container of the vpn-service-pod
Command: ```bash kubectl exec vpn-service-pod -c astro-container -- python ``` 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,...
Display detailed information about the 'service-account-context' context in your kubeconfig file.
Command: ```bash kubectl config get-contexts service-account-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Add a taint to the node 'gpu-node-12' with key 'app' and no value
Command: ```bash kubectl taint nodes gpu-node-12 app: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|...
Listen on port 5000 on localhost and IP address 10.19.21.23, and forward the traffic to port 8088 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 5000: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 crite...
Execute the command 'sleep 3600' in the 'quantum-quark' container of the 'e-commerce-pod' pod. Get the output from the command.
Command: ```bash kubectl exec e-commerce-pod -c quantum-quark -- sleep 3600 ``` 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...
Wait until the pod named busybox1 is not in Ready state
Command: ```bash kubectl wait --for=condition=Ready=false pod/busybox1 ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command can...
Create a debug copy of the web-app-pod by adding a debug container and changing container images.
Command: ```bash kubectl debug web-app-pod -it --copy-to=dgb-img --image=debian --set-image=proxy=nginx:1.21,proxy=nginx:1.21 ``` 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. Pod...
Add a taint on nodes with the label version=v1.0.0, the taint key is 'dedicated', and the effect is 'PreferNoSchedule'
Command: ```bash kubectl taint node -l version=v1.0.0 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": "", "usa...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=log_level --from=configmap/env-vars 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 definitions in...
Create an ingress resource called 'rontend-ingress' with a rule that directs requests from testing.com/example to the service 'svc1' on port 9092, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress rontend-ingress --rule="testing.com/example=svc1:9092,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": "", "...
Forward traffic from local port 8081 to port 3000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-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 automa...
Create a job named "certificate-renewal" with the Redis image and run the command "redis-server"
Command: ```bash kubectl create job certificate-renewal --image=redis -- redis-server ``` 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 ...
Create a job with a command
Command: ```bash kubectl create job scaling-job --image=golang -- go version ``` 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. O...
Create a priority class named critical-priority with a value of 10000 and a description of "Highest criticality and resource allocation"
Command: ```bash kubectl create priorityclass critical-priority --value=10000 --description="Highest criticality and resource allocation" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=B...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/log-config 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 varia...
Create a job named "report-generation-job" using the "node" image and the command "node"
Command: ```bash kubectl create job report-generation-job --image=node -- node ``` 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....
Update the annotation 'owner' of the pod 'log-aggregator' with the value 'alice-smith', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods log-aggregator owner='alice-smith' ``` 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...
Retrieve the list of deployments in the "v2.1.0" version of the "web-apps" API group in JSON format
Command: ```bash kubectl get deployments.v2.1.0.web-apps -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 will o...
Remove the "var-to-remove" environment variable for the "cluster-admin" entry in the exec auth plugin configuration.
Command: ```bash kubectl config set-credentials cluster-admin --exec-env=var-to-remove- ``` 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 fl...
List the deployments in the "v2.0.0" version of the "third-party-apps" API group in YAML format
Command: ```bash kubectl get deployments.v2.0.0.third-party-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 yo...
update the cpu and memory limits of the nginx container in the deployment called nginx
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=100m,memory=1Gi ``` 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 i...
Create an ingress with two annotations "ingress.annotation1" and "ingress.annotation2"
Command: ```bash kubectl create ingress annotated --class=default --rule="foo.com/input=svc:port" \ --annotation ingress.annotation1=foo \ --annotation ingress.annotation2=bla ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp velero/file-server-pod-14:/tmp/foo /tmp/bar_dir ``` 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 kube...
Create an interactive debugging session in the "payment-gateway-pod" pod and attach to it using the "busybox" image.
Command: ```bash kubectl debug payment-gateway-pod -it --image=busybox ``` 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 if no resource is specified. ...
Create a deployment named sonarqube using the redis image
Command: ```bash kubectl create deployment sonarqube --image=redis ``` 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|yaml|n...
Restart the daemon set named "namespace-1"
Command: ```bash kubectl rollout restart daemonset/namespace-1 ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resou...
Forward traffic from local port 3000 to port 5432 in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod 3000: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...
Add a taint with the key 'dedicated' on nodes that have the label component=proxy
Command: ```bash kubectl taint node -l component=proxy 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": "", "us...
Set the service account for the deployment "api-server-deployment" to "vault"
Command: ```bash kubectl set serviceaccount deployment api-server-deployment vault ``` 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: `kubectl s...
Create a debug copy of the 'chat-app-pod' pod with a custom name 'my-custom-dbg', using the image 'debian' for the debug container
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-custom-dbg --image=debian --set-image=proxy=nginx:1.21,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and ...
Create a new config map named api-config by reading the key-value pairs from the file located at path/to/settings
Command: ```bash kubectl create configmap api-config --from-file=path/to/settings ``` 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 map based on a file, the key will default to the basename o...
Retrieve information about the desired resources
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/cdn-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 name...
Forward local traffic from port 3000 to port 8000 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-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 be selected...
Create an ingress named 'app2-ingress' that routes requests from 'site.com/input' to 'svc1:8082' with a TLS certificate named 'my-cert'
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/input=svc1:8082,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": ...
Forward local port 6379 to port 6379 inside the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Set the cluster field of the 'my-context' context to 'kube-cluster-2'
Command: ```bash kubectl config set contexts.cloud-context.cluster kube-cluster-2 ``` 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 ...
Set the cluster field of the "service-account-context" context to "on-prem-cluster"
Command: ```bash kubectl config set contexts.service-account-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...
Copy the directory "/var/run/secrets/kubernetes.io/serviceaccount/" from the remote pod "monitoring-agent-pod-6" in the "kube-proxy" namespace to the local directory "/tmp/bar_dir".
Command: ```bash kubectl cp kube-proxy/monitoring-agent-pod-6:/var/run/secrets/kubernetes.io/serviceaccount/ /tmp/bar_dir ``` 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": "", "usa...
remove the pods and services with the names 'auth' and 'frontend'
Command: ```bash kubectl delete pod,service auth frontend ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. S...
List the deployments in the "custom-apps" API group, using the "v1.1.1" version, and display the output in JSON format.
Command: ```bash kubectl get deployments.v1.1.1.custom-apps -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 wil...
Open the analytics-service service for editing using the nano editor.
Command: ```bash KUBE_EDITOR="nano" kubectl edit svc/analytics-service ``` 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 EDITOR environment variabl...
Create a debug container for the monitoring-pod by adding a new container with the image of "debian" and changing the container images to "logging-app:debug".
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifie...
Retrieve the snapshot logs from container 'chat-app-pod-1' of the 'order-processing-deployment' deployment.
Command: ```bash kubectl logs deployment/order-processing-deployment -c chat-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: "...
Start a Kubernetes pod using the NGINX image, but customize the pod configuration by providing a partial set of values in JSON format.
Command: ```bash kubectl run nginx --image=nginx --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] -- [COMMA...
Create an ingress named 'app1-ingress' that routes requests for 'testing.com/bar' to the service 'svc1' on port 5432, using the TLS certificate 'my-cert'
Command: ```bash kubectl create ingress app1-ingress --rule="testing.com/bar=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": "", "usage":...
Delete pods and services that have the label "zone=us-east-1"
Command: ```bash kubectl delete pods,services -l zone=us-east-1 ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selec...
Create a copy of the proxy-service-pod named my-custom-dbg, and change all container images to docker.elastic.co/elasticsearch/elasticsearch.
Command: ```bash kubectl debug proxy-service-pod --copy-to=my-custom-dbg --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and na...
Create a job named "log-collection" using the image "mcr.microsoft.com/dotnet/core/runtime" and the command "dotnet"
Command: ```bash kubectl create job log-collection --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", "default": ...
List the deployments in YAML output format, using the "alpha-2.0" version of the "api-v2" API group
Command: ```bash kubectl get deployments.alpha-2.0.api-v2 -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 ...
Copy the contents of "/var/run/secrets/kubernetes.io/serviceaccount/" from your local machine to "/tmp/bar_dir" inside the pod "kube-node-lease/message-broker-pod-15" in the specified namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-node-lease/message-broker-pod-15:/tmp/bar_dir ``` 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": "", ...
Set the custom TLS server name as 'sun-cluster' to be used for validation for the 'cluster-beta' cluster entry.
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=sun-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-...
View the details of a specific revision of a daemonset.
Command: ```bash kubectl rollout history daemonset/namespace-2 --revision=3 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Create a new config map named app-settings and populate it with specified keys and their corresponding file values
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/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...
Create a copy of the auth-service-pod resource and change all container images to "node"
Command: ```bash kubectl debug auth-service-pod --copy-to=debug-image-memcached --set-image=*=node ``` 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 i...
Start streaming the logs of the 'time-machine' container in the 'proxy-service-pod' pod
Command: ```bash kubectl logs -f -c time-machine proxy-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"...