prompt
stringlengths
13
282
response
stringlengths
128
3.11k
forward local port 6379 to port 8000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-pod 6379: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 automa...
Add a taint on nodes with the label 'role=database' with the key 'app=node-2' and effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database app=node-2: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": "Output for...
Run a 'bash' command inside the first pod of the monitoring-service service.
Command: ```bash kubectl exec svc/monitoring-service -- bash ``` 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 kubec...
Run the 'gem --version' command inside the first container of the 'monitoring-service' service
Command: ```bash kubectl exec svc/monitoring-service -- gem --version ``` 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 ...
Add a taint with the key 'dedicated' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha dedicated=node-2: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...
Copy the kube configuration file from the remote pod `kube-flannel/ingress-controller-pod-8` to the local `/tmp/bar` directory.
Command: ```bash kubectl cp kube-flannel/ingress-controller-pod-8:~/.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 omitte...
Copy the local file at ~/.config/kube to the /etc/kubernetes directory of the 'database-pod-2' pod in the 'kubeapps' namespace.
Command: ```bash kubectl cp ~/.config/kube kubeapps/database-pod-2:/etc/kubernetes ``` 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 t...
Add a taint with the key 'dedicated' on all nodes having the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy dedicated=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": "Ou...
Display only the most recent 12 lines of output in the log-aggregator-pod pod
Command: ```bash kubectl logs --tail=12 log-aggregator-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...
forward port 5432 to pod port 8080 on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5432:8080 ``` 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 an ingress that directs requests to a specific service with a TLS secret
Command: ```bash kubectl create ingress external-ingress --rule="testing.com/module=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": "", "...
Create a new config map named 'app-config' using the specified settings and configurations files
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/settings/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 creati...
Create a copy of the proxy-server-pod with a debug container and updated container images
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-app --image=debian --set-image=web=nginx:latest,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Copy the local file ~/.config/kube to the /tmp/bar directory in the task-processor-pod-17 pod
Command: ```bash kubectl cp ~/.config/kube task-processor-pod-17::/tmp/bar -c web-app-container ``` 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 o...
Run the 'go' command inside the first container of the 'cache-service' service
Command: ```bash kubectl exec svc/cache-service -- 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 kubectl.kube...
Start streaming the logs of the "quantum-quark" container in the "log-aggregator-pod" pod.
Command: ```bash kubectl logs -f -c quantum-quark log-aggregator-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": "--containe...
Copy the local kube config file to a specific location in a remote pod's container.
Command: ```bash kubectl cp ~/.config/kube cache-pod-5:/etc/kubernetes -c image-resizer ``` 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, ...
Set the cluster field in the 'client-2-context' context to 'app-cluster'
Command: ```bash kubectl config set contexts.client-2-context.cluster app-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 service for the nginx replication controller, which serves on port 5432 and connects to the containers on port 8080
Command: ```bash kubectl expose rc nginx --port=5432 --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 specified port. ...
Create a copy of the 'payment-gateway-pod' pod and rename it to 'debug-image-web'
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-web --image=debian --set-image=api=api:v2,api=api:v2 ``` 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....
Run the 'bash' command in the 'nano-bot' container of the 'media-stream-pod' pod and get the output
Command: ```bash kubectl exec media-stream-pod -c nano-bot -- bash ``` 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 ubuntu pod and expose port 8000 in the container
Command: ```bash kubectl run hazelcast --image=ubuntu --port=8000 ``` 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: "flag": "--f...
Create a new config map named app-name-config using values from an environment file
Command: ```bash kubectl create configmap app-name-config --from-env-file=path/to/preferences.env ``` 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 t...
Create a copy of the 'vpn-service-pod' pod, and change all container images to 'php'. The copy will be named 'debug-image-web'.
Command: ```bash kubectl debug vpn-service-pod --copy-to=debug-image-web --set-image=*=php ``` 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 res...
Create a debug pod named "dgb-img" that is a copy of "proxy-service-pod", and change the container image of all containers to "php".
Command: ```bash kubectl debug proxy-service-pod --copy-to=dgb-img --set-image=*=php ``` 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 ...
Set the service account for the deployment named email-server-deployment to cert-manager
Command: ```bash kubectl set serviceaccount deployment email-server-deployment cert-manager ``` 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: `...
Forward traffic from port 8081 on all addresses to port 8081 on the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8081: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 w...
Forward port 9090 locally to port 8081 in the pod web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 9090 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 automa...
Add a taint with key 'datacenter' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production datacenter=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": "",...
Update the image of all containers in the 'staging' daemonset to 'nginx:1.21.3'
Command: ```bash kubectl set image daemonset staging *=nginx:1.21.3 ``` 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: `kub...
Import the DATABASE_URL from the app-config-prod ConfigMap into the api-server-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-prod 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...
Get the output of the `kafka-topics --list` command in the `stardust-shuttle` container of the `chat-app-pod` pod.
Command: ```bash kubectl exec chat-app-pod -c stardust-shuttle -- kafka-topics --list ``` 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. ...
Display the pod specified in the "settings.yaml" file in YAML format.
Command: ```bash kubectl get -f settings.yaml -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 only see res...
Create a deployment named ingress with the redis image
Command: ```bash kubectl create deployment ingress --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|nam...
Create a new config map named api-config by specifying individual keys and their corresponding file paths
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/properties/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...
Scale the replica set named 'app-v2-replicaset' to 3 instances.
Command: ```bash kubectl scale --replicas=3 rs/app-v2-replicaset ``` 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 va...
List all deployments in the "stable-2.0.0" version of the "web-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.stable-2.0.0.web-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 ...
Create a new ClusterIP service named 'analytics-service-clusterip' with the TCP port mapping of 8181:9091.
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=8181:9091 ``` 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": "-...
Forward port 5432 on localhost and IP 10.19.21.23 to port 3000 in pod "log-aggregator-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 5432: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 ...
Forward local port 5432 to port 5432 in the pod named "e-commerce-pod" and listen for incoming connections.
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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...
create a job named image-build-job using the node image, and run the command 'npm --version' inside the job
Command: ```bash kubectl create job image-build-job --image=node -- npm --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 form...
Copy the file '/tmp/foo' from the 'ingress-nginx/payment-gateway-pod-19' pod to '/tmp/bar_dir' locally.
Command: ```bash kubectl cp ingress-nginx/payment-gateway-pod-19:/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, u...
Add a taint with the key 'hardware' and value 'backup-node-14:PreferNoSchedule' to all nodes with the label 'app=web-app'.
Command: ```bash kubectl taint node -l app=web-app hardware=backup-node-14: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": ...
Set the basic authentication credentials for the "robot-user" entry
Command: ```bash kubectl config set-credentials robot-user --username=admin --password=uXFGweU9l35qcif ``` 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 ...
Get the output from running the 'postgres' command in the 'cyber-sleuth' container, within the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c cyber-sleuth -- postgres ``` 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, u...
Create a new ExternalName service named external-notification-service with the external name of test-site.org
Command: ```bash kubectl create service externalname external-notification-service --external-name test-site.org ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference s...
Create an ingress called 'api-gateway-ingress' with the following rules:
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/module=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": ""...
Import specified keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/kube-system-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 environmen...
Update the annotation of a pod with a new value, overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods frontend contact-email='support@example.com' ``` 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 ...
Taint the node 'backup-node-14' with a 'zone' taint and set it to 'NoSchedule'.
Command: ```bash kubectl taint nodes backup-node-14 zone: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...
Forward port 6379 in the pod `api-service-pod` to a random port locally
Command: ```bash kubectl port-forward pod/api-service-pod :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...
Execute the 'elasticsearch --version' command in the nebula-navigator container of the monitoring-pod pod and retrieve the output.
Command: ```bash kubectl exec monitoring-pod -c nebula-navigator -- elasticsearch --version ``` 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 ...
Set the server field for the cloud-cluster cluster to the specified IP address
Command: ```bash kubectl config set clusters.cloud-cluster.server https://1.2.3.4 ``` 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 new ExternalName service named external-geolocation-service with the external name demo-service.dev.
Command: ```bash kubectl create service externalname external-geolocation-service --external-name demo-service.dev ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference...
Retrieve the snapshot logs from the container backend-microservice-deployment-1 of the deployment named chat-app-pod
Command: ```bash kubectl logs deployment/backend-microservice-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 flag...
Create a new ExternalName service named external-identity-provider-service with the external name mockup-cloud.cloud
Command: ```bash kubectl create service externalname external-identity-provider-service --external-name mockup-cloud.cloud ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to r...
Create an ingress resource called 'external-ingress' with the following rules:
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/example=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": "", "usa...
Add a taint with the key 'cpu-type' on nodes having the label environment=production
Command: ```bash kubectl taint node -l environment=production 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": "", "...
Update the pod named 'analytics' with the annotation 'scaling-policy' and the value 'auto-horizontal-scaling'
Command: ```bash kubectl annotate --overwrite pods analytics scaling-policy='auto-horizontal-scaling' ``` 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...
Start a pod named 'nginx' using the 'amazonlinux' image, but override the spec with a partial set of values parsed from the provided JSON file.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "feature-branch-2.3.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] [--...
Partially update a node by applying a strategic merge patch using a YAML file.
Command: ```bash kubectl patch node monitoring-node-15 -p $'data:\n key: new-value' ``` 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]` Helpfu...
Update the label of the pod named 'payment' to have the key 'env' and the value 'development'
Command: ```bash kubectl label pods payment env=development ``` 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"...
Auto scale the deployment "payment" with the desired number of pods between 6 and 10.
Command: ```bash kubectl autoscale deployment payment --min=6 --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 uses...
Create a debug instance of a pod, copying the configuration of the backend pod and adding a debug container with a different container image
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-app --image=debian --set-image=app=app:debug,api=api:v2 ``` 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...
Remove all taints with the key 'cpu-type' from the node 'app-node-6'
Command: ```bash kubectl taint nodes app-node-6 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|yaml|n...
Remove the taint with key 'app' from the node 'kube-master-9'
Command: ```bash kubectl taint nodes kube-master-9 app- ``` 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|yaml|nam...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/kube-system-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 definiti...
Forward all traffic from port 8000 on all addresses to port 6379 in the chat-app-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8000: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...
Set the service account of the deployment "email-server-deployment" to "istio"
Command: ```bash kubectl set serviceaccount deployment email-server-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: `kubectl...
Forward local port 3000 to port 8081 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000 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...
Set the cpu limits of the nginx container in the deployment named "node" to "200m" and the memory limits to "4Gi".
Command: ```bash kubectl set resources deployment node -c=nginx --limits=cpu=200m,memory=4Gi ``` 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 it...
Create a copy of the chat-app-pod, replacing all container images with the Ruby image.
Command: ```bash kubectl debug chat-app-pod --copy-to=my-custom-dbg --set-image=*=ruby ``` 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 resourc...
Create a single ingress called 'website-ingress' that directs requests to site.com/input to svc1:8181 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="site.com/input=svc1:8181,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...
Restart the 'test' daemon set by executing the 'rollout restart' command
Command: ```bash kubectl rollout restart daemonset/test ``` 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 resource to ...
Set the custom TLS server name to use for validation for the testing-cluster cluster entry
Command: ```bash kubectl config set-cluster testing-cluster --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] [--certific...
Create a copy of the analytics-pod, add a debug container, and change container images
Command: ```bash kubectl debug analytics-pod -it --copy-to=dgb-img --image=debian --set-image=cache=redis:alpine,web=nginx:latest ``` 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....
Create an ingress named 'internal-ingress' that routes requests from 'website.com/module' to 'svc1:3001' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/module=svc1:3001,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": "", "...
Set specific environment variables from a config map for a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/namespace-config 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 defi...
Create a debug copy of a pod, named "my-debugger", with a Debian container image
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=my-debugger --image=debian --set-image=logger=logging-app:debug,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Forward local port 6379 to port 8080 in a pod selected by the mydeployment deployment.
Command: ```bash kubectl port-forward deployment/mydeployment 6379 8080 ``` 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...
Increase the number of replicas for the replica set 'payment-service-rs' to a desired count of 5.
Command: ```bash kubectl scale --replicas=5 rs/payment-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 v...
Set the cluster field in the 'my-context' context to 'sun-cluster'
Command: ```bash kubectl config set contexts.cloud-context.cluster sun-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 wan...
Update the image of a container in a pod using a JSON patch with positional arrays
Command: ```bash kubectl patch pod backend-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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 ...
Retrieve the previous terminated container logs from the pod "email-service-pod"
Command: ```bash kubectl logs -p -c quantum-quark email-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...
Create a service for the replication controller specified in the "alpine-controller.yaml" file
Command: ```bash kubectl expose -f alpine-controller.yaml --port=9090 --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...
Retrieve the phase value of a specific pod
Command: ```bash kubectl get -o template pod/gateway-pod --template={{.status.phase}} ``` 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 ...
Remove the environment variables associated with the "admin" user in the exec auth plugin configuration.
Command: ```bash kubectl config set-credentials 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 flags: -...
Get output from running pod media-stream-pod by attaching to the default container.
Command: ```bash kubectl attach media-stream-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 kubect...
Forward local port 9090 to port 8000 in the selected pod from the deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 9090 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 po...
Import the "my-example-key" key from the "monitoring-config" ConfigMap and set it as an environment variable in the "log-aggregator-deployment" Deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/monitoring-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 variabl...
Apply the configuration in the manifest file and delete any resources that are not in the file and have the label app=nginx, while also applying the label project=project-alpha
Command: ```bash kubectl apply --prune -f manifest.yaml -l project=project-alpha ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'app...
Begin streaming the logs from all containers in pods with the label instance=app-instance-1
Command: ```bash kubectl logs -f -l instance=app-instance-1 --all-containers=true ``` 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"...
Create a new role named "custom_role" with delete access to pods, specifically to the "identity-provider" and "cdn-proxy" resources.
Command: ```bash kubectl create role custom_role --verb=delete --resource=pods --resource-name=identity-provider --resource-name=cdn-proxy ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=ser...
Embed the certificate authority data for the 'on-prem-cluster' cluster entry using the command:
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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 confi...
Import the environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/tls-certificate-secret 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 definitions in one or mo...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-secrets deployment/payment-processor-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...
Retrieve the snapshot logs from the container 'backend-pod-1' of the 'database-deployment' deployment
Command: ```bash kubectl logs deployment/database-deployment -c backend-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": "-...
Remove the taint with key 'environment' and effect 'NoSchedule' from the node 'web-node-8', if it exists
Command: ```bash kubectl taint nodes web-node-8 environment: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 o...
Create a copy of the pod named 'mypod', add a 'busybox' container for debugging purposes, and attach to it
Command: ```bash kubectl debug mypod -it --image=busybox --copy-to=debug-image-api ``` 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...
Delete the pods and services named "api" and "monitoring"
Command: ```bash kubectl delete pod,service api monitoring ``` 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. ...