prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Copy the local file '/tmp/foo_dir' to '/tmp/bar_dir' in the remote 'front-end-pod-12' pod in the 'kube-system' namespace.
Command: ```bash kubectl cp /tmp/foo_dir kube-system/front-end-pod-12:/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 t...
Create a debug copy of a pod with a different container image
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-debugger --image=debian --set-image=api=api:v2,mailer=mailer: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....
Listen on all addresses on port 3000 and forward the traffic to port 5000 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-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 w...
Retrieve the output of the 'elasticsearch-plugin --list' command from the pod 'analytics-pod' in the container 'quantum-quark'
Command: ```bash kubectl exec analytics-pod -c quantum-quark -- elasticsearch-plugin --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container ...
Create a new secret named 'app-config-secret' with keys for each file in the 'path/to/configurations' folder
Command: ```bash kubectl create secret generic app-config-secret --from-file=path/to/configurations ``` 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 base...
retrieve information about the replication controller named 'web', the service named 'e-commerce-rc', and the pod named 'frontend-pod'
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/frontend-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 pod disruption budget named 'web-app-pdb' that will select all pods with the 'tier=frontend' label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=tier=frontend --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--d...
Import the environment variables from the 'private-key-secret' secret into the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --from=secret/private-key-secret deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or m...
Forward traffic from port 8888 on all addresses to port 8080 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8888:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Create a copy of the media-stream-pod with a debug container and change the container images to debian
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-1 --image=debian --set-image=scheduler=my-scheduler:1.0,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...
Create a service for the replicated php pods, serving on port 8084 and connecting to the containers on port 844300
Command: ```bash kubectl expose rc php --port=8084 --target-port=844300 ``` 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 a new config map named kube-system-config with the keys 'settings' and 'key2' using the specified files '/path/to/preferences/file1.txt' and '/path/to/profiles/file2.txt' respectively.
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When c...
Create a job named 'backup' using the 'golang' image and run the command 'go run hello.go'
Command: ```bash kubectl create job backup --image=golang -- go run hello.go ``` 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. O...
Forward local port 5000 to port 9090 in the security-service-pod
Command: ```bash kubectl port-forward pod/security-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 select...
import the environment variables from a secret into a deployment
Command: ```bash kubectl set env --from=secret/jwt-secret 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 definitions in one or more p...
Create a new secret named 'password-secret' using the environment variables specified in the 'options.env' file
Command: ```bash kubectl create secret generic password-secret --from-env-file=path/to/options.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...
Add a taint with key 'workload' on nodes having the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend workload=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": "Ou...
Check if you have permission to list the job named "certificates-renewal-job" in the "namespace-1" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-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 p...
Forward port 8080 on all addresses to port 6379 in the pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8080: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 ...
Import the 'debug_mode' key from the 'env-vars' config map and set it as an environment variable in the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/env-vars deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one...
Create a new LoadBalancer service named vpn-service-lb that maps port 5000 to port 3306
Command: ```bash kubectl create service loadbalancer vpn-service-lb --tcp=5000:3306 ``` 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...
Execute the 'bash' command in the 'mycontainer' container from the 'database-pod' pod and display the output.
Command: ```bash kubectl exec database-pod -c mycontainer -- bash ``` 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 ...
Check if the current user has permission to list the "report-generation-job" job in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-job -n staging ``` 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 ...
Embed the certificate authority data for the e2e cluster entry by running the command 'kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/cluster-alpha/kubernetes.ca.crt'.
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/cluster-alpha/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-cluster...
Create a new ingress called 'app-gateway-ingress' that directs requests to 'site.com/bar' to the service 'svc1' running on port '8443'
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.com/bar=svc1:8443,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...
Copy the file "/tmp/foo" from the pod "task-processor-pod-17" on the kube-server to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp kube-server/task-processor-pod-17::/tmp/foo /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...
Forward traffic from port 9090 on your local machine to port 8080 in the cdn-service-pod pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 9090:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Display the most recent 43 lines of logs for the pod "proxy-service-pod"
Command: ```bash kubectl logs --tail=43 proxy-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"...
Return the snapshot logs from the api-service-pod-1 container of the api-server-deployment deployment.
Command: ```bash kubectl logs deployment/api-server-deployment -c api-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "fla...
Set the service account of the deployment "frontend-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment frontend-deployment fluentd ``` 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: `kubectl s...
Forward traffic from a local port to a specific port on a pod
Command: ```bash kubectl port-forward pod/backend-pod :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 automatica...
Embed the certificate authority data for the 'on-prem-cluster' cluster entry by running the command:
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-1/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl confi...
Get the output from the 'quantum-quark' container in the 'payment-gateway-pod' pod
Command: ```bash kubectl attach payment-gateway-pod -c quantum-quark ``` 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 omi...
Forward traffic from port 5000 on localhost and IP address 10.19.21.23 to port 9090 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-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 th...
Check if you have permission to list the batch processing job in the specified namespace
Command: ```bash kubectl auth can-i list jobs.batch/batch-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...
Start a Mongo pod with some custom specifications by parsing a partial set of values from a JSON file.
Command: ```bash kubectl run nginx --image=mongo --overrides='{ "apiVersion": "v2.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] -- [COMMAND...
Remove the label 'env' from the pod named 'security'
Command: ```bash kubectl label pods security env- ``` 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 true...
Create a new configmap named "app-name-config" with specified keys for files "conf" and "data".
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/profiles/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 ...
Display the replication controllers for 'web', the service 'proxy-server-rc', and the pod 'e-commerce-pod'
Command: ```bash kubectl get rc/web service/proxy-server-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 namesp...
Create a service for the replicated node using replica set, which serves on port 3000 and connects to the containers on port 8080
Command: ```bash kubectl expose rs node --port=3000 --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 specified port. A...
Listen on port 5000 locally, forwarding data to/from port 3000 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-pod 5000 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...
Create a copy of the email-service-pod with a debug container by running the command `kubectl debug email-service-pod -it --copy-to=dgb-img --image=debian --set-image=web=nginx:latest,web=nginx:latest`
Command: ```bash kubectl debug email-service-pod -it --copy-to=dgb-img --image=debian --set-image=web=nginx:latest,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 nam...
Create a new NodePort service named security-service-nodeport that maps the local TCP port 8080 to the target port 27017.
Command: ```bash kubectl create service nodeport security-service-nodeport --tcp=8080:27017 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "def...
Continuously stream the logs of the "rocket-ranger" container in the "api-service-pod" pod.
Command: ```bash kubectl logs -f -c rocket-ranger api-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",...
Copy the local file "/tmp/foo" to the remote pod "auth-service-pod-11" in the "default" namespace at the path "/etc/kubernetes".
Command: ```bash kubectl cp /tmp/foo default/auth-service-pod-11:/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 the...
Create a role binding for multiple users and groups using a specific cluster role
Command: ```bash kubectl create rolebinding reader --clusterrole=reader --user=developer3 --user=k8s-admin --group=qa-engineers ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [...
Update the image of all containers in the daemonset 'prod' to 'java:11.0.12'
Command: ```bash kubectl set image daemonset prod *=java:11.0.12 ``` 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: `kubect...
Create a new config map named ui-config in the default namespace, using the files /path/to/properties/file1.txt and /path/to/data/file2.txt as the values for the settings and key2 keys, respectively.
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a conf...
Set the service account of the deployment named 'mydeployment' to 'kube-scheduler'
Command: ```bash kubectl set serviceaccount deployment mydeployment kube-scheduler ``` 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: `kubectl s...
Add a taint with key 'datacenter' and no value to the node 'testing-node-11'.
Command: ```bash kubectl taint nodes testing-node-11 datacenter:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. On...
Create a deployment named 'grafana' using the 'mcr.microsoft.com/dotnet/core/runtime' image with 7 replicas.
Command: ```bash kubectl create deployment grafana --image=mcr.microsoft.com/dotnet/core/runtime --replicas=7 ``` 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": "", "...
Import the SMTP_SERVER key from the env-vars config map and set it as an environment variables for the payment-processor-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/env-vars deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Create a job from an existing cron job named "data-sync"
Command: ```bash kubectl create job test-job --from=cronjob/data-sync ``` 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: ...
Add a taint with key 'workload' on nodes having label team=devops
Command: ```bash kubectl taint node -l team=devops workload=gpu-node-12: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": "Ou...
Import the environment variables from the 'my-secret' secret into the 'gateway-deployment' deployment
Command: ```bash kubectl set env --from=secret/my-secret deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templat...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/namespace-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 def...
Create a new config map named db-config using the files file1.txt and file2.txt
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ...
Remove resource requests for Kafka containers in a deployment.
Command: ```bash kubectl set resources deployment kafka --limits=cpu=0,memory=0 --requests=cpu=0,memory=0 ``` 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 b...
Forward the local port 8080 to the pod's port 8088
Command: ```bash kubectl port-forward pod/proxy-server-pod 8080: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 a...
Return the snapshot logs from the container 'load-balancer-deployment-1' of the deployment named 'e-commerce-pod'
Command: ```bash kubectl logs deployment/load-balancer-deployment -c e-commerce-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "f...
Create a new config map named log-config with the specified keys, properties, and key1, using the files file1.txt and file2.txt, respectively, located in /path/to/settings and /path/to/preferences
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Import specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config 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...
Create a copy of the "analytics-pod" pod, replacing all container images with the "node" image.
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-web --set-image=*=node ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
create a service for the replication controller specified in the "ubuntu-controller.yaml" file, serving on port 9092 and connecting to containers on port 808000
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=9092 --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...
Set the service account of the 'search-engine-deployment' deployment to 'metrics-server'
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment metrics-server ``` 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...
Create a job named "backup" using the Python image, running the command "python --version"
Command: ```bash kubectl create job backup --image=python -- python --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 format. ...
Remove the label 'tier' from the pod named 'database'
Command: ```bash kubectl label pods database tier- ``` 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 tru...
Create a service for the replicated alpine pod
Command: ```bash kubectl expose rc alpine --port=9090 --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....
Create a cluster role named "foo" with the verb "connect" and the resources "pods" with the specified resource names "prod-api-gateway" and "content-delivery"
Command: ```bash kubectl create clusterrole foo --verb=connect --resource=pods --resource-name=prod-api-gateway --resource-name=content-delivery ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Forward traffic from local port 8080 to port 9090 in the specified pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8080: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 aut...
Start a hazelcast pod and expose port 8000 on the container
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8000 ``` 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:...
Remove the namespace setting for the admin-context context
Command: ```bash kubectl config unset contexts.admin-context.namespace ``` What it does: Unset 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. Syntax: `kubectl config unset PROPERTY_NAME`
Update the pod named 'foo' with the annotation 'custom-label' and the value 'my-custom-value'.
Command: ```bash kubectl annotate pods foo 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 arbit...
Taint nodes with a certain label to prefer no scheduling for a specific workload.
Command: ```bash kubectl taint node -l stack=tech-stack 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":...
Update the 'authentication-service-deployment' deployment by adding a new environment variable named S3_BUCKET with the value of 'my-s3-bucket'
Command: ```bash kubectl set env deployment/authentication-service-deployment S3_BUCKET=my-s3-bucket ``` 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 mo...
Retrieve the 'media-stream-pod' pod in JSON format
Command: ```bash kubectl get -o json pod media-stream-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see...
Attach to the 'log-aggregator-pod' pod and stream the output from the 'quantum-quark' container
Command: ```bash kubectl attach log-aggregator-pod -c quantum-quark ``` 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...
Deny the Certificate Signing Request 'csr-prometheus-8'
Command: ```bash kubectl certificate deny csr-prometheus-8 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kube...
Apply a taint on nodes with the label 'app=web-app' and key 'hardware=edge-node-10' with the effect of 'PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app hardware=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Listen on all addresses for incoming traffic on port 9090, and forward it to port 5000 in the `security-service-pod` pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Forward traffic from port 5432 on your local machine to port 8888 in the mypod pod.
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Create a role binding named "reader" that grants the "reader" cluster role to the "app-operator" user, "sysadmin" user, and "security-auditors" group.
Command: ```bash kubectl create rolebinding reader --clusterrole=reader --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupn...
Update the label of pod 'database' to 'release=v1.0'
Command: ```bash kubectl label pods database release=v1.0 ``` 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": ...
Disable SSL certificate verification for the 'data-cluster' entry in the kubeconfig file
Command: ```bash kubectl config set-cluster data-cluster --insecure-skip-tls-verify=true ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Create a new config map named db-config from a file with key=value pairs
Command: ```bash kubectl create configmap db-config --from-file=path/to/configurations ``` 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...
Copy the local file /tmp/foo_dir to the remote pod logging/worker-pod-4 in the /tmp/bar directory.
Command: ```bash kubectl cp /tmp/foo_dir logging/worker-pod-4:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Get the output from running the 'kafka-topics --list' command in the lunar-launcher container inside the media-stream-pod pod.
Command: ```bash kubectl exec media-stream-pod -c lunar-launcher -- kafka-topics --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name...
Scale the deployment named baz to 3 replicas if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=3 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...
Set the cluster field in the "service-account-context" context to "kube-cluster-2"
Command: ```bash kubectl config set contexts.service-account-context.cluster kube-cluster-2 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new ...
Forward local port 8081 to port 3000 of a pod selected by the deployment named "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Forward data from local ports 5000 and 6000 to ports 8080 and 6000, respectively, on a pod selected by the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 5000 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Copy the ~/.config/kube file from the remote pod named backend-pod-13 to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp kube-proxy/backend-pod-13:~/.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 omitted, use...
Create an ingress named 'myapp-ingress' that directs requests from site.com/example to svc1:8081 with a tls secret "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="site.com/example=svc1:8081,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...
Forward port locally from pod
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Embed client certificate data for "web-app" entry
Command: ```bash kubectl config set-credentials web-app --client-certificate=~/.kube/admin.crt --embed-certs=true ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-k...
Create a new ClusterIP service named monitoring-service-clusterip that maps port 8181 on the service to port 8083 on the target pods.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8181:8083 ``` 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": "...
Partially update the node with the settings specified in "node-settings.json" using the strategic merge patch, setting the "unschedulable" field to true.
Command: ```bash kubectl patch -f node-settings.json -p '{"spec":{"unschedulable":true}}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` ...
Get the output from running the 'jenkins-plugin-cli' command in the 'cyber-sleuth' container of the 'auth-service-pod' pod.
Command: ```bash kubectl exec auth-service-pod -c cyber-sleuth -- jenkins-plugin-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 name. I...
Execute the 'geth version' command in the rocket-ranger container of the e-commerce-pod and retrieve the output.
Command: ```bash kubectl exec e-commerce-pod -c rocket-ranger -- 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 omitt...
Create a debug container in the analytics-pod with the image "debian" and change the container image for "app" to "app:debug"
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-api --image=debian --set-image=app=app:debug,app=app:debug ``` 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....