prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Output the modified deployment configuration in YAML format without making any changes to the actual object on the server.
Command: ```bash kubectl set env deployment/backend-microservice-deployment SECRET_KEY=your-secret-key -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...
Create an ingress with TLS enabled and define different paths and services for each path
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="testing.com/=svc:https,tls" \ --rule="testing.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"...
Forward traffic from port 3000 on all addresses to port 6379 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 3000: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 wi...
Update the image of all containers in the daemonset named "staging" to "amazonlinux:2"
Command: ```bash kubectl set image daemonset staging *=amazonlinux:2 ``` 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: `ku...
Set a custom TLS server name for the my-k8s-cluster cluster entry
Command: ```bash kubectl config set-cluster my-k8s-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] [--certific...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/media-stream-rc pods/proxy-server-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 name...
Import specific keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-config deployment/authentication-service-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...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8000 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8088: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 crite...
Import specific keys from a config map to a deployment by running the command `kubectl set env --keys=secret_key --from=configmap/api-config deployment/web-app-deployment`.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/api-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 in o...
Set the service account of the 'api-server-deployment' deployment to 'metrics-server'
Command: ```bash kubectl set serviceaccount deployment api-server-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 Syntax: `...
get deployments in JSON format from a specific API group and version
Command: ```bash kubectl get deployments.v2.0.0.sandbox-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 wi...
Retrieve the previous terminated logs of the 'mycontainer' container from the 'web-app-pod' pod.
Command: ```bash kubectl logs -p -c mycontainer web-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", "shor...
Create a job named image-build-job using the amazonlinux image, with the command /bin/bash -c "echo 'Hello'".
Command: ```bash kubectl create job image-build-job --image=amazonlinux -- /bin/bash -c "echo 'Hello ``` 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": "", "u...
Create a ClusterIP service named security-service-clusterip
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=8443:9000 ``` 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...
Check if you have permission to list the "deploy-artifacts-job" job in the "testing" namespace
Command: ```bash kubectl auth can-i list jobs.batch/deploy-artifacts-job -n testing ``` 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 U...
Create a LoadBalancer service named media-stream-lb for TCP traffic from port 9092 to port 8089.
Command: ```bash kubectl create service loadbalancer media-stream-lb --tcp=9092:8089 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Start a postgres pod with the name "hazelcast" using the postgres image, and expose port 3000.
Command: ```bash kubectl run hazelcast --image=postgres --port=3000 ``` 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": "-...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/proxy-server-pod :8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a service for the replication controller specified in "hazelcast-controller.yaml" by mapping port 5432 on the service to port 500100 on the containers.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=5432 --target-port=500100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
Use an alternative editor to edit a service
Command: ```bash KUBE_EDITOR="atom" kubectl edit svc/email-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, ...
Embed the certificate authority data for the 'data-cluster' cluster entry using the command: `kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt`
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Create a job with a specific command to run
Command: ```bash kubectl create job monitoring-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch ``` 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": "-...
View the resource utilization metrics for all pods in a specific namespace
Command: ```bash kubectl top pod --namespace=external-metrics-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: `kubec...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from local to /tmp/bar_dir in the remote pod 'auth-service-pod-11' in the 'monitoring' namespace
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ monitoring/auth-service-pod-11:/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"...
Update the pod 'email' by setting the annotation 'team' with the value 'frontend-team', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods email team='frontend-team' ``` 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...
Listen on port 8000 on localhost and IP 10.19.21.23, and forward the traffic to port 8081 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8000: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 cr...
Execute the 'elasticsearch' command in the 'astro-container' from the 'auth-service-pod' and display the output.
Command: ```bash kubectl exec auth-service-pod -c astro-container -- 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 ...
Add/update the annotation 'contact-email' with the value 'support@example.com' for the pod 'frontend'
Command: ```bash kubectl annotate pods frontend contact-email=support@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 and inc...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from your local machine to the /etc/kubernetes directory inside the logging-agent-pod-7 pod
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ logging-agent-pod-7:/etc/kubernetes -c api-server-container ``` 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", "defau...
Create a new config map named 'namespace-config' using the properties files in the 'path/to/properties' folder
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/properties ``` 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 ba...
Create a copy of the 'security-service-pod' pod, adding a 'debug' container
Command: ```bash kubectl debug security-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=database=mysql:5.7,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Update the label of the 'proxy' pod to 'release=v2.0'
Command: ```bash kubectl label pods proxy release=v2.0 ``` 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...
Create a new ClusterIP service named 'api-service-clusterip' that maps port 7000 of the service to port 8082 of the pods.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=7000: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", "d...
Start a pod with the nginx image from docker.elastic.co/elasticsearch/elasticsearch, but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "dev-2.2.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] [--ove...
Add a taint with key 'zone' and value 'db-node-7:PreferNoSchedule' to nodes with the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend zone=db-node-7: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...
Add a taint with key 'hardware' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 hardware=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": "", "usage"...
Update the deployment named 'mydeployment' by adding a new environment variable 'API_KEY' with the value 'your-api-key'
Command: ```bash kubectl set env deployment/mydeployment API_KEY=your-api-key ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (withi...
Create a service for a WordPress deployment on port 80 that connects to the containers on port 8000.
Command: ```bash kubectl expose deployment wordpress --port=5000 --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 spec...
Expose a replication controller as a service, serving on port 8080 and connecting to containers on port 801000
Command: ```bash kubectl expose -f wordpress-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 ...
Forward traffic from local port 6379 to port 3000 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 6379:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Add a taint with key 'app' and no value to the node 'dev-node-4'
Command: ```bash kubectl taint nodes dev-node-4 app:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|y...
Create a cluster role named "bar" with the ability to update services resources, specifically the "notification-service" and "file-processing" resources.
Command: ```bash kubectl create clusterrole bar --verb=update --resource=services --resource-name=notification-service --resource-name=file-processing ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serve...
Get output from the 'elasticsearch --version' command running on the first pod of the gateway-service service.
Command: ```bash kubectl exec svc/gateway-service -- elasticsearch --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...
Update the image of the containers in the daemonset named 'nginx' to 'python:3.9.7'
Command: ```bash kubectl set image daemonset nginx *=python:3.9.7 ``` 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: `kubec...
Monitor the deployment status of a test deployment
Command: ```bash kubectl rollout status deployment/test ``` What it does: Show the status of the rollout. By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts in-bet...
Create an ingress called 'public-api-ingress' that directs requests to website.com/bar to service 'svc1' on port 8084, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/bar=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Forward the local port 5432 to port 8088 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 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 will be selected...
Add a taint with the key 'datacenter' on nodes with the label 'service=auth'
Command: ```bash kubectl taint node -l service=auth datacenter=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": "...
Create a service for an ubuntu deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment ubuntu --port=3001 --target-port=808900 ``` 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...
Copy the ~/.config/kube directory from the remote pod named 'image-resizer-pod-20' in the 'kube-system' namespace to the local directory '/tmp/bar_dir'.
Command: ```bash kubectl cp kube-system/image-resizer-pod-20:~/.config/kube /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,...
Create a role named "view" with the specified SubResource.
Command: ```bash kubectl create role view --verb=update,get,patch --resource=namespaces,namespaces/status ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags:...
Retrieve a list of deployments in the "legacy-1.0.0" version of the "custom-deployments" API group in JSON format
Command: ```bash kubectl get deployments.legacy-1.0.0.custom-deployments -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 names...
List the replication controller named 'web', the service named 'security-service-rc', and the pod named 'payment-gateway-pod'.
Command: ```bash kubectl get rc/web service/security-service-rc pods/payment-gateway-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type ...
Add a taint with the key 'disktype=storage-node-13:PreferNoSchedule' to nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 disktype=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": "", "usag...
Import the 'debug_mode' key from the 'env-vars' config map and set it as an environment variable for the 'frontend-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --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 in on...
Create a new ClusterIP service named my-cs that maps local port 8088 to target port 8088
Command: ```bash kubectl create service clusterip my-cs --tcp=8088:8088 ``` 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", "default": "", "us...
Add a taint on nodes with the label 'service=auth' and the taint key 'zone=dev-node-4'
Command: ```bash kubectl taint node -l service=auth zone=dev-node-4: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...
Connect to a running container and interact with it in a terminal
Command: ```bash kubectl attach gateway-pod -c mycontainer -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 omitted...
Create a service for a replicated node that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc node --port=5001 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Update the deployment 'backend-microservice-deployment' by setting the environment variable SMTP_HOST to smtp.example.com
Command: ```bash kubectl set env deployment/backend-microservice-deployment SMTP_HOST=smtp.example.com ``` 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 ...
Forward local port 5000 to port 8081 in the pod log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Forward traffic to/from ports 3000 and 8080 in a local machine to a pod selected by the deployment "email-server-deployment"
Command: ```bash kubectl port-forward deployment/email-server-deployment 3000 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
taint nodes with label 'environment=production' with taint key 'workload=kube-master-9:PreferNoSchedule'
Command: ```bash kubectl taint node -l environment=production workload=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": "",...
Add the label 'release' with the value 'v1.0' to the pod named 'proxy'
Command: ```bash kubectl label pods proxy release=v1.0 ``` 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...
Forward traffic from local port 5000 to the target port of the "https" service port in a pod selected by the "logging-service" service
Command: ```bash kubectl port-forward service/logging-service 5000:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create a new ExternalName service named 'external-notification-service' with the external name 'documentation-tech.tech'
Command: ```bash kubectl create service externalname external-notification-service --external-name documentation-tech.tech ``` 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 r...
Forward local port 8088 to port 5432 in the pod named 'frontend-pod', listening on localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-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 criter...
Get the output of the command 'ruby --version' from the first pod of the frontend-deployment deployment.
Command: ```bash kubectl exec deploy/frontend-deployment -- ruby --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,...
Create a pod disruption budget named replica-set-pdb that will select all pods with the app=rails label and require a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=app=rails --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 [--d...
Create a cluster role named "view" with specified resource names
Command: ```bash kubectl create clusterrole view --verb=watch --resource=pods --resource-name=error-logger --resource-name=blog-backend ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]`...
Switch to raw terminal mode and attach to the 'stardust-shuttle' container in the 'monitoring-pod' pod
Command: ```bash kubectl attach monitoring-pod -c stardust-shuttle -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...
Apply a taint to the 'monitoring-node-15' node with the key 'environment' and no value
Command: ```bash kubectl taint nodes monitoring-node-15 environment: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...
Run the 'geth' command in the 'rocket-ranger' container of the 'chat-app-pod' pod and retrieve its output
Command: ```bash kubectl exec chat-app-pod -c rocket-ranger -- geth ``` 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...
Import environment variables from the "oauth-secret" secret and set it as environment variables for the "cache-cluster-deployment" deployment.
Command: ```bash kubectl set env --from=secret/oauth-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 more po...
Create a new config map named 'monitoring-config' using the 'properties' file located at '/path/to/options/file1.txt' and the 'key1' file located at '/path/to/parameters/file2.txt'
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Copy the local file '/tmp/foo_dir' to the remote pod 'logging/worker-pod-4' at the destination path '/tmp/bar' in the specified namespace.
Command: ```bash kubectl cp /tmp/foo_dir logging/worker-pod-4::/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....
Set the resource request and limits for all containers in the 'amazonlinux' deployment
Command: ```bash kubectl set resources deployment amazonlinux --limits=cpu=200m,memory=512Mi --requests=cpu=3,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 reque...
Create a pod disruption budget named database-pdb that will select all pods with the tier=frontend label, and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=tier=frontend --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 [--...
Add a taint with key 'environment' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 environment=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...
Set cluster field of my-context context to web-cluster
Command: ```bash kubectl config set contexts.app-2-context.cluster web-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 wan...
Create a new service named 'database-nodeport' with a NodePort type, and forward traffic from port 8181 on the host to port 8080 on the pods.
Command: ```bash kubectl create service nodeport database-nodeport --tcp=8181:8080 ``` 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": ""...
List deployments in the JSON output format, using the "custom-version" version of the "my-apps" API group.
Command: ```bash kubectl get deployments.custom-version.my-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...
Forward port 5000 on all addresses to port 8888 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 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 pod will...
Forward local port 8000 to port 8080 in the pod
Command: ```bash kubectl port-forward pod/web-app-pod 8000 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/db-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 port 8080 to port 8080 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Copy the file named "foo" from the "/tmp" directory in the local machine to the "/etc/kubernetes" directory in the "api-server-pod-3" pod, specifically in the "web-app-container" container.
Command: ```bash kubectl cp :/tmp/foo api-server-pod-3:/etc/kubernetes -c web-app-container ``` 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...
Listen on port 8000 on all addresses and forward the traffic to port 8080 in the pod named 'api-service-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Create a copy of the e-commerce pod, replacing the command of the code-explorer container with a shell session for debugging
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-api --container=code-explorer -- 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 ...
Switch to raw terminal mode and attach to a running pod called "database-pod" using the container "code-explorer"
Command: ```bash kubectl attach database-pod -c code-explorer -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...
Taint node "node-1" with key "environment" and no value
Command: ```bash kubectl taint nodes node-1 environment: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: js...
Forward traffic from port 8081 on localhost and IP 10.19.21.23 to port 9090 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8081: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 cr...
Set the resource request and limits for all containers in the nginx deployment
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 requeste...
Create a copy of the chat-app-pod with a modified code-explorer command
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-custom-dbg --container=code-explorer -- 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 defa...
Update the image of the 'nginx' container in all deployments and replica sets to 'openjdk:16.0.2'
Command: ```bash kubectl set image deployments,rc openjdk=openjdk:16.0.2 --all ``` 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) S...
Update the image of all containers in the 'services' daemonset to 'node:14.17.3'
Command: ```bash kubectl set image daemonset services *=node:14.17.3 ``` 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: `ku...
Edit the 'last-applied-configuration' annotations of the resource in the 'preferences.yaml' file using the JSON output format
Command: ```bash kubectl apply edit-last-applied -f preferences.yaml -o json ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will ope...
Retrieve details of a specific pod in YAML format
Command: ```bash kubectl get -o yaml pod 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 namespaced you will only see...
Forward port 5000 on your local machine to port 9090 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward pod/web-app-pod 5000: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 automa...
Update the 'gateway-deployment' deployment by adding a new environment variable JWT_SECRET with the value 'your-jwt-secret'
Command: ```bash kubectl set env deployment/gateway-deployment JWT_SECRET=your-jwt-secret ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...