prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a taint with key 'dedicated' on nodes having the label 'myLabel' and value 'dev-node-4' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel dedicated=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": "Output...
Start a postgres pod with custom spec values from JSON
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "v3.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
List the replication controller named "web", the service named "monitoring-rc", and the pod named "proxy-server-pod"
Command: ```bash kubectl get rc/web service/monitoring-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 namesp...
Set the custom TLS server name for the "sun-cluster" cluster entry
Command: ```bash kubectl config set-cluster sun-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...
Auto scale the deployment "monitoring" with a minimum of 7 pods and a maximum of 14 pods.
Command: ```bash kubectl autoscale deployment monitoring --min=7 --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 u...
Expose a replica set as a service, serving on port 8443 and connecting to the containers on port 8000
Command: ```bash kubectl expose rs hazelcast --port=8443 --target-port=8000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port...
Execute the 'node' command in the first container of the first pod of the 'loadbalancer-service' service and get the output.
Command: ```bash kubectl exec svc/loadbalancer-service -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Create a new ExternalName service called 'external-email-service' with the external name 'sample-domain.net'
Command: ```bash kubectl create service externalname external-email-service --external-name sample-domain.net ``` 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 serv...
Forward local port 8088 to remote port 8888 of the pod selected by the deployment "search-engine-deployment".
Command: ```bash kubectl port-forward deployment/search-engine-deployment 8088 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
List the replication controller named 'web', the service named 'frontend-rc', and the pod named 'monitoring-pod'
Command: ```bash kubectl get rc/web service/frontend-rc pods/monitoring-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...
Add a taint with key 'hardware' on nodes having a label 'project=project-alpha' and value 'backup-node-14' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l project=project-alpha hardware=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Create a new config map named global-config with keys and values from specified files
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/profiles/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 creat...
Import the 'secret_key' from the 'global-config' config map into the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/global-config 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 defi...
Import the LOG_LEVEL key from the monitoring-config ConfigMap and set it as an environment variable for the load-balancer-deployment Deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/monitoring-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 defi...
Create a pod disruption budget named payment-gateway-pdb that will select all pods with the version=v2 label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=version=v2 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Retrieve logs from all containers in the pods labeled with 'team=devops'
Command: ```bash kubectl logs -l team=devops --all-containers=true ``` 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"...
Create a cluster role named "view" with the verb "list" and the non-resource URL "/port-forward" specified.
Command: ```bash kubectl create clusterrole "view" --verb=list --non-resource-url=/port-forward ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "sh...
Forward local port 8088 to port 5432 in the pod web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 8088 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a config map named app-config-prod with specified keys and their corresponding files.
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/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 creati...
Import the `secret_key` key from the `kube-system-config` config map and set it as an environment variable for the `web-app-deployment` deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/kube-system-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 definiti...
Get the documentation for a specific field of a resource
Command: ```bash kubectl explain resource=services.spec.selector ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag to...
Create a service for the replicated php using replica set, which serves on port 8089 and connects to the containers on port 637900
Command: ```bash kubectl expose rs php --port=8089 --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 ...
Update the annotation 'scaling-policy' of the pod 'database' to 'auto-horizontal-scaling', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods database scaling-policy='auto-horizontal-scaling' ``` 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 ...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/monitoring-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...
Update the image of all containers in the daemonset "test" to "ruby:3.0.2"
Command: ```bash kubectl set image daemonset test *=ruby:3.0.2 ``` 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: `kubectl ...
Attach to a specific container within a pod and interact with it in raw terminal mode
Command: ```bash kubectl attach media-stream-pod -c time-machine -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/monitoring-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
import the 'log_level' key from the 'global-config' config map and set it as an environment variable in the 'mydeployment' deployment
Command: ```bash kubectl set env --keys=log_level --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 in one o...
Assign the label 'role' with the value 'backend' to the pod 'security'
Command: ```bash kubectl label pods security role=backend ``` 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": ...
Create a job named 'indexing' with the image 'ethereum/client-go' and execute the command 'geth version' inside the job.
Command: ```bash kubectl create job indexing --image=ethereum/client-go -- geth 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": "Outpu...
Return the snapshot logs from the analytics-pod pod
Command: ```bash kubectl logs analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c", "defau...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/api-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Copy the file named 'foo' located at '/tmp' on the local machine to the '/tmp' directory inside the 'bar' pod in the 'prometheus' namespace.
Command: ```bash kubectl cp :/tmp/foo prometheus/metrics-exporter-pod-10::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Forward port 8888 on localhost and IP 10.19.21.23 to port 3000 in the analytics-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8888: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 crite...
Create an ingress resource named 'api-ingress' with a rule that directs requests for 'website.com/bar' to the service 'svc1' on port 8088
Command: ```bash kubectl create ingress api-ingress --rule="website.com/bar=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": "", "usage": ...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/data/file1.txt --from-file=key1=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Check if you can list the 'cleanup-job' job in the 'development' namespace
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-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 URL th...
Create a deployment named wordpress using the golang image and expose port 8082
Command: ```bash kubectl create deployment wordpress --image=golang --port=8082 ``` 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...
Forward local port 5000 to port 5432 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward pod/security-service-pod 5000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Update the deployment 'mydeployment' by adding a new environment variable QUEUE_NAME with the value 'task-queue'.
Command: ```bash kubectl set env deployment/mydeployment QUEUE_NAME=task-queue ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (with...
Create a new secret named cert-manager-secret with keys for each file in folder bar
Command: ```bash kubectl create secret generic cert-manager-secret --from-file=path/to/configs ``` 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 ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --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 i...
import the 'LOG_LEVEL' key from the 'app-config-prod' config map to the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-prod 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 defini...
Execute the 'python' command in the 'astro-container' inside the 'log-aggregator-pod' pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c astro-container -- python ``` 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...
Set the service account of deployment "email-server-deployment" to "gitlab-runner"
Command: ```bash kubectl set serviceaccount deployment email-server-deployment gitlab-runner ``` 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: ...
Import keys from a config map to a deployment's environment variables
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...
Create an ingress called 'service-ingress' with a rule that directs requests to testing.com/input to svc # svc1:9000
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/input=svc1:9000,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": "", "us...
Create a new config map named app-secrets with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
Create a deployment named db that runs the node image
Command: ```bash kubectl create deployment db --image=node ``` 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|name|go-t...
Update the release notes annotation for a pod identified by type and name in "conf.json" file
Command: ```bash kubectl annotate -f conf.json release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larg...
Set environment variables using specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/env-vars deployment/scheduler-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 definit...
Auto scale the 'log-aggregator' deployment, allowing the number of pods to vary between 3 and 15.
Command: ```bash kubectl autoscale deployment log-aggregator --min=3 --max=15 ``` 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 th...
Forward local traffic from port 8088 to port 5000 on a pod selected by the deployment "authentication-service-deployment".
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8088 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, ...
Add a taint with the key 'disktype' and the value 'node-1:PreferNoSchedule' to nodes that have the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 disktype=node-1: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 specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/ui-config 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 definiti...
Add a taint to 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 o...
Display the most recent 43 lines of logs for pod gateway-pod
Command: ```bash kubectl logs --tail=43 gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c"...
Create a deployment named my-dep with the confluentinc/cp-kafka image
Command: ```bash kubectl create deployment my-dep --image=confluentinc/cp-kafka ``` 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...
Add a taint with key 'dedicated' on nodes having the label app-type=microservice, and the taint value as 'testing-node-11:PreferNoSchedule'
Command: ```bash kubectl taint node -l app-type=microservice dedicated=testing-node-11: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": "...
Retrieve the logs of the previously terminated "cyber-sleuth" container from the "backend-pod" pod.
Command: ```bash kubectl logs -p -c cyber-sleuth backend-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...
Retrieve the snapshot logs from the container "vpn-service-pod-1" of the deployment "api-server-deployment".
Command: ```bash kubectl logs deployment/api-server-deployment -c vpn-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...
Listen on port 9090 on all addresses, and forward the traffic to the 3000 port of the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 9090: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 w...
Retrieve the snapshot logs from the container named 'web-app-pod-1' in the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c web-app-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: "flag...
Forward local port 8080 to port 9090 in the backend-pod and locally listen on port 8080.
Command: ```bash kubectl port-forward pod/backend-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 automa...
Create a new ExternalName service named external-metrics-service and set its external name as placeholder-app.app
Command: ```bash kubectl create service externalname external-metrics-service --external-name placeholder-app.app ``` 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 ...
Create a role named "reader" with the following permissions:
Command: ```bash kubectl create role reader --verb=watch --resource=pods --resource-name=error-logger --resource-name=cdn-proxy ``` 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|client|...
Get output from running a command in a specific container within a pod
Command: ```bash kubectl exec mypod -c lunar-launcher -- kafka-server-start /etc/kafka/server.properties ``` 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"...
Use 'notepad' as the editor to edit the 'backend-service' service
Command: ```bash KUBE_EDITOR="notepad" 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 variab...
Listen on port 6379 on all addresses and forward the traffic to the 'proxy-server-pod' pods 8088 port
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 6379: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 ...
Display the resource usage metrics for the 'edge-node-10' node.
Command: ```bash kubectl top node edge-node-10 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=api_key --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 definit...
Forward all traffic from port 8888 on all addresses to port 3000 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8888: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 ...
Edit the 'notification-service' service configuration
Command: ```bash kubectl edit svc/notification-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back...
Taint node 'edge-node-10' with a key 'special', value 'backup', and effect 'NoSchedule', replacing any existing taint with the same key and effect.
Command: ```bash kubectl taint nodes edge-node-10 special=backup: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. O...
Set the service account for the 'api-server-deployment' deployment to 'default'
Command: ```bash kubectl set serviceaccount deployment api-server-deployment default ``` 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...
Copy the local file /tmp/foo_dir to the remote pod kube-node-lease/database-pod-2 in the /tmp/bar_dir directory
Command: ```bash kubectl cp /tmp/foo_dir kube-node-lease/database-pod-2:/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...
Scale the deployment named "web" to have 3 replicas, keeping its current size as 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=3 deployment/web ``` 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...
Auto scale the replication controller "log-aggregator" with a target CPU utilization of 60% and a minimum of 1 pod and a maximum of 8 pods.
Command: ```bash kubectl autoscale rc log-aggregator --max=8 --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 th...
Create a service named "frontend" to expose the analytics-pod. The service should serve on port 444.
Command: ```bash kubectl expose pod analytics-pod --port=80 --name=frontend ``` 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...
Add a taint with the key 'environment' on nodes that have the label environment=production, specifically on the node named 'db-node-7', and set the taint effect as 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l environment=production environment=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": "", ...
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-app --image=debian --set-image=worker=my-custom-worker:1.2.3,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects iden...
Create a copy of the payment-gateway-pod with all container images changed to "confluentinc/cp-kafka"
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-1 --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 ...
Update the "client-key" field for the "cluster-admin" entry in the kubeconfig file, without modifying any other values
Command: ```bash kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key ``` 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-key=keyfile Bearer tok...
Execute the 'node' command within the pod named 'email-service-pod' and retrieve the output.
Command: ```bash kubectl exec email-service-pod -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Create a service named "frontend" that exposes the "security-service-pod" pod on port 9092.
Command: ```bash kubectl expose pod security-service-pod --port=9092 --name=frontend ``` 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 speci...
Forward local port 8000 to port 8888 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-pod 8000: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 autom...
Create a copy of the 'security-service-pod' pod as 'debug-image-1' while changing all container images to 'mcr.microsoft.com/dotnet/core/runtime'
Command: ```bash kubectl debug security-service-pod --copy-to=debug-image-1 --set-image=*=mcr.microsoft.com/dotnet/core/runtime ``` 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. P...
Set the service account of the 'monitoring-stack-deployment' deployment to 'metrics-server'
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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 Syn...
Listen on your local machine's port 8000 and forward the traffic to port 6379 on the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-pod 8000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a job named 'indexing' using the 'centos' image and run the command 'yum install -y wget'
Command: ```bash kubectl create job indexing --image=centos -- yum install -y wget ``` 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 for...
Switch to the cluster-beta context
Command: ```bash kubectl config use-context cluster-beta ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Listen on port 8000 on localhost and IP 10.19.21.23, and forward the traffic to port 8888 in the backend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8000: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 criteri...
Listen on port 6379 on localhost and IP address 10.19.21.23, forwarding it to port 3000 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 6379: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 criteri...
Switch to the star-cluster context
Command: ```bash kubectl config use-context star-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Create a cluster role named "view" with SubResource specified
Command: ```bash kubectl create clusterrole view --verb=list,create,update --resource=nodes,nodes/proxy ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--outp...
Forward traffic from local ports 8081 and 6000 to ports 5432 and 6000 respectively in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8081 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Copy the file "/tmp/foo" from the remote pod "kube-system/load-balancer-pod-9" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp kube-system/load-balancer-pod-9::/tmp/foo /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, us...
List the deployments in the "v1.0.0" version of the "alpha-apps" API group in YAML output format
Command: ```bash kubectl get deployments.v1.0.0.alpha-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will...
Create a cluster role named "custom_role" with the ability to delete services and access backup-service and file-storage
Command: ```bash kubectl create clusterrole custom_role --verb=delete --resource=services --resource-name=backup-service --resource-name=file-storage ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server...
Set the cluster field in the 'app-1-context' context to 'sun-cluster'
Command: ```bash kubectl config set contexts.app-1-context.cluster sun-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wan...