prompt
stringlengths
13
282
response
stringlengths
128
3.11k
import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/git-credentials-secret deployment/web-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 in one or mor...
Create a pod named 'hazelcast' using the 'mcr.microsoft.com/dotnet/core/runtime' image and expose port 8084.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=8084 ``` 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......
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 9090 in the frontend-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Create a new config map named app-secrets with specified keys and file paths
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Create a service for the replicated nginx deployment which serves on port 5432 and connects to the containers on port 8888
Command: ```bash kubectl expose rc nginx --port=5432 --target-port=888800 ``` 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. ...
Get output from running the 'nginx' command in the security-service-pod container.
Command: ```bash kubectl exec security-service-pod -- 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 the kubect...
Listen on port 8080 on localhost and IP 10.19.21.23, and forward the traffic to port 9090 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8080:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cr...
Create an ingress called 'public-ingress' that directs requests to testing.com/example to a service named svc1 on port 3306, and use the tls secret "my-cert" for secure communication.
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/example=svc1:3306,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...
Copy the directory named 'foo_dir' located in the /tmp directory of the 'ingress-controller-pod-8' pod in the 'istio-system' namespace to the /tmp directory on your local machine, and save it as 'bar'.
Command: ```bash kubectl cp istio-system/ingress-controller-pod-8:/tmp/foo_dir /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, ...
List deployments in YAML output format, specifically in the "alpha-2.0" version of the "experimental-apps" API group
Command: ```bash kubectl get deployments.alpha-2.0.experimental-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 namespace...
Add a taint with key 'disktype' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 disktype=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": "", "usag...
Create an ingress called 'private-api-ingress' that directs requests to site.com/input to svc1:6379 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="site.com/input=svc1:6379,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Forward traffic from local port 8088 to pod port 6379 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-service-pod 8088 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Forward traffic from port 5000 on all addresses to port 8081 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5000: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 sel...
Start a python pod and expose port 9090 in the container
Command: ```bash kubectl run hazelcast --image=python --port=9090 ``` 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...
Update the label of the 'cdn' pod to set the 'app' label value as 'myapp'
Command: ```bash kubectl label pods cdn 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 true...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config-prod deployment/web-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...
Import specific keys from a config map into a deployment for the monitoring stack.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/api-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 d...
Update the 'key' value for the 'prod-node-5' node by applying a strategic merge patch specified as JSON
Command: ```bash kubectl patch node prod-node-5 -p '{"data":{"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]` Helpful f...
Import specific keys from the 'my-example-key' in the 'configmap/namespace-config' into the 'frontend-deployment' deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/namespace-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Forward local port 5432 to port 8081 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-pod 5432 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 autom...
Forward local port 3000 to pod port 9090
Command: ```bash kubectl port-forward pod/chat-app-pod 3000 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a copy of a specific pod by adding a debug container and changing the container images
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-1 --image=debian --set-image=api=api:v2,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. ...
Listen on port 6379 locally and forward the traffic to port 8888 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 6379:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Create an ingress called 'public-ingress' that directs requests to website.com/module to svc1:9000 with a TLS secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="website.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": "", "us...
Update the pod named 'backend' with the annotation 'env' and the value 'staging', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods backend env='staging' ``` 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 arbi...
Create a new config map named db-config using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/data/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 map ...
Set the basic authentication credentials for the "deploy-bot" entry
Command: ```bash kubectl config set-credentials deploy-bot --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 ...
Import the secret_key key from the app-secrets config map into the environment variables of the database-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-secrets 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...
Begin streaming the logs of the "mycontainer" container in the "email-service-pod" pod
Command: ```bash kubectl logs -f -c mycontainer 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 debug version of the database pod by adding a debug container and changing container images.
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-web --image=debian --set-image=logger=logging-app:debug,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifie...
Create a new ingress resource called 'private-api-ingress' with a rule that directs requests from 'website.com/input' to the service 'svc1' on port '8084'
Command: ```bash kubectl create ingress private-api-ingress --rule="website.com/input=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/global-config 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 ...
Create a pod disruption budget named frontend-pdb that selects pods with the tier=frontend label
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=tier=frontend --min-available=4 ``` 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 [--...
Copy the local file ~/.config/kube to the /tmp/bar directory of the remote pod 'web-app-pod-1' in the 'kube-proxy' namespace.
Command: ```bash kubectl cp ~/.config/kube kube-proxy/web-app-pod-1:/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 kub...
Copy the local directory "/tmp/foo_dir" to the remote pod "file-server-pod-14" in the default namespace at the location "/tmp/bar_dir".
Command: ```bash kubectl cp :/tmp/foo_dir file-server-pod-14:/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...
Port forward from local port 5000 to port 8081 in the pod web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 5000: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...
Copy the file "foo" from the "/tmp" directory in the "web-app-pod-1" pod in the "kube-public" namespace to the "/etc/kubernetes" directory locally.
Command: ```bash kubectl cp kube-public/web-app-pod-1::/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 the ...
Copy the file /tmp/foo from the pod 'kube-public/api-server-pod-3' to the local machine at /tmp/bar.
Command: ```bash kubectl cp kube-public/api-server-pod-3:/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 kubec...
Get the resource usage metrics for all nodes
Command: ```bash kubectl top node ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) ...
List deployments in JSON output format, using the "v2.0.0" version of the "apps" API group
Command: ```bash kubectl get deployments.v2.0.0.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 only ...
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to testing.com/input to svc # svc1:5000
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/input=svc1:5000,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 the environment variables from the 'private-key-secret' secret and set them in the 'mydeployment' deployment.
Command: ```bash kubectl set env --from=secret/private-key-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 pod temp...
Create a new config map named api-config using the data from the environment file located at path/to/data.env
Command: ```bash kubectl create configmap api-config --from-env-file=path/to/data.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 to the basena...
Copy the file "/var/run/secrets/kubernetes.io/serviceaccount/" from your local machine to the "/tmp/bar" directory in the "front-end-pod-12" pod in the "argocd" namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ argocd/front-end-pod-12::/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": "Contain...
Create an ingress called 'default-ingress' that directs requests to foo.com/input to svc # svc1:8010 with a tls secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/input=svc1:8010,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 secret named "database-secret" from an environment file.
Command: ```bash kubectl create secret generic database-secret --from-env-file=path/to/parameters.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the ba...
Listen on local ports 5000 and 6000, and forward data to/from ports 5432 and 6000 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 criteria, a pod will be selected aut...
Create a service for the replication controller specified in the "python-controller.yaml" file
Command: ```bash kubectl expose -f python-controller.yaml --port=9091 --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...
Execute the 'dotnet --list-sdks' command in the 'cyber-sleuth' container of the 'cdn-service-pod' pod and display the output.
Command: ```bash kubectl exec cdn-service-pod -c cyber-sleuth -- dotnet --list-sdks ``` 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...
Create a cluster role named "view" with specified verbs and resources
Command: ```bash kubectl create clusterrole view --verb=delete --resource=services --resource-name=nginx-proxy --resource-name=monitoring-prometheus ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|...
Start a pod with the image "confluentinc/cp-kafka" and set the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default"
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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] [--c...
Add the label 'tier=database' to the pod named 'gateway'
Command: ```bash kubectl label pods gateway tier=database ``` 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": ...
Partially update the configuration of a specific node by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node gpu-node-12 -p '{"spec":{"unschedulable":true}}' ``` 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]` Helpf...
Get the output from running the 'go run hello.go' command on the pod named auth-service-pod.
Command: ```bash kubectl exec auth-service-pod -- go run hello.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 ...
delete both the pods and services named "payment" and "frontend"
Command: ```bash kubectl delete pod,service payment frontend ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...
Create a new config map named api-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/profiles/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 ma...
Create a job named 'deployment-rollout-job' with the 'postgres' image and execute the command 'psql' within the job.
Command: ```bash kubectl create job deployment-rollout-job --image=postgres -- psql ``` 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 fo...
Scale the deployment named mysql to 1 if its current size is already 1.
Command: ```bash kubectl scale --current-replicas=1 --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...
Create a job named 'image-build-job' with the PHP image, and run the command 'php --version' inside the job.
Command: ```bash kubectl create job image-build-job --image=php -- php --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 forma...
Attach to the warp-drive container in the api-service-pod and get its output.
Command: ```bash kubectl attach api-service-pod -c warp-drive ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
View the snapshot logs from container named backend-pod-1 of a deployment named search-engine-deployment
Command: ```bash kubectl logs deployment/search-engine-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...
Import specific keys from a config map in a deployment's environment variables
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/ui-config 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 ...
Delete the pods and services named "analytics" and "security"
Command: ```bash kubectl delete pod,service analytics security ``` 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 select...
Set the environment variables of a deployment by importing them from a secret.
Command: ```bash kubectl set env --from=secret/oauth-secret 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 definitions in one or more...
Add a taint with the key 'workload' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 workload=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": "Outp...
Create a pod disruption budget named messaging-pdb that will select all pods with the project=my-project label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=project=my-project --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...
Forward local port 6379 to port 5432 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 6379: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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config-prod deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Check if you have permission to list the cron-job job in the namespace-1 namespace
Command: ```bash kubectl auth can-i list jobs.batch/cron-job -n namespace-1 ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that ...
create a service for a replicated php application, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose rc php --port=8084 --target-port=808300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Create a service for a replicated Ubuntu container on port 80, connecting to the container on port 8000.
Command: ```bash kubectl expose rc ubuntu --port=8000 --target-port=300000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Start the mcr.microsoft.com/dotnet/core/runtime pod with a different command and custom arguments
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --command -- <cmd> <arg1> ... <argN> ``` 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] ...
Wait for the pod "email-service-pod" to reach the "Ready" status condition
Command: ```bash kubectl wait --for=condition=Ready pod/email-service-pod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command ...
Create a new ExternalName service named external-third-party-api-service with the external name "illustration-shop.shop"
Command: ```bash kubectl create service externalname external-third-party-api-service --external-name illustration-shop.shop ``` 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...
Create a service named "frontend" for the pod "cdn-service-pod", serving on port 444.
Command: ```bash kubectl expose pod cdn-service-pod --port=80 --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 specified po...
Forward traffic from a random port on your local machine to port 5000 in the chat-app-pod pod.
Command: ```bash kubectl port-forward pod/chat-app-pod :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 be selected automatic...
Attach to a specific container in a pod and interact with it in raw terminal mode
Command: ```bash kubectl attach monitoring-pod -c astro-container -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 ...
Forward traffic from port 8000 on all addresses to port 6379 in the pod/api-service-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-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 w...
Create an ingress called 'external-ingress' that routes requests for 'website.com/example' to 'svc1:5432' and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress external-ingress --rule="website.com/example=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Create a job named 'security-scan-job' using the 'docker.elastic.co/elasticsearch/elasticsearch' image
Command: ```bash kubectl create job security-scan-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch --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"...
delete the pods and services with the names "proxy-server" and "payment"
Command: ```bash kubectl delete pod,service proxy-server payment ``` 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 sele...
Copy the local file /tmp/foo_dir to the remote pod cache-pod-5 in the container backend-container at the destination /tmp/bar_dir
Command: ```bash kubectl cp /tmp/foo_dir cache-pod-5:/tmp/bar_dir -c backend-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 omitted, u...
Add a taint with key 'zone' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack zone=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":...
Embed the certificate authority data for the kube-cluster-1 cluster entry by running the command "kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/app-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...
Edit the configuration of the 'cache-service' service
Command: ```bash kubectl edit svc/cache-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 variables, or fall back to 'vi...
Create a pod named nginx using the golang image, but customize the pod specification by providing a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Create a service for a replicated node using replica set, which serves on port 8080 and connects to the containers on port 8181
Command: ```bash kubectl expose rs node --port=8080 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Create a service for the replication controller specified in the "hazelcast-controller.yaml" file, serving on port 8080 and connecting to the containers on port 808300.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8080 --target-port=808300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
List all deployments in the "backup-apps" API group with the version "v1.1.1" in JSON output format
Command: ```bash kubectl get deployments.v1.1.1.backup-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Access the bash shell in the astro-container of the vpn-service-pod pod.
Command: ```bash kubectl exec vpn-service-pod -c astro-container -- 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, u...
import the `DATABASE_URL` key from the `monitoring-config` ConfigMap and set it as an environment variable in the `search-engine-deployment` deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/monitoring-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create a service for the python deployment, which serves on port 8084 and connects to the containers on port 300000.
Command: ```bash kubectl expose deployment python --port=8084 --target-port=300000 ``` 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 log-aggregator-pod with all container images changed to mcr.microsoft.com/dotnet/core/runtime
Command: ```bash kubectl debug log-aggregator-pod --copy-to=my-debugger --set-image=*=mcr.microsoft.com/dotnet/core/runtime ``` 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 ...
Update the last-deployment annotation of the pod identified in the docker-registry.yaml file to "2023-03-15"
Command: ```bash kubectl annotate -f docker-registry.yaml last-deployment=2023-03-15 ``` 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 ...
Create a copy of a pod with a debug container and attach to it
Command: ```bash kubectl debug proxy-service-pod -it --image=busybox --copy-to=debug-image-1 ``` 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...
Set the cluster field in a specific context to a given value
Command: ```bash kubectl config set contexts.testing-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 yo...
Forward local port 8088 to port 5432 in the pod named "chat-app-pod".
Command: ```bash kubectl port-forward pod/chat-app-pod 8088: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 autom...
Forward traffic from port 8080 on your local machine to port 8888 in the cdn-service-pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8080 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Rename a context in your kubeconfig file from 'cluster-1-context' to 'app-2-context'
Command: ```bash kubectl config rename-context cluster-1-context app-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 a...