prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a secret named "ldap-credentials-secret" from an environment file
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-env-file=path/to/parameters.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 t...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/env-vars 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 defini...
Create a new config map named app-config using the key=value pairs from the file at path/to/configurations
Command: ```bash kubectl create configmap app-config --from-file=path/to/configurations ``` 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 base...
Add the label 'app=myapp' to the 'analytics' pod.
Command: ```bash kubectl label pods analytics app=myapp ``` 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...
Import the API_KEY key from the app-config-dev config map into the email-server-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-dev deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Print the result of updating the nginx container image from a local file, without making any changes to the server.
Command: ```bash kubectl set image -f path/to/file.yaml python=python:3.9.7 --local -o yaml ``` 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), repli...
Retrieve the documentation for the "volumes" field under the "spec" section of the "pods" resource.
Command: ```bash kubectl explain resource=pods.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 to disp...
List the replication controllers for web, the service for e-commerce-rc, and the pods for gateway-pod
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/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 is namespaced ...
Add a taint with key 'special' on nodes having label service=auth
Command: ```bash kubectl taint node -l service=auth special=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Output the modified 'cache-cluster-deployment' deployment in YAML format after setting the environment variable 'DB_PASSWORD' to 'secretpassword' but do not alter the object on the server.
Command: ```bash kubectl set env deployment/cache-cluster-deployment DB_PASSWORD=secretpassword -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...
Create a pod disruption budget named logging-pdb with the following criteria:
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=owner=team-1 --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dr...
Create an ingress resource called "default-ingress" with a rule that directs requests from website.com/module to svc1:8888, and use the TLS secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="website.com/module=svc1:8888,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...
Create a deployment named my-dep using the ruby image and expose port 6379
Command: ```bash kubectl create deployment my-dep --image=ruby --port=6379 ``` 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...
Scale the deployment named webapp-replicaset's replicas to 3 when its current size is 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=3 deployment/webapp-replicaset ``` 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-v...
Apply a taint on the nodes with the 'role=database' label, with a key 'cpu-type' and value 'backup-node-14' using the 'PreferNoSchedule' effect
Command: ```bash kubectl taint node -l role=database cpu-type=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": "", "usage"...
get the output from running the 'php --version' command in the first container of the backend-service pod.
Command: ```bash kubectl exec svc/backend-service -- php --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...
Create a pod using the data specified in the options.json file
Command: ```bash kubectl create -f ./options.json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use to creat...
Create an ingress called 'private-service-ingress' that directs requests for foo.com/example to svc1:8083 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="foo.com/example=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": "...
Drain node "db-node-7" even if there are pods not managed by a replication controller, replica set, job, daemon set or stateful set on it, forcefully.
Command: ```bash kubectl drain db-node-7 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, it...
Add a taint with key 'disktype' and no value to the 'storage-node-13' node
Command: ```bash kubectl taint nodes storage-node-13 disktype: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 ...
Interact with a specific pod using a raw terminal mode
Command: ```bash kubectl attach payment-gateway-pod -c nano-bot -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config 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 i...
Create an ingress resource named 'private-ingress' that routes requests from site.com/module to svc1 listening on port 6379
Command: ```bash kubectl create ingress private-ingress --rule="site.com/module=svc1:6379,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 an ingress called 'service-ingress' with a rule that directs requests from 'website.com/example' to service 'svc1' on port '5432', using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress service-ingress --rule="website.com/example=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Run the 'ash' command inside the backend-pod and display the output
Command: ```bash kubectl exec backend-pod -- ash ``` 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.kubernete...
Create a debug container for cdn-service-pod, copying it to my-debugger and changing container images for database and web.
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=my-debugger --image=debian --set-image=database=mysql:5.7,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
Get snapshot logs from container "auth-service-pod-1" of the deployment "search-engine-deployment".
Command: ```bash kubectl logs deployment/search-engine-deployment -c auth-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: ...
Copy the "~/.config/kube" file from your local machine to the "/tmp/bar_dir" directory in the "logging/database-pod-2" pod within the specified namespace.
Command: ```bash kubectl cp ~/.config/kube logging/database-pod-2:/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 k...
Set resource requests and limits for all containers in a Hazelcast deployment.
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource reques...
Set the cluster field in the specified context to a specific cluster name
Command: ```bash kubectl config set contexts.edge-context.cluster kube-cluster-1 ``` 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 w...
Set up auto scaling for the replication controller "media-stream" with a target CPU utilization of 50% and a range of 1 to 7 pods.
Command: ```bash kubectl autoscale rc media-stream --max=7 --cpu-percent=50 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that...
Create a pod disruption budget named critical-services-pdb that selects pods with the app=rails label and ensures that at least four of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget critical-services-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=...
Execute the command 'geth' in the 'code-explorer' container of the 'monitoring-pod' pod and display the output
Command: ```bash kubectl exec monitoring-pod -c code-explorer -- 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 ...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/tls-certificate-secret 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 definitions in...
Forward port 3000 on localhost and IP 10.19.21.23 to port 5432 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 3000: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...
Forward traffic between local port 8088 and pod port 5000 in the analytics-pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8088 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Embed the certificate authority data for the `my-k8s-cluster` cluster entry
Command: ```bash kubectl config set-cluster my-k8s-cluster --embed-certs --certificate-authority=~/.kube/prod-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 s...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=SMTP_SERVER --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 definition...
Update the annotation of pod 'monitoring' with the value 'https' for the key 'deployment-script', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods monitoring deployment-script='https://example.com/deploy.sh' ``` 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...
Set the custom TLS server name to 'on-prem-cluster' for validation of the 'kube-cluster-1' cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=on-prem-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] [--certif...
Create a new secret named aws-credentials-secret and populate the keys from each file in the folder "path/to/profiles"
Command: ```bash kubectl create secret generic aws-credentials-secret --from-file=path/to/profiles ``` 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 basen...
Remove the label 'bar' from pod 'api' if it exists
Command: ```bash kubectl label pods api component- ``` 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 tru...
Taint nodes with label customer=acme-corp by adding the taint 'zone=k8s-node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l customer=acme-corp zone=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create an ingress named 'app-loadbalancer-ingress' with a rule that directs requests for website.com/example to svc1:8089 using the 'my-cert' TLS secret.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="website.com/example=svc1:8089,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", "defaul...
Update the label of a pod by removing a specific label
Command: ```bash kubectl label pods media-stream unhealthy- ``` 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"...
Output the modified deployment for the email server, while setting the GOOGLE_API_KEY environment variable, in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/email-server-deployment GOOGLE_API_KEY=your-google-api-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 a cluster role binding named reader and assign the reader cluster role to the app-operator user, sysadmin user, and security-auditors group.
Command: ```bash kubectl create clusterrolebinding reader --clusterrole=reader --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=grou...
Forward local port 9090 to port 8000 in the backend-pod pod
Command: ```bash kubectl port-forward pod/backend-pod 9090:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Forward port 8088 locally to port 3000 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 8088: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 auto...
Create a new ingress named 'ingress1' with multiple hosts and configure the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8088" \ --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...
Execute the 'nginx' command in the cyber-sleuth container of the e-commerce-pod pod and retrieve the output
Command: ```bash kubectl exec e-commerce-pod -c cyber-sleuth -- nginx ``` 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 ...
Update the label of the 'payment' pod to 'tier=backend'
Command: ```bash kubectl label pods payment 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", "usage": "...
Create a debug container named "debug-image-web" based on the "cdn-service-pod" pod, replacing all container images with the "python" image.
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-web --set-image=*=python ``` 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 no ...
Attach to the 'astro-container' in 'gateway-pod' and switch to raw terminal mode
Command: ```bash kubectl attach gateway-pod -c astro-container -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...
Display only the last 12 lines of logs for the gateway-pod pod
Command: ```bash kubectl logs --tail=12 gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c"...
Start the python pod named 'nginx' using the specified command and custom arguments <cmd> <arg1> ... <argN>
Command: ```bash kubectl run nginx --image=python --command -- <cmd> <arg1> ... <argN> ``` 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...]` Helpfu...
Expose the 'ruby' replication controller as a service, serving on port 6379 and connecting to the containers on port 8000
Command: ```bash kubectl expose rc ruby --port=6379 --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. A...
Remove all the taints with key 'zone' from the node 'storage-node-13'
Command: ```bash kubectl taint nodes storage-node-13 zone- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|...
Forward port 5000 on all addresses to port 5432 in the "chat-app-pod" pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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 criteria, a pod will...
Run the command 'python' in the 'rocket-ranger' container within the 'vpn-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec vpn-service-pod -c rocket-ranger -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Retrieve the previous terminated container logs with the name "quantum-quark" from the pod named "e-commerce-pod".
Command: ```bash kubectl logs -p -c quantum-quark e-commerce-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", ...
List deployments in YAML output format for the "web-apps" API group with the version "legacy-1.0.0"
Command: ```bash kubectl get deployments.legacy-1.0.0.web-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 ...
Get the logs of container "e-commerce-pod-1" in the deployment "cache-cluster-deployment"
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c e-commerce-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: "f...
Delete pods and services named "api" and "payment"
Command: ```bash kubectl delete pod,service api 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...
Remove the taint with key 'app' and effect 'PreferNoSchedule' from node 'web-node-8'
Command: ```bash kubectl taint nodes web-node-8 app: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 format. One of:...
Add a taint to nodes with the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops dedicated=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
List the non-namespaced resources that are supported by the API server.
Command: ```bash kubectl api-resources --namespacedspaced=false ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Forward traffic from port 8081 to port 8080 in the pod "cdn-service-pod" and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-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 w...
Display the most recent 43 lines of logs for the media-stream-pod pod
Command: ```bash kubectl logs --tail=43 media-stream-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short":...
Embed the certificate authority data for the cluster entry named 'app-cluster' by running the command: kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/testing-cluster/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/testing-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 s...
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/kube-cluster-2/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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 s...
Create a deployment named 'wordpress' using the 'golang' image, and also run the 'hello.go' command inside the container.
Command: ```bash kubectl create deployment wordpress --image=golang -- go run hello.go ``` 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....
Add an annotation to the pod 'cdn' with the key 'deployment-script' and the value 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate pods cdn deployment-script='https://example.com/deploy.sh' ``` 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 lab...
Retrieve the snapshot logs from the container "log-aggregator-deployment-1" of the deployment "cdn-service-pod".
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c cdn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: ...
Create a copy of the 'cdn-service-pod' pod with a debug container and change the container images
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-app --image=debian --set-image=logger=logging-app:debug,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identi...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp kube-public/backend-pod-13:/tmp/foo /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 kub...
Scale the mysql deployment named 'bar' to 3 replicas, only if the current size is already 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/bar ``` 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 spec...
Create a pod disruption budget named web-app-pdb that selects all pods with the project=my-project label and requires a minimum of one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=project=my-project --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...
Listen on port 8000 locally and forward it to port 8888 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8000: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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/global-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 d...
Forward local port 8080 to port 9090 in the pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8080:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Add a taint with the key 'disktype' and value 'dev-node-4:PreferNoSchedule' to nodes that have the label 'role=database'
Command: ```bash kubectl taint node -l role=database disktype=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": "O...
Start a pod named "nginx" using the Docker image "mcr.microsoft.com/dotnet/core/runtime"
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "v2.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inli...
Add a taint with key 'disktype' on nodes having the label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack disktype=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": "", "usag...
Create an ingress called 'service-ingress' that directs requests to testing.com/module to the service svc1 on port 8081, using the TLS secret named "my-cert".
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/module=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": "", "u...
Create a copy of the 'payment-gateway-pod', adding a debug container and changing the container images
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-api --image=debian --set-image=scheduler=my-scheduler:1.0,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifi...
Create a single ingress called 'app-proxy-ingress' that directs requests to website.com/input to svc1:9090 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.com/input=svc1:9090,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": "", "...
Get the deployments in JSON output format, specifying the API group version.
Command: ```bash kubectl get deployments.v1.1.0.apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only ...
Add a taint with key 'cpu-type' on nodes having label 'myLabel'
Command: ```bash kubectl taint node -l myLabel cpu-type=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": "Output form...
Begin streaming the logs of the 'nebula-navigator' container in the 'media-stream-pod' pod.
Command: ```bash kubectl logs -f -c nebula-navigator media-stream-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": "--contain...
Delete pods and services named "frontend" and "email"
Command: ```bash kubectl delete pod,service frontend email ``` 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. ...
Create an ingress named 'public-ingress' with a rule that directs requests from testing.com/input to the service svc1 on port 3306
Command: ```bash kubectl create ingress public-ingress --rule="testing.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": "", "usa...
Create a new ClusterIP service named my-cs that maps port 8080 externally to port 8000 internally
Command: ```bash kubectl create service clusterip my-cs --tcp=8080:8000 ``` 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...
Create a job called 'monitoring-job' using the ethereum/client-go image, and run the command 'geth' inside the job
Command: ```bash kubectl create job monitoring-job --image=ethereum/client-go -- geth ``` 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 ...
Taint nodes labeled with 'myLabel' as 'special' with the effect of 'PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel special=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Create a debug container and attach to a pod by running the `kubectl debug` command with the provided flags
Command: ```bash kubectl debug web-app-pod -it --image=busybox --copy-to=debug-image-app ``` 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 no resou...
Forward port 8000 from the frontend-pod to port 8080 locally
Command: ```bash kubectl port-forward pod/frontend-pod 8080: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...
List the replication controllers, services, and pods named "web", "media-stream-rc", and "auth-service-pod"
Command: ```bash kubectl get rc/web service/media-stream-rc pods/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 name...
Import the environment variable 'api-key-secret' from the secret and set it in the deployment 'monitoring-stack-deployment'
Command: ```bash kubectl set env --from=secret/api-key-secret deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or mo...
Update the environment variables of a deployment using specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/env-vars 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 defini...