prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set up autoscaling for the "database" deployment with a minimum of 4 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment database --min=4 --max=9 ``` 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...
Display the CPU and memory metrics for the 'vpn-service-pod' and its containers.
Command: ```bash kubectl top pod vpn-service-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top p...
import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/global-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 definitio...
Create a service for nginx deployment, exposing port 8080 and connecting to containers on port 808400
Command: ```bash kubectl expose deployment nginx --port=8080 --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 specifie...
Execute a command inside a running pod.
Command: ```bash kubectl exec deploy/user-management-deployment -- go run hello.go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Create a pod disruption budget named "load-balancer-pdb" that will select all pods with the label "region=us-east" and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=region=us-east --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available...
Update the role binding for jane.doe, bob.smith, and the developers group with the admin role.
Command: ```bash kubectl set subject rolebinding admin --user=jane.doe --user=bob.smith --group=developers ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceacco...
Create a cron job named cron-task that runs the command "postgres" every minute using the Postgres image.
Command: ```bash kubectl create cronjob cron-task --image=postgres --schedule="*/1 * * * *" -- postgres ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "d...
Copy the local file "/tmp/foo_dir" to the remote pod named "monitoring-agent-pod-6" in the "logging" namespace, and place it at the remote path "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo_dir logging/monitoring-agent-pod-6::/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...
Add a taint to all nodes with the label 'app=web-app', specifying the key as 'environment' and the taint effect as 'PreferNoSchedule' using the command kubectl taint node -l app=web-app environment=edge-node-10:PreferNoSchedule
Command: ```bash kubectl taint node -l app=web-app environment=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": "", "usage":...
Create a service for a replication controller identified by type and name specified in "centos-controller.yaml", which serves on port 8083 and connects to the containers on port 808200
Command: ```bash kubectl expose -f centos-controller.yaml --port=8083 --target-port=808200 ``` 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...
Create a new config map named global-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/configurations/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...
Set resource requests and limits for containers in the "ubuntu" deployment.
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested...
Display metrics for a pod and its containers
Command: ```bash kubectl top pod log-aggregator-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl to...
Create a secret named encryption-key-secret from files in a given folder
Command: ```bash kubectl create secret generic encryption-key-secret --from-file=path/to/settings ``` 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 basena...
Create an ingress that directs requests to a specific service with TLS encryption
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/bar=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Create an ingress called 'web-ingress' that directs requests to website.com/bar to svc1:9000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="website.com/bar=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": "", "usage": ...
Create a new config map named monitoring-config with specified keys and corresponding files
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/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 crea...
Create an ingress called 'myapp-ingress' with a rule that directs requests to website.com/example to svc1:3001
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/example=svc1:3001,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...
Scale the "staging-app-rs" deployment to 3 replicas if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=3 deployment/staging-app-rs ``` 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-vers...
Execute the 'nginx -t' command in the first container of the 'frontend-deployment' deployment and display the output.
Command: ```bash kubectl exec deploy/frontend-deployment -- nginx -t ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Start a new nginx pod with the docker.elastic.co/elasticsearch/elasticsearch image, but override the spec with a partial set of values parsed from the JSON provided in the command
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --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] [--overri...
Retrieve the previous logs of the terminated ruby container from the pod named "mypod"
Command: ```bash kubectl logs -p -c ruby mypod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c", "de...
Start a mysql pod named hazelcast and expose port 5432
Command: ```bash kubectl run hazelcast --image=mysql --port=5432 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Get the output from running the 'ash' command in the 'rocket-ranger' container from the 'proxy-service-pod' pod.
Command: ```bash kubectl exec proxy-service-pod -c rocket-ranger -- ash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Copy the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod "image-resizer-pod-20" in the "kube-public" namespace, and place it in the "/tmp/bar" directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-public/image-resizer-pod-20::/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":...
Import specific keys from a config map to a deployment by setting environment variables
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/ui-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Forward a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod :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 aut...
Create an ingress called 'app-loadbalancer-ingress' that directs requests to testing.com/example to svc1:8089 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/example=svc1:8089,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", "defaul...
Import the "api_key" key from the "namespace-config" config map to the "payment-processor-deployment" deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/namespace-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 def...
Update the resource request and limits for all containers in the Jenkins deployment
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=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 reque...
Delete the pods and services with the names "vpn" and "foo"
Command: ```bash kubectl delete pod,service vpn foo ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some re...
Update the 'prod-node-5' node by adding a taint with key 'datacenter', value 'dc-1', and effect 'NoExecute'
Command: ```bash kubectl taint nodes prod-node-5 datacenter=dc-1:NoExecute ``` 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. On...
Create a service for the alpine replica set that serves on port 8443 and connects to the containers on port 500100
Command: ```bash kubectl expose rs alpine --port=8443 --target-port=500100 ``` 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 NodePort service called e-commerce-nodeport with port mapping of 8083 to 5432.
Command: ```bash kubectl create service nodeport e-commerce-nodeport --tcp=8083:5432 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Run the 'node' command in the nebula-navigator container within the vpn-service-pod pod.
Command: ```bash kubectl exec vpn-service-pod -c nebula-navigator -- 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, ...
Set the CPU limits of the mysql deployment's nginx container to "50m" and the memory limits to "1Gi".
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=50m,memory=1Gi ``` 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 it...
Switch to raw terminal mode and attach to the 'nebula-navigator' container in the 'api-service-pod' pod.
Command: ```bash kubectl attach api-service-pod -c nebula-navigator -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. I...
Update the environment variables of the specified deployment with the values of the keys "external_api_url" from the config map "ui-config".
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/ui-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
list the replication controller named "web", the service named "gateway-rc", and the pod named "payment-gateway-pod"
Command: ```bash kubectl get rc/web service/gateway-rc pods/payment-gateway-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...
Connect to the 'rocket-ranger' container in the 'email-service-pod' pod to retrieve the output.
Command: ```bash kubectl attach email-service-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 omitt...
Forward traffic from local port 9090 to port 8081 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 9090 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 be selected auto...
Scale the deployment named payment-service-rs to 1 replica if its current size is 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/payment-service-rs ``` 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-...
Create a new secret named private-key-secret and populate it with keys for each file in the folder path/to/settings.
Command: ```bash kubectl create secret generic private-key-secret --from-file=path/to/settings ``` 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 ...
Embed certificate authority data for a cluster entry
Command: ```bash kubectl config set-cluster my-k8s-cluster --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Set the service account of the 'user-management-deployment' deployment to 'elasticsearch'
Command: ```bash kubectl set serviceaccount deployment user-management-deployment elasticsearch ``` 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 Synta...
Create a pod disruption budget named 'notification-service-pdb' that selects all pods with the 'component=web' label and ensures that at least four of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=component=web --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-ava...
List deployments in JSON format, in the specific version and API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.mobile-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 y...
Embed the certificate authority data for the app-cluster cluster entry by running the command "kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/e2e/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/e2e/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-cluster N...
Get the output from running the 'ash' command in the 'nebula-navigator' container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c nebula-navigator -- ash ``` 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, ...
set environment variables for the deployment using specific keys from a config map
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-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 in...
Copy the ~/.config/kube file from a remote pod named `metrics-exporter-pod-10` to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kube-proxy/metrics-exporter-pod-10:~/.config/kube /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Update the 'log-aggregator' pod by adding the annotation 'SLA' with the value '99.9% uptime', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods log-aggregator SLA='99.9% uptime' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and ...
Forward local port 8080 to port 8088 in the pod selected by the 'notification-handler-deployment' deployment.
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8080 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Create a new config map named log-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/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 cre...
Set the service account of the 'search-engine-deployment' deployment to 'my-service-account'
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment my-service-account ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Sy...
Create a job named "log-processing-job" using the redis image, and run the "redis-server" command within the job.
Command: ```bash kubectl create job log-processing-job --image=redis -- redis-server ``` 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 f...
Attach a debug container to a pod named payment-gateway-pod, create a copy of it and use the busybox image for the debug container.
Command: ```bash kubectl debug payment-gateway-pod -it --image=busybox --copy-to=my-custom-dbg ``` 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...
Create a role named "reader" with API Group specified to allow updating, getting, and patching network policies.
Command: ```bash kubectl create role reader --verb=update,get,patch --resource=networkpolicies.networking.k8s.io ``` 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|none]` Helpful...
Start a proxy to the Kubernetes API server on port 9092 and serve static content from the "./local/www/" directory
Command: ```bash kubectl proxy --port=9092 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Create an ingress named 'api-v1-ingress' that routes requests from 'testing.com/module' to 'svc1:8081' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/module=svc1:8081,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...
Execute the 'dotnet' command in the 'warp-drive' container of the 'proxy-service-pod' pod and display the output.
Command: ```bash kubectl exec proxy-service-pod -c warp-drive -- 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, us...
Start a pod named hazelcast using the golang image and allow the container to expose port 8080
Command: ```bash kubectl run hazelcast --image=golang --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 flags: "flag": "--f...
Taint nodes with the label 'component=proxy' and apply the taint 'datacenter=testing-node-11:PreferNoSchedule'
Command: ```bash kubectl taint node -l component=proxy datacenter=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": "", "u...
import the smtp_server key from the log-config config map into the email-server-deployment deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/log-config 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 definition...
Forward traffic from port 5432 on localhost and IP address 10.19.21.23 to port 8000 in the security-service-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 5432: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...
List all deployments in the "feature-branch-2.3.0" version of the "third-party-apps" API group and display the output in JSON format
Command: ```bash kubectl get deployments.feature-branch-2.3.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...
Forward local port 8080 to the Kubernetes pod's port 8088
Command: ```bash kubectl port-forward pod/chat-app-pod 8080 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Setup autoscaling for the replication controller "payment" with a target CPU utilization of 60% and a minimum of 1 pod and a maximum of 7 pods.
Command: ```bash kubectl autoscale rc payment --max=7 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Expose a replica set as a service, with ports mapping configured.
Command: ```bash kubectl expose rs node --port=8082 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Annotate the pod 'media-stream' with the annotation 'backup-strategy' and set its value as 'daily backups'.
Command: ```bash kubectl annotate pods media-stream 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 and i...
Update the label of the pods with the key "status" and the value "unhealthy", replacing any existing value
Command: ```bash kubectl label --overwrite pods security status=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": "f...
Execute the 'irb' command inside the 'log-aggregator-pod' pod using the 'cosmic-container' container
Command: ```bash kubectl exec log-aggregator-pod -c cosmic-container -- irb ``` 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...
Copy the /tmp/foo_dir directory from the api-server-pod-3 pod in the istio-system namespace to the /tmp/bar directory locally.
Command: ```bash kubectl cp istio-system/api-server-pod-3:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Create a copy of the "api-service-pod" and change all the container images to "wordpress" for debugging purposes.
Command: ```bash kubectl debug api-service-pod --copy-to=my-debugger --set-image=*=wordpress ``` 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 r...
Create a new config map named app-config using the specified files as data
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/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 con...
Update the label of the pod 'auth' to set the label 'env' with the value 'development'
Command: ```bash kubectl label pods auth env=development ``` 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": "...
Forward local port 3000 to port 8081 in the pod 'security-service-pod'
Command: ```bash kubectl port-forward pod/security-service-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 be select...
Auto scale the replication controller "payment" so that it maintains between 1 and 2 pods, with a target CPU utilization of 81%.
Command: ```bash kubectl autoscale rc payment --max=2 --cpu-percent=81 ``` 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...
Expose the hazelcast deployment as a service on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment hazelcast --port=3001 --target-port=844300 ``` 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...
Start a pod named "hazelcast" using the Jenkins image and expose port 8084 on the container
Command: ```bash kubectl run hazelcast --image=jenkins --port=8084 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--...
Import the smtp_server key from the kube-system-config config map and set it as an environment variable for the frontend-deployment deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/kube-system-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 defini...
import the 'CONFIG_FILE_PATH' key from the 'app-secrets' config map into the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-secrets deployment/monitoring-stack-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 ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-name-config 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 definitio...
Create a pod disruption budget named cache-cluster-pdb that will select all pods with the role=worker label and require a minimum of one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=role=worker --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Listen on port 3000 on all the addresses and forward the traffic to port 8088 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 3000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Copy the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod "backend-pod-13" in the "monitoring" namespace, and store it as "/tmp/bar".
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ monitoring/backend-pod-13:/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": "Contai...
Add a taint with the key 'dedicated' on nodes having the label 'stack=tech-stack', specifically on the node with the label 'gpu-node-12', and mark it for 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l stack=tech-stack dedicated=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...
Update the pod named 'api' by adding or updating the annotation 'release-notes' with the value 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods api 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 larger t...
List specific resources by their type and names.
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/email-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is na...
Create a service for the ubuntu deployment, which serves on port 5001 and connects to the containers on port 909100
Command: ```bash kubectl expose deployment ubuntu --port=5001 --target-port=909100 ``` 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 specifi...
Set a custom TLS server name for the moon-cluster cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=testing-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] [--certific...
Forward traffic from port 8081 on all addresses to port 3000 in the backend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8081:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Set the custom TLS server name for the my-k8s-cluster cluster entry to web-cluster
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=web-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] [--certificat...
Create a pod disruption budget named auth-service-pdb that will select all pods with the version=v2 label and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=version=v2 --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [-...
Update the pod named 'monitoring' by adding a label with the key 'component' and the value 'web'
Command: ```bash kubectl label pods monitoring 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", "usage...
Forward local port 8088 to port 3000 in a pod selected by the authentication-service-deployment deployment
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8088 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, ...
Listen on port 6379 on localhost and IP 10.19.21.23, and forward the traffic to the backend-pod's port 6379.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 6379:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Create a new LoadBalancer service named proxy-service-lb
Command: ```bash kubectl create service loadbalancer proxy-service-lb --tcp=8888:3000 ``` 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", "d...
Create a new secret named cert-manager-secret using the configurations from the path/to/configurations.env file
Command: ```bash kubectl create secret generic cert-manager-secret --from-env-file=path/to/configurations.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 t...