prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a pod disruption budget named elastic-search-pdb that will select all pods with the app=rails label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=app=rails --min-available=9 ``` 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 [...
Remove the taint with key 'workload' and effect 'NoSchedule' from the node named 'app-node-6' if one exists
Command: ```bash kubectl taint nodes app-node-6 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: ...
Auto scale the replication controller "monitoring" with the number of pods between 1 and 8, and set the target CPU utilization at 40%
Command: ```bash kubectl autoscale rc monitoring --max=8 --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 u...
Open the service named "docker-registry" for editing using the VI editor.
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/docker-registry ``` 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 variables, ...
Update the pod identified by type and name in the "settings.json" file and add the annotation "alert-email" with the value "alerts@example.com"
Command: ```bash kubectl annotate -f settings.json alert-email=alerts@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 labels and inc...
Update the 'k8s-node-1' node with a taint having key 'cpu-type' and value 'x86' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes k8s-node-1 cpu-type=x86: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...
Retrieve the snapshot logs from container cache-cluster-deployment-1 of the deployment named proxy-server-pod
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c proxy-server-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: ...
Create a role named "default_role" with the verb "watch" and specify the resource "pods" with resource names "error-logger" and "error-logger"
Command: ```bash kubectl create role default_role --verb=watch --resource=pods --resource-name=error-logger --resource-name=error-logger ``` 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=serve...
Apply a taint with the key 'environment' on nodes that have the label 'zone=us-east-1' with the effect 'PreferNoSchedule' on the node named 'node-1'
Command: ```bash kubectl taint node -l zone=us-east-1 environment=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": "O...
Set the cluster field in the 'user-b-context' context to 'my-k8s-cluster'
Command: ```bash kubectl config set contexts.user-b-context.cluster my-k8s-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
create a deployment named api using the golang image and expose port 9000
Command: ```bash kubectl create deployment api --image=golang --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": "Output format. One of: json...
Create a copy of the log-aggregator-pod, adding a debug container with the debian image
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-web --image=debian --set-image=mailer=mailer:latest,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects iden...
Copy the file /var/run/secrets/kubernetes.io/serviceaccount/ from your local machine to the /tmp/bar_dir directory in a remote pod named argocd/api-server-pod-3 in the specified namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ argocd/api-server-pod-3:/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": "Cont...
Forward port 3000 from the pod to the local machine.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 3000: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 ...
Forward port 8888 on all addresses to port 8081 in the backend-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8888: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 ...
Attach to a running pod and connect to the raw terminal mode
Command: ```bash kubectl attach email-service-pod -c warp-drive -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Create a new secret named gcp-service-account-secret using the information from the specified env file
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-env-file=path/to/properties.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will defaul...
Create a cron job named 'database-maintenance' with the centos image that runs the command 'sleep 3600' every minute.
Command: ```bash kubectl create cronjob database-maintenance --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...
Copy the file /tmp/foo from the remote pod kube-dns/web-app-pod-1 to the local directory /tmp/bar
Command: ```bash kubectl cp kube-dns/web-app-pod-1::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 5432 in the pod 'log-aggregator-pod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 5000: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 ...
Create a deployment named "loadbalancer" with the image "mongo" and 6 replicas.
Command: ```bash kubectl create deployment loadbalancer --image=mongo --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...
Create an ingress named 'public-service-ingress' to direct requests from foo.com/bar to svc1:8443 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/bar=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": "", "u...
Update the cluster field in the team-beta-context context to cluster-beta.
Command: ```bash kubectl config set contexts.team-beta-context.cluster cluster-beta ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Add a taint with key 'cpu-type' on nodes having label app-type=microservice, and the taint value is set to 'backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l app-type=microservice cpu-type=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": "",...
Set the custom TLS server name to 'kube-cluster-1' for the cluster entry 'my-k8s-cluster'
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=kube-cluster-1 ``` 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...
Start a new nginx pod using the amazonlinux image and override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "rc-1.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] -- ...
Start streaming the logs of the "rocket-ranger" container in the "media-stream-pod" pod.
Command: ```bash kubectl logs -f -c rocket-ranger media-stream-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Create an ingress that directs requests to a specific service and uses a TLS secret
Command: ```bash kubectl create ingress api-v1-ingress --rule="foo.com/input=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": "", "usage":...
Create a service for the replicated alpine containers, serving on port 8089, and connecting to the containers on port 330600
Command: ```bash kubectl expose rc alpine --port=8089 --target-port=330600 ``` 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....
Rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context old-name client-2-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also be...
Open a raw terminal connection to the api-service-pod container named nano-bot and interact with it in real-time.
Command: ```bash kubectl attach api-service-pod -c nano-bot -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Display the documentation for the 'name' field of the 'metadata' section of the 'configmaps' resource.
Command: ```bash kubectl explain resource=configmaps.metadata.name ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag ...
Print the list of supported API resources
Command: ```bash kubectl api-resources ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-secrets deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
import the 'LOG_LEVEL' key from the 'app-config-dev' ConfigMap into the environment variables of the 'mydeployment' deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-dev deployment/mydeployment ``` 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 ...
Update the deployment 'web-app-deployment' by adding a new environment variable SMTP_HOST=smtp.example.com
Command: ```bash kubectl set env deployment/web-app-deployment SMTP_HOST=smtp.example.com ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 8080 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8080: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...
Check if you have permission to list the "deploy-artifacts-job" job in the "default" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/deploy-artifacts-job -n default ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial U...
Create a service named "frontend" for the pod "log-aggregator-pod", which serves on port 444
Command: ```bash kubectl expose pod log-aggregator-pod --port=3000 --name=frontend ``` 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...
Create a debug copy of the "log-aggregator-pod" by adding a debug container and changing container images to "debian".
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-1 --image=debian --set-image=cache=redis:alpine,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 resou...
Add a taint with the key 'datacenter' on nodes having the label release=beta with the value 'k8s-node-1' and the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l release=beta datacenter=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": "...
Update the 'type' field of the 'edge-node-10' node with the value 'LoadBalancer' using a strategic merge patch in YAML format.
Command: ```bash kubectl patch node edge-node-10 -p $'spec:\n type: LoadBalancer' ``` 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 ...
Create a secret named "api-key-secret" with keys for each file in the "bar" folder.
Command: ```bash kubectl create secret generic api-key-secret --from-file=path/to/parameters ``` 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 basename of...
Retrieve the output from running the 'gem --version' command in the astro-container of the pod named api-service-pod.
Command: ```bash kubectl exec api-service-pod -c astro-container -- 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 o...
Start an alpine pod and expose port 8082
Command: ```bash kubectl run hazelcast --image=alpine --port=8082 ``` 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...
Copy the file named "foo" from the remote pod named "metallb-system/database-pod-2" at the "/tmp/foo" location to the "/etc/kubernetes" directory on your local machine
Command: ```bash kubectl cp metallb-system/database-pod-2::/tmp/foo /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 ...
Create a debug version of the media-stream-pod by adding a debug container and changing container images
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-web --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 ...
Create an ingress named 'myapp-ingress' that routes requests for foo.com/module to svc1:8084, using the tls secret 'my-cert'.
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/module=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":...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=database_url --from=configmap/ui-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 definitions in...
Create a role named "custom_role" with ResourceName specified for watching pods with the specified resource names "cache-redis" and "content-delivery".
Command: ```bash kubectl create role custom_role --verb=watch --resource=pods --resource-name=cache-redis --resource-name=content-delivery ``` 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...
Retrieve information about the replication controller named 'web', the service named 'web-app-rc', and the pod named 'email-service-pod'
Command: ```bash kubectl get rc/web service/web-app-rc pods/email-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespac...
Copy a file named "foo" from the "/tmp" directory of the "file-server-pod-14" pod in the "rook-ceph" namespace to the local "/tmp/bar_dir" directory.
Command: ```bash kubectl cp rook-ceph/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 ...
Begin streaming the logs of the 'lunar-launcher' container in the 'monitoring-pod' pod
Command: ```bash kubectl logs -f -c lunar-launcher monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Create a pod based on the JSON provided in the "settings.json" file.
Command: ```bash cat settings.json | kubectl create -f - ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use t...
Copy the contents of
Command: ```bash kubectl cp kube-public/auth-service-pod-11:/var/run/secrets/kubernetes.io/serviceaccount/ /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "...
Forward traffic from port 8080 on your local machine to port 8000 in a pod selected by the web-app-deployment deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8080 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be s...
Create a new config map named app-secrets with specified keys instead of file basenames on disk, using the properties file from /path/to/options/file1.txt and the key1 file from /path/to/preferences/file2.txt.
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Retrieve the previous terminated logs of the 'lunar-launcher' container from the 'log-aggregator-pod' pod.
Command: ```bash kubectl logs -p -c lunar-launcher 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": "--contain...
Start a nginx pod using the amazonlinux image, but customize the pod spec by providing a partial set of values parsed from a JSON file
Command: ```bash kubectl run nginx --image=amazonlinux --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] -- [C...
Forward traffic from port 5432 on all addresses to port 8088 in the backend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 5432: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 criteria, a pod will ...
Auto scale the "vpn" replication controller with a target CPU utilization of 90%, allowing the number of pods to range from 1 to 8.
Command: ```bash kubectl autoscale rc vpn --max=8 --cpu-percent=90 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Get output from nebula-navigator in the email-service-pod pod.
Command: ```bash kubectl attach email-service-pod -c nebula-navigator ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Import environment variables from the azure-storage-secret secret and set them for the backend-microservice-deployment deployment
Command: ```bash kubectl set env --from=secret/azure-storage-secret deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Update the pod 'api' and label it as 'unhealthy' only if its resource version is still 1.
Command: ```bash kubectl label pods api status=unhealthy --resource-version=1 ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default"...
View the last-applied-configuration annotations for the resource specified in the 'setup.yaml' file in JSON format.
Command: ```bash kubectl apply view-last-applied -f setup.yaml -o json ``` 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-app...
Set the certificate-authority-data field on the 'kube-cluster-2' cluster
Command: ```bash kubectl config set clusters.kube-cluster-2.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 contai...
Add a taint with the key 'dedicated' on the nodes that have the label instance=app-instance-1, and set the taint on the edge-node-10 node to PreferNoSchedule.
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=edge-node-10: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": ""...
Retrieve the snapshot of the previously terminated logs from the 'code-explorer' container in the 'payment-gateway-pod' pod.
Command: ```bash kubectl logs -p -c code-explorer payment-gateway-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": "--contain...
Output the modified 'monitoring-stack-deployment' deployment in YAML format, without making any changes to the object on the server
Command: ```bash kubectl set env deployment/monitoring-stack-deployment QUEUE_NAME=task-queue -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 m...
Set the cluster field in the specified context to the desired cluster name
Command: ```bash kubectl config set contexts.cloud-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wan...
Set resource limits for the Python container in the deployment named "python"
Command: ```bash kubectl set resources deployment python -c=nginx --limits=cpu=500m,memory=512Mi ``` 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...
Create a deployment named "my-dep" using the Python image and expose port 8888.
Command: ```bash kubectl create deployment my-dep --image=python --port=8888 ``` 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: j...
Provide a detailed description of the 'monitoring-agent-pod-6' pod
Command: ```bash kubectl describe pods/monitoring-agent-pod-6 ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type,...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-settings deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Set the custom TLS server name to "testing-cluster" for the "star-cluster" cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=testing-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Update the deployment 'backend-microservice-deployment' with a new environment variable called 'GOOGLE_API_KEY' and provide the value for the key.
Command: ```bash kubectl set env deployment/backend-microservice-deployment GOOGLE_API_KEY=your-google-api-key ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Forward port 8000 in the pod "chat-app-pod" to port 8081 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8081: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...
Add a taint with key 'app' on nodes having label release=beta
Command: ```bash kubectl taint node -l release=beta app=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": "", "usage": "Ou...
Taint nodes with a key 'special' if they have a label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 special=worker-node-3: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 an ingress named 'api-v1-ingress' that routes requests for testing.com/bar to svc1:8181 with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.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 an ingress called 'public-ingress' that routes requests from testing.com/input to svc1:8083, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="testing.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": "", "usa...
Create a service for a replica set using nginx, with the service serving on port 3306 and connecting to the containers on port 8000
Command: ```bash kubectl expose rs nginx --port=3306 --target-port=800000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Execute the 'set-last-applied' operation against each configuration file in the 'conf/' directory.
Command: ```bash kubectl apply set-last-applied -f conf/ ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of the obj...
Get the output from running the 'psql' command in the 'time-machine' container of the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c time-machine -- psql ``` 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 t...
Copy the file at "/var/run/secrets/kubernetes.io/serviceaccount/" on the local machine to the "/tmp/bar" directory on the remote pod named "database-pod-2" in the "prometheus" namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ prometheus/database-pod-2:/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": "Contai...
Check if you have permission to list the job named "virus-scan-job" in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/virus-scan-job -n staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL tha...
Start a pod named 'hazelcast' using the 'confluentinc/cp-kafka' image and expose port 8181
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --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 flag...
Set the cluster field in the 'my-context' context to 'staging-cluster'
Command: ```bash kubectl config set contexts.on-prem-context.cluster staging-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value y...
Switch to raw terminal mode and attach to the 'cyber-sleuth' container in the 'frontend-pod'.
Command: ```bash kubectl attach frontend-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 omitt...
Update the label of the pod named 'cdn' with the label 'tier' and the value 'backend'
Command: ```bash kubectl label pods cdn tier=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": "If t...
Create a job called "data-migration-job" using the specified image and run the command "dotnet" inside the job
Command: ```bash kubectl create job data-migration-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "defaul...
Import environment variables from the 'app-config-prod' config map into the 'scheduler-app-deployment' deployment, with a prefix of 'MYSQL_'
Command: ```bash kubectl set env --from=configmap/app-config-prod --prefix=MYSQL_ 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 definit...
Create a service for the 'node' replica set, which will serve on port 8083 and connect to the containers on port 8000
Command: ```bash kubectl expose rs node --port=8083 --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...
create a cron job named 'database-maintenance' using the image 'mcr.microsoft.com/dotnet/core/runtime', with a schedule of running every minute
Command: ```bash kubectl create cronjob database-maintenance --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags:...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/gcp-service-account-secret deployment/mydeployment ``` 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 ...
Add or update a taint on a specific node with a given key, value, and effect
Command: ```bash kubectl taint nodes edge-node-10 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. O...
Set the service account of the deployment "cache-cluster-deployment" to "cert-manager"
Command: ```bash kubectl set serviceaccount deployment cache-cluster-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: ...
Execute the 'nginx' command in the 'warp-drive' container of the 'auth-service-pod' and display the output.
Command: ```bash kubectl exec auth-service-pod -c warp-drive -- nginx ``` 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 ...
Delete the pods and services named "proxy-server" and "database"
Command: ```bash kubectl delete pod,service proxy-server database ``` 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 sel...
Create an ingress object called 'api-ingress' that directs requests from foo.com/module to a service named 'svc1' on port 9092
Command: ```bash kubectl create ingress api-ingress --rule="foo.com/module=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": "", "usage": "...