prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Switch to raw terminal mode and attach to the 'time-machine' container in the 'analytics-pod' pod.
Command: ```bash kubectl attach analytics-pod -c time-machine -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Retrieve the output from the rocket-ranger container in the 'database-pod' pod.
Command: ```bash kubectl attach database-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...
Add a taint with key 'zone' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database zone=monitoring-node-15: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 resource limits of the Elasticsearch container in the nginx deployment
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=200m,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 bur...
Create a new NodePort service named media-stream-nodeport, mapping the local port 9090 to the pod port 27017.
Command: ```bash kubectl create service nodeport media-stream-nodeport --tcp=9090:27017 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default...
Create an ingress called 'api-v1-ingress' that directs requests to site.com/example to svc1:5001 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="site.com/example=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a new config map named api-config using the files located at path/to/preferences folder.
Command: ```bash kubectl create configmap api-config --from-file=path/to/preferences ``` 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 basenam...
Create a deployment named mattermost with 5 replicas running the golang image
Command: ```bash kubectl create deployment mattermost --image=golang --replicas=5 ``` 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 ...
Create a cron job named database-maintenance that runs the command "node --version" every minute, using the node image.
Command: ```bash kubectl create cronjob database-maintenance --image=node --schedule="*/1 * * * *" -- node --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "sho...
Listen on port 8888 on all addresses and forward the traffic to port 8088 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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...
get the logs of a specific pod in JSON output format
Command: ```bash kubectl get -o json pod log-aggregator-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only s...
Create a cron job named "backup-job" using the image "jenkins" with a schedule of running every minute
Command: ```bash kubectl create cronjob backup-job --image=jenkins --schedule="*/1 * * * *" -- jenkins-plugin-cli ``` 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"...
Forward traffic from local port 8080 to port 6379 in the pod.
Command: ```bash kubectl port-forward pod/web-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 automa...
Partially update the 'worker-node-3' node by specifying the 'password' field as 'new-password' using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node worker-node-3 -p '{"stringData":{"password":"new-password"}' ``` 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 F...
Run the 'irb' command inside the 'security-service-pod' and get the output
Command: ```bash kubectl exec security-service-pod -- 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, use the kubectl....
Set the resource request and limits for all containers in the golang deployment
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=128Mi ``` 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...
Add a taint with key 'special' on nodes having label owner=john-doe. Set the taint value to prod-node-5:PreferNoSchedule.
Command: ```bash kubectl taint node -l owner=john-doe special=prod-node-5: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 cron job named "data-sync" with an image named "node"
Command: ```bash kubectl create cronjob data-sync --image=node --schedule="*/1 * * * *" -- npm --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "...
Create a pod disruption budget named 'worker-pdb' that will select all pods with the 'project=my-project' label and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=project=my-project --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 ...
Forward local traffic from port 8888 to port 8000 in a pod named "api-service-pod".
Command: ```bash kubectl port-forward pod/api-service-pod 8888 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Add a taint with the key 'app' on nodes labeled with 'role=database'
Command: ```bash kubectl taint node -l role=database app=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": "", "usage": "O...
Forward traffic from local port 5432 to port 5000 in the pod "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 5432: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 a...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/ui-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 def...
Forward local ports 3000 and 6000 to ports 3000 and 6000 of a selected pod in the deployment notification-handler-deployment
Command: ```bash kubectl port-forward deployment/notification-handler-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 ...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/kube-system-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 varia...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-settings 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 ...
Create a job called "image-build-job" using the "postgres" image, and run the command "psql" inside the job.
Command: ```bash kubectl create job image-build-job --image=postgres -- psql ``` 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. O...
Delete all pods and services with the label app-type=microservice.
Command: ```bash kubectl delete pods,services -l app-type=microservice ``` 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 labe...
Import specific keys from a config map into environment variables for a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/namespace-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Retrieve resources from a directory with kustomization.yaml
Command: ```bash kubectl get -k dir/ ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in your curr...
Display the resource usage metrics for all pods with the label 'service=auth'.
Command: ```bash kubectl top pod -l service=auth ``` 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 pod [NAME | -l...
Create an ingress named "ingtls" with TLS enabled
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="testing.com/=svc:https,tls" \ --rule="website.com/path/subpath*=othersvc:7000" ``` 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"...
Import the secret_key from the monitoring-config config map into the api-server-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/monitoring-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/env-vars 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 ...
Create a debug container of the chat-app-pod and change all container images to php
Command: ```bash kubectl debug chat-app-pod --copy-to=debug-image-app --set-image=*=php ``` 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 resour...
Forward the local port 8081 to port 8000 in the pod named 'mypod'
Command: ```bash kubectl port-forward pod/mypod 8081 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Embed the certificate authority data for the "moon-cluster" cluster entry.
Command: ```bash kubectl config set-cluster moon-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 ...
Create a copy of the 'proxy-service-pod' with all container images changed to 'mongo' using the 'kubectl debug' command.
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-memcached --set-image=*=mongo ``` 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...
Forward traffic from port 6379 on all addresses to port 8088 in the pod "chat-app-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 6379:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/auth-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 namesp...
Add new exec auth plugin args for the "operator" entry with arguments "arg1" and "arg2".
Command: ```bash kubectl config set-credentials operator --exec-arg=arg1 --exec-arg=arg2 ``` 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 f...
import the specific key 'DATABASE_URL' from the 'app-config-dev' config map and set it as an environment variable for the 'search-engine-deployment' deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-dev 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 defi...
Copy the file "/tmp/foo" from the remote pod "cache-pod-5" in the "istio-system" namespace to the local path "/tmp/bar".
Command: ```bash kubectl cp istio-system/cache-pod-5::/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 the kubectl...
Embed the certificate authority data for the "prod-cluster" cluster entry.
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/dev-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-...
Set resource limits and requests for all containers in the Jenkins deployment
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=128Mi ``` 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 requ...
Update the pod identified by type and name in the "docker-registry.yaml" file by adding the annotation "alert-email" with the value "alerts@example.com"
Command: ```bash kubectl annotate -f docker-registry.yaml 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 ...
Copy the local file "/tmp/foo" to the directory "/etc/kubernetes" in the remote pod "api-server-pod-3" in the "prometheus" namespace.
Command: ```bash kubectl cp /tmp/foo prometheus/api-server-pod-3:/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 the...
Create a new config map named app-config-prod using the provided files for keys
Command: ```bash kubectl create configmap app-config-prod --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/options/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 c...
Run the 'psql' command inside the gateway-pod pod and display the output
Command: ```bash kubectl exec gateway-pod -- psql ``` 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.kubernet...
Get deployments in the dev-2.2.0 version of the api-v1 API group, and output the result in JSON format.
Command: ```bash kubectl get deployments.dev-2.2.0.api-v1 -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 will ...
Get the output from running the 'kafka-topics --list' command in the astro-container from the chat-app-pod.
Command: ```bash kubectl exec chat-app-pod -c astro-container -- kafka-topics --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. I...
Create a pod named 'hazelcast' using the 'mysql' image, and expose port 8000 in the container.
Command: ```bash kubectl run hazelcast --image=mysql --port=8000 ``` 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...
Add a taint with the key 'datacenter' and value 'app-node-6:PreferNoSchedule' on nodes that have the label 'app=web-app'.
Command: ```bash kubectl taint node -l app=web-app datacenter=app-node-6: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": "O...
Scale the deployment named "baz" from the current size of 1 replica to 5 replicas
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/baz ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Create a deployment named "nats" using the "python" image and expose port 9090
Command: ```bash kubectl create deployment nats --image=python --port=9090 ``` 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...
Expose the deployment "ubuntu" as a service, with the service listening on port 8010 and forwarding traffic to the containers on port 8080.
Command: ```bash kubectl expose deployment ubuntu --port=8010 --target-port=808300 ``` 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...
Get the output of the `dotnet --list-sdks` command from the first container of the pod named `payment-service` in the `payment-service` service.
Command: ```bash kubectl exec svc/payment-service -- 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 omitted, us...
Display the resource usage metrics for the node named dev-node-4.
Command: ```bash kubectl top node dev-node-4 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (la...
Embed the certificate authority data for the on-prem-cluster cluster entry using the command:
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/prod-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 ...
Create a secret named api-key-secret from files in a folder
Command: ```bash kubectl create secret generic api-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 basenam...
Set the CPU limits of the nginx container in the amazonlinux deployment to "2" and the memory limits to "512Mi".
Command: ```bash kubectl set resources deployment amazonlinux -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...
Add a taint to a specific node with a specific key and no value
Command: ```bash kubectl taint nodes storage-node-13 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: ...
create a service for the replication controller specified in "node-controller.yaml", serving on port 8080 and connecting to containers on port 801000
Command: ```bash kubectl expose -f node-controller.yaml --port=8080 --target-port=801000 ``` 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 s...
Apply a taint with the key 'zone' and the value 'node-2:PreferNoSchedule' on nodes that have the label 'app-type=microservice'.
Command: ```bash kubectl taint node -l app-type=microservice zone=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": "O...
Retrieve previous logs of the terminated stardust-shuttle container from the pod named cdn-service-pod
Command: ```bash kubectl logs -p -c stardust-shuttle cdn-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": "--containe...
Start forwarding traffic from port 5000 on the localhost and IP address 10.19.21.23 to port 8888 in the pod named "mypod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 5000: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 p...
Expose a deployment as a service
Command: ```bash kubectl expose deployment ruby --port=6379 --target-port=909200 ``` 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...
Create a debug copy of the "chat-app-pod" pod, with an interactive terminal, and change the command of the "lunar-launcher" container to "sh".
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-api --container=lunar-launcher -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by d...
Expose a replication controller as a service, specifying the port configuration
Command: ```bash kubectl expose -f centos-controller.yaml --port=8082 --target-port=808300 ``` 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...
Update the size of the deployment "baz" to 5, assuming its current size is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/baz ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Execute the command 'go run hello.go' in the nano-bot container of the pod cdn-service-pod and display the output.
Command: ```bash kubectl exec cdn-service-pod -c nano-bot -- 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 omitte...
Forward local port 8088 to port 5432 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8088:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Get the output from running the 'irb' command in the first pod of the deployment 'order-processing-deployment', using the first container by default.
Command: ```bash kubectl exec deploy/order-processing-deployment -- 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, us...
Set up an autoscaling policy for the "media-stream" deployment with a minimum of 1 pod and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment media-stream --min=1 --max=8 ``` 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 ...
Import environment from a config map with a prefix
Command: ```bash kubectl set env --from=configmap/app-config-prod --prefix=MYSQL_ 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 definit...
Run the command 'redis-server' inside the first container of the first pod of the 'backend-service' service.
Command: ```bash kubectl exec svc/backend-service -- redis-server ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
update the image of all containers in a daemonset to 'centos:8.4.2105'
Command: ```bash kubectl set image daemonset services *=centos:8.4.2105 ``` 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: ...
Create a secret named azure-storage-secret which contains keys for each file in the folder bar
Command: ```bash kubectl create secret generic azure-storage-secret --from-file=path/to/properties ``` 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 basen...
Forward traffic from local port 9090 to port 3000 in a pod selected by the monitoring-stack-deployment deployment
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 9090 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Create a new secret named 'database-secret' with keys for each file in the 'path/to/preferences' folder
Command: ```bash kubectl create secret generic database-secret --from-file=path/to/preferences ``` 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 ...
Create a pod disruption budget named api-service-pdb that will select all pods with the tier=frontend label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=tier=frontend --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Partially update a node by applying a strategic merge patch in JSON format
Command: ```bash kubectl patch node backup-node-14 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (...
Delete the pods and services with the names "cdn" and "foo"
Command: ```bash kubectl delete pod,service cdn 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...
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 5432 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8000: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 criter...
Create an ingress called 'default-ingress' that routes requests from testing.com/example to svc1:8084 with TLS encryption using the secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/example=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 a new config map named 'env-vars' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/preferences/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 ...
Get the output from running the 'nginx' command in the stardust-shuttle container of the pod named proxy-service-pod
Command: ```bash kubectl exec proxy-service-pod -c stardust-shuttle -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Forward local port 6379 to port 8081 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 6379 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 au...
Forward port from local machine to a pod
Command: ```bash kubectl port-forward pod/web-app-pod :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 automatica...
Create a copy of the proxy-server-pod and add a debug container, set its image to debian, and also change the image of the existing container to loggging-app:debug
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-app --image=debian --set-image=logger=logging-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 identif...
Retrieve the snapshot logs from the container "monitoring-pod-1" in the deployment "scheduler-app-deployment".
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c monitoring-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "f...
Retrieve the logs from the container named media-stream-pod-1 of the deployment order-processing-deployment
Command: ```bash kubectl logs deployment/order-processing-deployment -c media-stream-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 flag...
Start a golang pod with partially overridden values
Command: ```bash kubectl run nginx --image=golang --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...
Set the custom TLS server name to use for validation for the staging-cluster cluster entry
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=cloud-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] [--certifi...
Set a custom TLS server name for validation for the "app-cluster" cluster entry
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=data-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] [--certificate-...
Create a pod disruption budget named cron-jobs-pdb that will select all pods with the tier=frontend label, and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=tier=frontend --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=N [-...
Get the output from running the 'go run hello.go' command in stardust-shuttle from the pod vpn-service-pod
Command: ```bash kubectl exec vpn-service-pod -c stardust-shuttle -- 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. I...
Run the command 'npm --version' inside the 'nebula-navigator' container of the 'proxy-server-pod' pod and print the output.
Command: ```bash kubectl exec proxy-server-pod -c nebula-navigator -- npm --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...
Create a new config map named db-config using the files /path/to/settings/file1.txt and /path/to/preferences/file2.txt, and specify the keys as conf and data respectively.
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/preferences/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...
Forward traffic from local port 6379 to port 8088 in the pod "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 6379:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crite...