prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a copy of proxy-service-pod with a debug container and different container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-web --image=debian --set-image=app=app:debug,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 r...
Create a copy of the 'web-app-pod' pod by adding a 'debug' container and changing the container images
Command: ```bash kubectl debug web-app-pod -it --copy-to=dgb-img --image=debian --set-image=mailer=mailer:latest,proxy=nginx:1.21 ``` 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....
Create a new config map named 'kube-system-config' with the specified keys
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. Wh...
Create a new ClusterIP service named messaging-service-clusterip, mapping port 9092 on the service to port 3306 on the pod
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=9092:3306 ``` 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": "-...
Expose a replication controller named "php" as a service on port 9000, connecting to the containers on port 637900.
Command: ```bash kubectl expose rc php --port=9000 --target-port=637900 ``` 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 ...
Restart a specific deployment
Command: ```bash kubectl rollout restart deployment/development ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the reso...
Start a new pod named nginx with the image docker.elastic.co/elasticsearch/elasticsearch, but override the pod's spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "legacy-1.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] [--...
Update the image of all containers in the daemonset "development" to "java:11.0.12"
Command: ```bash kubectl set image daemonset development *=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: ...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/cdn-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 names...
Create a job with a command by specifying the image and the command to be executed
Command: ```bash kubectl create job certificate-renewal --image=jenkins -- jenkins-plugin-cli ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Create an ingress called 'app-gateway-ingress' that directs requests to foo.com/module to svc1:5432 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/module=svc1:5432,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...
Create a deployment named "web" with the image "mysql" and specify a version using the kubectl create command.
Command: ```bash kubectl create deployment web --image=mysql -- mysql --version ``` 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...
Create a cluster role named "view" with the specified permissions to get services and access the resources named "api-server" and "auth-service"
Command: ```bash kubectl create clusterrole view --verb=get --resource=services --resource-name=api-server --resource-name=auth-service ``` 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]`...
Create a new config map named 'api-config' by reading the contents of the files '/path/to/configurations/file1.txt' and '/path/to/profiles/file2.txt'
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/configurations/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...
List the replication controller "web", the service "security-service-rc", and the pod "chat-app-pod"
Command: ```bash kubectl get rc/web service/security-service-rc pods/chat-app-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...
Add an annotation 'alert-email=alerts@example.com' to the pod 'api'
Command: ```bash kubectl annotate pods api 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 arb...
Listen on port 9090 on localhost and IP address 10.19.21.23, and forward the traffic to port 5000 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Create an ingress named 'service-ingress' that routes requests from site.com/input to svc1:9090 in the default namespace with TLS enabled using the 'my-cert' secret.
Command: ```bash kubectl create ingress service-ingress --rule="site.com/input=svc1:9090,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...
Create a deployment named nats with the amazonlinux image and expose port 8089.
Command: ```bash kubectl create deployment nats --image=amazonlinux --port=8089 ``` 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...
View previous terminated container logs for the email-service-pod with the container name "astro-container"
Command: ```bash kubectl logs -p -c astro-container 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": "--contain...
Apply a taint with the key 'special' on nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice special=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": "", "us...
import the 'CONFIG_FILE_PATH' key from the 'kube-system-config' config map and apply it to the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/kube-system-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environm...
Set the CPU limit of the redis container in the deployment named "redis" to "10" and the memory limit to "2Gi"
Command: ```bash kubectl set resources deployment redis -c=nginx --limits=cpu=10,memory=2Gi ``` 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 its...
Import the DATABASE_URL key from the config map named 'global-config' and set it as an environment variable in the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --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 defin...
Create a cluster role binding for multiple users and groups using a specific cluster role
Command: ```bash kubectl create clusterrolebinding reader --clusterrole=reader --user=admin --user=devops-user --group=operations-team ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname]...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Copy the local file /tmp/foo to the remote pod message-broker-pod-15 in the container image-resizer, and place it in the /tmp/bar directory.
Command: ```bash kubectl cp /tmp/foo message-broker-pod-15::/tmp/bar -c image-resizer ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
execute the 'psql' command in the 'astro-container' of the 'database-pod' and get the output
Command: ```bash kubectl exec database-pod -c astro-container -- 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 ...
get the replication controller with the name "web", the service with the name "media-stream", and the pod with the name "security-service"
Command: ```bash kubectl get rc/web service/media-stream-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 ...
Create an ingress named 'web-ingress' that directs requests to site.com/bar to svc1:8080 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="site.com/bar=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": "", "usage": "Ou...
Return the logs of the container named security-service-pod-1 from the load-balancer-deployment deployment.
Command: ```bash kubectl logs deployment/load-balancer-deployment -c security-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful fla...
Retrieve the previous terminated container logs from the pod "chat-app-pod" for the container named "mycontainer"
Command: ```bash kubectl logs -p -c mycontainer chat-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Delete the pods and services with the names "log-aggregator" and "backend"
Command: ```bash kubectl delete pod,service log-aggregator backend ``` 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...
Create a new config map named app-config-prod using the values from the profiles.env file located at path/to/profiles.env
Command: ```bash kubectl create configmap app-config-prod --from-env-file=path/to/profiles.env ``` 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 t...
Execute the 'redis-server' command in the 'astro-container' from the 'proxy-server-pod' and retrieve the output.
Command: ```bash kubectl exec proxy-server-pod -c astro-container -- redis-server ``` 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...
Create a role binding named "view" for the "admin" user, "devops-user" user, and "operations-team" group, using the "view" cluster role.
Command: ```bash kubectl create rolebinding view --clusterrole=view --user=admin --user=devops-user --group=operations-team ``` 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] [--se...
Create a new ClusterIP service named "analytics-service-clusterip"
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=8443: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": "-...
Apply a taint with the key 'cpu-type' and the value 'node-2:PreferNoSchedule' on all nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production 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...
Embed the certificate authority data for the 'kube-cluster-2' cluster entry using the provided certificate authority file "~/.kube/data-cluster/kubernetes.ca.crt".
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Create a copy of the frontend pod with a debug container and different container images
Command: ```bash kubectl debug frontend-pod -it --copy-to=debug-image-web --image=debian --set-image=cache=redis:alpine,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 resourc...
Open the 'proxy-service' service for editing using the nano editor.
Command: ```bash KUBE_EDITOR="nano" kubectl edit svc/proxy-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, ...
Get output from running the 'apk add curl' command in the mycontainer container from the proxy-service-pod pod
Command: ```bash kubectl exec proxy-service-pod -c mycontainer -- apk add curl ``` 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 omit...
Embed the certificate authority data for the specified cluster entry in the Kubernetes configuration file.
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/moon-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Partially update a node using a strategic merge patch, providing the patch as a JSON format.
Command: ```bash kubectl patch node monitoring-node-15 -p '{"spec":{"someField":"newValue"}' ``` 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]...
Forward local port 8000 to port 5000 in the mypod pod
Command: ```bash kubectl port-forward pod/mypod 8000: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 automaticall...
Create an ingress called 'rontend-ingress' with the following rule: site.com/bar should redirect requests to svc1:7000
Command: ```bash kubectl create ingress rontend-ingress --rule="site.com/bar=svc1:7000,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":...
Copy the contents of /tmp/foo_dir from the front-end-pod-12 pod in the argocd namespace to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp argocd/front-end-pod-12:/tmp/foo_dir :/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 kubec...
Remove taint from a specific node
Command: ```bash kubectl taint nodes prod-node-5 environment:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Forward traffic from port 8080 on all addresses to port 5432 in the frontend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8080: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...
List the specified resources by their respective types and names
Command: ```bash kubectl get rc/web service/log-aggregator-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 name...
Create a single ingress called 'private-api-ingress' that directs requests to testing.com/module to svc # svc1:8088 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/module=svc1:8088,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 deployments in YAML output format in a specific version of the apps API group
Command: ```bash kubectl get deployments.v3.0.0.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 only ...
Copy the file "/tmp/foo" from the "kube-proxy/task-processor-pod-17" pod to the local directory "/tmp/bar_dir".
Command: ```bash kubectl cp kube-proxy/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 ...
Create a pod named 'hazelcast' using the 'mysql' image, and expose port 8089
Command: ```bash kubectl run hazelcast --image=mysql --port=8089 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Forward traffic from your local port 8080 to the pod's port 8088 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Create a new config map named api-config by specifying the keys and their corresponding file paths.
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/configurations/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 creatin...
Update the label of the 'cdn' pod to have the key 'component' and the value 'api'
Command: ```bash kubectl label pods cdn component=api ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
Copy the ~/.config/kube file from the load-balancer-pod-9 pod to the local directory /tmp/bar
Command: ```bash kubectl cp kubeapps/load-balancer-pod-9:~/.config/kube :/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 th...
Run the 'elasticsearch' command in nebula-navigator from the 'media-stream-pod' pod
Command: ```bash kubectl exec media-stream-pod -c nebula-navigator -- elasticsearch ``` 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...
Check if you have the permission to list the "load-testing-job" job in the "development" namespace
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n development ``` 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 U...
Create a role named "default_role" with the ability to delete pods and manage resources named "app-worker-1" and "content-delivery".
Command: ```bash kubectl create role default_role --verb=delete --resource=pods --resource-name=app-worker-1 --resource-name=content-delivery ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=...
Add a taint with key 'datacenter' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz datacenter=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"...
Execute the 'go run hello.go' command inside the container named astro-container running in the pod named database-pod and display the output.
Command: ```bash kubectl exec database-pod -c astro-container -- go run hello.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 om...
Retrieve the output from running the 'sleep 3600' command in the stardust-shuttle container of the security-service-pod
Command: ```bash kubectl exec security-service-pod -c stardust-shuttle -- sleep 3600 ``` 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...
Forward local ports 8000 and 6000 to ports 5432 and 6000 respectively in a pod selected by the email-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8000 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...
Forward local traffic on port 8081 to port 5000 in the pod named 'security-service-pod'
Command: ```bash kubectl port-forward pod/security-service-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 be select...
Import the 'CONFIG_FILE_PATH' key from the 'monitoring-config' config map to the deployment 'mydeployment'
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/monitoring-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 definitio...
Create a new LoadBalancer service named log-aggregator-lb with a TCP port mapping from 8000 to 8010.
Command: ```bash kubectl create service loadbalancer log-aggregator-lb --tcp=8000:8010 ``` 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", "...
Create a copy of the auth-service-pod, replacing the code-explorer container with a debug image, and access the shell of the debug container
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-memcached --container=code-explorer -- 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 ...
Embed the certificate authority data for the 'cluster-alpha' cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
Delete the pods and services with the names "cdn" and "auth"
Command: ```bash kubectl delete pod,service cdn auth ``` 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. Some r...
Check if you have permission to list the job named "data-migration-job" in the "production" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n production ``` 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 ...
List deployments in YAML output format using the "v3.0.0" version of the "external-apps" API group.
Command: ```bash kubectl get deployments.v3.0.0.external-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 w...
List the deployments in the "legacy-apps" API group with the version "v1.1.1" in YAML output format.
Command: ```bash kubectl get deployments.v1.1.1.legacy-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...
Remove the label named 'tier' from the pod named 'foo'
Command: ```bash kubectl label pods foo 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 true, ch...
Import the specified keys from a config map into a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-config deployment/user-management-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 ...
Execute the 'npm --version' command in the first container of the 'user-service' service and display the output.
Command: ```bash kubectl exec svc/user-service -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Edit the YAML configuration of the 'log-aggregator-deployment' deployment and save the modified configuration in its annotation.
Command: ```bash kubectl edit deployment/log-aggregator-deployment -o yaml --save-config ``` 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 e...
Open the backend-service service for editing using the gedit editor
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/backend-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 variable...
Create a job named "audit-job" using the nginx image, running the command "nginx"
Command: ```bash kubectl create job audit-job --image=nginx -- nginx ``` 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...
Embed the certificate authority data for the edge-cluster cluster entry with the command "kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/dev-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/dev-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/gateway-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 namespaced...
Create a job named "security-scan-job" using the "mongo" image, and run the command "mongod" inside the job.
Command: ```bash kubectl create job security-scan-job --image=mongo -- mongod ``` 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. ...
Create a cluster role named "reader" with the ability to delete services and specific resource names, such as "content-delivery" and "app-worker-1"
Command: ```bash kubectl create clusterrole reader --verb=delete --resource=services --resource-name=content-delivery --resource-name=app-worker-1 ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Create a copy of the email-service-pod, changing all container images to nginx, and name it my-debugger
Command: ```bash kubectl debug email-service-pod --copy-to=my-debugger --set-image=*=nginx ``` 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 res...
Update pod 'backend' with the label 'component' and the value 'api'
Command: ```bash kubectl label pods backend component=api ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": ...
Import the specific keys "redis_host" from the config map "app-name-config" into the environment of the "payment-processor-deployment" deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-name-config 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 d...
Create a new ExternalName service named 'external-metrics-service' with the external name 'bar.com'
Command: ```bash kubectl create service externalname external-metrics-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 tha...
Create a job to run the command 'wp' using the 'wordpress' image
Command: ```bash kubectl create job database-seeding-job --image=wordpress -- wp ``` 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 forma...
Create a secret named api-key-secret with keys for each file in the specified folder.
Command: ```bash kubectl create secret generic api-key-secret --from-file=path/to/options ``` 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 th...
Set the custom TLS server name to "kube-cluster-2" for the "data-cluster" cluster entry.
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=kube-cluster-2 ``` 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...
Configure autoscaling for the "frontend" deployment, with a minimum of 3 pods and a maximum of 14 pods.
Command: ```bash kubectl autoscale deployment frontend --min=3 --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 use...
Get the output from running the 'apk add curl' command in the 'mycontainer' container of the 'payment-gateway-pod' pod.
Command: ```bash kubectl exec payment-gateway-pod -c mycontainer -- apk add curl ``` 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 om...
Copy a local file to a remote pod in a specific container
Command: ```bash kubectl cp :/tmp/foo security-scanner-pod-18:/tmp/bar -c image-resizer ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Start a pod using the image 'confluentinc/cp-kafka'
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka ``` 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...
Create a new secret named encryption-key-secret from an env file
Command: ```bash kubectl create secret generic encryption-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...
Create a debug container by copying the email-service-pod and specify the debian image for the debug container
Command: ```bash kubectl debug email-service-pod -it --copy-to=my-debugger --image=debian --set-image=cache=redis:alpine,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Start a pod named nginx using the centos image and run a different command with custom arguments
Command: ```bash kubectl run nginx --image=centos --command -- <cmd> <arg1> ... <argN> ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpfu...
Get the output from running the 'elasticsearch' command in the 'nano-bot' container from the pod 'api-service-pod'
Command: ```bash kubectl exec api-service-pod -c nano-bot -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create a new ClusterIP service named shipping-service-clusterip
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=8082:5001 ``` 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...