prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the image of the container named "kubernetes-serve-hostname" in the web-app-pod pod, with a new image.
Command: ```bash kubectl patch pod web-app-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME...
Import the REDIS_HOST key from the app-secrets config map into the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Get the output from running the command 'pg_dump --version' in the 'nano-bot' container of the 'api-service-pod' pod
Command: ```bash kubectl exec api-service-pod -c nano-bot -- pg_dump --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 omit...
Check if you have permission to list the "certificates-renewal-job" job in the "monitoring" namespace
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-job -n monitoring ``` 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 pa...
Import the 'smtp_server' key from the 'env-vars' config map into the deployment named 'frontend-deployment'
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/env-vars deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Forward traffic from port 5432 on localhost and IP 10.19.21.23 to port 8080 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 5432:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Remove an environment variable for a specific entry in the kubectl configuration for the "deploy-bot" user
Command: ```bash kubectl config set-credentials deploy-bot --exec-env=var-to-remove- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags...
Get the output from running the 'postgres' command in the 'mycontainer' container from the 'api-service-pod' pod.
Command: ```bash kubectl exec api-service-pod -c mycontainer -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Create a new LoadBalancer service named ingress-controller-lb with TCP port mapping from port 8888 to port 5001
Command: ```bash kubectl create service loadbalancer ingress-controller-lb --tcp=8888:5001 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Execute the command 'php --version' inside the pod 'media-stream-pod' using the 'rocket-ranger' container
Command: ```bash kubectl exec media-stream-pod -c rocket-ranger -- php --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 om...
Start a pod named 'hazelcast' using the 'confluentinc/cp-kafka' image and expose port 8443.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8443 ``` 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...
Import specific keys from a config map into environment variables
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/log-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...
create a service for a replication controller specified in a yaml file
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=5000 --target-port=808300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
Create a copy of the media-stream-pod and name it debug-image-web, changing all container images to ubuntu.
Command: ```bash kubectl debug media-stream-pod --copy-to=debug-image-web --set-image=*=ubuntu ``` 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...
View the last-applied-configuration annotations in JSON format for the resource defined in the "params.yaml" file.
Command: ```bash kubectl apply view-last-applied -f params.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-ap...
Create a debug pod named debug-image-memcached that is a copy of the gateway-pod with all container images changed to python.
Command: ```bash kubectl debug gateway-pod --copy-to=debug-image-memcached --set-image=*=python ``` 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...
List all the environment variables defined on all pods
Command: ```bash kubectl set env pods --all --list ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (within replication controllers o...
Attach to the mycontainer in the security-service-pod and view the output.
Command: ```bash kubectl attach security-service-pod -c mycontainer ``` 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 omit...
Create a new config map named app-config-prod with the specified keys and files
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/data/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...
Create a pod disruption budget named critical-services-pdb that will select all pods with the owner=team-1 label and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=owner=team-1 --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-availab...
Set a custom TLS server name for the "cluster-gamma" cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=edge-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Execute the 'postgres' command inside the first pod of the 'gateway-deployment' deployment.
Command: ```bash kubectl exec deploy/gateway-deployment -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Copy the local file /tmp/foo to the remote pod worker-pod-4 in the kube-proxy namespace and save it as /tmp/bar
Command: ```bash kubectl cp :/tmp/foo kube-proxy/worker-pod-4:/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...
View the logs of the first container in a job named "cron-job"
Command: ```bash kubectl logs job/cron-job ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c", "defaul...
Forward port 8080 from the chat-app-pod to port 8000 on localhost and IP 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8000: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 criter...
Create an ingress called 'app-loadbalancer-ingress' that directs requests to a specific path to a service, with TLS enabled
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/bar=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": ...
Create a new secret named "jwt-secret" using the parameters defined in the "path/to/parameters.env" file.
Command: ```bash kubectl create secret generic jwt-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 basenam...
Create a new config map named app-config-prod using the specified keys and files
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/data/file1.txt --from-file=key1=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cre...
Return the snapshot logs from the 'backend-pod' container in the 'scheduler-app-deployment' deployment
Command: ```bash kubectl logs deployment/scheduler-app-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...
Delete pods and services with the names "web" and "cdn"
Command: ```bash kubectl delete pod,service web cdn ``` 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. Some re...
Create a new resource quota named "best-effort" with a limit of 100 pods and scope set to "BestEffort"
Command: ```bash kubectl create quota best-effort --hard=pods=100 --scopes=BestEffort ``` What it does: Create a resource quota with the specified name, hard limits, and optional scopes. Syntax: `kubectl create quota NAME [--hard=key1=value1,key2=value2] [--scopes=Scope1,Scope2] [--dry-run=server|client|none]` Helpf...
Create a new secret named my-secret using the provided SSH private key file and passphrase
Command: ```bash kubectl create secret generic my-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret ``` 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 fil...
Create a new config map named 'api-config' with the specified keys 'conf' and 'data', using the files '/path/to/properties/file1.txt' and '/path/to/configurations/file2.txt' respectively.
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
Execute the command 'yum install -y wget' inside the 'warp-drive' container of the 'monitoring-pod' pod
Command: ```bash kubectl exec monitoring-pod -c warp-drive -- yum install -y wget ``` 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...
Create a new config map named 'kube-system-config' with the following keys:
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/configurations/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. Wh...
Forward local port 8080 to port 5000 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 8080: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 au...
Import the keys "redis_host" from the config map "app-config" and set them as environment variables in the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
import the specific keys REDIS_HOST from the 'app-config-prod' config map into the 'database-deployment' deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-config-prod 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 definition...
Set the cluster field in the service-account-context context to staging-cluster.
Command: ```bash kubectl config set contexts.service-account-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...
Forward traffic from port 8000 on all addresses to port 9090 in the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8000: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 sel...
Create a new ExternalName service named external-third-party-api-service that will map to the hostname "blog-test.blog"
Command: ```bash kubectl create service externalname external-third-party-api-service --external-name blog-test.blog ``` 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 referen...
Create an ingress named "external-ingress" with a rule that directs requests for "website.com/module" to the service "svc1" on port 8082
Command: ```bash kubectl create ingress external-ingress --rule="website.com/module=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Forward local port 8088 to port 5000 in the pod named "frontend-pod".
Command: ```bash kubectl port-forward pod/frontend-pod 8088: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 autom...
Create a new secret from an env file
Command: ```bash kubectl create secret generic ssl-key-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 bas...
Forward port 8000 on localhost and IP 10.19.21.23 to port 8081 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8000: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 cri...
Run the command "mysql --version" in the code-explorer container of the media-stream-pod and display the output.
Command: ```bash kubectl exec media-stream-pod -c code-explorer -- mysql --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 ...
Add a taint to the 'edge-node-10' node with the key 'datacenter' and no value.
Command: ```bash kubectl taint nodes edge-node-10 datacenter:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Create a deployment named proxy with the alpine image that will run on port 8000.
Command: ```bash kubectl create deployment proxy --image=alpine --port=8000 ``` 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: js...
Forward local port 5432 to port 8088 in the backend-pod
Command: ```bash kubectl port-forward 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 be selected automa...
Delete both the 'foo' pod and service, as well as the 'web' pod and service.
Command: ```bash kubectl delete pod,service foo web ``` 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. Some re...
Update the deployment 'search-engine-deployment' by setting a new environment variable 'DB_PASSWORD' with the value 'secretpassword'
Command: ```bash kubectl set env deployment/search-engine-deployment DB_PASSWORD=secretpassword ``` 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 po...
Create a new config map named env-vars using the properties.env file as the source of environment variables
Command: ```bash kubectl create configmap env-vars --from-env-file=path/to/properties.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 ba...
Update the image of all containers in the nginx daemonset to 'httpd:2.4.48'
Command: ```bash kubectl set image daemonset nginx *=httpd:2.4.48 ``` 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: `kubec...
Forward traffic from port 5000 on all addresses to port 8000 in the pod named api-service-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 5000: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 w...
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=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": "", "usage":...
Retrieve the output from running the 'sleep 3600' command inside the mycontainer in the payment-gateway-pod.
Command: ```bash kubectl exec payment-gateway-pod -c mycontainer -- sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Forward local port 8888 to port 3000 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 8888 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a secret named 'api-secret-key' and use files from the 'path/to/parameters' folder as the secret data keys.
Command: ```bash kubectl create secret generic api-secret-key --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...
Create a cron job that runs a specific command at a scheduled interval
Command: ```bash kubectl create cronjob log-rotation --image=alpine --schedule="*/1 * * * *" -- apk add curl ``` 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": "-o...
Create a new config map named log-config using the specified files as key-value pairs
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/configs/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 conf...
Create a debug container in a pod by making a copy of the original pod and changing the container images
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=api=api:v2,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and nam...
Create a new config map named namespace-config with specified settings from configuration files
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs....
Set the custom TLS server name "edge-cluster" to use for validation for the "cloud-cluster" cluster entry.
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=edge-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/monitoring-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Delete both the pod and service with the name "log-aggregator" and the pod and service with the name "chat-app"
Command: ```bash kubectl delete pod,service log-aggregator chat-app ``` 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 s...
Auto scale the "media-stream" deployment with a minimum of 3 and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment media-stream --min=3 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that...
Create a pod disruption budget named 'elastic-search-pdb' that will select all pods with the 'owner=team-1' label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=owner=team-1 --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=...
Forward traffic from port 6379 on localhost and IP address 10.19.21.23 to port 8081 in the pod named chat-app-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 6379: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 criter...
Forward local port 5432 to pod port 8081.
Command: ```bash kubectl port-forward pod/api-service-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 au...
Partially update the node "k8s-node-1" by setting the "replicas" field to 3 using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node k8s-node-1 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags: ...
Return the phase value of the analytics-pod pod
Command: ```bash kubectl get -o template pod/analytics-pod --template={{.status.phase}} ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type i...
Update the user field of the cluster-2-context context entry to "cluster-admin" without modifying any other values.
Command: ```bash kubectl config set-context cluster-2-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nick...
Add a taint with the key 'disktype' on nodes that have the label region=eu-west-2, and the taint value is set to 'PreferNoSchedule' for the node with the label 'disktype=storage-node-13'.
Command: ```bash kubectl taint node -l region=eu-west-2 disktype=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Execute the 'node' command in the 'nebula-navigator' container within the 'analytics-pod' pod and display the output.
Command: ```bash kubectl exec analytics-pod -c nebula-navigator -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Add a taint with the key 'workload' and no value to the node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 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 o...
Add the annotation 'criticality' with the value 'high' to the pod named 'auth'
Command: ```bash kubectl annotate pods auth criticality=high ``` 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 string...
Create an ingress named 'private-ingress' that routes requests from foo.com/input to a service named svc1 at port 5000
Command: ```bash kubectl create ingress private-ingress --rule="foo.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": "", "usage"...
Output the modified 'gateway-deployment' deployment with the environment variable REDIS_HOST set to 'redis-server' in YAML format without making any changes to the actual deployment on the server.
Command: ```bash kubectl set env deployment/gateway-deployment REDIS_HOST=redis-server -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod...
Import specific keys from a config map into the environment of a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/global-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Mark the "node-1" node as schedulable
Command: ```bash kubectl uncordon node-1 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Import the SECRET_KEY key from the db-config ConfigMap to the email-server-deployment Deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/db-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 definitions ...
Add a taint with key 'special' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha 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": "", "usa...
Edit a job named 'log-rotation-job' using the v1 API format in JSON
Command: ```bash kubectl edit job.v1.batch/log-rotation-job -o json ``` 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,...
Forward the local ports 9090 and 6000 to ports 3000 and 6000 respectively in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 9090 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Set the resource request and limits for all containers in the "go" deployment to limit cpu usage to 200m and memory usage to 512Mi, and request a minimum of 1 cpu and 256Mi memory.
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=256Mi ``` 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, b...
Update node 'testing-node-11' with a taint to specify that it has a GPU with the effect of 'NoExecute'
Command: ```bash kubectl taint nodes testing-node-11 hardware=gpu: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...
Add a taint with the key 'special' on nodes having the label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 special=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...
Create an ingress rule named 'api-v2-ingress' that maps incoming requests for 'testing.com/input' to 'svc1:9092' and uses the 'my-cert' TLS secret.
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/input=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": "", "usa...
Create a role binding named `default_role` that assigns the `default_role` cluster role to the users `app-operator`, `sysadmin`, and the group `security-auditors`
Command: ```bash kubectl create rolebinding default_role --clusterrole=default_role --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/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 creat...
Create a new config map named namespace-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/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 crea...
Scale the deployment named baz to 7 replicas if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=7 deployment/baz ``` 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 spec...
Create a deployment named api running the python image and exposing port 8888
Command: ```bash kubectl create deployment api --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: json...
Add a taint with the key 'datacenter' and value 'PreferNoSchedule' on nodes that have the label 'feature=feature-xyz' and the name 'db-node-7'.
Command: ```bash kubectl taint node -l feature=feature-xyz datacenter=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
replace a pod based on the configuration provided in the "conf.json" file.
Command: ```bash cat conf.json | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FILE...
List deployments in the JSON output format from the "hotfix-1.1.2" version of the "alpha-apps" API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.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 yo...
Remove the label named 'component' from the pod named 'frontend'
Command: ```bash kubectl label pods frontend 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...
Copy the file `/tmp/foo` from the remote pod `openfaas/ingress-controller-pod-8` to the local location `/tmp/bar`
Command: ```bash kubectl cp openfaas/ingress-controller-pod-8::/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...
Create a single ingress called 'public-api-ingress' that directs requests to testing.com/example to svc1:8089 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-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": ""...
Forward port 6379 on all addresses to port 9090 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 6379: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 wil...