prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Display the most recent 20 lines of logs for the pod "auth-service-pod"
Command: ```bash kubectl logs --tail=20 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":...
Create a copy of the web-app-pod and add a debug container
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-memcached --image=debian --set-image=database=mysql:5.7,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Display information about the replication controller 'web', service 'monitoring-rc', and pod 'e-commerce-pod'
Command: ```bash kubectl get rc/web service/monitoring-rc pods/e-commerce-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 namespac...
Forward traffic from port 8080 of all addresses to port 6379 in the analytics-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-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 wil...
Create a job using the specified image
Command: ```bash kubectl create job batch-processing --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 of: j...
Set environment variable from specific keys in a config map for a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod 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 defi...
Set up an autoscaling policy for the 'security' deployment with the number of pods ranging from 4 to 8.
Command: ```bash kubectl autoscale deployment security --min=4 --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 uses...
Create a service for the replicated hazelcast using replica set 'hazelcast', which will serve on port 80 and connect to the containers on port 8000.
Command: ```bash kubectl expose rs hazelcast --port=80 --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 specified port...
Update the annotation 'env' of the pod 'chat-app' with the value 'staging'
Command: ```bash kubectl annotate pods chat-app env=staging ``` 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 string ...
Import specific keys from a config map into a deployment called "payment-processor-deployment" by using the keys "DATABASE_URL" from the config map "app-config".
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-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 defi...
Execute the 'kafka-console-producer' command in the 'cyber-sleuth' container of the 'proxy-service-pod' pod and get the output.
Command: ```bash kubectl exec proxy-service-pod -c cyber-sleuth -- kafka-console-producer --broker-list localhost:9092 --topic test ``` 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": "...
Execute the 'mongo' command in the rocket-ranger container of the backend-pod and retrieve the output.
Command: ```bash kubectl exec backend-pod -c rocket-ranger -- 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 th...
Create a new secret named jwt-secret using the files in the path/to/settings folder
Command: ```bash kubectl create secret generic jwt-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 of the f...
Import the 'config_file_path' key from the 'env-vars' config map and set it as an environment variable in the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/env-vars 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 definit...
Forward local port 6379 to port 5000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 6379 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 automa...
Set the service account of the deployment "authentication-service-deployment" to "default"
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment default ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Synt...
Forward the local ports 8888 to port 3000 in a pod selected by the `monitoring-stack-deployment` deployment.
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 8888 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/namespace-config deployment/notification-handler-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 ...
Start a mysql pod named 'hazelcast', using the mysql image, and expose port 6379 for the container.
Command: ```bash kubectl run hazelcast --image=mysql --port=6379 ``` 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...
Create a role named "reader" with the ability to watch pods and specific resources named "file-uploader" and "blog-backend".
Command: ```bash kubectl create role reader --verb=watch --resource=pods --resource-name=file-uploader --resource-name=blog-backend ``` 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|cli...
Create a deployment named "monitoring" using the hazelcast image and expose port 8000.
Command: ```bash kubectl create deployment monitoring --image=hazelcast/hazelcast --port=8000 ``` 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 ...
Update the pod named 'proxy-server' and add/update the annotation 'expiration-date' with the value '2024-12-31'
Command: ```bash kubectl annotate pods proxy-server expiration-date='2024-12-31' ``` 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 incl...
Create a service with an ExternalName type named "external-dns-service" that points to the external name "dummy-website.io"
Command: ```bash kubectl create service externalname external-dns-service --external-name dummy-website.io ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference service...
Add a taint with key 'special' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice special=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
List deployments in JSON output format, using the "v2.0.0" version of the "beta-apps" API group.
Command: ```bash kubectl get deployments.v2.0.0.beta-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 will ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-secrets 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 definitio...
Taint nodes that have the label 'feature=feature-xyz' by adding the taint with key 'dedicated=kube-master-9' and the effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l feature=feature-xyz dedicated=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Create a single ingress called 'web-ingress' with a rule that directs requests for 'website.com/bar' to 'svc1:8080' and uses the TLS secret 'my-cert'
Command: ```bash kubectl create ingress web-ingress --rule="website.com/bar=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Forward local port 8080 to port 8088 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Forward local port 8080 to port 9090 on the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8080:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Start a new pod named "nginx" with the image "ubuntu", but override some of the specifications with values parsed from a JSON file.
Command: ```bash kubectl run nginx --image=ubuntu --overrides='{ "apiVersion": "v1.1.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...
Execute the 'elasticsearch' command inside the 'monitoring-pod' pod to get the output.
Command: ```bash kubectl exec monitoring-pod -- elasticsearch ``` 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 kube...
Create a debug copy of mypod with all container images changed to hazelcast/hazelcast
Command: ```bash kubectl debug mypod --copy-to=debug-image-api --set-image=*=hazelcast/hazelcast ``` 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 ...
Retrieve a list of deployments in the "custom-version" version of the "external-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.custom-version.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 namespac...
Apply a taint on nodes with the label stack=tech-stack and the key 'cpu-type' set to 'gpu-node-12' with the effect PreferNoSchedule.
Command: ```bash kubectl taint node -l stack=tech-stack cpu-type=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"...
Output the modified analytics-platform-deployment deployment in YAML format with the QUEUE_NAME environment variable set to "task-queue", and do not alter the deployment on the server.
Command: ```bash kubectl set env deployment/analytics-platform-deployment QUEUE_NAME=task-queue -o yaml ``` 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...
Copy the file /tmp/foo from the remote pod kube-dns/message-broker-pod-15 to the local machine at /tmp/bar.
Command: ```bash kubectl cp kube-dns/message-broker-pod-15:/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 ku...
Set the service account of the deployment "backend-microservice-deployment" to "metrics-server"
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment metrics-server ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset ...
Forward traffic from port 9090 on all addresses to port 8000 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 9090: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 wi...
Execute the npm --version command in the first container of the payment-processor-deployment deployment and display the output.
Command: ```bash kubectl exec deploy/payment-processor-deployment -- 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 ...
Auto scale the replication controller named "database" to have a minimum of 1 pod and a maximum of 3 pods, targeting a CPU utilization of 81%.
Command: ```bash kubectl autoscale rc database --max=3 --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 use...
Create a pod disruption budget named frontend-pdb that will select all pods with the role=worker label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=role=worker --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 [--dr...
Connect to a specific pod and interact with the `nebula-navigator` container in a raw terminal mode
Command: ```bash kubectl attach gateway-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. If om...
Update the pod identified by the type and name specified in "options.json" by adding an annotation with the release notes URL 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate -f options.json release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be l...
Create a job with a specific image and command.
Command: ```bash kubectl create job monitoring-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 forma...
Set the resource request and limits for all containers in the ubuntu deployment
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=2Gi ``` 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...
Create a new config map named log-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ...
Expose the replica set called "python" as a service, with port 8888 on the service mapped to port 637900 on the replica set's containers.
Command: ```bash kubectl expose rs python --port=8888 --target-port=637900 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Import the environment variables from the 'database-secret' secret and set them for the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --from=secret/database-secret deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more...
Remove a specific taint from a node
Command: ```bash kubectl taint nodes app-node-6 workload- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|n...
Retrieve logs from the container named "analytics-pod-1" in the deployment "payment-processor-deployment".
Command: ```bash kubectl logs deployment/payment-processor-deployment -c analytics-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:...
Create a deployment with 3 replicas named my-dep using the centos image
Command: ```bash kubectl create deployment my-dep --image=centos --replicas=3 ``` 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: ...
Get the output from running the 'pip --version' command in the 'warp-drive' container of the 'cdn-service-pod' pod
Command: ```bash kubectl exec cdn-service-pod -c warp-drive -- pip --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 omitte...
Delete the pods and services with the names "monitoring" and "payment"
Command: ```bash kubectl delete pod,service monitoring payment ``` 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 select...
Import the environment variables from the "app-config-secret" secret and apply them to the "cache-cluster-deployment" deployment
Command: ```bash kubectl set env --from=secret/app-config-secret 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 in one or mo...
Create a service for the replicated centos using a replica set, with port 80 as the external port and connecting to the containers on port 8000
Command: ```bash kubectl expose rs centos --port=3306 --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 specified port....
Execute the 'mongo' command in the rocket-ranger container of the gateway-pod pod and display the output.
Command: ```bash kubectl exec gateway-pod -c rocket-ranger -- 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 th...
Forward local port 8088 to port 9090 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 8088 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 autom...
forward data from local ports 8000 to 6379 in the pod `frontend-pod`
Command: ```bash kubectl port-forward pod/frontend-pod 8000 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Forward local ports 5432 and 6000 to ports 8088 and 6000 in the selected pod of the deployment
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 5432 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 ...
Forward all incoming traffic on port 9090 to the pod 'log-aggregator-pod' on port 9090, listening on all addresses (0.0.0.0)
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Update the image of all containers in the daemonset "namespace-1" to "golang:1.17".
Command: ```bash kubectl set image daemonset namespace-1 *=golang:1.17 ``` 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 an ingress resource called 'app-loadbalancer-ingress' with a rule that directs requests for site.com/bar to the service 'svc1' on port 3001
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/bar=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": "",...
Import the 'database_url' key from the 'api-config' ConfigMap into the 'user-management-deployment' deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/api-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 defini...
Create a priority class with a low priority level of 10 and a description of "Minimal resource allocation, lowest priority"
Command: ```bash kubectl create priorityclass low-priority --value=10 --description="Minimal resource allocation, lowest priority" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--...
Forward local port 3000 to the targetPort of the "https" port in a pod selected by the monitoring-service service
Command: ```bash kubectl port-forward service/monitoring-service 3000: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 sel...
Update the environment variables for the frontend-deployment deployment by importing the REDIS_HOST key from the app-secrets config map.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets 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...
Add a taint with the key 'cpu-type' on nodes having the label 'service=auth'. Set the taint to 'gpu-node-12:PreferNoSchedule'.
Command: ```bash kubectl taint node -l service=auth cpu-type=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": "O...
import the MAX_CONNECTIONS key from the monitoring-config config map and set it as an environment variable in the payment-processor-deployment deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/monitoring-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment var...
Set the CPU and memory limits for a specific container in a deployment
Command: ```bash kubectl set resources deployment golang -c=nginx --limits=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 requested, but may burst up t...
Create an ingress called 'api-v2-ingress' that directs requests from foo.com/bar to svc1:9091, and use the tls secret "my-cert".
Command: ```bash kubectl create ingress api-v2-ingress --rule="foo.com/bar=svc1:9091,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": "...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-prod deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment vari...
Copy the local file "/tmp/foo" to the remote pod "velero/image-resizer-pod-20" at the destination directory "/tmp/bar_dir" in the specified namespace.
Command: ```bash kubectl cp /tmp/foo velero/image-resizer-pod-20:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Auto scale the replication controller "analytics" to have a maximum of 2 pods and target a CPU utilization of 50%.
Command: ```bash kubectl autoscale rc analytics --max=2 --cpu-percent=50 ``` 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 us...
Set the resource limits for the go container in the deployment named "go" to a CPU limit of 3 and a memory limit of 1Gi.
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=3,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 its spe...
Check if you have the permission to list a specific job in a namespace
Command: ```bash kubectl auth can-i list jobs.batch/virus-scan-job -n monitoring ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL ...
Create a pod named 'hazelcast' using the 'mongo' image and expose port 8443
Command: ```bash kubectl run hazelcast --image=mongo --port=8443 ``` 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...
View metrics for all pods in the specified namespace
Command: ```bash kubectl top pod --namespace=external-email-service ``` 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...
Create a new service account named argocd
Command: ```bash kubectl create serviceaccount argocd ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-tem...
Display the most recent 12 lines of logs for the pod named "database-pod"
Command: ```bash kubectl logs --tail=12 database-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c...
Display the replication controller named 'web', the service named 'gateway-rc', and the pod named 'e-commerce-pod'.
Command: ```bash kubectl get rc/web service/gateway-rc pods/e-commerce-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 ...
Create a single ingress called 'private-api-ingress' that directs requests to testing.com/bar to the svc1 service on port 5001, with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/bar=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": "", "...
Create a service for a Python deployment that serves on port 9092 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment python --port=9092 --target-port=8000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified...
forward local port 8081 to port 5000 of a pod selected by the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8081 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 po...
View the previous logs of the terminated "stardust-shuttle" container from the "gateway-pod" pod.
Command: ```bash kubectl logs -p -c stardust-shuttle gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", ...
Open the 'backend-service' service for editing using the 'nano' editor.
Command: ```bash KUBE_EDITOR="nano" kubectl edit svc/backend-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables...
Import the 'log_level' key from the 'app-name-config' config map and set it as an environment variable in the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-name-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Create an ingress resource named 'ingtls' with TLS enabled using the default ingress certificate
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="site.com/path/subpath*=othersvc:5432" ``` 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": "--o...
Delete the pods and services with the names "email" and "vpn"
Command: ```bash kubectl delete pod,service email vpn ``` 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 ...
Create an autoscaling policy for the replication controller "api" that scales the number of pods between 1 and 5 based on the CPU utilization target of 60%.
Command: ```bash kubectl autoscale rc api --max=5 --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 the...
Add a taint with key 'app' and value 'backup-node-14:PreferNoSchedule' on nodes having the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha app=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": "", "usa...
Partially update the 'k8s-node-1' node using a strategic merge patch
Command: ```bash kubectl patch node k8s-node-1 -p $'spec:\n type: LoadBalancer' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful fl...
Retrieve the snapshot logs from the container named 'proxy-service-pod-1' in the 'email-server-deployment' deployment.
Command: ```bash kubectl logs deployment/email-server-deployment -c proxy-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: ...
Update the 'replicas' field of the 'node-1' node to 3 using a strategic merge patch in YAML format.
Command: ```bash kubectl patch node node-1 -p $'spec:\n replicas: 3' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags: "flag"...
Retrieve the logs for the container "chat-app-pod-1" from the deployment "database-deployment".
Command: ```bash kubectl logs deployment/database-deployment -c chat-app-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "...
List deployments in YAML output format, in the "beta-1.0" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.beta-1.0.third-party-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced ...
Set custom TLS server name for a cluster
Command: ```bash kubectl config set-cluster kube-cluster-1 --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] [--certifica...
Create an ingress called 'website-ingress' that directs requests to foo.com/input to svc1:9000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="foo.com/input=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Apply a taint with the key 'zone' and value 'storage-node-13:PreferNoSchedule' on all nodes labeled with app=web-app.
Command: ```bash kubectl taint node -l app=web-app zone=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Create a copy of the 'gateway-pod' with a debug container, using the 'debian' image
Command: ```bash kubectl debug gateway-pod -it --copy-to=my-debugger --image=debian --set-image=api=api:v2,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 identified by resource an...