prompt
stringlengths
13
282
response
stringlengths
128
3.11k
View the last 3 lines of the logs for the pod named "cdn-service-pod"
Command: ```bash kubectl logs --tail=3 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": "--container", "short": "...
Remove all the taints with key 'zone' from the 'dev-node-4' node
Command: ```bash kubectl taint nodes dev-node-4 zone- ``` 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|name|...
Create a copy of the auth-service-pod and add a debug container with debian image
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=app=app:debug,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Create a copy of the 'email-service-pod' pod, adding a debug container and changing container images
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified b...
Create an ingress called 'public-service-ingress' with the following rule: redirect requests from foo.com/input to svc1:5001 and use the TLS secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/input=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": "", ...
Attach to pod vpn-service-pod in container warp-drive and interact with its terminal
Command: ```bash kubectl attach vpn-service-pod -c warp-drive -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...
Create a config map named app-settings using specific keys instead of filenames from disk
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/settings/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 creati...
Set the service account of the deployment backend-microservice-deployment to kube-controller-manager
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment kube-controller-manager ``` 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), sta...
Import environment from a secret to a deployment.
Command: ```bash kubectl set env --from=secret/azure-storage-secret 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 definitions in one...
Create an ingress called 'app-proxy-ingress' that directs requests to 'foo.com/bar' to 'svc1:5000' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="foo.com/bar=svc1:5000,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"...
Expose a pod as a service with a specific port and name
Command: ```bash kubectl expose pod chat-app-pod --port=8000 --name=frontend ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified por...
Add a taint with the key 'cpu-type' and value 'web-node-8' on nodes that have the label 'stack=tech-stack'.
Command: ```bash kubectl taint node -l stack=tech-stack cpu-type=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Import specific keys from a config map to the environment variables of a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/log-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 definitions...
Update the environment annotation of a pod specified in the "settings.json" file to "staging"
Command: ```bash kubectl annotate -f settings.json 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 stri...
Get the output from the nano-bot container in the api-service-pod pod
Command: ```bash kubectl attach api-service-pod -c nano-bot ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Set the service account of the deployment "order-processing-deployment" to "cert-manager".
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment cert-manager ``` 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 job named "batch-processing" using the nginx image and run the command "nginx -t"
Command: ```bash kubectl create job batch-processing --image=nginx -- nginx -t ``` 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....
Create an ingress called ingtls with TLS enabled
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="website.com/=svc:https,tls" \ --rule="foo.com/path/subpath*=othersvc:6379" ``` 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": "-...
Set the client-key-data field in the app-operator user by providing the certificate data and using the --set-raw-bytes=true option
Command: ```bash kubectl config set users.app-operator.client-key-data cert_data_here --set-raw-bytes=true ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VA...
Forward traffic from port 8080 on localhost and IP address 10.19.21.23 to port 6379 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/cdn-service-pod :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 a deployment to the default service account.
Command: ```bash kubectl set serviceaccount deployment web-app-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 Syntax: `kubectl se...
Create a new ClusterIP service named billing-service-clusterip with the mapping of TCP port 9091 on the service to TCP port 8082 on the pods.
Command: ```bash kubectl create service clusterip billing-service-clusterip --tcp=9091:8082 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
retrieve the logs from the backend-pod pod
Command: ```bash kubectl logs backend-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", "default...
Run a mysql pod with overridden specifications using JSON
Command: ```bash kubectl run nginx --image=mysql --overrides='{ "apiVersion": "v1.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] -- [COMMAND...
Create a debug container for the 'auth-service-pod' pod, and copy it to a new pod named 'debug-image-api' with the 'debian' image
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-api --image=debian --set-image=mailer=mailer:latest,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Create a pod disruption budget named logging-pdb that will select all pods with the owner=team-1 label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=owner=team-1 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dr...
Set the CPU and memory limits for the Elasticsearch container in the deployment to "200m" and "64Mi" respectively.
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=200m,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, but may burs...
Get the output from running the 'psql' command from the pod named proxy-server-pod, using the first container by default
Command: ```bash kubectl exec proxy-server-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.kub...
Import the 'SMTP_SERVER' key from the 'api-config' config map and set it as an environment variable for the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --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 definit...
Apply the configuration in the './preferences.json' file to a pod
Command: ```bash kubectl apply -f ./preferences.json ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config...
Update the pod 'monitoring' by adding the annotation 'app-version' with the value '2.5.1'
Command: ```bash kubectl annotate pods monitoring app-version=2.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 than labels and include arbitrary...
List deployments in the "internal-apps" API group using the "custom-version" version, and display the output in JSON format
Command: ```bash kubectl get deployments.custom-version.internal-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...
Create an ingress called 'private-api-ingress' that routes requests from 'foo.com/example' to 'svc1:5432'
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/example=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Retrieve the logs of the previous terminated code-explorer container from the pod named "chat-app-pod".
Command: ```bash kubectl logs -p -c code-explorer chat-app-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", "s...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/e-commerce-pod :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 automat...
Run the 'python --version' command inside the 'auth-service-pod' pod and print the output
Command: ```bash kubectl exec auth-service-pod -- python --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
List deployments in YAML output format, specifically targeting the "stable-2.0.0" version of the "apps" API group.
Command: ```bash kubectl get deployments.stable-2.0.0.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 you will...
Create a new config map named app-secrets with the specified keys and corresponding file paths
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a conf...
Create a deployment named "db" using the "confluentinc/cp-kafka" image and expose port 8080
Command: ```bash kubectl create deployment db --image=confluentinc/cp-kafka --port=8080 ``` 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...
Expose the Python deployment as a service, serving on port 8082 and connecting to the containers on port 844300.
Command: ```bash kubectl expose deployment python --port=8082 --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 specifi...
Check if you have permission to list the job named "cache-warming-job" in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cache-warming-job -n kube-system ``` 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 ...
Delete the pods and services named "auth" and "api"
Command: ```bash kubectl delete pod,service auth api ``` 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 r...
Execute the 'go run hello.go' command in the nebula-navigator container, running inside the monitoring-pod pod, and display the output.
Command: ```bash kubectl exec monitoring-pod -c nebula-navigator -- 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...
Set the resource request and limits for all containers in elasticsearch.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=4Gi ``` 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 ...
Copy the file "/tmp/foo" from the remote pod "argocd/auth-service-pod-11" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp argocd/auth-service-pod-11::/tmp/foo /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...
Start port forwarding to listen on port 8088 for all addresses and forward the traffic to port 5000 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8088: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 w...
Copy the local file ~/.config/kube to the /etc/kubernetes directory of the pod named metrics-exporter-pod-10 in the kube-dns namespace.
Command: ```bash kubectl cp ~/.config/kube kube-dns/metrics-exporter-pod-10:/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 omitt...
Remove taints with key 'datacenter' from node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 datacenter- ``` 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...
import the REDIS_HOST key from the config map named kube-system-config and set it as an environment variable in the deployment named analytics-platform-deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/kube-system-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Set resource requests and limits for containers in Amazon Linux deployment
Command: ```bash kubectl set resources deployment amazonlinux --limits=cpu=200m,memory=512Mi --requests=cpu=5,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 reque...
Set the service account of the 'web-app-deployment' deployment to 'tekton'.
Command: ```bash kubectl set serviceaccount deployment web-app-deployment tekton ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl set...
Set up an autoscaling policy for the 'api' deployment, allowing the number of pods to scale between 1 and 13
Command: ```bash kubectl autoscale deployment api --min=1 --max=13 ``` 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...
Create a copy of the payment-gateway-pod with a debug container using the debian image
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-api --image=debian --set-image=app=app:debug,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Create a new config map named namespace-config and specify the keys to use instead of using the file basenames on disk.
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/settings/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 c...
Set the autoscaling policy for the deployment 'log-aggregator' with the minimum number of pods set to 2 and the maximum number of pods set to 13.
Command: ```bash kubectl autoscale deployment log-aggregator --min=2 --max=13 ``` 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 th...
Forward local port 5000 to pod port 8000
Command: ```bash kubectl port-forward pod/web-app-pod 5000: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 automa...
Forward traffic from port 8000 on all addresses to port 3000 inside the pod "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8000: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 wi...
Remove the label named 'bar' from the pod 'api'
Command: ```bash kubectl label pods api app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, che...
Auto scale the replication controller "payment" with a target CPU utilization of 20%, ensuring that the number of pods stays between 1 and 3.
Command: ```bash kubectl autoscale rc payment --max=3 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Create a deployment named grafana that runs the postgres image with 5 replicas
Command: ```bash kubectl create deployment grafana --image=postgres --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 o...
Expose a service for a replication controller using a yaml file, specifying the port mappings
Command: ```bash kubectl expose -f centos-controller.yaml --port=8089 --target-port=800000 ``` 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 pod named 'hazelcast' using the 'jenkins' image, and expose port 8010
Command: ```bash kubectl run hazelcast --image=jenkins --port=8010 ``` 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": "--...
Create a new namespace named 'kube-dns'
Command: ```bash kubectl create namespace kube-dns ``` What it does: Create a namespace with the specified name. Syntax: `kubectl create namespace NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-template|go-templ...
Create a cluster role named "default_role" with ResourceName specified
Command: ```bash kubectl create clusterrole default_role --verb=exec --resource=services --resource-name=monitoring-prometheus --resource-name=image-processor ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-r...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/global-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...
Create an ingress named 'public-service-ingress' that routes requests from foo.com/module to svc1:8083 and use the TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/module=svc1:8083,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": "",...
List the deployments in the "rc-1.1.0" version of the "api-v2" API group in JSON output format.
Command: ```bash kubectl get deployments.rc-1.1.0.api-v2 -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 o...
Set up automatic scaling for the 'payment' deployment, with the number of pods ranging from 2 to 12.
Command: ```bash kubectl autoscale deployment payment --min=2 --max=12 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Execute a command "node --version" in the first container of the first pod of the deployment "log-aggregator-deployment"
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- node --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 om...
Create a cron job named "log-rotation" that runs the command "redis-server --version" every minute using the image "redis".
Command: ```bash kubectl create cronjob log-rotation --image=redis --schedule="*/1 * * * *" -- redis-server --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", "sh...
Add a taint with key 'workload' on nodes having label release=beta
Command: ```bash kubectl taint node -l release=beta workload=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"...
Create a single ingress called 'api-v2-ingress' that directs requests to testing.com/bar to svc1:9091 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.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...
Listen on port 8888 on all addresses and forward the traffic to port 6379 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8888: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 w...
Import the 'redis_host' key from the 'log-config' config map into the environment variables of the 'payment-processor-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-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 defini...
create a cron job named 'metrics-collection' using the 'ethereum/client-go' image that runs the command 'geth attach' every minute
Command: ```bash kubectl create cronjob metrics-collection --image=ethereum/client-go --schedule="*/1 * * * *" -- geth attach ``` 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": "--outp...
Create a deployment named prometheus with 7 replicas
Command: ```bash kubectl create deployment prometheus --image=ubuntu --replicas=7 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Copy the local file named 'foo' located at '/tmp' to the '/etc/kubernetes' directory inside the 'ingress-controller-pod-8' pod in the 'kube-proxy' namespace.
Command: ```bash kubectl cp :/tmp/foo kube-proxy/ingress-controller-pod-8:/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...
Forward local port 3000 to port 8000 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000 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 on nodes with a specific label
Command: ```bash kubectl taint node -l service=auth hardware=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 API_KEY key from the db-config config map and set it as an environment variable for the frontend-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-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 one ...
Forward local port 8080 to port 8888 in the pod "proxy-server-pod" and listen on both localhost and IP address 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8080: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 cr...
Display the merged kubeconfig settings
Command: ```bash kubectl config view ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpful flags: "flag": "--output", "short": "-o", "default": "yaml", "usa...
Add a taint with key 'environment' on nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel 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": "Ou...
Return the snapshot logs from the container named gateway-pod-1 in the deployment named database-deployment.
Command: ```bash kubectl logs deployment/database-deployment -c gateway-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": "-...
Update the pod 'monitoring' by adding the annotation 'compliance-level' with the value 'PCI-DSS'.
Command: ```bash kubectl annotate pods monitoring compliance-level=PCI-DSS ``` 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 ar...
import the specific keys 'my-example-key' from the 'db-config' config map into the 'web-app-deployment' deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/db-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Set the cluster field to 'dev-cluster' in the 'my-context' context.
Command: ```bash kubectl config set contexts.cluster-2-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Create a service for the replicated php using a replica set
Command: ```bash kubectl expose rs php --port=8080 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Create a priority class named high-priority with a value of 1000 and a description of "Top priority, critical workloads"
Command: ```bash kubectl create priorityclass high-priority --value=1000 --description="Top priority, critical workloads" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --glob...
Create a deployment named "jenkins-x" with the image "mcr.microsoft.com/dotnet/core/runtime" and expose port 7000.
Command: ```bash kubectl create deployment jenkins-x --image=mcr.microsoft.com/dotnet/core/runtime --port=7000 ``` 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": "", ...
Update the description of the pod 'analytics' only if its resource version is 1
Command: ```bash kubectl annotate pods analytics description='my frontend running nginx' --resource-version=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 b...
View detailed information about all configmaps
Command: ```bash kubectl describe configmaps ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a name p...
Execute the 'python' command in the 'warp-drive' container of the 'chat-app-pod' pod and get the output.
Command: ```bash kubectl exec chat-app-pod -c warp-drive -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Forward traffic from port 8080 on all addresses to port 8888 of the web-app-pod in the default namespace.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8080:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Partially update the 'node-2' node by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node node-2 -p '{"spec":{"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...
import the specific key 'max_connections' from the 'app-config-dev' config map and set it as an environment variable in the 'email-server-deployment' deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-dev 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 de...
Forward traffic from local port 5000 to port 8081 in the pod named api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 5000: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...
Remove a taint on a specific node
Command: ```bash kubectl taint nodes dev-node-4 datacenter: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. One of:...
Forward port 6379 on all addresses to port 5432 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 6379: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 ...