prompt
stringlengths
13
282
response
stringlengths
128
3.11k
List deployments in YAML format with the specified version and API group.
Command: ```bash kubectl get deployments.custom-version.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 ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-prod deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Set the service account of the deployment "authentication-service-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment my-service-account ``` 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), statef...
Create an ingress named 'app-gateway-ingress' that routes requests from testing.com/module to svc1:8443 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/module=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": ""...
Create a Pod Disruption Budget named cache-cluster-pdb that will select all pods with the tier=frontend label and ensure that at least one of them is always available.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-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=...
Create a cron job called "data-processing" that runs the command "php --version" every minute
Command: ```bash kubectl create cronjob data-processing --image=php --schedule="*/1 * * * *" -- php --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", "short": "-...
Retrieve the snapshot logs from the container named web-app-deployment-1 in the deployment named mypod.
Command: ```bash kubectl logs deployment/web-app-deployment -c mypod-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: "flag": "--contai...
Auto scale the replication controller "frontend" with a minimum of 1 and a maximum of 3 pods, targeting a CPU utilization of 50%.
Command: ```bash kubectl autoscale rc frontend --max=3 --cpu-percent=50 ``` 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...
Set the service account of the deployment "scheduler-app-deployment" to "spinnaker"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment spinnaker ``` 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...
Forward local port 8888 to port 6379 in a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 8888 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selecte...
Create a new config map named env-vars with the properties and key1 keys from the specified files
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/properties/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...
Create an ingress called 'public-service-ingress' that routes requests from website.com/input to the service named svc1 listening on port 8084, using the TLS secret named "my-cert".
Command: ```bash kubectl create ingress public-service-ingress --rule="website.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": ...
Partially update a node using a strategic merge patch with a JSON patch.
Command: ```bash kubectl patch node monitoring-node-15 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 pat...
Create a service for the replicated nginx using replica set, which will serve on port 80 and connect to the containers on port 543200
Command: ```bash kubectl expose rs nginx --port=80 --target-port=543200 ``` 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 ...
Add a taint with key 'zone' on nodes having label service=auth
Command: ```bash kubectl taint node -l service=auth zone=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output...
Create a copy of the "api-service-pod" with a debug container and different container images
Command: ```bash kubectl debug api-service-pod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,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...
Set the resource request and limits for all containers in the kafka deployment
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=64Mi ``` 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 request...
Start forwarding traffic from port 8088 on both localhost and IP 10.19.21.23 to port 9090 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8088: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...
Create a custom debug pod by copying the frontend-pod and changing the command of the container "lunar-launcher" to start a shell session.
Command: ```bash kubectl debug frontend-pod -it --copy-to=my-custom-dbg --container=lunar-launcher -- 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 def...
Copy the local file /tmp/foo to the remote pod logging-agent-pod-7 in the kube-node-lease namespace, and save it as /tmp/bar.
Command: ```bash kubectl cp /tmp/foo kube-node-lease/logging-agent-pod-7:/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...
Taint nodes with label 'team=devops' adding a taint with key 'hardware=db-node-7' and effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l team=devops hardware=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": "Outp...
Create a deployment named ingress that runs the postgres image
Command: ```bash kubectl create deployment ingress --image=postgres ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|...
Create a copy of the database pod, changing all container images to hazelcast/hazelcast for debugging purposes
Command: ```bash kubectl debug database-pod --copy-to=debug-image-1 --set-image=*=hazelcast/hazelcast ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by defaul...
Forward port 9090 locally to port 5000 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 9090:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Create a pod disruption budget named load-balancer-pdb that selects all pods with the version=v2 label and ensures that at least one of them is available at any point in time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=version=v2 --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 [...
Create a job named "security-scan-job" using the "node" image and running the "npm --version" command.
Command: ```bash kubectl create job security-scan-job --image=node -- npm --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 fo...
Create a new ClusterIP service named shipping-service-clusterip
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=9090:27017 ``` 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": "-...
Create a service to expose the wordpress replicated controller on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose rc wordpress --port=80 --target-port=888800 ``` 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 local port 9090 to the target port of the "https" service port in the pod selected by the "payment-service" service
Command: ```bash kubectl port-forward service/payment-service 9090:https ``` 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...
Update the 'proxy-server' pod by adding an annotation with the key 'criticality' and the value 'high', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server criticality='high' ``` 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 in...
Forward traffic from port 8081 on all addresses to port 3000 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8081:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Create a role named "foo" with the ability to only get pods with the resource names "keycloak-server" and "database-master"
Command: ```bash kubectl create role foo --verb=get --resource=pods --resource-name=keycloak-server --resource-name=database-master ``` 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=server|cli...
Import the 'log_level' key from the 'app-config-prod' config map and set it as an environment variable in the 'payment-processor-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-prod 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 de...
Update the pod named 'backend' with the annotation 'last-deployment' and the value '2023-03-15'.
Command: ```bash kubectl annotate pods backend last-deployment=2023-03-15 ``` 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...
Run the 'redis-server' command in the first container of the 'frontend-deployment' deployment and display the output.
Command: ```bash kubectl exec deploy/frontend-deployment -- 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 omitted, u...
Import the `config_file_path` key from the `app-secrets` ConfigMap into the environment of the `api-server-deployment` deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-secrets deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Forward local port 6379 to port 6379 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 6379:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Output the modified YAML of the frontend-deployment deployment with the environment variable DB_HOST set to localhost
Command: ```bash kubectl set env deployment/frontend-deployment DB_HOST=localhost -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...
Copy the local file `/tmp/foo` to the remote pod named `logging-agent-pod-7` in the `prometheus` namespace, placing it in the destination directory `/tmp/bar_dir`.
Command: ```bash kubectl cp /tmp/foo prometheus/logging-agent-pod-7:/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 the...
Get the output of the 'python --version' command from the pod named 'web-app-pod' in the container 'cyber-sleuth'
Command: ```bash kubectl exec web-app-pod -c cyber-sleuth -- python --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 new NodePort service named auth-service-nodeport with the port mapping TCP 7000:5432.
Command: ```bash kubectl create service nodeport auth-service-nodeport --tcp=7000:5432 ``` 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", "default"...
Create a pod disruption budget that ensures at least 9 pods with the label project=my-project are always available.
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=project=my-project --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-av...
Create an ingress called 'private-service-ingress' that directs requests to website.com/bar to svc1:8888 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/bar=svc1:8888,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 of the "my-apps" API group in the "hotfix-1.1.2" version, and output the results in JSON format.
Command: ```bash kubectl get deployments.hotfix-1.1.2.my-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Import specific keys from a config map to set environment variables for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/global-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Create a copy of the media-stream-pod named my-debugger, with all container images changed to redis
Command: ```bash kubectl debug media-stream-pod --copy-to=my-debugger --set-image=*=redis ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Add a taint with key 'app' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe app=web-node-8: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": "Outpu...
Create an ingress resource named 'private-api-ingress' that directs requests for 'website.com/bar' to the service 'svc1:5001' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="website.com/bar=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Copy the ~/.config/kube file from the remote pod "argocd/backend-pod-13" to the local directory /tmp/bar
Command: ```bash kubectl cp argocd/backend-pod-13:~/.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 the kubect...
Add a taint with key 'zone' on nodes having label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 zone=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Retrieve the logs of the previously terminated "mycontainer" container from the "email-service-pod" pod.
Command: ```bash kubectl logs -p -c mycontainer email-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Print the output of running the 'mysql' command inside the backend-pod using the first container
Command: ```bash kubectl exec backend-pod -- mysql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kuberne...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/ui-config 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 defin...
Forward traffic from localhost port 8000 to port 3000 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 8000 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 automaticall...
Edit the configuration of a service using the nvim editor
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/scheduler-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 variabl...
Set the custom TLS server name "on-prem-cluster" for the "app-cluster" cluster entry.
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=on-prem-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Create a new NodePort service named my-ns that forwards traffic from port 8888 to port 6379
Command: ```bash kubectl create service nodeport my-ns --tcp=8888:6379 ``` 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", "default": "", "usage": "...
Create a copy of the e-commerce pod with a debug container and updated container images.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-1 --image=debian --set-image=web=nginx:latest,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Set the resource requests and limits for all containers in the 'alpine' deployment with a CPU limit of 200m and memory limit of 512Mi, and a CPU request of 1 and memory request of 256Mi.
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Create an ingress resource called 'external-ingress' with a rule that directs requests for foo.com/example to the service 'svc1' on port 6379
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/example=svc1:6379,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a copy of the api-service-pod and change all container images to confluentinc/cp-kafka for debugging
Command: ```bash kubectl debug api-service-pod --copy-to=my-custom-dbg --set-image=*=confluentinc/cp-kafka ``` 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 d...
Update the annotation for a pod, overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods gateway SLA='99.9% uptime' ``` 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...
Open an interactive shell in the lunar-launcher container of the web-app-pod pod.
Command: ```bash kubectl exec web-app-pod -c lunar-launcher -- 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 th...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/kube-system-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 defin...
Import the 'secret_key' key from the 'api-config' ConfigMap into the 'database-deployment' deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/api-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Create an ingress called 'public-service-ingress' that routes requests to website.com/example to a service named svc1 on port 8181
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/example=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default"...
Start a pod named 'nginx' using the 'confluentinc/cp-kafka' image, but override the specification with a partial set of values parsed from a JSON file.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --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] [...
Get deployments in JSON output format from the "alpha-2.0" version of the "external-apps" API group
Command: ```bash kubectl get deployments.alpha-2.0.external-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 yo...
Execute the 'nginx -t' command in the time-machine container of the pod named 'gateway-pod'
Command: ```bash kubectl exec gateway-pod -c time-machine -- 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, use ...
Set the cpu and memory limits for the wordpress container in the deployment to 3 and 64Mi respectively
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=3,memory=64Mi ``` 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...
Start a pod using the php image, but customize the pod specification using a JSON override.
Command: ```bash kubectl run nginx --image=php --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] -- [COMMAND...
Create a new config map named api-config with the keys "settings" and "key2" using the files /path/to/parameters/file1.txt and /path/to/properties/file2.txt respectively
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/path/to/properties/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...
Execute the 'geth' command inside the pod named 'api-service-pod' and get the output.
Command: ```bash kubectl exec api-service-pod -- geth ``` 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.kube...
Attach to the stardust-shuttle container in the media-stream-pod pod to get its output.
Command: ```bash kubectl attach media-stream-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 omi...
Switch to a raw terminal mode and connect to the 'cosmic-container' in the 'backend-pod' pod
Command: ```bash kubectl attach backend-pod -c cosmic-container -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 om...
Create a debug copy of the api-service-pod by adding a debug container and changing container images
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-web --image=debian --set-image=api=api:v2,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. ...
Forward local port 3000 to port 8088 in the pod named 'mypod' using the IP address 'localhost' and '10.19.21.23'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Create a pod disruption budget named messaging-pdb that selects all pods with the owner=team-1 label and requires a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=owner=team-1 --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 [--...
Create an ingress called 'default-ingress' that directs requests to foo.com/module to svc1:8181 with a tls secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/module=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Set up autoscaling for the replication controller 'security' with a target CPU utilization of 60% and a maximum of 2 pods.
Command: ```bash kubectl autoscale rc security --max=2 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Execute the 'mysql --version' command in the time-machine container of the gateway-pod pod and retrieve the output
Command: ```bash kubectl exec gateway-pod -c time-machine -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Import the SECRET_KEY from the config map named 'monitoring-config' into the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/monitoring-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/web-app-pod 3000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Rename the context 'local-context' to 'service-account-context' in your kubeconfig file
Command: ```bash kubectl config rename-context local-context service-account-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field ...
Copy the ~/.config/kube file from the remote pod "front-end-pod-12" to the /etc/kubernetes directory on your local machine.
Command: ```bash kubectl cp logging/front-end-pod-12:~/.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 ...
Import the "external_api_url" key from the "app-config-prod" ConfigMap and set it as an environment variable for the "order-processing-deployment" deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config-prod 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 varia...
Start streaming the logs of the 'cosmic-container' container in the 'mypod' pod
Command: ```bash kubectl logs -f -c cosmic-container mypod ``` 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...
Port-forward the local port 3000 to the pod's port 8000
Command: ```bash kubectl port-forward pod/api-service-pod 3000: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 au...
Expose the replica set "ruby" as a service on port 5000, which will connect to the containers on port 300000.
Command: ```bash kubectl expose rs ruby --port=5000 --target-port=300000 ``` 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...
Import specific keys from a config map to set environment variables for a deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/namespace-config 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 v...
Approve the Certificate Signing Request (CSR) for 'csr-node-1'
Command: ```bash kubectl certificate approve csr-node-1 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attribu...
Forward local port 8888 to port 6379 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 8888:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Retrieve the snapshot logs from the container "backend-pod-1" of the deployment named "order-processing-deployment".
Command: ```bash kubectl logs deployment/order-processing-deployment -c backend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "f...
Update the deployment 'api-server-deployment' by setting the environment variable SMTP_PASSWORD to 'your-password'
Command: ```bash kubectl set env deployment/api-server-deployment SMTP_PASSWORD=your-password ``` 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 ...
Update the annotation 'compliance-level' of the pod named 'database' to 'PCI-DSS', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods database compliance-level='PCI-DSS' ``` 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 an...
Create an ingress called 'app2-ingress' that directs requests to 'site.com/example' to the 'svc1' service on port '9090' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/example=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"...
Check if you have permissions to list the "content-import-job" job in the "staging" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/content-import-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 URL...
Expose the nginx deployment as a service on port 8443, connecting to the containers on port 8888.
Command: ```bash kubectl expose deployment nginx --port=8443 --target-port=888800 ``` 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 specifie...
Execute the 'pg_dump --version' command inside the security-service-pod and display the output.
Command: ```bash kubectl exec security-service-pod -- pg_dump --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...
Import specific keys from a config map and set them as environment variables in a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/global-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...