prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a taint with the key 'disktype' and value 'backup-node-14:PreferNoSchedule' on nodes that have the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops 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": "", "usage": ...
Resume a previously paused deployment or rollout.
Command: ```bash kubectl rollout resume deployment/services ``` What it does: Resume a paused resource. Paused resources will not be reconciled by a controller. By resuming a resource, we allow it to be reconciled again. Currently only deployments support being resumed. Syntax: `kubectl rollout resume RESOURCE` Help...
Update deployment 'backend-microservice-deployment' by setting a new environment variable named QUEUE_NAME with the value 'task-queue'.
Command: ```bash kubectl set env deployment/backend-microservice-deployment QUEUE_NAME=task-queue ``` 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 ...
Import the 'SMTP_SERVER' key from the 'env-vars' config map and set it as an environment variable in the 'frontend-deployment' deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/env-vars deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Listen on ports 8088 locally and forward data to/from port 3000 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-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 criteria, a pod will be selected auto...
Run the command 'yum install -y aws-cli' in the lunar-launcher container of the vpn-service-pod and provide the output.
Command: ```bash kubectl exec vpn-service-pod -c lunar-launcher -- yum install -y aws-cli ``` 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 na...
Check if you have permission to list the job named "queue-processing-job" in the namespace "namespace-1".
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n namespace-1 ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Add a taint on nodes owned by John Doe
Command: ```bash kubectl taint node -l owner=john-doe dedicated=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": ...
Create a deployment named logging that runs the nginx image and exposes port 9092
Command: ```bash kubectl create deployment logging --image=nginx --port=9092 ``` 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...
Start a nginx pod named "hazelcast" and expose port 8083
Command: ```bash kubectl run hazelcast --image=nginx --port=8083 ``` 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": "--fi...
Get output from stardust-shuttle in the analytics-pod
Command: ```bash kubectl attach analytics-pod -c stardust-shuttle ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Retrieve the output of the 'geth version' command by executing it inside the first container of the frontend-deployment deployment.
Command: ```bash kubectl exec deploy/frontend-deployment -- geth 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, u...
Run 'irb' command on the first pod of the service notification-service to get its output.
Command: ```bash kubectl exec svc/notification-service -- irb ``` 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 kube...
Retrieve the snapshot logs from the 'payment-gateway-pod' deployment for the container named 'user-management-deployment-1'
Command: ```bash kubectl logs deployment/user-management-deployment -c payment-gateway-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 fl...
Create a new LoadBalancer service named my-lbs that will forward TCP traffic from port 8083 to port 9092
Command: ```bash kubectl create service loadbalancer my-lbs --tcp=8083:9092 ``` 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", "default": "...
Update the 'database' pod with the annotation 'release-notes' and set its value to 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods database 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...
Start a wordpress pod with the specified image, but override the pod specification with the values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "rc-1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [C...
Add a taint with key 'cpu-type' on the node(s) that have the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy cpu-type=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": "Out...
Get the output from running the 'irb' command in the nano-bot container of the proxy-service-pod pod.
Command: ```bash kubectl exec proxy-service-pod -c nano-bot -- irb ``` 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...
Retrieve the deployments in the "feature-branch-2.3.0" version of the "alpha-apps" API group in JSON format.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.alpha-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is names...
List deployments in the JSON output format using the "custom-version" version of the "prod-apps" API group
Command: ```bash kubectl get deployments.custom-version.prod-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 y...
Describe a specific node in the cluster
Command: ```bash kubectl describe nodes gateway-node-14.gateway-cluster.net ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects...
Get the output of running the 'psql' command in the first container of the 'e-commerce-pod' pod.
Command: ```bash kubectl exec e-commerce-pod -- psql ``` 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.kuber...
Update the image of all containers in the 'services' daemonset to 'alpine:3.14'
Command: ```bash kubectl set image daemonset services *=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: `kub...
Create a cluster role named "admin_role" with specific resource names
Command: ```bash kubectl create clusterrole admin_role --verb=list --resource=pods --resource-name=log-aggregator --resource-name=queue-consumer ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
List deployments in YAML output format using the "v2.0.0" version of the "alpha-apps" API group
Command: ```bash kubectl get deployments.v2.0.0.alpha-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 will...
Create a new secret named 'aws-credentials-secret' from the 'path/to/settings.env' env file
Command: ```bash kubectl create secret generic aws-credentials-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...
Get the output of 'composer --version' from the first pod in the payment-service service
Command: ```bash kubectl exec svc/payment-service -- 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 name. If omitted, us...
Forward traffic from local port 3000 to port 8088 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000: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 au...
Update the pods named 'backend' by adding or updating the annotation 'alert-email' with the value 'alerts@example.com'
Command: ```bash kubectl annotate pods backend alert-email=alerts@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 include...
Add a taint to the node 'backup-node-14' with key 'app', value 'backend', and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes backup-node-14 app=backend: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 form...
Create a service for the centos replication controller, which will serve on port 5001 and connect to containers on port 300100.
Command: ```bash kubectl expose rc centos --port=5001 --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....
Forward traffic from local port 5000 to port 5432 in the pod
Command: ```bash kubectl port-forward pod/frontend-pod 5000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named log-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...
Update the container images of a deployment
Command: ```bash kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.21.3 ``` 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...
Add a taint with key 'dedicated' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster dedicated=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a new config map named 'env-vars' using the specified keys and file paths
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/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 creating a c...
Create a config map named log-config from specified files and keys
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/options/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 c...
Create an ingress named 'external-ingress' that maps requests from website.com/input to the service 'svc1' running on port 8083
Command: ```bash kubectl create ingress external-ingress --rule="website.com/input=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Get the documentation for the "selector" field of the "spec" section of the "pods" resource.
Command: ```bash kubectl explain resource=pods.spec.selector ``` 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 dis...
Create a cron job named 'monthly-audit' using the 'wordpress' image and running the command 'mysql --version' every minute.
Command: ```bash kubectl create cronjob monthly-audit --image=wordpress --schedule="*/1 * * * *" -- mysql --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", "shor...
Create a backup job using the postgres image
Command: ```bash kubectl create job backup --image=postgres -- postgres ``` 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...
Set the service account of the deployment 'api-server-deployment' to 'cert-manager'
Command: ```bash kubectl set serviceaccount deployment api-server-deployment cert-manager ``` 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: `ku...
Import the 'secret_key' key from the 'app-config-dev' config map to the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-config-dev deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Retrieve the snapshot logs from the container monitoring-stack-deployment-1 of the deployment named proxy-server-pod.
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c proxy-server-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 flag...
Forward data from local port 8088 to port 8888 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod 8088 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 automa...
Create a single ingress called 'app2-ingress' that directs requests to testing.com/example to the svc1 service on port 8080, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/example=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a service for the replicated nginx, which serves on port 8081 and connects to the containers on port 808200
Command: ```bash kubectl expose rc nginx --port=8081 --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 port. ...
Execute the command "nginx -t" in the "warp-drive" container of the "api-service-pod" pod and display the output.
Command: ```bash kubectl exec api-service-pod -c warp-drive -- nginx -t ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Expose a deployment as a service on port 9090, connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment node --port=9090 --target-port=8000 ``` 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 p...
Create a cluster role named "admin_role" with the following permissions: allow "connect" verb for "services" resources with resource names "order-fulfillment" and "report-generator"
Command: ```bash kubectl create clusterrole admin_role --verb=connect --resource=services --resource-name=order-fulfillment --resource-name=report-generator ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run...
Create a copy of the api-service-pod with modified command for cyber-sleuth container
Command: ```bash kubectl debug api-service-pod -it --copy-to=my-custom-dbg --container=cyber-sleuth -- 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 de...
Forward port 8088 on localhost to port 8888 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 8088: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...
Update the pod 'cdn' with the annotation 'app-version' and set it to the value 2.5.1
Command: ```bash kubectl annotate pods cdn 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 arbitrary string...
Listen on port 5000 locally and forward the traffic to port 8000 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 5000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Expose the replica set named 'python' as a service on port 80. The service will connect to the containers on port 8000.
Command: ```bash kubectl expose rs python --port=8181 --target-port=801000 ``` 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....
Delete the pods and services with the names "proxy-server" and "media-stream"
Command: ```bash kubectl delete pod,service proxy-server media-stream ``` 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...
Create a copy of the 'api-service-pod' pod in the 'rocket-ranger' container and start a debug session with an interactive terminal.
Command: ```bash kubectl debug api-service-pod -it --copy-to=dgb-img --container=rocket-ranger -- 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 default...
Display only the last 3 lines of logs for the 'auth-service-pod' pod
Command: ```bash kubectl logs --tail=3 auth-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": ...
update the deployment "email-server-deployment" by importing the "debug_mode" key from the "app-secrets" config map
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-secrets deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Retrieve information about the ReplicaSet 'web', the Service 'proxy-server-rc', and the Pod 'cdn-service-pod'
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/cdn-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 names...
create a service for the hazelcast deployment, which serves on port 6379 and connects to the containers on port 909100
Command: ```bash kubectl expose deployment hazelcast --port=6379 --target-port=909100 ``` 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 spec...
Start an alpine pod named 'nginx' and override its spec by providing a partial set of values parsed from the JSON in the --overrides flag.
Command: ```bash kubectl run nginx --image=alpine --overrides='{ "apiVersion": "stable-2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [...
Delete the pods and services with the names "log-aggregator" and "payment"
Command: ```bash kubectl delete pod,service log-aggregator payment ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label se...
Remove all taints with key 'special' from node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 special- ``` 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...
Create a cluster role named "foo" with specified SubResource
Command: ```bash kubectl create clusterrole foo --verb=list,use,connect --resource=nodes,nodes/metrics ``` 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": "--outpu...
Create a new config map named kube-system-config, using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/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 creati...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/global-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 definiti...
Create a pod disruption budget named critical-services-pdb that will select all pods with the region=us-east label and require at least four of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=region=us-east --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-avail...
Copy the '/var/run/secrets/kubernetes.io/serviceaccount/' directory from the 'task-processor-pod-17' pod in the 'ingress-nginx' namespace to the '/tmp/bar' directory locally.
Command: ```bash kubectl cp ingress-nginx/task-processor-pod-17:/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": "", "usag...
Create a new resource quota named storage-quota with a storage limit of 100Gi.
Command: ```bash kubectl create quota storage-quota --hard=storage=100Gi ``` 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: "fl...
Expose the centos deployment as a service, serving on port 9091 and connecting to the containers on port 808000
Command: ```bash kubectl expose deployment centos --port=9091 --target-port=808000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Create a deployment named prometheus that runs the wordpress image.
Command: ```bash kubectl create deployment prometheus --image=wordpress ``` 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|y...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/frontend-rc pods/e-commerce-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...
Display the most recent 3 lines of logs for the pod "monitoring-pod"
Command: ```bash kubectl logs --tail=3 monitoring-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": "-...
Attach to the time-machine container in the chat-app-pod
Command: ```bash kubectl attach chat-app-pod -c time-machine ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Forward traffic from port 9090 on all addresses to port 8000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 9090:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Forward local ports 5000 and 6000 to ports 5000 and 6000, respectively, in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Create a cron job that runs a command on a schedule
Command: ```bash kubectl create cronjob email-notifications --image=nginx --schedule="*/1 * * * *" -- nginx -g "daemon off;" ``` 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": "--outpu...
Create a deployment named proxy that runs the redis image and exposes port 5001
Command: ```bash kubectl create deployment proxy --image=redis --port=5001 ``` 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: jso...
Set the service account for the deployment 'email-server-deployment' to 'dashboard'
Command: ```bash kubectl set serviceaccount deployment email-server-deployment dashboard ``` 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: `kub...
Copy the local file /tmp/foo to the remote pod metrics-exporter-pod-10 in the cert-manager namespace, and place it at /tmp/bar
Command: ```bash kubectl cp /tmp/foo cert-manager/metrics-exporter-pod-10::/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 ...
Forward traffic from port 5000 locally to port 9090 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Execute the `redis-server --version` command on the `time-machine` container within the `mypod` pod and display the output.
Command: ```bash kubectl exec mypod -c time-machine -- redis-server --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 omitt...
Dump the current cluster state and save it to the /tmp/foo directory
Command: ```bash kubectl cluster-info dump --output-directory=:/tmp/foo ``` What it does: Dump cluster information out suitable for debugging and diagnosing cluster problems. By default, dumps everything to stdout. You can optionally specify a directory with --output-directory. If you specify a directory, Kubernetes...
Create an ingress that routes requests from testing.com/input to svc1:8084 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/input=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create an autoscaling policy for the "media-stream" deployment, with a minimum of 2 pods and a maximum of 14 pods.
Command: ```bash kubectl autoscale deployment media-stream --min=2 --max=14 ``` 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...
Update the 'cloud-cluster' cluster configuration by setting the server field to 'https://1.2.3.4', without modifying any other values.
Command: ```bash kubectl config set-cluster cloud-cluster --server=https://1.2.3.4 ``` 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-auth...
Switch to raw terminal mode and attach to the 'time-machine' container in the 'chat-app-pod'
Command: ```bash kubectl attach chat-app-pod -c time-machine -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Switch to the raw terminal mode for the database-pod, connecting to the quantum-quark container
Command: ```bash kubectl attach database-pod -c quantum-quark -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Create a secret named cert-manager-secret by using the contents of the file located at "path/to/id_rsa" as the ssh-privatekey and by specifying the passphrase as "topsecret".
Command: ```bash kubectl create secret generic cert-manager-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 base...
Create a deployment named "mattermost" with the mongo image and expose port 9092.
Command: ```bash kubectl create deployment mattermost --image=mongo --port=9092 ``` 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...
Get the output from running the 'mysql --version' command in the nebula-navigator container of the pod proxy-server-pod.
Command: ```bash kubectl exec proxy-server-pod -c nebula-navigator -- 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. ...
Create a new ClusterIP service named "ldap-service-clusterip" and map port 5000 from the service to port 9091 on the target pods.
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=5000:9091 ``` 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", "...
Import the 'external_api_url' key from the 'app-config-dev' config map into the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config-dev 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 va...
Create a copy of the chat-app-pod and add a debug container, using the 'debian' image
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-web --image=debian --set-image=worker=my-custom-worker:1.2.3,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 iden...
Execute the 'yum install -y aws-cli' command inside the 'stardust-shuttle' container of the 'e-commerce-pod' pod and get the output.
Command: ```bash kubectl exec e-commerce-pod -c stardust-shuttle -- yum install -y aws-cli ``` 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 n...
Get the output from running the 'apache2ctl -D FOREGROUND' command in the stardust-shuttle container of the vpn-service-pod pod.
Command: ```bash kubectl exec vpn-service-pod -c stardust-shuttle -- apache2ctl -D FOREGROUND ``` 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": "Containe...
Create a new config map named 'app-config-dev' in the current namespace
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/preferences ``` 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 bas...
Delete the pods and services with the names "security" and "email"
Command: ```bash kubectl delete pod,service security email ``` 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. ...