prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a copy of the "payment-gateway-pod" pod with a debug container and changed container images.
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=dgb-img --image=debian --set-image=app=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 and name. Pods...
Apply a taint with key 'workload' and no value to the node 'monitoring-node-15'
Command: ```bash kubectl taint nodes monitoring-node-15 workload: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. O...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-prod deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Listen on all addresses on port 5432 and forward the traffic to port 8081 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5432: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 sel...
Create a service for a replicated php application that serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc php --port=8888 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Forward port 8088 on localhost and IP 10.19.21.23 to port 5432 in the pod log-aggregator-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 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 ...
Listen on port 8088 on all addresses and forward traffic to port 8080 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8088: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...
Run the 'ruby --version' command in the 'time-machine' container of the 'analytics-pod' pod
Command: ```bash kubectl exec analytics-pod -c time-machine -- ruby --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Create a new config map named app-config-prod with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/profiles/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 cre...
Listen on port 8088 on all addresses, and forward the traffic to port 8088 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-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 po...
Create a service for a replicated node, which serves on port 3001 and connects to the containers on port 500100
Command: ```bash kubectl expose rc node --port=3001 --target-port=500100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Copy the local file "/tmp/foo" to the remote pod "task-processor-pod-17" in the "monitoring" namespace, and save it as "/tmp/bar_dir".
Command: ```bash kubectl cp /tmp/foo monitoring/task-processor-pod-17:/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 t...
Copy the ~/.config/kube file from the 'front-end-pod-12' pod in the 'kube-server' namespace to the /tmp/bar_dir directory locally
Command: ```bash kubectl cp kube-server/front-end-pod-12:~/.config/kube /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Copy the ~/.config/kube file from your local machine to the /tmp/bar_dir directory in the web-app-container of the file-server-pod-14 pod.
Command: ```bash kubectl cp ~/.config/kube file-server-pod-14:/tmp/bar_dir -c web-app-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Add an annotation to the pod mentioned in the "parameters.json" file
Command: ```bash kubectl annotate -f parameters.json 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 large...
Create a deployment named jenkins with 3 replicas running the amazonlinux image.
Command: ```bash kubectl create deployment jenkins --image=amazonlinux --replicas=3 ``` 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. On...
Forward traffic from port 8080 on all addresses to port 6379 in the pod "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8080:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Update the image of all containers in the 'staging' daemonset to 'java:11.0.12'
Command: ```bash kubectl set image daemonset staging *=java:11.0.12 ``` 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: `kub...
List the replication controller "web", service "monitoring-rc", and pod "proxy-service-pod"
Command: ```bash kubectl get rc/web service/monitoring-rc pods/proxy-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 names...
Update the role binding named "admin" to include "user1", "user2", and "group1" as subjects
Command: ```bash kubectl set subject rolebinding admin --user=user1 --user=user2 --group=group1 ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=namespa...
Create a new ClusterIP service named notification-service-clusterip
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=9000:8084 ``` 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":...
Create a new config map named app-name-config with specified keys from file paths
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/options/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 co...
Create a new config map named 'app-config-prod' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/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 cre...
Update the image of all containers in the daemonset named 'prod' to 'ubuntu:20.04'
Command: ```bash kubectl set image daemonset prod *=ubuntu:20.04 ``` 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: `kubect...
Create an Ingress resource named "ingress1" with two rules
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="site.com/path*=svc:9092" \ --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 new config map named namespace-config using the specified files /path/to/configurations/file1.txt for the settings key and /path/to/parameters/file2.txt for the key2 key
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/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. Whe...
Create a deployment named drupal that uses the alpine image and exposes port 5432
Command: ```bash kubectl create deployment drupal --image=alpine --port=5432 ``` 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: j...
Copy the local file "foo" from the "/tmp" directory to the remote pod named "image-resizer-pod-20" in the "velero" namespace, and place it in the "/tmp/bar_dir" directory
Command: ```bash kubectl cp :/tmp/foo velero/image-resizer-pod-20:/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...
Create a single ingress called 'external-ingress' that directs requests from 'foo.com/bar' to service 'svc1' on port '8089' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/bar=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", "default": "", "usage":...
Create a pod disruption budget named messaging-pdb that selects all pods with the component=web label and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-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 [-...
Execute the 'dotnet' command inside the 'quantum-quark' container in the 'frontend-pod' pod
Command: ```bash kubectl exec frontend-pod -c quantum-quark -- dotnet ``` 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 ...
Create a new config map named app-config using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/data/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 c...
Add a taint with key 'app' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha app=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": "Ou...
Forward port 6379 on localhost and IP 10.19.21.23 to port 8000 in the web-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 6379: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 criteri...
Forward local port 5000 to port 8888 in the pod selected by the "web-app-deployment" deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 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 s...
Update the 'email' pod with the label 'component' and set the value as 'web'
Command: ```bash kubectl label pods email component=web ``` 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 specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-settings deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Update the image of all containers in the daemonset "namespace-2" to "java:11.0.12"
Command: ```bash kubectl set image daemonset namespace-2 *=java:11.0.12 ``` 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: ...
Start a pod named 'hazelcast' using the 'redis' image and expose port 8081 inside the container
Command: ```bash kubectl run hazelcast --image=redis --port=8081 ``` 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": "--fi...
Create a service for a replicated php, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc php --port=5000 --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 the specified port. A ...
Get output from running a command inside a pod
Command: ```bash kubectl exec analytics-pod -- redis-cli ``` 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 new config map named monitoring-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Set a custom TLS server name for validation in the e2e cluster configuration.
Command: ```bash kubectl config set-cluster e2e --tls-server-name=e2e ``` 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] [--certificate-authority=path/to...
Create a new config map named "app-settings" with the specified keys and corresponding files
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/properties/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 an ingress that directs requests to a specific service with TLS encryption
Command: ```bash kubectl create ingress app2-ingress --rule="foo.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", "default": "", "usage":...
Create an ingress with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:9090" \ --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", "sh...
Add a taint with key 'dedicated' on nodes having the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 dedicated=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"...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "app-service" entry
Command: ```bash kubectl config set-credentials app-service --auth-provider=oidc --auth-provider-arg=client-secret- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client...
delete the pods and services named "proxy-server" and "foo"
Command: ```bash kubectl delete pod,service proxy-server foo ``` 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 a new LoadBalancer service named security-service-lb and map port 5000 on the LoadBalancer to port 8082 on the service
Command: ```bash kubectl create service loadbalancer security-service-lb --tcp=5000:8082 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o",...
Listen locally on ports 5000 and 8081, forwarding data to/from ports 8081 and 6000 in the 'search-engine-deployment' pods.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 5000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Set custom TLS server name to use for validation for the prod-cluster cluster entry
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=app-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] [--certificate-...
Retrieve a list of deployments in the "custom-version" version of the "custom-apps" API group in YAML format.
Command: ```bash kubectl get deployments.custom-version.custom-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...
Create a job called 'audit-job' using the 'php' image
Command: ```bash kubectl create job audit-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: json|yaml...
Apply a taint with the key 'cpu-type' and value 'gpu-node-12:PreferNoSchedule' on nodes labeled with 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe cpu-type=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Create a pod disruption budget named messaging-pdb that will select all pods with the env=production label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=env=production --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 [...
Attach to the first pod of replica set named php to get output.
Command: ```bash kubectl attach rs/php ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubernet...
Listen on port 8081 locally and forward the traffic to port 5000 in the cdn-service-pod pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081: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 au...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 3000 in the backend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8888: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 criteri...
Set a custom TLS server name for the cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=cluster-alpha ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Expose the replica set "ruby" with a service on port 80, connecting to the containers on port 8000
Command: ```bash kubectl expose rs ruby --port=80 --target-port=330600 ``` 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...
Create a copy of the cdn-service-pod with a debug container and modified container images
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-web --image=debian --set-image=database=mysql:5.7,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Scale the deployment named app-v2-replicaset down to 3 replicas if its current size is 5
Command: ```bash kubectl scale --current-replicas=5 --replicas=3 deployment/app-v2-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...
Add a taint with the key 'dedicated=backup-node-14:PreferNoSchedule' on nodes having the label 'zone=us-east-1'.
Command: ```bash kubectl taint node -l zone=us-east-1 dedicated=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...
Update the image of all containers in the "development" daemonset to "golang:1.17".
Command: ```bash kubectl set image daemonset development *=golang:1.17 ``` 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: `...
Delete the pods and services with the names "frontend" and "media-stream".
Command: ```bash kubectl delete pod,service frontend 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 sel...
Start port forwarding to the pod named api-service-pod, mapping local port 8888 to port 8888 on the pod.
Command: ```bash kubectl port-forward pod/api-service-pod 8888 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 au...
import the DATABASE_URL key from the config map "app-name-config" and set it as an environment variable in the "frontend-deployment" deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-name-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Create a cluster role named "reader" with permissions to update and access non-resource URLs starting with "/logs/*"
Command: ```bash kubectl create clusterrole "reader" --verb=update --non-resource-url=/logs/* ``` 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", "shor...
Add a taint with the key 'disktype' to nodes with the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice disktype=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"...
Expose the replica set "php" with a service that serves on port 8181 and connects to the containers on port 543200.
Command: ```bash kubectl expose rs php --port=8181 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Begin streaming the logs of a specific container within a pod.
Command: ```bash kubectl logs -f -c quantum-quark monitoring-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", ...
Create a new secret named docker-registry-secret from the environment variables file located at path/to/options.env
Command: ```bash kubectl create secret generic docker-registry-secret --from-env-file=path/to/options.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 th...
Execute the 'wp' command in the first container of the 'log-aggregator-deployment' deployment and retrieve the output
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- wp ``` 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 t...
Create a new config map named api-config with the specified keys, properties and key1, using the files file1.txt and file2.txt as the values for each key.
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/configurations/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 crea...
Create a debug container and copy it to the proxy-server-pod, using the debian image and changing the container images for app and cache.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-memcached --image=debian --set-image=app=app:debug,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by reso...
Add a taint with key 'cpu-type' on nodes having label tier=frontend, setting the cpu-type value as 'testing-node-11' and the effect as 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l tier=frontend cpu-type=testing-node-11: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...
Scale down the deployment named db-migration-replicaset for mysql to 1 replica
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/db-migration-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 --reso...
Update the 'team' annotation of pod 'web' with the value 'frontend-team', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods web team='frontend-team' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Create a deployment named my-dep using the nginx image and expose port 8083
Command: ```bash kubectl create deployment my-dep --image=nginx --port=8083 ``` 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: js...
Execute 'irb' command in backend-pod and get the output
Command: ```bash kubectl exec backend-pod -- irb ``` 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 deployment named web that runs the mysql image with 3 replicas
Command: ```bash kubectl create deployment web --image=mysql --replicas=3 ``` 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...
Open a raw terminal session to interact with the 'code-explorer' container in the 'proxy-service-pod' pod
Command: ```bash kubectl attach proxy-service-pod -c code-explorer -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Execute the command 'node --version' in the 'warp-drive' container of the 'e-commerce-pod' pod and display the output.
Command: ```bash kubectl exec e-commerce-pod -c warp-drive -- node --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Create a new config map named 'log-config' using the files '/path/to/profiles/file1.txt' and '/path/to/settings/file2.txt' as values for the keys 'conf' and 'data' respectively.
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a confi...
Create an ingress named 'api-ingress' that routes requests from foo.com/example to svc1:8081 with the specified TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-ingress --rule="foo.com/example=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": "", "usage": ...
Expose a service for the replication controller specified in the "node-controller.yaml" file, serving on port 8088 and connecting to the containers on port 808200.
Command: ```bash kubectl expose -f node-controller.yaml --port=8088 --target-port=808200 ``` 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 s...
Display the most recent 20 lines of logs for the 'backend-pod' pod.
Command: ```bash kubectl logs --tail=20 backend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c"...
Create a Jenkins pod and expose port 8082
Command: ```bash kubectl run hazelcast --image=jenkins --port=8082 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--...
Forward local port 3000 to port 8000 in a pod selected by the search-engine-deployment deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 3000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Monitor the status of a deployment rollout
Command: ```bash kubectl rollout status deployment/namespace-1 ``` What it does: Show the status of the rollout. By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts...
Create a debug copy of the security-service-pod, replacing all container images with 'hazelcast/hazelcast'
Command: ```bash kubectl debug security-service-pod --copy-to=my-debugger --set-image=*=hazelcast/hazelcast ``` 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 ...
Create a deployment named 'api' that runs the 'nginx' image and exposes port 8082.
Command: ```bash kubectl create deployment api --image=nginx --port=8082 ``` 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|...
Copy the "~/.config/kube" file to the "/tmp/bar_dir" directory in a remote pod named "kube-node-lease/image-resizer-pod-20" in the specified namespace.
Command: ```bash kubectl cp ~/.config/kube kube-node-lease/image-resizer-pod-20:/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 omit...
Create a deployment named logging with 5 replicas
Command: ```bash kubectl create deployment logging --image=docker.elastic.co/elasticsearch/elasticsearch --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...
Check if you have permission to list the job named "data-synchronization-job" in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-job -n default ``` 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 parti...
Interact with the 'astro-container' in the 'web-app-pod' by switching to raw terminal mode
Command: ```bash kubectl attach web-app-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...
Autoscale the replication controller "proxy-server" to have a minimum of 1 pod and a maximum of 5 pods, with a target CPU utilization of 50%.
Command: ```bash kubectl autoscale rc proxy-server --max=5 --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...
Get the output of the 'elasticsearch-plugin --list' command from the code-explorer container running in the monitoring-pod
Command: ```bash kubectl exec monitoring-pod -c code-explorer -- elasticsearch-plugin --list ``` 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...
Create a new config map named global-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/profiles/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 con...