prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a label to the pod 'foo' with the key 'env' and the value 'development'
Command: ```bash kubectl label pods foo env=development ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "I...
Partially update a node using strategic merge patch
Command: ```bash kubectl patch -f node-config.toml -p '{"data":{"key":"new-value"}' ``` 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]` Helpfu...
Delete the pods and services named "web" and "chat-app"
Command: ```bash kubectl delete pod,service web chat-app ``` 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. So...
Forward all traffic on port 5432 to the 'proxy-server-pod' pod's port 5432, and listen on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5432: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 ...
Create a cron job named 'data-processing' with the image 'ethereum/client-go' that runs the command 'geth' every minute
Command: ```bash kubectl create cronjob data-processing --image=ethereum/client-go --schedule="*/1 * * * *" -- geth ``` 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", "shor...
Create a pod disruption budget named cron-jobs-pdb that will select all pods with the project=my-project label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=project=my-project --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...
Create a new config map named app-config using the key=value pairs found in the file located at path/to/parameters.
Command: ```bash kubectl create configmap app-config --from-file=path/to/parameters ``` 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 basename...
Mark the node named "web-node-8" as schedulable
Command: ```bash kubectl uncordon web-node-8 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Forward traffic from port 6379 on all addresses to port 5000 in the backend pod
Command: ```bash kubectl port-forward --address 0.0.0.0 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 ...
create a job named "log-processing-job" using the PHP image.
Command: ```bash kubectl create job log-processing-job --image=php -- ``` 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: ...
Edit the configuration of the 'db-service' service.
Command: ```bash kubectl edit svc/db-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, or fall back to 'vi' f...
Listen on port 8081 locally and forward data to/from port 8080 in the backend-pod.
Command: ```bash kubectl port-forward pod/backend-pod 8081 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...
Copy the file from the local directory '/var/run/secrets/kubernetes.io/serviceaccount/' to the remote pod 'worker-pod-4' in the namespace 'istio-system' and place it in the '/tmp/bar' directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ istio-system/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": "Contai...
Get the output from running the 'elasticsearch' command from the 'email-service-pod' pod
Command: ```bash kubectl exec email-service-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 k...
List the deployments in the "legacy-apps" API group with the version "v2.1.0" and display the output in JSON format.
Command: ```bash kubectl get deployments.v2.1.0.legacy-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 wil...
Create an ingress rule called 'internal-ingress' that directs requests to 'website.com/module' to the 'svc1:8083' service using the 'my-cert' tls secret.
Command: ```bash kubectl create ingress internal-ingress --rule="website.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": "", "...
Retrieve information for the replication controller `web`, service `email-service-rc`, and pod `monitoring-pod`.
Command: ```bash kubectl get rc/web service/email-service-rc pods/monitoring-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 names...
Add a taint with key 'special' on nodes that have the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta special=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": "...
Return the snapshot logs from the container notification-handler-deployment-1 of the deployment named log-aggregator-pod.
Command: ```bash kubectl logs deployment/notification-handler-deployment -c log-aggregator-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]` Helpfu...
Delete the pods and services named "payment" and "api"
Command: ```bash kubectl delete pod,service payment 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. Som...
Import the specific keys "external_api_url" from the "db-config" ConfigMap into the "scheduler-app-deployment" deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/db-config deployment/scheduler-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 defin...
Create a job named 'scaling-job' using the 'amazonlinux' image and running the 'bash' command
Command: ```bash kubectl create job scaling-job --image=amazonlinux -- bash ``` 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. On...
Create a service for a replicated centos using the replica set "centos" which serves on port 6379 and connects to the containers on port 900000.
Command: ```bash kubectl expose rs centos --port=6379 --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....
Create a copy of the log-aggregator-pod and add a debug container with a different container image.
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-app --image=debian --set-image=api=api:v2,api=api:v2 ``` 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. ...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 3000 in the 'cdn-service-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 5000: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 cri...
Copy the local file '/tmp/foo' to the remote pod 'velero/api-server-pod-3' in the namespace and place it in '/tmp/bar'.
Command: ```bash kubectl cp /tmp/foo velero/api-server-pod-3::/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.k...
Create a deployment named "nats" that uses the "golang" image and exposes port 5000.
Command: ```bash kubectl create deployment nats --image=golang --port=5000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
create a deployment named cache with the hazelcast image and expose port 8443
Command: ```bash kubectl create deployment cache --image=hazelcast/hazelcast --port=8443 ``` 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 forma...
Create a new ExternalName service named 'external-geolocation-service' with the external name 'dummy-website.io'
Command: ```bash kubectl create service externalname external-geolocation-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...
Create a pod named hazelcast using the image mcr.microsoft.com/dotnet/core/runtime and configure the container to expose port 8080
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=8080 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args......
Create a service for the replicated 'ubuntu' pod, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc ubuntu --port=8888 --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 specified port....
Create an ingress that directs requests to a specific service with TLS
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Create an ingress with multiple hosts and the pathType as Prefix.
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8082" \ --rule="bar.com/admin*=svc2:http" ``` 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",...
Copy the /tmp/foo_dir file from your local machine to the /etc/kubernetes directory in the remote pod named file-server-pod-14 in the default namespace.
Command: ```bash kubectl cp /tmp/foo_dir default/file-server-pod-14:/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 ...
Create a job with a command
Command: ```bash kubectl create job log-collection --image=mysql -- mysql --version ``` 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 fo...
Create a new config map named app-config-prod using the key-value pairs from the file located at path/to/parameters
Command: ```bash kubectl create configmap app-config-prod --from-file=path/to/parameters ``` 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 bas...
Forward traffic between local port 3000 and pod port 8080.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 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 be selected...
Change the service account of the deployment "log-aggregator-deployment" to "spinnaker".
Command: ```bash kubectl set serviceaccount deployment log-aggregator-deployment spinnaker ``` 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: `k...
Import the specific keys "config_file_path" from the config map "app-config" into the deployment "load-balancer-deployment".
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config 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 defi...
Set the service account of the deployment "api-server-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment api-server-deployment my-service-account ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Synta...
Create a new ExternalName service named 'external-database-service' with the external name 'demo-service.dev'
Command: ```bash kubectl create service externalname external-database-service --external-name demo-service.dev ``` 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 se...
Retrieve the output from running the 'mysql' command in the 'nebula-navigator' container within the 'log-aggregator-pod' pod.
Command: ```bash kubectl exec log-aggregator-pod -c nebula-navigator -- mysql ``` 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 omitt...
Add a taint with the key 'datacenter' and value 'node-2' to the nodes that have the label 'app=web-app'
Command: ```bash kubectl taint node -l app=web-app datacenter=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outpu...
Set the environment variable `log_level` in the deployment `backend-microservice-deployment` from the `db-config` config map by importing specific keys.
Command: ```bash kubectl set env --keys=log_level --from=configmap/db-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 defin...
Forward traffic from port 8888 on all addresses to port 5432 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Listen on local ports 8088 and 6000, then forward data to/from ports 5432 and 6000 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8088 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Auto scale the replication controller "api" with a maximum of 2 pods and a target CPU utilization of 81%
Command: ```bash kubectl autoscale rc api --max=2 --cpu-percent=81 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Set the cluster field of the app-2-context context to data-cluster.
Command: ```bash kubectl config set contexts.app-2-context.cluster data-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 wa...
List the deployments in the "hotfix-1.1.2" version of the "extensions" API group and display the output in JSON format.
Command: ```bash kubectl get deployments.hotfix-1.1.2.extensions -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 yo...
View the logs of container mydeployment-1 in the deployment log-aggregator-pod
Command: ```bash kubectl logs deployment/mydeployment -c log-aggregator-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": "-...
Embed the certificate authority data for the 'moon-cluster' cluster entry using the certificate authority located at '~/.kube/sun-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/sun-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-...
Get output from mycontainer in analytics-pod
Command: ```bash kubectl attach analytics-pod -c mycontainer ``` 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, us...
create a service for the node deployment, which listens on port 9091 and connects to the containers on port 808400
Command: ```bash kubectl expose deployment node --port=9091 --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...
Add a taint to nodes that have a specific label
Command: ```bash kubectl taint node -l tier=frontend dedicated=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Edit the 'analytics-platform-deployment' deployment by opening its YAML configuration file, make the necessary modifications, and save the updated configuration in its annotation.
Command: ```bash kubectl edit deployment/analytics-platform-deployment -o yaml --save-config ``` 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 EDIT...
Import specific keys from a config map for a deployment's environment variables.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/monitoring-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Forward connections from port 8000 on all addresses to port 8000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8000: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...
Forward traffic from local port 8080 to port 8888 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-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 be selected autom...
Create a new config map named app-config-prod with the keys "properties" and "key1", using the contents of the files file1.txt and file2.txt located at /path/to/configs.
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/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 creatin...
Create a new ingress named 'default-ingress' and configure it to direct requests to website.com/bar to a service named 'svc1' listening on port 3000
Command: ```bash kubectl create ingress default-ingress --rule="website.com/bar=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
import specific keys from a config map to a 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...
execute the 'psql' command inside the log-aggregator-pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-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.k...
Create a job with a specific command.
Command: ```bash kubectl create job certificate-renewal --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...
Start a ethereum/client-go pod with custom specifications parsed from JSON
Command: ```bash kubectl run nginx --image=ethereum/client-go --overrides='{ "apiVersion": "custom-version", "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] [-...
List all deployments in the "beta-1.0" version of the "internal-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.beta-1.0.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 namespaced you...
Execute the 'elasticsearch' command in the first container of the first pod of the 'loadbalancer-service' service.
Command: ```bash kubectl exec svc/loadbalancer-service -- 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, us...
Update the pod named 'proxy-server' with the annotation 'criticality' and set its value to 'high'.
Command: ```bash kubectl annotate pods proxy-server criticality=high ``` 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 arbitrar...
Create a new ClusterIP service named order-service-clusterip that maps port 3000 on the service to port 8010 on the target pods.
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=3000:8010 ``` 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", ...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-name-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create a service for the replication controller specified in the "hazelcast-controller.yaml" file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8089 --target-port=909000 ``` 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 ...
Create a cluster role named "default_role" with API Group specified
Command: ```bash kubectl create clusterrole default_role --verb=list,create,connect --resource=jobs.batch ``` 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]` Helpful flags: "flag": "--ou...
Set the service account of the deployment named "frontend-deployment" to "vault"
Command: ```bash kubectl set serviceaccount deployment frontend-deployment vault ``` 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...
Add a taint to nodes labeled with app=web-app
Command: ```bash kubectl taint node -l app=web-app datacenter=worker-node-3: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 new secret named monitoring-credentials-secret and add keys for each file in the path/to/settings folder.
Command: ```bash kubectl create secret generic monitoring-credentials-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 th...
Listen on port 8000 locally and forward it to port 8000 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 8000: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 autom...
Import specific keys from a config map to an application deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod deployment/gateway-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...
Expose a replicated node as a service on port 80, connecting to the containers on port 8000
Command: ```bash kubectl expose rc node --port=80 --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 d...
Import the SECRET_KEY key from the config map called namespace-config and set it in the environment variables of the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/namespace-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 variab...
Update the pod 'database' by adding or updating the annotation 'release-notes' with the value 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate --overwrite pods database 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 tha...
Set the CPU limit of the 'centos' container in the 'nginx' deployment to 5 and the memory limit to 2Gi.
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=5,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, but may burst up to its...
import the DEBUG_MODE key from the config map called app-name-config and set it as an environment variable in the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-name-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Create an ingress named 'ingtls' with TLS enabled
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="testing.com/=svc:https,tls" \ --rule="foo.com/path/subpath*=othersvc:8888" ``` 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": "-...
Configure autoscaling for the deployment "chat-app" with a minimum of 7 pods and a maximum of 11 pods
Command: ```bash kubectl autoscale deployment chat-app --min=7 --max=11 ``` 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...
Forward traffic from local port 9090 to port 6379 in the pod
Command: ```bash kubectl port-forward pod/api-service-pod 9090: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 au...
Forward port 5000 on all addresses to port 9090 in the web-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 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 ...
Embed certificate authority data for the dev-cluster cluster entry.
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/cloud-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 new config map named ui-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/preferences/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 conf...
Delete the pods and services with the names "cdn" and "payment"
Command: ```bash kubectl delete pod,service cdn 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 selector. Som...
Scale the deployment named api-service-rs to 1 replica, only if its current size is 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/api-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-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 variable...
Forward local port 6379 to port 8888 on the backend-pod, allowing access from localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 6379: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 criteri...
Import specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/env-vars deployment/database-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...
Set the environment variable 'API_KEY' to 'your-api-key' for the 'web-app-deployment' deployment
Command: ```bash kubectl set env deployment/web-app-deployment 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 ...
Create a deployment named 'scheduler' using the mysql image and expose port 3000
Command: ```bash kubectl create deployment scheduler --image=mysql --port=3000 ``` 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:...
Import specific keys from a config map for a deployment named "scheduler-app-deployment".
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/api-config deployment/scheduler-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 definition...
Import the DEBUG_MODE key from the app-name-config config map into the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-name-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 variable ...
List the replication controller 'web', the service 'auth-service-rc', and the pod 'log-aggregator-pod'
Command: ```bash kubectl get rc/web service/auth-service-rc pods/log-aggregator-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is na...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from the local machine to the /tmp/bar_dir directory in the worker-pod-4 pod within the cert-manager namespace
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cert-manager/worker-pod-4:/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": "Co...
Attach and get output from the nebula-navigator container in the log-aggregator-pod
Command: ```bash kubectl attach log-aggregator-pod -c nebula-navigator ``` 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 o...
Forward local port 8000 to port 3000 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-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 will be selected autom...