prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Get the output from the astro-container in the vpn-service-pod pod
Command: ```bash kubectl attach vpn-service-pod -c astro-container ``` 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...
Forward local port 9090 to port 8080 in the pod named "web-app-pod" for bidirectional data transfer
Command: ```bash kubectl port-forward pod/web-app-pod 9090 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 selected automa...
Expose replica set "python" as a service on port 80, forwarding traffic to the container's port 8000.
Command: ```bash kubectl expose rs python --port=80 --target-port=808800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Wait for the deletion of the pod "security-service-pod" with a timeout of 60 seconds after executing the delete command
Command: ```bash kubectl delete pod/security-service-pod kubectl wait --for=delete pod/busybox1 --timeout=60s ``` 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 r...
run the 'mongo' command in the cyber-sleuth container of the gateway-pod pod and display the output.
Command: ```bash kubectl exec gateway-pod -c cyber-sleuth -- mongo ``` 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...
Create an ingress called 'api-ingress' with a routing rule that directs requests from testing.com/example to the service named 'svc1' on port 8089, and use the tls secret named 'my-cert'.
Command: ```bash kubectl create ingress api-ingress --rule="testing.com/example=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": "", "usag...
Create a copy of the monitoring-pod named debug-image-api, replacing all container images with the alpine image.
Command: ```bash kubectl debug monitoring-pod --copy-to=debug-image-api --set-image=*=alpine ``` 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 r...
Create an ingress called 'service-ingress' that directs requests to site.com/module to svc # svc1:9000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="site.com/module=svc1:9000,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...
create a pod disruption budget named messaging-pdb that will select all pods with the component=web label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=component=web --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [-...
Edit the 'notification-service' service using the 'atom' editor
Command: ```bash KUBE_EDITOR="atom" kubectl edit svc/notification-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 vari...
Assign the label 'tier=frontend' to the pod named 'vpn'
Command: ```bash kubectl label pods vpn tier=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
Create a service for the ubuntu deployment, which serves on port 8000 and connects to the containers on port 909000
Command: ```bash kubectl expose deployment ubuntu --port=8000 --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 specifi...
Apply a taint to node 'k8s-node-1' with the key 'datacenter', value 'dc-1', and effect 'NoExecute'
Command: ```bash kubectl taint nodes k8s-node-1 datacenter=dc-1:NoExecute ``` 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...
Partially update a node using a strategic merge patch, specifying the patch as YAML
Command: ```bash kubectl patch node db-node-7 -p $'stringData:\n password: new-password' ``` 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]` H...
retrieve the logs from the container with the name 'frontend-pod-1' in the deployment 'backend-microservice-deployment'
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c frontend-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...
View detailed information about a specific node in the cluster.
Command: ```bash kubectl describe nodes networking-node-19.networking-cluster.local ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all...
import the `SMTP_SERVER` key from the `configmap/namespace-config` and set it as an environment variable in the `order-processing-deployment` deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/namespace-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create a new config map named ui-config, using the properties file at /path/to/properties/file1.txt and the key1 file at /path/to/configs/file2.txt instead of file basenames on disk.
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/configs/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...
Import the 'log_level' key from the 'app-config' ConfigMap into the 'scheduler-app-deployment' deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
import the specific keys "redis_host" from the config map "app-config-dev" into the environment variables of the "database-deployment" deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev 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 definitions...
Copy the content of the '/var/run/secrets/kubernetes.io/serviceaccount/' directory from the 'auth-service-pod-11' pod to the '/tmp/bar_dir' directory locally.
Command: ```bash kubectl cp kube-proxy/auth-service-pod-11:/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": "", "usage"...
Switch to raw terminal mode and attach to the 'cyber-sleuth' container in the 'monitoring-pod' pod
Command: ```bash kubectl attach monitoring-pod -c cyber-sleuth -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 omi...
Expose the wordpress replica set as a service on port 9000, connecting to the containers on port 801000
Command: ```bash kubectl expose rs wordpress --port=9000 --target-port=801000 ``` 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...
Import the 'redis_host' key from the 'app-config' config map and set it as an environment variable in the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Taint nodes with label 'component=proxy' General idea: Add a taint with key 'app' on nodes having label component=proxy
Command: ```bash kubectl taint node -l component=proxy 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": "", "usage": ...
Create a pod named "hazelcast" using the "golang" image and expose port 8083.
Command: ```bash kubectl run hazelcast --image=golang --port=8083 ``` 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...
Switch to the prod-cluster context
Command: ```bash kubectl config use-context prod-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Set the custom TLS server name for the testing-cluster cluster entry to "cluster-alpha"
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=cluster-alpha ``` 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] [--certifi...
Create a new ExternalName service named external-payment-gateway-service with the --external-name document-company.com
Command: ```bash kubectl create service externalname external-payment-gateway-service --external-name document-company.com ``` 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 a cron job named data-processing with the command "dotnet --list-sdks" scheduled to run every minute
Command: ```bash kubectl create cronjob data-processing --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-sdks ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful...
Apply a taint with key 'app' on nodes labeled with component=proxy
Command: ```bash kubectl taint node -l component=proxy app=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": "Outp...
Return snapshot logs from container load-balancer-deployment-1 of a deployment named vpn-service-pod.
Command: ```bash kubectl logs deployment/load-balancer-deployment -c vpn-service-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: "...
Scale the replication controller "backend" with the desired number of pods and target CPU utilization.
Command: ```bash kubectl autoscale rc backend --max=7 --cpu-percent=81 ``` 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...
Set environment variables in a deployment by importing specific keys from a config map.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-name-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Embed certificate authority data for the galaxy-cluster cluster entry.
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/cloud-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Start a pod named hazelcast using the ubuntu image, and expose port 8181 inside the container.
Command: ```bash kubectl run hazelcast --image=ubuntu --port=8181 ``` 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 an ingress named 'app-gateway-ingress' with a rule that directs requests to foo.com/module to svc1:8080, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/module=svc1:8080,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": "", "u...
Create an ingress called 'api-gateway-ingress' with a rule that directs requests for 'site.com/bar' to 'svc1:8888'
Command: ```bash kubectl create ingress api-gateway-ingress --rule="site.com/bar=svc1:8888,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...
Remove the taint with key 'zone' and effect 'PreferNoSchedule' from the node 'gpu-node-12'
Command: ```bash kubectl taint nodes gpu-node-12 zone: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 format. One o...
Create a copy of the pod "web-app-pod" with container images changed to "php"
Command: ```bash kubectl debug web-app-pod --copy-to=debug-image-memcached --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 r...
Create a new config map named 'ui-config' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 config m...
List the deployments in JSON output format from the "v2.0.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.v2.0.0.third-party-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 yo...
List all deployments in the "alpha-2.0" version of the "alpha-apps" API group, and display the output in JSON format
Command: ```bash kubectl get deployments.alpha-2.0.alpha-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 w...
Create a cluster role named "admin_role" with the specified API Group and permissions
Command: ```bash kubectl create clusterrole admin_role --verb=use,proxy,delete --resource=deployments.apps ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--o...
Create a cron job named "report-generation" that runs the command "sleep 3600" every minute using the CentOS image.
Command: ```bash kubectl create cronjob report-generation --image=centos --schedule="*/1 * * * *" -- sleep 3600 ``` 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": ...
Update the image of all containers in the daemonset named 'services' to 'postgres:13.4'
Command: ```bash kubectl set image daemonset services *=postgres:13.4 ``` 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: `k...
View the last-applied-configuration annotations for a specific resource in YAML format.
Command: ```bash kubectl apply view-last-applied deployment/node ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-applied (...
Create a service for a replicated ruby, which serves on port 8010 and connects to the containers on port 700000.
Command: ```bash kubectl expose rc ruby --port=8010 --target-port=700000 ``` 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. A...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/env-vars deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Update the 'auth' pod with the annotation 'team' and the value 'frontend team'
Command: ```bash kubectl annotate pods auth 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 arbitrary st...
Create an ingress called 'private-api-ingress' that directs requests to site.com/module to a service called 'svc1' running on port '9090'
Command: ```bash kubectl create ingress private-api-ingress --rule="site.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": "", "...
Embed certificate authority data for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster ...
Remove all the taints with key 'cpu-type' from node 'node-2'
Command: ```bash kubectl taint nodes node-2 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|name|...
Create a new ExternalName service named external-analytics-service that points to museum-example.museum
Command: ```bash kubectl create service externalname external-analytics-service --external-name museum-example.museum ``` 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 refere...
Create a service for the replicated ruby containers, which serves on port 9000 and connects to the containers on port 8000
Command: ```bash kubectl expose rc ruby --port=9000 --target-port=8000 ``` 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. A d...
Begin streaming the logs of the "code-explorer" container in the "backend-pod" pod.
Command: ```bash kubectl logs -f -c code-explorer backend-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", "sh...
Forward traffic from localhost and a selected IP to port 8888, which will be forwarded to port 8080 in the pod named "backend-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8888: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 criteri...
Add a taint with key 'zone' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster zone=k8s-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": "...
List deployments in JSON output format, using the specific version and API group
Command: ```bash kubectl get deployments.v1.1.0.beta-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 ...
Retrieve the snapshot logs from the container named 'mypod-1' in the 'payment-processor-deployment' deployment.
Command: ```bash kubectl logs deployment/payment-processor-deployment -c mypod-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 label 'release-' from the 'proxy-server' pod
Command: ```bash kubectl label pods proxy-server release- ``` 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": ...
Update the pod named 'security' with the label 'env' and the value 'production'
Command: ```bash kubectl label pods security env=production ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage"...
Create a new ExternalName service named external-metrics-service pointing to the external name document-company.com
Command: ```bash kubectl create service externalname external-metrics-service --external-name document-company.com ``` 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...
Create a new secret named "azure-storage-secret" using the key-value pairs provided
Command: ```bash kubectl create secret generic azure-storage-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a s...
Scale the mysql deployment in the db-migration-replicaset to 1, assuming the current size is 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/db-migration-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 --reso...
Create a single ingress that directs requests from foo.com/input to svc1:8081 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/input=svc1:8081,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 analytics-pod with all container images changed to nginx
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-web --set-image=*=nginx ``` 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...
Scale the deployment named dev-environment-rs from 3 replicas to 5 replicas
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/dev-environment-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-...
Taint the nodes that have the label team=devops with the key 'cpu-type' and value 'testing-node-11' and set the effect to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l team=devops cpu-type=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": "", "usage":...
Remove the label "component" from the pod "chat-app"
Command: ```bash kubectl label pods chat-app component- ``` 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": "I...
Create and run a golang pod named "hazelcast" using the "golang" image, and expose port 8088 inside the container.
Command: ```bash kubectl run hazelcast --image=golang --port=8088 ``` 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 copy of the web-app-pod and change all container images to busybox. The copy will be named debug-image-1.
Command: ```bash kubectl debug web-app-pod --copy-to=debug-image-1 --set-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 resou...
Embed certificate authority data for the cloud-cluster cluster entry:
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
Add a taint with key 'special' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack special=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": ...
Add a taint with key 'zone' and value 'storage-node-13:PreferNoSchedule' on nodes having the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster zone=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": "", "usag...
Copy specific keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-name-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create an ingress called 'private-api-ingress' that directs requests to 'testing.com/module' to 'svc1:7000' with the TLS secret "my-cert".
Command: ```bash kubectl create ingress private-api-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": ""...
Get output from running 'irb' command in quantum-quark container of payment-gateway-pod
Command: ```bash kubectl exec payment-gateway-pod -c quantum-quark -- irb ``` 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, ...
Create a copy of a pod named `monitoring-pod` and change all container images to `amazonlinux` by running the command `kubectl debug monitoring-pod --copy-to=my-custom-dbg --set-image=*=amazonlinux`.
Command: ```bash kubectl debug monitoring-pod --copy-to=my-custom-dbg --set-image=*=amazonlinux ``` 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 n...
Create an ingress named 'app1-ingress' that routes requests from website.com/input to the service 'svc1' on port 8083, using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/input=svc1:8083,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...
Start a pod called 'nginx' with the 'jenkins' image and apply the specified overrides from the provided JSON
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "v2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMA...
Create a job named "log-processing-job" using the Ubuntu image, and run the "docker run -it ubuntu" command within the job.
Command: ```bash kubectl create job log-processing-job --image=ubuntu -- docker run -it ubuntu ``` 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":...
Copy a file from a pod to a local directory
Command: ```bash kubectl cp kubeapps/database-pod-2:/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 kubect...
Update the label of the pod 'frontend' to 'app=myapp'
Command: ```bash kubectl label pods frontend app=myapp ``` 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": "If...
Create a cron job that runs a specific command on a schedule
Command: ```bash kubectl create cronjob daily-report --image=mongo --schedule="*/1 * * * *" -- mongo --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": "...
Update the server field for the web-cluster cluster entry while preserving the existing config
Command: ```bash kubectl config set-cluster web-cluster --server=https://1.2.3.4 ``` 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-author...
Apply a taint with the key 'workload' on nodes that have the label 'service=auth'.
Command: ```bash kubectl taint node -l service=auth workload=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": "Ou...
Create a new config map named api-config with specified keys from files on disk
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/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 cr...
Create a deployment named loadbalancer using the confluentinc/cp-kafka image and expose port 9000.
Command: ```bash kubectl create deployment loadbalancer --image=confluentinc/cp-kafka --port=9000 ``` 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": "Out...
Update the pod 'monitoring' with the label 'role' and set the value to 'backend'
Command: ```bash kubectl label pods monitoring role=backend ``` 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"...
Add an annotation to the pod 'frontend' with the key 'expiration-date' and the value '2024-12-31'
Command: ```bash kubectl annotate pods frontend 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 and include ...
Autoscale the deployment "gateway" with the number of pods between 2 and 9, using the default autoscaling policy
Command: ```bash kubectl autoscale deployment gateway --min=2 --max=9 ``` 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 ...
Update the image of all containers in the daemonset 'namespace-3' to 'redis:6.2.5'
Command: ```bash kubectl set image daemonset namespace-3 *=redis:6.2.5 ``` 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: `...
Copy local file /tmp/foo to remote pod monitoring-agent-pod-6 in namespace metallb-system, and place it in the /tmp/bar directory.
Command: ```bash kubectl cp /tmp/foo metallb-system/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...
Create an ingress called 'app-ingress' that directs requests to 'website.com/bar' to a service called 'svc1' on port 8181, and use the TLS secret named "my-cert".
Command: ```bash kubectl create ingress app-ingress --rule="website.com/bar=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": ...
Create a new config map named app-secrets with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/parameters/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...
Roll back a daemonset to a specific revision.
Command: ```bash kubectl rollout undo daemonset/my-deployment --to-revision=1 ``` 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...
Scale the deployment named mysql to 1 replica by specifying the current size as 5 replicas.
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/mysql ``` 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 sp...
Set up port forwarding from port 9090 on all addresses to port 5000 in the pod named frontend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 9090: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 golang pod named 'hazelcast' using the 'golang' image and expose port 5000
Command: ```bash kubectl run hazelcast --image=golang --port=5000 ``` 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...