prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 8080 on all addresses to port 8080 in the pod named chat-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a new ExternalName service named external-logging-service that points to the external DNS name "mockup-cloud.cloud"
Command: ```bash kubectl create service externalname external-logging-service --external-name mockup-cloud.cloud ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference s...
Add a taint to a node named 'k8s-node-1' with the key 'environment' and no value
Command: ```bash kubectl taint nodes k8s-node-1 environment:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of...
Scale the deployment named 'baz' to 1 replica if its current size is already 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 deployment/baz ``` 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...
resume the deployment named "staging" that is currently paused
Command: ```bash kubectl rollout resume deployment/staging ``` What it does: Resume a paused resource. Paused resources will not be reconciled by a controller. By resuming a resource, we allow it to be reconciled again. Currently only deployments support being resumed. Syntax: `kubectl rollout resume RESOURCE` Helpf...
Delete the pods and services with the names "payment" and "monitoring"
Command: ```bash kubectl delete pod,service payment monitoring ``` 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 select...
Set the cpu limits of the wordpress deployment's nginx container to "3" and the memory limits to "1Gi"
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=3,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, but may burst up to ...
Forward local port 8888 to port 5432 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Start a pod using the "confluentinc/cp-kafka" image, but customize the pod specification using a JSON override.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "rc-1.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=inline-json] [--co...
Create an ingress called 'app-gateway-ingress' that directs requests to site.com/example to svc1:8081 and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.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": "", ...
Update the pod 'analytics' with a new annotation 'custom-label' and value 'my-custom-value', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods analytics custom-label='my-custom-value' ``` 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 single ingress called 'default-ingress' with a rule that directs requests from site.com/example to svc1:8181 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="site.com/example=svc1:8181,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...
Import the `redis_host` key from the `global-config` ConfigMap into the environment variables of the `cache-cluster-deployment` deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/global-config 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 definit...
Create a single ingress resource called 'api-gateway-ingress' that directs requests for 'testing.com/example' to the service 'svc1:5001' with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/example=svc1:5001,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": "...
Forward local port 5000 to port 8080 in the pod
Command: ```bash kubectl port-forward pod/api-service-pod 5000 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 pod disruption budget named web-app-pdb that will select all pods with the app=nginx label and require at least half of the pods selected to be available at any point in time
Command: ```bash kubectl create pdb web-app-pdb --selector=app=nginx --min-available=50% ``` 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-run=server|clie...
Create a new secret named 'ssl-key-secret' and include keys for each file in the 'path/to/options' folder.
Command: ```bash kubectl create secret generic ssl-key-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 basename of th...
Add a taint to the node 'worker-node-3' with the key 'zone', value 'us-west-1a', and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes worker-node-3 zone=us-west-1a: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 f...
Create a copy of chat-app-pod with a debug container, and change the container images.
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-api --image=debian --set-image=proxy=nginx:1.21,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 ...
Create a new secret named gcp-service-account-secret using the values from the env file located at path/to/configs.env
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-env-file=path/to/configs.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...
Create a service for the replicated python using the python replica set
Command: ```bash kubectl expose rs python --port=8088 --target-port=300000 ``` 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....
Import the 'log_level' key from the 'app-secrets' config map and set it as an environment variable for the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-secrets deployment/notification-handler-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...
Create a new pod called `hazelcast` using the `amazonlinux` image and expose port `3001` in the container.
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=3001 ``` 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":...
Update the image of all containers in the daemonset named 'test' to 'amazonlinux:2'
Command: ```bash kubectl set image daemonset test *=amazonlinux:2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubec...
Set the cluster field in a specific context to a new value
Command: ```bash kubectl config set contexts.cluster-1-context.cluster star-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 yo...
Set the cluster field in the my-context context to edge-cluster
Command: ```bash kubectl config set contexts.cluster-2-context.cluster edge-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 yo...
Delete the pods and services named "media-stream" and "backend"
Command: ```bash kubectl delete pod,service media-stream backend ``` 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 sele...
Describe a pod based on options in a JSON file
Command: ```bash kubectl describe -f options.json ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a n...
Create a deployment named 'proxy' using the Jenkins image and expose port 9091.
Command: ```bash kubectl create deployment proxy --image=jenkins --port=9091 ``` 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...
Open the frontend-service service for editing using the "code" editor.
Command: ```bash KUBE_EDITOR="code" kubectl edit svc/frontend-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variable...
import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-dev deployment/log-aggregator-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...
Copy the directory '/tmp/foo_dir' from the pod 'api-server-pod-3' in the 'kube-dns' namespace to the local directory '/tmp/bar_dir'
Command: ```bash kubectl cp kube-dns/api-server-pod-3:/tmp/foo_dir /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 ...
Update the annotation 'app-version' of pod 'foo' to '2.5.1', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods foo app-version='2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ar...
Start a pod named nginx using the Redis image, but customize the pod specification by providing a partial set of values parsed from a JSON override file.
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "v1.1.1", "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] -- [COMMAND...
create a secret named docker-registry-secret with a file and a literal value
Command: ```bash kubectl create secret generic docker-registry-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret ``` 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 b...
Create a service for the replication controller specified in "node-controller.yaml", which serves on port 8080 and connects to the containers on port 8000
Command: ```bash kubectl expose -f node-controller.yaml --port=8080 --target-port=8000 ``` 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 spe...
Add a taint to nodes labeled with 'project=project-alpha' restricting scheduling on a specific node.
Command: ```bash kubectl taint node -l project=project-alpha zone=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": "O...
Update the image of a container in a pod using a JSON patch with positional arrays
Command: ```bash kubectl patch pod email-service-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patc...
Create a new LoadBalancer service named web-app-lb with port mapping from 9092 to 5000.
Command: ```bash kubectl create service loadbalancer web-app-lb --tcp=9092:5000 ``` 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", "default...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8088 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Create a new service named "hazelcast-https" based on the existing service "hazelcast", and configure it to expose container port 8443 as port 443
Command: ```bash kubectl expose service hazelcast --port=443 --target-port=3000 --name=nginx-https ``` 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 servic...
Update the pod named 'database' with the annotation 'monitoring-tool' and the value 'Prometheus', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods database monitoring-tool='Prometheus' ``` 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 ...
Create a job called monitoring-job using the nginx image, and run the command 'nginx' within the job
Command: ```bash kubectl create job monitoring-job --image=nginx -- nginx ``` 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 ...
Cordon a node
Command: ```bash kubectl cordon dev-node-4 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Copy the kube config file from your local machine to a directory in a remote pod in the given namespace.
Command: ```bash kubectl cp ~/.config/kube kubeapps/payment-gateway-pod-19:/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, ...
Import environment variables from a config map with a specified prefix
Command: ```bash kubectl set env --from=configmap/db-config --prefix=MYSQL_ deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create an ingress called 'private-service-ingress' that directs requests to testing.com/input to svc1:9000 using the TLS secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/input=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":...
Auto scale a deployment named "chat-app" with a minimum of 4 and a maximum of 14 pods
Command: ```bash kubectl autoscale deployment chat-app --min=4 --max=14 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Add a taint with the key 'environment' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production environment=prod-node-5: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": ""...
Create a service for the replicated centos resource, serving on port 9090 and connecting to the containers on port 500000
Command: ```bash kubectl expose rc centos --port=9090 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a deployment named "prometheus" using the nginx image.
Command: ```bash kubectl create deployment prometheus --image=nginx ``` 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|...
Create a new config map named global-config using the settings file at /path/to/parameters/file1.txt as the value for the key "settings" and the file at /path/to/options/file2.txt as the value for the key "key2"
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/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...
Start a postgres pod with the image 'nginx', but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "alpha-2.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [C...
Update the annotation 'monitoring-tool' of the pod 'log-aggregator' with the value 'Prometheus'
Command: ```bash kubectl annotate pods log-aggregator monitoring-tool=Prometheus ``` 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 incl...
Set the service account of the deployment named 'database-deployment' to 'tiller'
Command: ```bash kubectl set serviceaccount deployment database-deployment tiller ``` 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 se...
List all the supported namespaced resources
Command: ```bash kubectl api-resources --storageVersionHashspaced=true ``` 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. "
Add a taint with key 'disktype' on nodes having label component=proxy and value kube-master-9:PreferNoSchedule
Command: ```bash kubectl taint node -l component=proxy disktype=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Listen on port 8888 locally, forwarding to port 8888 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-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 automa...
Create an ingress named 'api-v2-ingress' that routes requests from testing.com/bar to svc1:8081 and uses the TLS secret "my-cert".
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/bar=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...
Set custom TLS server name for cluster sun-cluster
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=dev-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-a...
Set a custom TLS server name for the cluster-beta cluster entry
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=galaxy-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] [--certifica...
Listen on port 9090 on your local machine and forward traffic to port 3000 in the e-commerce-pod.
Command: ```bash kubectl port-forward pod/e-commerce-pod 9090: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 aut...
Retrieve the output of the 'elasticsearch --version' command executed in the cyber-sleuth container of the pod log-aggregator-pod
Command: ```bash kubectl exec log-aggregator-pod -c cyber-sleuth -- elasticsearch --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container ...
Listen on port 8888 on all addresses and forward the traffic to port 6379 in the frontend pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8888: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...
Update the taint for node 'kube-master-9' by adding or replacing a taint with key 'datacenter' and value 'dc-1' and effect 'NoExecute'
Command: ```bash kubectl taint nodes kube-master-9 datacenter=dc-1:NoExecute ``` 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. ...
Start a Jenkins pod with custom configuration using a JSON file.
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "legacy-1.0.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=inline-json] [--command] -- ...
Disable certificate checking for the dev cluster entry.
Command: ```bash kubectl config set-cluster cluster-alpha --insecure-skip-tls-verify=true ``` 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] [--certifica...
Create a job named "batch-processing" with the image "mongo" and the command "mongod"
Command: ```bash kubectl create job batch-processing --image=mongo -- mongod ``` 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. O...
Get the output from running the 'mysqld' command in the pod named 'chat-app-pod'
Command: ```bash kubectl exec chat-app-pod -- mysqld ``` 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.kuber...
Create an ingress called 'app-ingress' that directs requests to testing.com/input to svc1:9091 with the tls secret "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/input=svc1:9091,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 new config map named "app-config-prod" with specified keys and their corresponding file paths
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
List specific resources by their type and names
Command: ```bash kubectl get rc/web service/frontend-rc pods/cdn-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 namespace...
Create a new ingress called 'app1-ingress' with the rule that directs requests from 'website.com/input' to 'svc1' on port '8081', with the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/input=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Embed the certificate authority data for the web-cluster cluster entry by running the command 'kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp kube-flannel/metrics-exporter-pod-10:/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, u...
Create a cron job that syncs data using a specific command, Redis image, and a schedule specified in cron format
Command: ```bash kubectl create cronjob data-sync --image=redis --schedule="*/1 * * * *" -- redis-server --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...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-prod deployment/notification-handler-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...
Set the service account of the deployment 'cache-cluster-deployment' to the default service account
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment default ``` 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: `kube...
Forward traffic from port 8088 on all addresses to port 8081 in the pod named "security-service-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8088: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 ...
Set the resource request and limits for all containers in the Kafka deployment.
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=128Mi ``` 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...
import the DEBUG_MODE key from the config map called app-name-config and set it as an environment variable in the log-aggregator-deployment deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-name-config deployment/log-aggregator-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...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp cert-manager/monitoring-agent-pod-6::/tmp/foo /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Forward traffic from local port 8080 to port 5000 in the pod
Command: ```bash kubectl port-forward pod/mypod 8080: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 automaticall...
Create a debug container named 'dgb-img' by copying the 'api-service-pod' pod and updating all container images inside the pod to 'jenkins'
Command: ```bash kubectl debug api-service-pod --copy-to=dgb-img --set-image=*=jenkins ``` 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 resourc...
Create a deployment named "drupal" using the "hazelcast/hazelcast" image and expose port 8000.
Command: ```bash kubectl create deployment drupal --image=hazelcast/hazelcast --port=8000 ``` 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 form...
Copy the file '/tmp/foo' from the 'security-scanner-pod-18' pod in the 'logging' namespace to the local directory '/etc/kubernetes'
Command: ```bash kubectl cp logging/security-scanner-pod-18:/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, use...
Add an annotation to the pod specified in the "settings.json" file to enable auto-horizontal scaling.
Command: ```bash kubectl annotate -f settings.json scaling-policy=auto-horizontal-scaling ``` 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...
Add a taint with the key 'zone' on nodes having the label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp zone=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": "", "usage":...
Create a role binding called "bar" and assign the "bar" cluster role to the "app-operator" user, "sysadmin" user, and "security-auditors" group.
Command: ```bash kubectl create rolebinding bar --clusterrole=bar --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [...
Partially update the 'gpu-node-12' node by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node gpu-node-12 -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl p...
Forward port 8081 on your local machine to port 8088 in the pod named web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 8081: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 automa...
Execute the 'mongod' command inside the cdn-service-pod and retrieve the output
Command: ```bash kubectl exec cdn-service-pod -- 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 the kubectl.ku...
Update the resource requirements and limits for the 'php' deployment
Command: ```bash kubectl set resources deployment php --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, bu...
Set the service account of the deployment named "mydeployment" to "elasticsearch".
Command: ```bash kubectl set serviceaccount deployment mydeployment elasticsearch ``` 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 se...
Wait for the pod "auth-service-pod" to have the status condition of type "Ready"
Command: ```bash kubectl wait --for=condition=Ready pod/auth-service-pod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command c...
Listen on all addresses on port 8000 and forward the traffic to port 5000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Create an ingress resource called 'public-ingress' with a rule that directs requests to site.com/bar to svc1:8081, using the tls secret "my-cert".
Command: ```bash kubectl create ingress public-ingress --rule="site.com/bar=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": ...
Add a taint with key 'environment' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster environment=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": ""...
Create a debug session of the analytics-pod with the name debug-image-api and change all container images to mongo
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-api --set-image=*=mongo ``` 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 res...
Update the label 'status' of the pod 'email' to 'unhealthy', overwriting any existing value
Command: ```bash kubectl label --overwrite pods email status=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": "fals...