prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import specific keys from a config map into an environment variable of a deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-dev 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 defi...
Update the 'frontend' pod by setting the 'release-notes' annotation to 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods frontend release-notes='https://example.com/release-notes/v2.5.1' ``` 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 lar...
Create a pod disruption budget named 'payment-gateway-pdb' that selects all pods with the 'release=1.0.0' label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=release=1.0.0 --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-availabl...
Import the environment variables from the secret/password-secret secret and set them on the deployment/proxy-service-deployment deployment
Command: ```bash kubectl set env --from=secret/password-secret deployment/proxy-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 definitions in one or more...
Copy the file located at /var/run/secrets/kubernetes.io/serviceaccount/ in your local machine to the /etc/kubernetes directory inside the pod named ingress-controller-pod-8 in the default namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ default/ingress-controller-pod-8:/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": "", "u...
Add a taint on nodes with label 'stack=tech-stack' and key 'app' set to 'monitoring-node-15:PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack app=monitoring-node-15: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 'website.com/example' to a service named 'svc1' on port '9091', and uses the TLS secret 'my-cert'
Command: ```bash kubectl create ingress private-api-ingress --rule="website.com/example=svc1:9091,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": "...
List the proxy-service-pod pod in JSON format
Command: ```bash kubectl get -o json pod proxy-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 namespaced you will only se...
Forward local port 3000 to port 3000 in the frontend pod
Command: ```bash kubectl port-forward pod/frontend-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 will be selected autom...
Import the SMTP_SERVER key from the config map "namespace-config" and set it as an environment variable in the "load-balancer-deployment" deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/namespace-config deployment/load-balancer-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...
Copy the `/var/run/secrets/kubernetes.io/serviceaccount/` file from the local host to the `/tmp/bar` directory in the remote pod named `web-app-pod-1`
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ web-app-pod-1::/tmp/bar -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...
Create a pod named "hazelcast" using the WordPress image and expose port 7000.
Command: ```bash kubectl run hazelcast --image=wordpress --port=7000 ``` 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": "...
Listen on port 9090 locally, forwarding to port 5432 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 9090: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 automa...
Partially update the specified node by applying a strategic merge patch from the "node.json" file
Command: ```bash kubectl patch -f node.json -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]` Helpful f...
Create a new ExternalName service named 'external-analytics-service' with the --external-name flag set to 'blog-test.blog'
Command: ```bash kubectl create service externalname external-analytics-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 reference ser...
Create a new ClusterIP service named frontend-service-clusterip, forwarding traffic from port 6379 to port 6379
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=6379:6379 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Set the cluster field in the team-beta-context context to kube-cluster-1
Command: ```bash kubectl config set contexts.team-beta-context.cluster kube-cluster-1 ``` 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 ...
Set resource limits and requests for all containers in a deployment named "wordpress".
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=128Mi ``` 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 re...
Forward port 9090 on all addresses to port 8088 in the proxy-server-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 9090: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 ...
Auto scale the deployment "gateway" with a minimum of 1 and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment gateway --min=1 --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 uses...
Update the description of a pod identified by its type and name in the "params.json" file.
Command: ```bash kubectl annotate -f params.json description='Web server for marketing site' ``` 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 lab...
Add a taint with key 'datacenter' and value 'monitoring-node-15:PreferNoSchedule' on nodes having the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 datacenter=monitoring-node-15: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": "", ...
View the logs of the previously terminated quantum-quark container in the backend-pod.
Command: ```bash kubectl logs -p -c quantum-quark backend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sh...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/db-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Import the specific keys from a config map into the deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-prod deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create a service for the 'centos' deployment, which serves on port 8888 and connects to the containers on port 300100.
Command: ```bash kubectl expose deployment centos --port=8888 --target-port=300100 ``` 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...
edit the configuration of the 'payment-service' service
Command: ```bash kubectl edit svc/payment-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 '...
Create a deployment named jenkins-x using the nginx image with a startup command of "nginx -g 'daemon off;'"
Command: ```bash kubectl create deployment jenkins-x --image=nginx -- nginx -g "daemon off;" ``` 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 f...
Update the 'frontend' pod by adding or updating the 'env' annotation with the value 'staging'.
Command: ```bash kubectl annotate --overwrite pods frontend 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 arb...
Update the image of all containers in the daemonset 'staging' to 'mongo:5.0.2'
Command: ```bash kubectl set image daemonset staging *=mongo:5.0.2 ``` 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: `kube...
Execute the 'go' command inside the first pod of the 'frontend-service' service and retrieve the output.
Command: ```bash kubectl exec svc/frontend-service -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Forward traffic from port 5432 on all addresses to port 5000 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 5432: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 ...
Get output from running the 'kafka-topics --list' command in code-explorer from pod backend-pod
Command: ```bash kubectl exec backend-pod -c code-explorer -- kafka-topics --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Partially update a node using a strategic merge patch with a JSON file
Command: ```bash kubectl patch node app-node-6 -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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 pa...
Execute the command `pg_dump --version` in the `cosmic-container` of the `e-commerce-pod` pod and display the output.
Command: ```bash kubectl exec e-commerce-pod -c cosmic-container -- 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. ...
Create a pod disruption budget named "frontend-pdb" that selects all pods with the "version=v2" label and ensures that at least 9 of these pods are always available.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=version=v2 --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 [--dry...
Set the cluster field in the "team-beta-context" context to "prod-cluster"
Command: ```bash kubectl config set contexts.team-beta-context.cluster prod-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...
Add a taint to a specific node
Command: ```bash kubectl taint nodes kube-master-9 dedicated: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 debug copy of e-commerce-pod with modified container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-api --image=debian --set-image=proxy=nginx:1.21,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name...
Delete pods and services with the names "chat-app" and "frontend"
Command: ```bash kubectl delete pod,service chat-app 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 selecto...
Retrieve the output of the 'dotnet --list-runtimes' command executed in the stardust-shuttle container of the gateway-pod pod.
Command: ```bash kubectl exec gateway-pod -c stardust-shuttle -- dotnet --list-runtimes ``` 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...
Create a new config map named app-config and include specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/preferences/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...
Retrieve the documentation for the 'conditions' field under the 'status' field of the 'pods' resource
Command: ```bash kubectl explain resource=pods.status.conditions ``` 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 to...
Import the environment from the secret "private-key-secret" and set it as an environment variable for the "cache-cluster-deployment" deployment
Command: ```bash kubectl set env --from=secret/private-key-secret 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 definitions in one or m...
Copy the local file '/tmp/foo' to the '/tmp/bar_dir' directory in the 'security-scanner-pod-18' pod, specifically in the 'image-resizer' container.
Command: ```bash kubectl cp /tmp/foo security-scanner-pod-18:/tmp/bar_dir -c image-resizer ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Scale the "frontend" replication controller to automatically adjust the number of pods between 1 and 6 based on the target CPU utilization of 60%
Command: ```bash kubectl autoscale rc frontend --max=6 --cpu-percent=60 ``` 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 use...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=max_connections --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 variabl...
Add or update the annotation 'contact-email' for the pod 'payment' with the value 'support@example.com'
Command: ```bash kubectl annotate pods payment contact-email=support@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and incl...
Get the previous terminated logs of the astro-container container from the pod named proxy-server-pod
Command: ```bash kubectl logs -p -c astro-container proxy-server-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Add the label 'component=api' to the pod with name 'vpn'
Command: ```bash kubectl label pods vpn component=api ``` 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 ...
Roll back a daemonset to a specific revision
Command: ```bash kubectl rollout undo daemonset/services --to-revision=7 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying th...
Import the 'log_level' key from the 'api-config' config map and set it as an environment variable in the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/api-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 definitions in...
set the resource requests and limits for all containers in the "jenkins" deployment
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=cpu=50m,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 reque...
Listen on port 8088 on localhost and IP address 10.19.21.23, and forward the traffic to port 8000 in the mypod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8088: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 p...
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/kube-cluster-1/kubernetes.ca.crt`
Command: ```bash kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/kube-cluster-1/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...
Import the environment from a secret to a deployment named "payment-processor-deployment"
Command: ```bash kubectl set env --from=secret/tls-certificate-secret deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
forward port 5432 on localhost and IP 10.19.21.23 to port 3000 in the frontend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 5432:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Get the output of the 'npm --version' command in the cyber-sleuth container of the frontend-pod.
Command: ```bash kubectl exec frontend-pod -c cyber-sleuth -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Create a deployment named sonarqube with the alpine image and 4 replicas
Command: ```bash kubectl create deployment sonarqube --image=alpine --replicas=4 ``` 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 o...
Forward local port 3000 to pod port 6379, listening on both localhost and IP address 10.19.21.23 for the pod named frontend-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 3000: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 criter...
Create a cron job called log-rotation with the image mongo, and a schedule of running every minute
Command: ```bash kubectl create cronjob log-rotation --image=mongo --schedule="*/1 * * * *" -- mongo --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "...
Edit the last-applied-configuration annotations of the postgres deployment in YAML format.
Command: ```bash kubectl apply edit-last-applied deployment/postgres ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the ed...
Get output from running 'geth attach' command in the first pod of the "gateway-deployment" using the first container
Command: ```bash kubectl exec deploy/gateway-deployment -- geth attach ``` 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...
Apply a taint on nodes labeled with 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
create a config map named app-secrets with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/parameters/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 c...
Create a role named "default_role" with ResourceName specified
Command: ```bash kubectl create role default_role --verb=get --resource=pods --resource-name=cdn-proxy --resource-name=log-aggregator ``` 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=server|c...
Add a taint with the key 'disktype' and value 'worker-node-3:PreferNoSchedule' to the nodes that have the label 'cluster=my-cluster'.
Command: ```bash kubectl taint node -l cluster=my-cluster disktype=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": "", "us...
Update a node by patching it with new values for the password using a strategic merge patch in YAML format
Command: ```bash kubectl patch node storage-node-13 -p $'stringData:\n password: new-password' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FIL...
Import the 'database_url' key from the 'app-config' config map into the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Create a single ingress called 'external-ingress' that directs requests to testing.com/example to svc1:8181 with a tls secret "my-cert"
Command: ```bash kubectl create ingress external-ingress --rule="testing.com/example=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": "", ...
Create a secret named private-key-secret with a file and a literal value
Command: ```bash kubectl create secret generic private-key-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...
Start a pod using the image "confluentinc/cp-kafka" and expose port 8084.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --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...]` Helpful flag...
Add a taint with the key 'hardware' on nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend hardware=dev-node-4: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...
Create a new resource quota named configmap-quota with a limit of 5 configmaps.
Command: ```bash kubectl create quota configmap-quota --hard=configmaps=5 ``` 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]` Helpful flags: "f...
Edit the data in the preferences.json file using JSON format, and then create the resource using the edited data
Command: ```bash kubectl create -f preferences.json --edit -o json ``` 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 file...
Import the SECRET_KEY key from the config map named app-config-prod into the deployment called mydeployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-config-prod 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 on...
Set the resource limits and requests for all containers in the "ubuntu" deployment.
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested,...
Retrieve the logs from container scheduler-app-deployment-1 of the deployment security-service-pod.
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c security-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful fla...
Add a taint to the node 'k8s-node-1' with the key 'app' and no value, causing pods to not be scheduled on that node
Command: ```bash kubectl taint nodes k8s-node-1 app: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: json|y...
Partially update a node using a strategic merge patch specified as YAML
Command: ```bash kubectl patch node dev-node-4 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n name: new-service' ``` 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. Syn...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-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 ...
Update the 'database-deployment' deployment by adding a new environment variable named SMTP_HOST with the value 'smtp.example.com'.
Command: ```bash kubectl set env deployment/database-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 tem...
Copy the directory /var/run/secrets/kubernetes.io/serviceaccount/ from the remote pod auth-service-pod-11 to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp kube-server/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": "...
Add a taint with key 'datacenter' and value 'dev-node-4:PreferNoSchedule' on nodes having the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace datacenter=dev-node-4: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": "", "...
Add a taint with key 'dedicated' on nodes having label stack=tech-stack. The taint should be 'dev-node-4:PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack dedicated=dev-node-4:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a pod disruption budget named ingress-controller-pdb that selects all pods with the app=nginx label and requires at least 20% of the selected pods to be available at any point in time.
Command: ```bash kubectl create pdb ingress-controller-pdb --selector=app=nginx --min-available=20% ``` 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 [--dry-run=...
Import the 'SMTP_SERVER' key from the 'global-config' config map into the 'notification-handler-deployment' deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-config deployment/notification-handler-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...
Forward traffic from port 8081 on all addresses to port 8088 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8081: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...
Import the 'external_api_url' key from the 'app-config-prod' config map and set it as an environment variable for the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config-prod deployment/proxy-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...
List deployments in the "dev-2.2.0" version of the "experimental-apps" API group, and display the output in JSON format
Command: ```bash kubectl get deployments.dev-2.2.0.experimental-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 namespace...
Create a job with a command to run.
Command: ```bash kubectl create job log-processing-job --image=ruby -- irb ``` 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 format. One...
Listen on port 5432 on all addresses and forward it to port 5432 in the pod named 'mypod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5432:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sel...
View the revision history of a daemonset and focus on revision 3.
Command: ```bash kubectl rollout history daemonset/prod --revision=3 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to fi...
Set the service account of the deployment backend-microservice-deployment to my-service-account
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment my-service-account ``` 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), stateful...
Import specific keys from a config map into the environment of a deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/log-config deployment/notification-handler-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 variab...
Set up auto scaling for the replication controller 'chat-app'
Command: ```bash kubectl autoscale rc chat-app --max=5 --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 use...
Return the snapshot logs from the container 'proxy-service-deployment-1' of the 'e-commerce-pod' deployment.
Command: ```bash kubectl logs deployment/proxy-service-deployment -c e-commerce-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: "f...
Create a debug session for the e-commerce-pod with the nano-bot container, and create a copy of it named debug-image-api
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-api --container=nano-bot -- sh ``` 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 defau...
Start the mysql pod using the command "kubectl run nginx --image=mysql --command -- <cmd> <arg1> ..
Command: ```bash kubectl run nginx --image=mysql --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] -- [COMMAND] [args...]` Helpful...
Copy the `/tmp/foo_dir` directory from the `kube-system/security-scanner-pod-18` pod to the local `/tmp/bar_dir` directory.
Command: ```bash kubectl cp kube-system/security-scanner-pod-18:/tmp/foo_dir /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...