prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Enable the Google Compute Platform auth provider for the "john.doe" entry
Command: ```bash kubectl config set-credentials john.doe --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: --to...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-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 definit...
Import the 'max_connections' key from the 'app-config-prod' config map into the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-prod 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 variabl...
Create a debugging copy of the monitoring pod and change all container images to nginx.
Command: ```bash kubectl debug monitoring-pod --copy-to=debug-image-app --set-image=*=nginx ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no re...
Get the output of 'pg_dump --version' command from the 'rocket-ranger' container in the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c rocket-ranger -- 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...
Forward traffic from port 9090 on your local machine to the targetPort of the "https" service port in a pod selected by the "gateway-service" service
Command: ```bash kubectl port-forward service/gateway-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 annotation value of pod 'cdn' with the key 'backup-strategy' to 'daily-backups'
Command: ```bash kubectl annotate --overwrite pods cdn backup-strategy='daily-backups' ``` 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...
Retrieve the output from running the 'dotnet --list-sdks' command inside the 'cosmic-container' container in the 'mypod' pod.
Command: ```bash kubectl exec mypod -c cosmic-container -- dotnet --list-sdks ``` 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...
Forward traffic from local port 8888 to port 5000 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 8888 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 aut...
Start a python pod with custom specifications
Command: ```bash kubectl run nginx --image=python --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] -- [COMMAN...
Create a service for a replication controller using the specified YAML file, which will serve on port 9092 and connect to the containers on port 330600.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=9092 --target-port=330600 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Set the server field on the "app-cluster" cluster to https://1.2.3.4
Command: ```bash kubectl config set clusters.app-cluster.server https://1.2.3.4 ``` 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...
Listen on port 8888 on localhost and IP address 10.19.21.23, forwarding traffic to port 8088 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8888: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 th...
Auto scale the replication controller "database" with a target CPU utilization of 20%, allowing the number of pods to range between 1 and 2.
Command: ```bash kubectl autoscale rc database --max=2 --cpu-percent=20 ``` 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...
Run the command 'pg_dump --version' in the 'quantum-quark' container of the 'e-commerce-pod' pod.
Command: ```bash kubectl exec e-commerce-pod -c quantum-quark -- 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 ...
Get the output from running the 'python' command in the first container of the first pod of the 'user-management-deployment' deployment.
Command: ```bash kubectl exec deploy/user-management-deployment -- 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 omitted, ...
Update the environment variable 'DB_HOST' of the deployment 'email-server-deployment' with the value 'localhost'
Command: ```bash kubectl set env deployment/email-server-deployment DB_HOST=localhost ``` 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 template...
Import the API_KEY key from the 'app-name-config' config map into the 'frontend-deployment' deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-name-config deployment/frontend-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 environment variables from a config map with a prefix for a specific deployment.
Command: ```bash kubectl set env --from=configmap/app-secrets --prefix=MYSQL_ 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 definitio...
Display only the most recent 53 lines of output for the media-stream-pod.
Command: ```bash kubectl logs --tail=53 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": "--container", "short":...
Include the certificate authority data for the 'edge-cluster' cluster entry
Command: ```bash kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Update the 'vpn' pod by adding the annotation 'scaling-policy' with the value 'auto-horizontal-scaling', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods vpn 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 than ...
Execute the command 'mysqld' in the 'cyber-sleuth' container of the 'log-aggregator-pod' pod and get the output.
Command: ```bash kubectl exec log-aggregator-pod -c cyber-sleuth -- mysqld ``` 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,...
Start streaming the logs from all containers in pods that have the label "project=project-alpha"
Command: ```bash kubectl logs -f -l project=project-alpha --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": ...
Get information about specific resources by their type and names
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/chat-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is names...
Create a job named "database-seeding-job" using the mysql image, and run the command "mysql --version" inside the job container.
Command: ```bash kubectl create job database-seeding-job --image=mysql -- mysql --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": "Out...
Embed the certificate authority data for the cluster-beta cluster entry using the command "kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Update the 'proxy' pod by adding or updating the annotation 'alert-email' with the value 'alerts@example.com'
Command: ```bash kubectl annotate --overwrite pods proxy alert-email='alerts@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels...
Update the image of all containers in the daemonset 'test' to 'redis:6.2.5'
Command: ```bash kubectl set image daemonset test *=redis:6.2.5 ``` 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...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-settings 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 definitions...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/log-config deployment/log-aggregator-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...
Retrieve the output of the 'mysqld' command running in the first container of the payment-processor-deployment deployment.
Command: ```bash kubectl exec deploy/payment-processor-deployment -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Create a job with the specified image
Command: ```bash kubectl create job database-seeding-job --image=busybox ``` 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 o...
Update the environment variables of the deployment named "user-management-deployment" with values from the "azure-storage-secret" secret.
Command: ```bash kubectl set env --from=secret/azure-storage-secret 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 definitions in one ...
Listen on local ports 3000 and 6000, forwarding data to/from ports 3000 and 6000 in the pod selected by the 'web-app-deployment' deployment
Command: ```bash kubectl port-forward deployment/web-app-deployment 3000 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 s...
Execute the 'dotnet' command in the first container of the 'email-service' service and get the output.
Command: ```bash kubectl exec svc/email-service -- dotnet ``` 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....
Create a service for the nginx deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment nginx --port=9000 --target-port=900000 ``` 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...
List deployments in JSON output format for the "beta-1.0" version of the "external-apps" API group.
Command: ```bash kubectl get deployments.beta-1.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 you...
Create a LoadBalancer service named "auth-service-lb" that maps port 8888 on the service to port 8888 on the pods.
Command: ```bash kubectl create service loadbalancer auth-service-lb --tcp=8888:8888 ``` 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...
Create a single ingress called 'private-ingress' with a rule that directs requests to testing.com/module to the svc1 service on port 9092, using the tls secret named "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="testing.com/module=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Create a cluster role named "foo" with specific resource names
Command: ```bash kubectl create clusterrole foo --verb=connect --resource=pods --resource-name=message-queue --resource-name=log-aggregator ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|no...
Create a job named "scaling-job" using the "mongo" image and run the "mongo" command.
Command: ```bash kubectl create job scaling-job --image=mongo -- mongo ``` 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:...
Create a new config map named 'log-config' with the keys 'settings' and 'key2' using the specified files '/path/to/parameters/file1.txt' and '/path/to/configs/file2.txt' accordingly.
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/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 ...
Retrieve the snapshot logs from the container named "order-processing-deployment-1" in the deployment "security-service-pod".
Command: ```bash kubectl logs deployment/order-processing-deployment -c security-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful ...
Execute the command 'dotnet --list-sdks' inside the first pod of the 'search-engine-deployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/search-engine-deployment -- dotnet --list-sdks ``` 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...
Execute the 'mongo' command in the 'warp-drive' container of the 'api-service-pod' pod and capture the output.
Command: ```bash kubectl exec api-service-pod -c warp-drive -- mongo ``` 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...
Retrieve snapshot logs from a specific container in a deployment.
Command: ```bash kubectl logs deployment/email-server-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": "--c...
Add a taint with key 'app' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database app=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": "Outpu...
Display only the most recent 5 lines of output for the pod named vpn-service-pod.
Command: ```bash kubectl logs --tail=5 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": "...
Listen on port 8088 on localhost and IP address 10.19.21.23, and forward the traffic to port 6379 in the pod named frontend-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 8088: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 criter...
Import environment variables from a secret for a deployment.
Command: ```bash kubectl set env --from=secret/jwt-secret deployment/email-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 definitions in one or more pod t...
Expose a replication controller as a service with specific ports using a configuration file.
Command: ```bash kubectl expose -f php-controller.yaml --port=5000 --target-port=808400 ``` 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 sp...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/kube-system-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 variabl...
Update the 'someField' attribute with the value 'newValue' on the kube-master-9 node using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node kube-master-9 -p '{"spec":{"someField":"newValue"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` He...
Create a debug copy of the analytics-pod by adding a debug container and changing container images.
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-1 --image=debian --set-image=logger=logging-app:debug,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identif...
Forward local port 6379 to the targetPort of the "https" service's port in a pod selected by the "payment-service" service.
Command: ```bash kubectl port-forward service/payment-service 6379: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...
Switch to raw terminal mode and connect to the lunar-launcher container inside the api-service-pod.
Command: ```bash kubectl attach api-service-pod -c lunar-launcher -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 ...
Create a new secret named 'git-credentials-secret' from the environment variables file located at 'path/to/data.env'
Command: ```bash kubectl create secret generic git-credentials-secret --from-env-file=path/to/data.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the b...
Listen on port 8000 on localhost and IP 10.19.21.23, forwarding to port 8000 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8000: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 th...
Forward traffic from port 3000 on all addresses to port 8081 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 3000: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 criteria, a pod will ...
Copy the local file /tmp/foo_dir to the remote pod backend-pod-13 in the kube-system namespace, and place it in the /etc/kubernetes directory.
Command: ```bash kubectl cp /tmp/foo_dir kube-system/backend-pod-13:/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 ...
Update the pod named 'monitoring' with the annotation 'monitoring-tool' and the value 'Prometheus', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods monitoring 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 label...
Create a cron job named "monthly-audit" with the following parameters:
Command: ```bash kubectl create cronjob monthly-audit --image=amazonlinux --schedule="*/1 * * * *" -- /bin/bash -c "echo 'Hello ``` 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": "--ou...
Copy the kube config file from a remote pod to a local directory
Command: ```bash kubectl cp kube-proxy/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 ku...
Update the pod 'log-aggregator' by adding the label 'component' with the value 'web'
Command: ```bash kubectl label pods log-aggregator component=web ``` 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", "u...
Create a cluster role named "bar" with the specified API Group
Command: ```bash kubectl create clusterrole bar --verb=delete,update,proxy --resource=persistentvolumeclaims.storage.k8s.io ``` 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 fl...
Attach to the 'frontend-pod' pod and view the output from the 'rocket-ranger' container
Command: ```bash kubectl attach frontend-pod -c rocket-ranger ``` 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, u...
Create a pod disruption budget named auth-service-pdb that will select all pods with the version=v2 label, and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-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 [-...
Forward port 8000 on your local machine to port 8888 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Apply a taint with the key 'datacenter' on nodes that have the label 'region' set to 'eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 datacenter=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create a debug version 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-1 --image=debian --set-image=mailer=mailer:latest,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and n...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/namespace-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Forward traffic between local ports 8888 and 6000, and the ports 8888 and 6000 in the 'analytics-platform-deployment' pod
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8888 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 po...
Create a deployment named "my-dep" with the "php" image and 7 replicas.
Command: ```bash kubectl create deployment my-dep --image=php --replicas=7 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Add a taint to node 'node-1' with key 'app' and no value that prevents scheduling new pods on that node
Command: ```bash kubectl taint nodes node-1 app: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|yaml|...
Update the 'analytics' pod by adding the annotation 'monitoring-tool' with the value 'Prometheus'
Command: ```bash kubectl annotate pods analytics 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 a...
Create a new config map named api-config from an env file.
Command: ```bash kubectl create configmap api-config --from-env-file=path/to/configs.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the bas...
Create a secret named tls-certificate-secret from an environment file
Command: ```bash kubectl create secret generic tls-certificate-secret --from-env-file=path/to/profiles.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to t...
Forward port 8088 in the pod to port 8888 locally
Command: ```bash kubectl port-forward pod/api-service-pod 8888:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a new config map named kube-system-config using the parameters found in the path/to/parameters folder.
Command: ```bash kubectl create configmap kube-system-config --from-file=path/to/parameters ``` 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 ...
Begin streaming the logs of the ruby container in the auth-service-pod pod
Command: ```bash kubectl logs -f -c ruby auth-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"...
Start a pod using a specific image and override its spec with values parsed from JSON
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "v1.1.1", "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=inli...
Apply a taint to nodes that have the label 'namespace=mynamespace', with the taint value 'cpu-type=backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l namespace=mynamespace cpu-type=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": "",...
Edit the 'queue-processing-job' job using the v1 API format in JSON
Command: ```bash kubectl edit job.v1.batch/queue-processing-job -o json ``` 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...
Update the pod named 'gateway' with the annotation 'owner' and set its value to 'alice-smith', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods gateway owner='alice-smith' ``` 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 includ...
Create a copy of the 'proxy-service-pod' pod, changing all container images to 'redis'. The new pod will be named 'dgb-img'.
Command: ```bash kubectl debug proxy-service-pod --copy-to=dgb-img --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 resourc...
List deployments in JSON output format, specifically from the "v1.0.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.third-party-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...
create a new config map named 'global-config' with the specified keys 'conf' and 'data' from the files '/path/to/properties/file1.txt' and '/path/to/parameters/file2.txt' respectively
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Add a taint with key 'datacenter' and no value to the node 'kube-master-9'
Command: ```bash kubectl taint nodes kube-master-9 datacenter:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Update the criticality annotation of the pod identified by the type and name specified in the "setup.json" file to be "high".
Command: ```bash kubectl annotate -f setup.json 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 include arbitrary st...
Import specific keys from a config map by setting environment variables on a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/env-vars deployment/log-aggregator-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 keys "config_file_path" from the configmap "global-config" into the deployment "web-app-deployment"
Command: ```bash kubectl set env --keys=config_file_path --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 definit...
Create a config map named env-vars with specified keys from files
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
Copy the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod named "backend-pod-13" in the "kube-system" namespace, and place it in the "/tmp/bar_dir" directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-system/backend-pod-13:/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": "C...
Create a new config map named ui-config with the specified keys, conf and data, using the files file1.txt and file2.txt located at /path/to/settings/ and /path/to/parameters/ respectively.
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a conf...
Deny the Certificate Signing Request (CSR) with the name 'csr-proxy-15'
Command: ```bash kubectl certificate deny csr-proxy-15 ``` 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: `kubectl ...
Display only the most recent 31 lines of output for the pod named "auth-service-pod".
Command: ```bash kubectl logs --tail=31 auth-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 specific keys from a config map
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/log-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 definitions i...
Set the cluster field in the client-2-context context to cloud-cluster
Command: ```bash kubectl config set contexts.client-2-context.cluster cloud-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 yo...
Forward traffic from port 5000 on all addresses to port 8080 in the pod named api-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 5000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...