prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Copy the contents of /var/run/secrets/kubernetes.io/serviceaccount/ from a remote pod named logging/image-resizer-pod-20 to the local directory :/tmp/bar.
Command: ```bash kubectl cp logging/image-resizer-pod-20:/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": "Co...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=log_level --from=configmap/ui-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Update node 'dev-node-4' by adding a taint with key 'hardware', value 'gpu', and effect 'NoExecute'
Command: ```bash kubectl taint nodes dev-node-4 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. One of...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/api-config deployment/analytics-platform-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...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/chat-app-rc pods/monitoring-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...
Create a new config map called kube-system-config using specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. Whe...
Import environment variables from the 'ui-config' ConfigMap with the prefix 'MYSQL_' into the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ 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 i...
Forward traffic from a local port to a pod port
Command: ```bash kubectl port-forward pod/backend-pod :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 automatica...
Import the 'max_connections' key from the 'app-secrets' config map and set it as an environment variable in the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-secrets 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 variab...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/analytics-rc pods/database-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 ...
Import the specific key(s) from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/api-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 definition...
Create a deployment named sonarqube that uses the amazonlinux image and exposes port 9000
Command: ```bash kubectl create deployment sonarqube --image=amazonlinux --port=9000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. O...
Create a pod named 'hazelcast' using the 'confluentinc/cp-kafka' image, and expose port 8089.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8089 ``` 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...
Create a service for a PHP deployment on port 80 that forwards traffic to containers on port 8000
Command: ```bash kubectl expose deployment php --port=8082 --target-port=808200 ``` 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 ...
Forward the traffic from port 3000 on all addresses to port 5000 within the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 3000: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 ...
Forward the local port 3000 to port 3000 in the frontend-pod, listening on localhost and IP address 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 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 criter...
Scale the deployment named bar to have 7 replicas, matching its current size.
Command: ```bash kubectl scale --current-replicas=7 --replicas=7 deployment/bar ``` 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...
Forward traffic from port 9090 on all addresses to port 5000 in the 'web-app-pod' pod, by running the command 'kubectl port-forward --address 0.0.0.0 pod/web-app-pod 9090:5000'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 9090:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Attach to a specific container in a pod and enter the raw terminal mode to interact with the container's shell.
Command: ```bash kubectl attach proxy-server-pod -c stardust-shuttle -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. ...
Forward data between local ports 9090 and 8088, and between local port 6000 and pod port 6000 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 will be selected aut...
Create a new secret named payment-gateway-secret from an environment file
Command: ```bash kubectl create secret generic payment-gateway-secret --from-env-file=path/to/settings.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 t...
Retrieve the logs of the 'mycontainer' container from the previously terminated 'frontend-pod' pod
Command: ```bash kubectl logs -p -c mycontainer frontend-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", "sho...
Create a cluster role named "view" with the NonResourceURL specified as "/debug/flags/v" and the verb set to "patch".
Command: ```bash kubectl create clusterrole "view" --verb=patch --non-resource-url=/debug/flags/v ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "...
Create a role named "foo" with the verb "create" and the resource "pods" specified
Command: ```bash kubectl create role foo --verb=create --resource=pods --resource-name=content-delivery --resource-name=content-delivery ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=serve...
Copy the local file "/tmp/foo" to the "/etc/kubernetes" directory inside the "front-end-pod-12" pod, specifically in the "front-end-container" container.
Command: ```bash kubectl cp :/tmp/foo front-end-pod-12:/etc/kubernetes -c front-end-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 omi...
Create an ingress called 'default-ingress' that directs requests to website.com/input to svc1:3306 with a tls secret called "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="website.com/input=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": "", "us...
Create an ingress called 'public-service-ingress' with a rule that directs requests from 'website.com/input' to 'svc1:6379' and use the 'my-cert' secret for TLS.
Command: ```bash kubectl create ingress public-service-ingress --rule="website.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": ...
Copy the ~/.config/kube local file to /tmp/bar_dir in the remote pod named auth-service-pod-11 in the kube-flannel namespace.
Command: ```bash kubectl cp ~/.config/kube kube-flannel/auth-service-pod-11:/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,...
Execute the 'mongo' command in the 'mycontainer' container of the 'auth-service-pod' pod and display the output.
Command: ```bash kubectl exec auth-service-pod -c mycontainer -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Copy the ~/.config/kube file from a remote pod named metrics-exporter-pod-10 in the istio-system namespace to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp istio-system/metrics-exporter-pod-10:~/.config/kube /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 o...
Check whether the current user has permission to list the "cache-warming-job" job in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cache-warming-job -n kube-dns ``` 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...
Update the image of all containers in the 'namespace-3' daemonset to 'alpine:3.14'
Command: ```bash kubectl set image daemonset namespace-3 *=alpine:3.14 ``` 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: `...
Listen on port 3000 on all addresses, and forward the traffic to port 5432 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 3000: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 po...
Get the output from running the 'python' command in the 'time-machine' container from the 'monitoring-pod' pod
Command: ```bash kubectl exec monitoring-pod -c time-machine -- python ``` 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...
Return the snapshot logs from the container scheduler-app-deployment-1 of the deployment named log-aggregator-pod
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c log-aggregator-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...
Update the annotation of the pod specified in the "options.json" file.
Command: ```bash kubectl annotate -f options.json deployment-script='https://example.com/deploy.sh' ``` 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 t...
List deployments in JSON output format for the "v2.1.0" version of the "extensions" API group
Command: ```bash kubectl get deployments.v2.1.0.extensions -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...
Start streaming the logs of the "nebula-navigator" container in the "log-aggregator-pod" pod
Command: ```bash kubectl logs -f -c nebula-navigator log-aggregator-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--conta...
remove the pods and services with the names "monitoring" and "log-aggregator"
Command: ```bash kubectl delete pod,service monitoring log-aggregator ``` 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...
Update the deployment 'monitoring-stack-deployment' by adding a new environment variable named CACHE_SIZE with the value 64MB.
Command: ```bash kubectl set env deployment/monitoring-stack-deployment CACHE_SIZE=64MB ``` 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 templa...
Forward the local port 6379 to the pod's port 3000 in the 'frontend-pod'
Command: ```bash kubectl port-forward pod/frontend-pod 6379 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...
Embed the certificate authority data for the app-cluster cluster entry.
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/moon-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Create a deployment named "gateway" with the nginx image
Command: ```bash kubectl create deployment gateway --image=nginx ``` 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|yaml|nam...
Create a deployment named grafana with 2 replicas running the mcr.microsoft.com/dotnet/core/runtime image
Command: ```bash kubectl create deployment grafana --image=mcr.microsoft.com/dotnet/core/runtime --replicas=2 ``` 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": "", "...
Create a job with a command
Command: ```bash kubectl create job backup --image=ethereum/client-go -- geth 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 ...
Create a debug copy of the chat-app-pod with all container images changed to hazelcast/hazelcast
Command: ```bash kubectl debug chat-app-pod --copy-to=debug-image-memcached --set-image=*=hazelcast/hazelcast ``` 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 b...
Create a new config map named app-config-prod using the contents of the profiles folder at the specified path
Command: ```bash kubectl create configmap app-config-prod --from-file=path/to/profiles ``` 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 basen...
Update the security scan status of a pod specified in the "conf.json" file.
Command: ```bash kubectl annotate -f conf.json security-scan-status=pass ``` 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...
Forward local port 5432 to port 8888 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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 aut...
Open the 'monitoring-service' service for editing using the 'sublime' editor
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/monitoring-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 var...
Create a deployment named 'registry' using the 'jenkins' image
Command: ```bash kubectl create deployment registry --image=jenkins ``` 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|yaml|...
Update the custom label of a pod using a configuration file
Command: ```bash kubectl annotate -f config.json custom-label=my-custom-value ``` 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...
Start a Jenkins pod with the specified environment variables in the container
Command: ```bash kubectl run hazelcast --image=jenkins --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] [--command] -- [CO...
Auto scale the replication controller "proxy-server" to have a minimum of 1 pod and a maximum of 7 pods, with a target CPU utilization of 60%.
Command: ```bash kubectl autoscale rc proxy-server --max=7 --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...
Import the 'database_url' key from the 'monitoring-config' ConfigMap into the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --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 d...
Listen on port 3000 locally and forward data to/from port 8888 on the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 3000 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 automaticall...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/ui-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 definitions ...
Create a deployment named ingress with the python image and 4 replicas
Command: ```bash kubectl create deployment ingress --image=python --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 of:...
Copy the file "/var/run/secrets/kubernetes.io/serviceaccount/" from the local machine to the directory "/tmp/bar_dir" in the remote pod "message-broker-pod-15" in the namespace "kube-flannel".
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-flannel/message-broker-pod-15:/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": "", "us...
Import the 'smtp_server' key from the 'log-config' config map and set it as an environment variable for the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/log-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Set the label 'env' to 'staging' for the pod 'proxy-server'.
Command: ```bash kubectl label pods proxy-server env=staging ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage...
Update the pod named 'security' with the annotation named 'monitoring-tool' and set its value to 'Prometheus', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods security monitoring-tool='Prometheus' ``` 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 ...
Update the annotation for the 'api' pod with the description 'my frontend running nginx', but only if the resource has not changed from version 1.
Command: ```bash kubectl annotate pods api description='my frontend running nginx' --resource-version=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 larg...
Create an ingress called 'app-loadbalancer-ingress' with a rule that directs requests to testing.com/bar to svc1 on port 8181, and use the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/bar=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/api-key-secret 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 definitions in one or more ...
Update the 'frontend-deployment' deployment by setting a new environment variable 'PORT' to '8080'
Command: ```bash kubectl set env deployment/frontend-deployment PORT=8080 ``` 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 re...
Create a new secret named 'private-key-secret' from the data in the 'path/to/data.env' file
Command: ```bash kubectl create secret generic private-key-secret --from-env-file=path/to/data.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 basen...
Set the service account of the deployment named "order-processing-deployment" to "default"
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment default ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `k...
Create a config map named 'global-config' with the specified keys from the given file paths
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...
Execute the 'node' command in the 'mycontainer' container of the 'api-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec api-service-pod -c mycontainer -- 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, use t...
Add a taint with key 'workload' on nodes having label service=auth
Command: ```bash kubectl taint node -l service=auth workload=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": "Output...
Create a new config map named kube-system-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/profiles/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 cr...
Update the environment variables of the 'proxy-service-deployment' deployment with a new value for MONGO_URI.
Command: ```bash kubectl set env deployment/proxy-service-deployment MONGO_URI=mongodb://localhost:27017/mydb ``` 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 ...
Display only the most recent 3 lines of logs in the gateway-pod pod
Command: ```bash kubectl logs --tail=3 gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c",...
List deployments in JSON output format, specifying the API group and version
Command: ```bash kubectl get deployments.custom-version.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...
Forward port 5000 on all addresses to port 6379 in the pod "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 5000: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 a pod disruption budget named auth-service-pdb that will select all pods with the tier=frontend label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=tier=frontend --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...
Execute the 'nginx' command inside the 'mypod' pod and display the output.
Command: ```bash kubectl exec mypod -- 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 kubectl.kubernetes.io...
Create an ingress called 'app2-ingress' that routes requests from site.com/example to the service called svc1 on port 9092, using a TLS secret named "my-cert".
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/example=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Embed certificate authority data for the kube-cluster-2 cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/dev-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...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ directory from the remote pod 'backend-pod-13' to the local directory /tmp/bar.
Command: ```bash kubectl cp monitoring/backend-pod-13:/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": "Contai...
Add the label 'tier' with value 'frontend' to the pod 'api'
Command: ```bash kubectl label pods api tier=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
Copy the local file ~/.config/kube to the remote pod web-app-pod-1 in the namespace ingress-nginx, and save it as /tmp/bar.
Command: ```bash kubectl cp ~/.config/kube ingress-nginx/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...
Create a pod named "hazelcast" using the "ruby" image and expose port 5432
Command: ```bash kubectl run hazelcast --image=ruby --port=5432 ``` 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": "--fil...
Get the output from running the 'mysql' command in the first container of the 'order-processing-deployment' deployment.
Command: ```bash kubectl exec deploy/order-processing-deployment -- mysql ``` 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, ...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/kube-system-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 ...
Set the CPU and memory limits for a container in a deployment.
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=200m,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, but may burst up to it...
Add a taint with the key 'special' on nodes that have the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend special=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": "Output...
Add a taint with key 'disktype' and value 'backup-node-14:PreferNoSchedule' on nodes having label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy disktype=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": "", "usag...
Remove the 'environment' taint from the 'node-1' node.
Command: ```bash kubectl taint nodes node-1 environment- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|na...
Create a cluster role named "reader" with a specific NonResourceURL
Command: ```bash kubectl create clusterrole "reader" --verb=watch --non-resource-url=/debug/flags/v ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output",...
Create a generic secret named 'ldap-credentials-secret' with two key-value pairs
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-literal=key1=supersecret --from-literal=key2=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 file,...
Scale the deployment named 'baz' to 7 replicas
Command: ```bash kubectl scale --current-replicas=3 --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...
Begin streaming the logs of the "code-explorer" container in the "database-pod" pod
Command: ```bash kubectl logs -f -c code-explorer database-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", "s...
Copy the local file /tmp/foo_dir to the remote pod web-app-pod-1 in the monitoring namespace
Command: ```bash kubectl cp /tmp/foo_dir monitoring/web-app-pod-1:/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 th...
Create a job named "deployment-rollout-job" using the image "postgres" and run the command "pg_dump --version"
Command: ```bash kubectl create job deployment-rollout-job --image=postgres -- pg_dump --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...
Create a service for the replication controller specified in the "hazelcast-controller.yaml" file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=80 --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 th...
Auto scale a replication controller "gateway" with a target CPU utilization of 40% and a maximum of 2 pods.
Command: ```bash kubectl autoscale rc gateway --max=2 --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 uses...
Copy the ~/.config/kube file from the argocd/security-scanner-pod-18 pod to the /tmp/bar_dir directory locally.
Command: ```bash kubectl cp argocd/security-scanner-pod-18:~/.config/kube /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, u...
Execute the 'go' command in the warp-drive container of the email-service-pod pod and retrieve the output.
Command: ```bash kubectl exec email-service-pod -c warp-drive -- 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 th...