prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a job with a command to build an image using the 'node' image
Command: ```bash kubectl create job image-build-job --image=node -- node ``` 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 o...
Display the resource usage metrics for the 'web-node-8' node
Command: ```bash kubectl top node web-node-8 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (la...
Copy the file named "foo" from the "/tmp" directory in the "monitoring/database-pod-2" pod to the "/tmp/bar" directory on your local machine.
Command: ```bash kubectl cp monitoring/database-pod-2::/tmp/foo /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl...
Get the output from running the 'go' command in the backend-pod pod.
Command: ```bash kubectl exec backend-pod -- 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.kubernetes...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/env-vars 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 ...
Apply a taint on nodes that have the label 'owner=john-doe' with the key 'datacenter' and value 'prod-node-5' to prevent scheduling new pods unless they tolerate the taint.
Command: ```bash kubectl taint node -l owner=john-doe datacenter=prod-node-5: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"...
Remove the taint with key 'datacenter' and effect 'NoExecute' from node 'node-2'
Command: ```bash kubectl taint nodes node-2 datacenter: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: jso...
Create a new secret named oauth-secret using the files in the path/to/settings directory
Command: ```bash kubectl create secret generic oauth-secret --from-file=path/to/settings ``` 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 the...
Set the cluster field of a specific context to a specific cluster
Command: ```bash kubectl config set contexts.client-2-context.cluster cluster-beta ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Create a new ExternalName service called external-git-service that maps to an external endpoint named bar.com
Command: ```bash kubectl create service externalname external-git-service --external-name bar.com ``` 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 services that ex...
Create a copy of the vpn-service-pod named debug-image-memcached and change all container images to redis
Command: ```bash kubectl debug vpn-service-pod --copy-to=debug-image-memcached --set-image=*=redis ``` 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 i...
Create a job with the specified image and command
Command: ```bash kubectl create job backup --image=nginx -- nginx -t ``` 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 of: j...
Forward port 8088 on localhost and IP 10.19.21.23 to port 6379 in the e-commerce pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8088:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Set the custom TLS server name to "star-cluster" for the "prod-cluster" cluster entry in the kubeconfig file.
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=star-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] [--certificate...
Create a new secret named private-key-secret using an environment file
Command: ```bash kubectl create secret generic private-key-secret --from-env-file=path/to/preferences.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 th...
Partially update the node identified by the type and name specified in "node.json" using strategic merge patch
Command: ```bash kubectl patch -f node-specific.yaml -p '{"spec":{"type":"LoadBalancer"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` ...
Create a deployment named "drupal" using the Redis image and run the command "redis-cli" inside the deployment.
Command: ```bash kubectl create deployment drupal --image=redis -- redis-cli ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Make the node "storage-node-13" available for scheduling new pods
Command: ```bash kubectl uncordon storage-node-13 ``` 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 "
View the last 23 lines of logs from pod email-service-pod
Command: ```bash kubectl logs --tail=23 email-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short"...
retrieve information about the 'web' replication controller, 'frontend-rc' service, and 'security-service-pod' pods
Command: ```bash kubectl get rc/web service/frontend-rc pods/security-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 name...
Get the output of running the command 'composer --version' in the container named quantum-quark within the pod named payment-gateway-pod
Command: ```bash kubectl exec payment-gateway-pod -c quantum-quark -- composer --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 nam...
Copy the local file `/tmp/foo` to the remote pod named `monitoring-agent-pod-6` in the `default` namespace, and place it in the `/tmp/bar_dir` directory.
Command: ```bash kubectl cp :/tmp/foo default/monitoring-agent-pod-6:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Forward port 8081 on all addresses to port 8088 in the pod "web-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-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 ...
Create a copy of the 'mypod' pod with a debug container named 'my-custom-dbg', using the 'debian' image
Command: ```bash kubectl debug mypod -it --copy-to=my-custom-dbg --image=debian --set-image=api=api:v2,web=nginx:latest ``` 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...
Edit the configuration of the 'gateway-service' service
Command: ```bash kubectl edit svc/gateway-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 '...
Copy the local file /tmp/foo_dir to the /etc/kubernetes directory in the admin-dashboard-pod-16 pod of the cert-manager namespace.
Command: ```bash kubectl cp /tmp/foo_dir cert-manager/admin-dashboard-pod-16:/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 omit...
List the name and image of the first container in the 'security-service-pod' pod in custom columns format.
Command: ```bash kubectl get pod security-service-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image ``` 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 ...
Update the pod named 'api' with the annotation 'team' and the value 'frontend team'
Command: ```bash kubectl annotate pods api team='frontend team' ``` 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 str...
Start a Jenkins pod and expose port 9091
Command: ```bash kubectl run hazelcast --image=jenkins --port=9091 ``` 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": "--...
List all the allowed actions in the "kube-public" namespace
Command: ```bash kubectl auth can-i --list --namespace=kube-public ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that starts wi...
Add a taint with key 'zone' on nodes having label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace zone=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": "", "usa...
Display the most recent 53 lines of logs for the pod named gateway-pod
Command: ```bash kubectl logs --tail=53 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"...
Display the most recent 43 lines of logs for a specific pod
Command: ```bash kubectl logs --tail=43 e-commerce-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": "...
List the replication controller with the name 'web', the service with the name 'cdn-service-rc', and the pod with the name 'proxy-service-pod'.
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/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 name...
Forward traffic from port 8081 of your local machine to port 5000 in the backend-pod pod. Listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8081: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 ...
Create a job named indexing using the image confluentinc/cp-kafka and run the command "kafka-server-start /etc/kafka/server.properties"
Command: ```bash kubectl create job indexing --image=confluentinc/cp-kafka -- kafka-server-start /etc/kafka/server.properties ``` 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"...
Set the CPU limit of the Python container in the deployment named "python" to "50m" and the memory limit to "128Mi".
Command: ```bash kubectl set resources deployment python -c=nginx --limits=cpu=50m,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 requested, but may burst up to...
Import the specific key 'config_file_path' from the 'ui-config' ConfigMap and set it as an environment variable in the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/ui-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Begin streaming the logs of the "rocket-ranger" container in the "payment-gateway-pod" pod.
Command: ```bash kubectl logs -f -c rocket-ranger payment-gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--contain...
Copy the file named "foo" from the local machine to the "/etc/kubernetes" directory in a specific container of a remote pod.
Command: ```bash kubectl cp :/tmp/foo admin-dashboard-pod-16:/etc/kubernetes -c ingress-controller ``` 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. I...
Configure the 'cluster' field of the 'client-1-context' context to be set to 'star-cluster'
Command: ```bash kubectl config set contexts.client-1-context.cluster star-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Retrieve the snapshot logs from container proxy-service-deployment-1 of the deployment named analytics-pod
Command: ```bash kubectl logs deployment/proxy-service-deployment -c analytics-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: "fl...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/security-service-rc pods/proxy-server-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 ...
Create a pod named "hazelcast" with the Ubuntu image and expose port 8082
Command: ```bash kubectl run hazelcast --image=ubuntu --port=8082 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Set the custom TLS server name "sun-cluster" for the "prod-cluster" cluster entry.
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=sun-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] [--certificate-...
Forward local port 3000 to port 6379 in the analytics-pod pod for data transfer
Command: ```bash kubectl port-forward pod/analytics-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 criteria, a pod will be selected auto...
import the MAX_CONNECTIONS key from the global-config config map and set it as an environment variable in the gateway-deployment deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/global-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 definiti...
Set the custom TLS server name to "kube-cluster-1" for validation for the "cluster-beta" cluster entry
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=kube-cluster-1 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
create a config map with specified keys and values from files
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/data/file1.txt --from-file=key1=/path/to/settings/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 co...
Create a service for a replicated ruby using replica set, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rs ruby --port=3306 --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 specified port. A...
Create an ingress named 'private-service-ingress' with the following rule: directs requests from testing.com/example to svc1:5000
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/example=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...
List the following resources: replication controller "web", service "database-rc", and pod "auth-service-pod".
Command: ```bash kubectl get rc/web service/database-rc pods/auth-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespac...
Forward local traffic on port 6379 to a pod selected by the deployment "search-engine-deployment"
Command: ```bash kubectl port-forward deployment/search-engine-deployment 6379 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 wil...
List all deployments in JSON output format from the "v2.1.0" version of the "beta-apps" API group
Command: ```bash kubectl get deployments.v2.1.0.beta-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will ...
Create a config map named log-config with the specified keys, using files for the values
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/profiles/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 crea...
Output the modified deployment in YAML without making any changes to the server object.
Command: ```bash kubectl set env deployment/analytics-platform-deployment SMTP_PASSWORD=your-password -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 ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Create a cron job with a specific schedule and command
Command: ```bash kubectl create cronjob weekly-summary --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag...
Create a deployment named gitlab that uses the mongo image and exposes port 9090.
Command: ```bash kubectl create deployment gitlab --image=mongo --port=9090 ``` 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...
Create a new LoadBalancer service in named vpn-service-lb with the TCP port mapping 9092:8181.
Command: ```bash kubectl create service loadbalancer vpn-service-lb --tcp=9092:8181 ``` 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", "def...
Setup autoscaling for deployment "api" with minimum 5 pods and maximum 11 pods.
Command: ```bash kubectl autoscale deployment api --min=5 --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 the...
Check if user has permission to list a specific job in a namespace
Command: ```bash kubectl auth can-i list jobs.batch/database-indexing-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 parti...
Scale the deployment named mysql to 1 replica while it currently has 7 replicas.
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/mysql ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is sp...
View the resource utilization metrics for a specific node
Command: ```bash kubectl top node testing-node-11 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selecto...
Create a deployment called "logging" using the "docker.elastic.co/elasticsearch/elasticsearch" image and expose port 8080 for this deployment.
Command: ```bash kubectl create deployment logging --image=docker.elastic.co/elasticsearch/elasticsearch --port=8080 ``` 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"...
Add a taint with the key 'workload' on nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend workload=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 secret named monitoring-credentials-secret with a key for the file in the path/to/preferences folder.
Command: ```bash kubectl create secret generic monitoring-credentials-secret --from-file=path/to/preferences ``` 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...
Add a taint with the key 'hardware' on nodes that have the label 'customer=acme-corp'.
Command: ```bash kubectl taint node -l customer=acme-corp hardware=app-node-6: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...
Start the alpine pod with custom arguments
Command: ```bash kubectl run nginx --image=alpine -- <arg1> <arg2> ... <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 flags: ...
List deployments in YAML output format for the "rc-1.1.0" version of the "prod-apps" API group.
Command: ```bash kubectl get deployments.rc-1.1.0.prod-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Create a debug container in the frontend-pod by copying the pod and changing the container images
Command: ```bash kubectl debug frontend-pod -it --copy-to=debug-image-api --image=debian --set-image=web=nginx:latest,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Forward port 8088 on localhost and IP 10.19.21.23 to port 3000 in the pod named proxy-server-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8088: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 cr...
Delete the pods and services named "gateway" and "vpn"
Command: ```bash kubectl delete pod,service gateway vpn ``` 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. Som...
Update the environment variable 'MAX_CONNECTIONS' in the deployment 'log-aggregator-deployment'
Command: ```bash kubectl set env deployment/log-aggregator-deployment MAX_CONNECTIONS=100 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...
Get logs from container "backend-pod-1" of the deployment "monitoring-stack-deployment"
Command: ```bash kubectl logs deployment/monitoring-stack-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: "f...
List the environment variables defined on a deployments 'frontend-deployment'
Command: ```bash kubectl set env deployment/frontend-deployment --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 repli...
Update the annotation 'app-version' of the pod 'log-aggregator' with the value 2.5.1
Command: ```bash kubectl annotate pods log-aggregator app-version=2.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 larger than labels and include arbit...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/cdn-service-pod 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 selected au...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/ui-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 ...
Create a service for a replication set serving on port 5001, targeting port 8084
Command: ```bash kubectl expose rs python --port=5001 --target-port=808400 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a Pod Disruption Budget named notification-service-pdb that selects all pods with the region=us-east label and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=region=us-east --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-av...
Start a new Centos pod with port 9091 exposed
Command: ```bash kubectl run hazelcast --image=centos --port=9091 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Configure the resource limits for the nginx container in the deployment "nginx" to 50m CPU and 256Mi memory.
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=50m,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 ...
execute the 'node' command inside the security-service-pod pod
Command: ```bash kubectl exec security-service-pod -- 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 the kubectl...
view the resource usage metrics for the pods labeled with component=proxy
Command: ```bash kubectl top pod -l component=proxy ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAME |...
import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-settings 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 definiti...
Create a debug container in the log-aggregator-pod with the image "debian" and change the container images to "mysql:5.7" for the database container and "redis:alpine" for the cache container.
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-api --image=debian --set-image=database=mysql:5.7,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Create a new config map named app-config-dev using the key=value pairs from the file at path/to/settings
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/settings ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basena...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-settings 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 d...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8088 on the backend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8088: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 criteri...
Listen on port 8000 on localhost and IP 10.19.21.23, and forward the traffic to port 6379 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/api-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 o...
Print the result of updating the 'php' container image in the file located at 'path/to/file.yaml' to 'php:7.4.22' without hitting the server, and display the output in yaml format.
Command: ```bash kubectl set image -f path/to/file.yaml php=php:7.4.22 --local -o yaml ``` 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...
Partially update the 'testing-node-11' node by adding a new 'password' field with the value 'new-password' using a strategic merge patch
Command: ```bash kubectl patch node testing-node-11 -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...
Forward local port 8081 to port 3000 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081 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 a...
Create a new config map named global-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-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. When cr...
Run the command 'mysql --version' inside the stardust-shuttle container in the pod frontend-pod
Command: ```bash kubectl exec frontend-pod -c stardust-shuttle -- 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 o...
View the details of a specific revision of a daemonset deployment
Command: ```bash kubectl rollout history daemonset/my-deployment --revision=1 ``` 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 ...
Embed the certificate authority data for the kube-cluster-2 cluster entry using the certificate authority file located at ~/.kube/kube-cluster-2/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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...
Create a ClusterIP service named backend-service-clusterip that maps port 8083 on the cluster IP to port 8088 on the service.
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=8083:8088 ``` 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"...