prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the service account of the deployment "monitoring-stack-deployment" to "prometheus".
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment prometheus ``` 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:...
Deny the Certificate Signing Request (CSR) with the name 'csr-api-server-2'
Command: ```bash kubectl certificate deny csr-api-server-2 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kube...
Create a copy of proxy-service-pod with a debug container and modified container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-app --image=debian --set-image=app=app:debug,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 res...
update the image of all containers in the 'services' daemonset to 'amazonlinux:2'
Command: ```bash kubectl set image daemonset services *=amazonlinux: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: `k...
Delete the pods and services with the names "proxy-server" and "gateway"
Command: ```bash kubectl delete pod,service proxy-server gateway ``` 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 sele...
Set the service account of the deployment "authentication-service-deployment" to "dashboard"
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment dashboard ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Sy...
Create a job called "deployment-rollout-job" using the Alpine image and run the command "apk add curl"
Command: ```bash kubectl create job deployment-rollout-job --image=alpine -- apk add curl ``` 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": "Out...
Create a pod disruption budget named logging-pdb that selects all pods with the env=production label and requires at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=env=production --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 [--...
Start listening on port 8080 on your local machine and forward the traffic to port 6379 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 8080:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Update the 'load-balancer-deployment' deployment by adding a new environment variable 'DEBUG' with a value of 'true'.
Command: ```bash kubectl set env deployment/load-balancer-deployment DEBUG=true ``` 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 (wit...
Start the nginx pod using a different command and custom arguments
Command: ```bash kubectl run nginx --image=nginx --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...]` Helpful...
Create a ClusterIP service named inventory-service-clusterip that maps port 8084 in the service to port 3001 on the backend pods.
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=8084:3001 ``` 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": "-...
Import the environment variables from the 'app-settings' config map with the prefix 'MYSQL_' into the 'authentication-service-deployment' deployment
Command: ```bash kubectl set env --from=configmap/app-settings --prefix=MYSQL_ 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...
Remove the taint with key 'workload' from node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 workload- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|n...
Create a new secret named "encryption-key-secret" with keys for each file in the "path/to/configurations" folder.
Command: ```bash kubectl create secret generic encryption-key-secret --from-file=path/to/configurations ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the ...
Check if you have permission to list the job named "batch-processing-job" in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n kube-dns ``` 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 ...
Forward local port 9090 to port 9090 in the pod selected by the api-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 9090 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 b...
Create a new LoadBalancer service named media-stream-lb with the TCP port mapping of 8181 to 8443.
Command: ```bash kubectl create service loadbalancer media-stream-lb --tcp=8181:8443 ``` 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", "de...
Expose the pod "e-commerce-pod" as a service named "frontend" on port 444
Command: ```bash kubectl expose pod e-commerce-pod --port=8088 --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 p...
Create a new config map named app-config-prod using the specified files as keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/data/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 ...
import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-secrets deployment/analytics-platform-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...
Retrieve the logs of the previous terminated "astro-container" container from the "media-stream-pod" pod.
Command: ```bash kubectl logs -p -c astro-container media-stream-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": "--containe...
Create a new ExternalName service named 'external-geolocation-service' that maps to the external name 'news-demo.news'
Command: ```bash kubectl create service externalname external-geolocation-service --external-name news-demo.news ``` 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 s...
Add a taint with key 'disktype' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice disktype=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Copy the directory '/tmp/foo_dir' from the remote pod 'ingress-controller-pod-8' in the 'kube-server' cluster to the '/tmp/bar' directory locally.
Command: ```bash kubectl cp kube-server/ingress-controller-pod-8:/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, ...
List the resources of type "ReplicationController" named "web", the resources of type "Service" named "proxy-service-rc", and the resources of type "Pod" named "proxy-server-pod"
Command: ```bash kubectl get rc/web service/proxy-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 nam...
import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-name-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Import the LOG_LEVEL key from the monitoring-config config map into the environment variables of the user-management-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/monitoring-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 de...
Create a service for a replication controller specified in "wordpress-controller.yaml" with port 8082, connecting to containers on port 808900.
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8082 --target-port=808900 ``` 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 ...
Set up autoscaling for the 'backend' deployment with a minimum of 3 pods and a maximum of 12 pods
Command: ```bash kubectl autoscale deployment backend --min=3 --max=12 ``` 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 uses...
Execute the command 'nginx -t' inside the 'time-machine' container of the 'cdn-service-pod' pod and get the output.
Command: ```bash kubectl exec cdn-service-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, ...
Forward traffic from port 6379 on all available IP addresses to port 8000 in the pod named cdn-service-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 6379:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Import the SECRET_KEY key from the config map named app-name-config into the environment variables of the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-name-config deployment/analytics-platform-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 ...
Return the logs of the previous terminated 'ruby' container from the 'vpn-service-pod' pod.
Command: ```bash kubectl logs -p -c ruby vpn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short":...
Import the SECRET_KEY key from the app-secrets ConfigMap and set it as an environment variable in the proxy-service-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-secrets 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 definitio...
import the MAX_CONNECTIONS key from the config map named namespace-config into the environment variables of the authentication-service-deployment deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/namespace-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...
Set the cluster field in the local-context context to edge-cluster
Command: ```bash kubectl config set contexts.local-context.cluster edge-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 wa...
Forward local port 8080 to port 5000 in the 'database-deployment' pod.
Command: ```bash kubectl port-forward deployment/database-deployment 8080 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 ...
Add a taint with key 'zone' and no value to the 'prod-node-5' node.
Command: ```bash kubectl taint nodes prod-node-5 zone: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 of: json...
Apply the configuration in manifest.yaml that matches the label 'role=database' and delete all other resources that are not in the file and match the label 'app=nginx'
Command: ```bash kubectl apply --prune -f manifest.yaml -l role=database ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or '...
Add a taint to nodes labeled with 'cluster=my-cluster' with the key 'zone' and value 'backup-node-14' with the effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l cluster=my-cluster zone=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8888 inside the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8088:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
attach to the chat-app-pod and get output from the nano-bot container
Command: ```bash kubectl attach chat-app-pod -c nano-bot ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Begin streaming the logs from all containers in pods that have the label team=devops
Command: ```bash kubectl logs -f -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": "--contain...
Retrieve the output from running the 'elasticsearch --version' command in the 'lunar-launcher' container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c lunar-launcher -- elasticsearch --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....
Forward port 5432 on localhost and IP 10.19.21.23 to port 3000 in the pod "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 5432: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...
Update the node node-1 to make it unschedulable
Command: ```bash kubectl patch node node-1 -p $'spec:\n unschedulable: true' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags...
Create a pod disruption budget named payment-gateway-pdb that selects all pods with the owner=team-1 label and ensures that at least one of them is always available.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-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...
Taint nodes with a label 'tier=frontend' using a taint key 'hardware' and a value 'backup-node-14' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l tier=frontend 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": "", "usage"...
View the most recent 43 lines of logs for a specific pod
Command: ```bash kubectl logs --tail=43 log-aggregator-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...
Create a copy of the frontend-pod named my-custom-dbg, adding a debian debug container and changing the cache container image to redis:alpine and the logger container image to logging-app:debug.
Command: ```bash kubectl debug frontend-pod -it --copy-to=my-custom-dbg --image=debian --set-image=cache=redis:alpine,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...
Add a taint with the key 'disktype' and the value 'testing-node-11:PreferNoSchedule' on nodes that have the label 'component=proxy'.
Command: ```bash kubectl taint node -l component=proxy disktype=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": "", "usa...
Forward traffic from port 8081 on localhost and IP 10.19.21.23 to port 5432 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Forward local port 3000 to port 8080 in the pod named chat-app-pod
Command: ```bash kubectl port-forward pod/chat-app-pod 3000 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named global-config using the specified keys and file paths
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When...
Copy the file /tmp/foo from the remote pod monitoring-agent-pod-6 in the istio-system namespace to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp istio-system/monitoring-agent-pod-6:/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, us...
Import environment variables from the 'app-secrets' ConfigMap with the prefix 'MYSQL_' into the 'mydeployment' deployment.
Command: ```bash kubectl set env --from=configmap/app-secrets --prefix=MYSQL_ 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 or m...
Remove the pods and services named "backend" and "cdn"
Command: ```bash kubectl delete pod,service backend cdn ``` 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. Som...
Copy the file /tmp/foo from the /tmp directory in the 'monitoring/payment-gateway-pod-19' pod to the /tmp directory locally
Command: ```bash kubectl cp monitoring/payment-gateway-pod-19::/tmp/foo :/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...
Apply a taint to nodes with the label "namespace=mynamespace"
Command: ```bash kubectl taint node -l namespace=mynamespace 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"...
Import the 'LOG_LEVEL' key from the 'app-config-dev' config map to the deployment 'payment-processor-deployment'
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-dev 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 def...
Start a hazelcast pod with specific labels
Command: ```bash kubectl run hazelcast --hazelcast/hazelcast --labels="app=hazelcast,env=prod" ``` 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...]`...
Copy the local file `/tmp/foo_dir` to `/tmp/bar_dir` in the `web-app-pod-1` pod. Specify the container as `database-container`.
Command: ```bash kubectl cp /tmp/foo_dir web-app-pod-1:/tmp/bar_dir -c database-container ``` 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...
Get the output from running the 'elasticsearch-plugin --list' command in the nano-bot container of the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c nano-bot -- elasticsearch-plugin --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name...
Create a new config map named api-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/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 a conf...
Create a new config map named app-config using specified files as input
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ma...
Enable the Google Compute Platform auth provider for the "admin" entry by running the command:
Command: ```bash kubectl config set-credentials admin --auth-provider=gcp ``` 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 token flags: --token...
Create a service for a WordPress deployment. The service will serve on port 8010 and connect to the containers on port 543200.
Command: ```bash kubectl expose deployment wordpress --port=8010 --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 spec...
Create a cron job named "alerts-cleanup" with the image "mcr.microsoft.com/dotnet/core/runtime" and the schedule set to run every minute
Command: ```bash kubectl create cronjob alerts-cleanup --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-runtimes ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Help...
Create a cluster role named "default_role" with the ability to delete services and specific resources named "machine-learning" and "auth-proxy"
Command: ```bash kubectl create clusterrole default_role --verb=delete --resource=services --resource-name=machine-learning --resource-name=auth-proxy ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serve...
Export all the local environment variables that have "RAILS_" in their name and set them as environment variables for the backend-microservice-deployment on the server.
Command: ```bash env | grep RAILS_ | kubectl set env -e - 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 definitions in one or mo...
Taint nodes with label 'service=auth' and add a taint with key 'workload' and value 'PreferNoSchedule'
Command: ```bash kubectl taint node -l service=auth workload=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Update the label of a pod named 'vpn' by removing the label 'bar' if it exists
Command: ```bash kubectl label pods vpn unhealthy- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If tru...
create an ingress called 'public-service-ingress' with a rule that directs requests for foo.com/example to svc1 on port 8080, using the tls secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/example=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Import the "secret_key" key from the config map named "app-secrets" and set it as environment variable in the "payment-processor-deployment" deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-secrets 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 defin...
Attach to a specific container in a pod and enter raw terminal mode
Command: ```bash kubectl attach cdn-service-pod -c nano-bot -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 omitte...
Add a taint with key 'datacenter' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 datacenter=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":...
Set resource limits for the elasticsearch container in the deployment.
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=50m,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 requested, but may burs...
Create a service for an nginx deployment, which serves on port 8089 and connects to the containers on port 500000
Command: ```bash kubectl expose deployment nginx --port=8089 --target-port=500000 ``` 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...
Import the REDIS_HOST key from the app-secrets config map into the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets 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 definitio...
Create a job named "testing" using the CentOS image and run the bash command
Command: ```bash kubectl create job testing --image=centos -- bash ``` 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: jso...
Update the 'backend' pod by adding an annotation with the key 'monitoring-tool' and the value 'Prometheus'.
Command: ```bash kubectl annotate pods backend monitoring-tool=Prometheus ``` 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 a pod using the image "confluentinc/cp-kafka" and expose port 8080.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8080 ``` 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 flag...
Create an ingress named 'www-ingress' that directs requests to foo.com/bar to the service svc1 on port 5432, and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/bar=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": "", "usage": "Out...
Add a taint with key 'zone=PreferNoSchedule' on nodes having label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 zone=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config-dev 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 defi...
Set the cluster field in the specified context to a specific cluster
Command: ```bash kubectl config set contexts.team-alpha-context.cluster galaxy-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...
Import the DEBUG_MODE key from the global-config ConfigMap into the scheduler-app-deployment Deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/global-config 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...
Edit the docker-registry service using the "nvim" editor
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/docker-registry ``` 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...
Add the annotation 'security-scan-status' with the value 'pass' to the pod named 'vpn'
Command: ```bash kubectl annotate pods vpn security-scan-status=pass ``` 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 arbitrar...
Forward local port 8080 to pod port 8081
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8080:8081 ``` 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...
Execute the 'composer --version' command inside the proxy-server-pod and display the output.
Command: ```bash kubectl exec proxy-server-pod -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Import the 'log_level' key from the 'app-config-prod' config map and set it as an environment variable in the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-prod deployment/cache-cluster-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...
Change the cluster field in the "on-prem-context" context to "app-cluster"
Command: ```bash kubectl config set contexts.on-prem-context.cluster app-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 w...
Create a copy of the database-pod with all container images changed to busybox, and name it my-custom-dbg
Command: ```bash kubectl debug database-pod --copy-to=my-custom-dbg --set-image=*=busybox ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Create a single ingress named 'public-service-ingress' with a rule that directs requests from 'site.com/bar' to 'svc1:7000', and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress public-service-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": "", "...
Forward traffic from your local machine's port 3000 to the pod's port 5000 in the cdn-service-pod pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Set the CPU limit to "2" and memory limit to "512Mi" for the go container in the nginx deployment.
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=2,memory=512Mi ``` 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 s...
Create a service for a replicated python application that serves on port 3000 and connects to the containers on port 500000.
Command: ```bash kubectl expose rc python --port=3000 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a new config map named app-config-prod based on configurations located in the path/to/configurations folder
Command: ```bash kubectl create configmap app-config-prod --from-file=path/to/configurations ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the...