prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Delete the edge-cluster cluster
Command: ```bash kubectl config delete-cluster edge-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Forward port 8088 on all addresses to port 8088 in the pod "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8088: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 w...
Get the output from running the 'go version' command inside the first container of the gateway-pod pod.
Command: ```bash kubectl exec gateway-pod -- go 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 kubectl.ku...
Create a copy of the `cdn-service-pod` pod, adding a debug container and changing the container images
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=logger=logging-app:debug,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 a...
delete the pods and services with the names "database" and "web"
Command: ```bash kubectl delete pod,service database web ``` 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 local port 8000 to port 8088 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 8000: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 auto...
Import the specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets 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 in ...
Import environment variables from a secret into a deployment
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret 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 variable def...
Update the pod 'log-aggregator' by adding or updating the 'env' annotation with the value 'staging'
Command: ```bash kubectl annotate --overwrite pods log-aggregator 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 inclu...
Listen on port 9090 locally and forward data to/from port 8081 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 9090 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 autom...
Listen on port 5000 on your localhost and IP 10.19.21.23, and forward the traffic to port 5432 in the pod named "e-commerce-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 5000: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 crit...
Create a new NodePort service named email-service-nodeport, mapping TCP port 3306 to port 8089.
Command: ```bash kubectl create service nodeport email-service-nodeport --tcp=3306:8089 ``` 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...
Execute the 'apache2ctl -D FOREGROUND' command in the 'nebula-navigator' container of the 'gateway-pod' pod and get the output.
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- apache2ctl -D FOREGROUND ``` 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 na...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/ui-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 definitions...
Autoscale the deployment "email" with a minimum of 5 pods and a maximum of 12 pods
Command: ```bash kubectl autoscale deployment email --min=5 --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 t...
Create a job named 'deployment-rollout-job' using the 'golang' image. The job should run the 'go version' command.
Command: ```bash kubectl create job deployment-rollout-job --image=golang -- go 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": "Outpu...
Add a taint with key 'datacenter' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster datacenter=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Import specific keys from a config map in a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config deployment/proxy-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 variable definitions...
Add a taint with the key 'environment' and the value 'backup-node-14:PreferNoSchedule' on nodes that have the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz environment=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Forward traffic from local port 5000 to port 3000 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-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 criteria, a pod will be select...
Create a deployment named 'gateway' that uses the 'alpine' image
Command: ```bash kubectl create deployment gateway --image=alpine ``` 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: json|yaml|na...
Start a Jenkins pod with the nginx image.
Command: ```bash kubectl run nginx --image=jenkins ``` 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": "--filename", "shor...
Listen on port 8081 on localhost and IP 10.19.21.23, and forward traffic to port 8080 in the analytics-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
Forward local port 8080 to port 8888 in the pod
Command: ```bash kubectl port-forward 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 be selected automa...
Import the 'debug_mode' key from the 'log-config' config map into the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/log-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 in o...
Get the documentation for the 'volumes' field under the 'spec' section of the 'configmaps' resource.
Command: ```bash kubectl explain resource=configmaps.spec.volumes ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag t...
Create a deployment named sonarqube that runs the mongo image with 5 replicas
Command: ```bash kubectl create deployment sonarqube --image=mongo --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 of...
Retrieve the snapshot logs from the container named 'database-pod-1' of the deployment named 'notification-handler-deployment'.
Command: ```bash kubectl logs deployment/notification-handler-deployment -c database-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flag...
List deployments in YAML output format for the specific version of the API group.
Command: ```bash kubectl get deployments.stable-2.0.0.beta-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...
Execute the 'mongod' command in the 'quantum-quark' container of the 'chat-app-pod' pod and get the output.
Command: ```bash kubectl exec chat-app-pod -c quantum-quark -- mongod ``` 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 ...
Import specific keys from a config map to an environment variable for a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/api-config deployment/proxy-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 variable defi...
Update the pod specified in the "preferences.json" file by adding an annotation with the key "alert-email" and the value "alerts@example.com"
Command: ```bash kubectl annotate -f preferences.json alert-email=alerts@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and ...
Forward local traffic from port 8081 to port 8000 in the selected pod of the "search-engine-deployment" deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 8081 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Attach to a pod and enter a raw terminal mode
Command: ```bash kubectl attach web-app-pod -c time-machine -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Create a copy of the 'api-service-pod' and change all container images to 'php'. Copy the pod to 'debug-image-memcached'.
Command: ```bash kubectl debug api-service-pod --copy-to=debug-image-memcached --set-image=*=php ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if ...
Rename the context 'cluster-2-context' to 'client-1-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cluster-2-context client-1-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field wil...
Create an ingress called 'app-ingress' that routes requests from foo.com/input to svc1:8080 with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress app-ingress --rule="foo.com/input=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Create a copy of the vpn-service-pod, changing all container images to "mcr.microsoft.com/dotnet/core/runtime"
Command: ```bash kubectl debug vpn-service-pod --copy-to=debug-image-app --set-image=*=mcr.microsoft.com/dotnet/core/runtime ``` 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...
Run the 'go' command in the cosmic-container of the e-commerce-pod and view the output
Command: ```bash kubectl exec e-commerce-pod -c cosmic-container -- 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 omitted, use...
Retrieve the snapshot logs from container 'analytics-pod-1' of the deployment named 'api-server-deployment'
Command: ```bash kubectl logs deployment/api-server-deployment -c analytics-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag"...
Set the service account of the deployment named "web-app-deployment" to "dashboard"
Command: ```bash kubectl set serviceaccount deployment web-app-deployment dashboard ``` 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 ...
Forward all traffic from port 8888 on all addresses to port 9090 in the frontend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8888: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...
Add a taint with key 'environment' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack 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": "", "us...
Copy the local file "/tmp/foo" to the remote pod named "load-balancer-pod-9" in the "kube-system" namespace at the path "/etc/kubernetes"
Command: ```bash kubectl cp :/tmp/foo kube-system/load-balancer-pod-9:/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, us...
Create an ingress called 'default-ingress' that directs requests to a specific path to a service, using TLS with a specific certificate secret.
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/bar=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a cluster role named "default_role" with the ability to update resources at the specified NonResourceURL /watch/*
Command: ```bash kubectl create clusterrole "default_role" --verb=update --non-resource-url=/watch/* ``` 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": "--output"...
Listen on port 8000 on localhost and IP 10.19.21.23, forwarding to port 6379 in the security-service-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching th...
Create a new config map named app-settings from a folder named data
Command: ```bash kubectl create configmap app-settings --from-file=path/to/data ``` 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 of ...
Create an ingress called 'api-gateway-ingress' that directs requests to site.com/bar to svc1:9000 with a TLS secret "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="site.com/bar=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Set the cluster field in a specific context to a given value
Command: ```bash kubectl config set contexts.admin-context.cluster on-prem-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...
Update the annotation 'git-repo' of the pod 'payment' with the value 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods payment git-repo='https://github.com/example/my-app' ``` 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 labe...
Create a new secret named payment-gateway-secret using files from the 'path/to/options' folder
Command: ```bash kubectl create secret generic payment-gateway-secret --from-file=path/to/options ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basena...
Update the 'log-aggregator' pod by adding the label 'tier' with the value 'backend'
Command: ```bash kubectl label pods log-aggregator tier=backend ``` 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", "us...
Output the modified search-engine-deployment deployment in YAML format, with the DB_HOST environment variable set to "localhost" and do not make any changes to the deployment object on the server.
Command: ```bash kubectl set env deployment/search-engine-deployment DB_HOST=localhost -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod...
Create a new config map named env-vars from specified files
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/properties/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 creating...
Forward port 8080 in the specified pod to port 5432 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 5432: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 po...
Set the resource request and limits for all containers in the 'runtime' deployment to CPU limit of 200m, memory limit of 512Mi, CPU request of 500m, and memory request of 1Gi.
Command: ```bash kubectl set resources deployment runtime --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 reques...
Forward traffic from port 8088 on localhost and IP address 10.19.21.23 to port 6379 in the analytics-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8088: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 crite...
Set the resource request and limits for all containers in the 'runtime' deployment to cpu=2, memory=1Gi (requests) and cpu=200m, memory=512Mi (limits)
Command: ```bash kubectl set resources deployment runtime --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested...
Create a pod disruption budget named api-service-pdb that will ensure at least 9 pods with the component=web label are always available.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=component=web --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Create a new secret named api-secret-key from an environment file
Command: ```bash kubectl create secret generic api-secret-key --from-env-file=path/to/configurations.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the...
Forward local port 5000 to port 8888 in the security-service-pod
Command: ```bash kubectl port-forward pod/security-service-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 be select...
Forward traffic from local port 5000 to port 6379 in the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5000: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 aut...
Create a cron job named 'cleanup-task' that runs the command 'php --version' every minute using the 'php' image.
Command: ```bash kubectl create cronjob cleanup-task --image=php --schedule="*/1 * * * *" -- php --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o",...
List all the allowed actions in the "monitoring" namespace
Command: ```bash kubectl auth can-i --list --namespace=monitoring ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that starts wit...
delete the pods and services named "api" and "media-stream"
Command: ```bash kubectl delete pod,service api media-stream ``` 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...
Forward the traffic from localhost and IP address 10.19.21.23 on port 8080 to port 8088 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8080:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Forward local port 9090 to pod port 8080
Command: ```bash kubectl port-forward pod/api-service-pod 9090: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 au...
Create a new secret named 'my-secret' with keys for each file in the 'path/to/parameters' folder
Command: ```bash kubectl create secret generic my-secret --from-file=path/to/parameters ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of the ...
Get the documentation for the 'namespace' field in the metadata section of the 'configmaps' resource.
Command: ```bash kubectl explain resource=configmaps.metadata.namespace ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive ...
Begin streaming logs of the 'code-explorer' container in the 'log-aggregator-pod' pod
Command: ```bash kubectl logs -f -c code-explorer log-aggregator-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Add a taint to a specific node to prevent scheduling of pods onto that node
Command: ```bash kubectl taint nodes node-2 hardware: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|...
Create a job called "backup" using the specified Docker image and execute the "dotnet" command in the job.
Command: ```bash kubectl create job backup --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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": "", "usa...
Scale the deployment named mysql from 5 replicas to 3 replicas
Command: ```bash kubectl scale --current-replicas=5 --replicas=3 deployment/mysql ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is sp...
Create a pod disruption budget named 'database-pdb' that selects all pods with the 'version=v2' label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=version=v2 --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry...
Start a pod with a specific image, but modify its configuration using a JSON override.
Command: ```bash kubectl run nginx --image=mysql --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] [--command] -- ...
Create a new NodePort service named backend-nodeport and map the port 8000 on the host to port 8083 on the service
Command: ```bash kubectl create service nodeport backend-nodeport --tcp=8000:8083 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Create a single ingress called 'app1-ingress' that directs requests to foo.com/input to svc1:3306 and use the tls secret "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="foo.com/input=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Import the specific keys "database_url" from the config map "app-config-dev" into the deployment "frontend-deployment"
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config-dev 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 definitio...
Attach to the 'time-machine' container in the 'proxy-server-pod' pod and switch to raw terminal mode
Command: ```bash kubectl attach proxy-server-pod -c time-machine -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Switch to raw terminal mode and attach to the 'chat-app-pod' pod in the 'lunar-launcher' container.
Command: ```bash kubectl attach chat-app-pod -c lunar-launcher -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 omi...
Set up an autoscaling policy for the "foo" deployment, allowing the number of pods to vary between 6 and 11.
Command: ```bash kubectl autoscale deployment foo --min=6 --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 uses the...
Create a cron job with a command that runs every minute
Command: ```bash kubectl create cronjob cron-task --image=php --schedule="*/1 * * * *" -- php --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "d...
Taint the nodes with label 'role=database' by adding a taint key 'datacenter' with value 'backup-node-14' and taint effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database datacenter=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a cluster role named "admin_role" with the ability to use specified resources
Command: ```bash kubectl create clusterrole admin_role --verb=use --resource=services --resource-name=file-processing --resource-name=machine-learning ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serve...
create an ingress with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:5001" \ --rule="input.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...
Create a cron job named 'weekly-summary' using the 'node' image, with a schedule to run every minute, and the command to execute is 'node'.
Command: ```bash kubectl create cronjob weekly-summary --image=node --schedule="*/1 * * * *" -- node ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "defa...
List the replication controller named "email-service-rc" in the ps output format
Command: ```bash kubectl get replicationcontroller email-service-rc ``` 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 a cluster role named "custom_role" with permissions to list resources via non-resource URLs.
Command: ```bash kubectl create clusterrole "custom_role" --verb=list --non-resource-url=/swagger-ui/* ``` 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": "--outpu...
Start a pod using the Elasticsearch image and expose port 5432.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=5432 ``` 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] ...
Copy the file /tmp/foo from the remote pod kube-proxy/task-processor-pod-17 to the local directory /etc/kubernetes
Command: ```bash kubectl cp kube-proxy/task-processor-pod-17:/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, us...
List the deployments in the "hotfix-1.1.2" version of the "api-v2" API group in JSON output format.
Command: ```bash kubectl get deployments.hotfix-1.1.2.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 wi...
Create a new config map named app-settings with the properties key set from the file at /path/to/configs/file1.txt and the key1 key set from the file at /path/to/parameters/file2.txt.
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/configs/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 creatin...
Update the image of all containers in the daemonset 'namespace-1' to 'mongo:5.0.2'
Command: ```bash kubectl set image daemonset namespace-1 *=mongo:5.0.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: `...
Get the output from running 'dotnet --list-sdks' command in the rocket-ranger container of the web-app-pod pod.
Command: ```bash kubectl exec web-app-pod -c rocket-ranger -- dotnet --list-sdks ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Create a new config map named app-settings with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a conf...
Copy the local directory "/tmp/foo_dir_dir" to the remote pod "front-end-pod-12" in the "/tmp/bar_dir" directory.
Command: ```bash kubectl cp /tmp/foo_dir_dir front-end-pod-12::/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Forward local ports 5432 and 6000 to ports 8000 and 6000 respectively in a pod selected by the email-server-deployment deployment
Command: ```bash kubectl port-forward deployment/email-server-deployment 5432 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...
Listen on your local machine's port 9090 and forward all traffic to port 8888 inside the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-pod 9090: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 auto...
Add a debug container to the proxy-server-pod, change container images, and create a copy
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-web --image=debian --set-image=cache=redis:alpine,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 a...