prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a taint with the key 'zone' on nodes that have the label 'role=database' in the value 'node-1' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database zone=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": "Output fo...
Copy local file to a remote pod/container
Command: ```bash kubectl cp /tmp/foo_dir api-server-pod-3:/tmp/bar -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 omitted, ...
Create a job with a command
Command: ```bash kubectl create job security-scan-job --image=ubuntu -- docker run ubuntu echo "Hello ``` 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": "", "...
Listen on port 8081 on your local machine and forward the traffic to port 5000 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward pod/api-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...
Create a job named "indexing" with the image "mongo" using the command "mongo --version"
Command: ```bash kubectl create job indexing --image=mongo -- mongo --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. ...
Partially update the 'dev-node-4' node by applying the specified JSON patch to its 'spec' field
Command: ```bash kubectl patch node dev-node-4 -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 pa...
Create a copy of the backend pod with a debug container, using the Debian image, and changing the container images for web and api.
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-memcached --image=debian --set-image=web=nginx:latest,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 n...
Expose a replication controller as a service on a specific port
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8081 --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 ...
Import the max_connections key from the monitoring-config config map and set it as an environmental variable in the authentication-service-deployment deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/monitoring-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environmen...
Import environment variables from a config map with a specified prefix
Command: ```bash kubectl set env --from=configmap/global-config --prefix=MYSQL_ deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Update the image of all containers in the 'namespace-3' DaemonSet to 'python:3.9.7'
Command: ```bash kubectl set image daemonset namespace-3 *=python:3.9.7 ``` 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: ...
Scale the deployment named "backend-service-replicaset" to 5 replicas, given that its current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/backend-service-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 --r...
Create a cron job named 'cleanup-task' that runs a command to sleep for 3600 seconds every minute, using the 'centos' image as the base image.
Command: ```bash kubectl create cronjob cleanup-task --image=centos --schedule="*/1 * * * *" -- sleep 3600 ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o",...
Listen on port 8088 locally and forward the traffic to port 8888 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8088: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...
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/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 creati...
Create a pod disruption budget named auth-service-pdb that will select all pods with the owner=team-1 label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-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 ...
Create a new secret named 'private-key-secret' with the following key-value pairs: - key1: supersecret - key2: topsecret
Command: ```bash kubectl create secret generic private-key-secret --from-literal=key1=supersecret --from-literal=key2=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 based on a file, the ...
Import the environment variables from the secret named "password-secret" into the deployment named "log-aggregator-deployment"
Command: ```bash kubectl set env --from=secret/password-secret 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 in one or mor...
Retrieve the previous terminated logs of the "stardust-shuttle" container from the pod named "mypod"
Command: ```bash kubectl logs -p -c stardust-shuttle mypod ``` 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...
Create a ClusterIP service named 'ldap-service-clusterip' that forwards traffic from port 8089 to port 9091.
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=8089:9091 ``` 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", "...
Create a new ClusterIP service named cache-service-clusterip that maps port 8084 on the cluster to port 5001 on the service.
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=8084:5001 ``` 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", ...
Create an ingress resource named "public-ingress" with a rule that directs requests from testing.com/example to svc1 on port 8081
Command: ```bash kubectl create ingress public-ingress --rule="testing.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": "", "u...
Create a cron job named backup-job that runs the command "python --version" every minute using the Python image.
Command: ```bash kubectl create cronjob backup-job --image=python --schedule="*/1 * * * *" -- python --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": "...
Start a port forwarding from local port 5432 to the pod selected by the log-aggregator-deployment deployment on port 5432.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 5432 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Forward local port 6379 to port 9090 in the pod 'e-commerce-pod'
Command: ```bash kubectl port-forward pod/e-commerce-pod 6379 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 aut...
Access the 'irb' command in the time-machine container of the proxy-server-pod and view the output.
Command: ```bash kubectl exec proxy-server-pod -c time-machine -- 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 ...
Forward local port 8000 to port 5432 in the analytics-pod
Command: ```bash kubectl port-forward pod/analytics-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Update the image of a container in a pod using a JSON patch with positional arrays
Command: ```bash kubectl patch pod vpn-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 patch ...
Update the label of the pod 'chat-app' to have the key 'component' and the value 'web'
Command: ```bash kubectl label pods chat-app 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":...
Get the output of the 'composer --version' command from the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -- composer --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...
Remove the operator user from the Kubernetes configuration.
Command: ```bash kubectl config delete-user operator ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`
Create a job with the given command
Command: ```bash kubectl create job testing --image=ruby -- ruby --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Import specific keys from a config map to a deployment environment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/ui-config deployment/mydeployment ``` 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 ...
Listen on port 9090 on all addresses and forward the traffic to the pod named 'analytics-pod' on port 6379.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Set the custom TLS server name to 'kube-cluster-1' for validation for the 'web-cluster' cluster entry.
Command: ```bash kubectl config set-cluster web-cluster --tls-server-name=kube-cluster-1 ``` 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] [--certificat...
Create a copy of the frontend-pod and add a debug container to it
Command: ```bash kubectl debug frontend-pod -it --copy-to=debug-image-api --image=debian --set-image=proxy=nginx:1.21,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Execute the 'geth attach' command in the first container of the first pod of the 'web-service' service.
Command: ```bash kubectl exec svc/web-service -- geth attach ``` 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 kubec...
Create a job with a specific image and command
Command: ```bash kubectl create job security-scan-job --image=postgres -- psql ``` 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....
Import the value of the "my-example-key" key from the "app-config-prod" config map and set it as an environment variable in the "frontend-deployment" deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config-prod 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 defini...
Import the 'SECRET_KEY' key from the 'api-config' config map to the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/api-config deployment/mydeployment ``` 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 ...
Autoscale the replication controller 'email' with a minimum of 1 and maximum of 3 pods, targeting a CPU utilization of 60%.
Command: ```bash kubectl autoscale rc email --max=3 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses t...
Create a copy of the 'monitoring-pod' pod, with all container images changed to 'ubuntu'. Name the new pod 'dgb-img'.
Command: ```bash kubectl debug monitoring-pod --copy-to=dgb-img --set-image=*=ubuntu ``` 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 resource ...
Set up autoscaling for the "database" deployment
Command: ```bash kubectl autoscale deployment database --min=1 --max=12 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a cluster role named "custom_role" with the AggregationRule specified as "rbac.example.com/aggregate-to-audit=true"
Command: ```bash kubectl create clusterrole custom_role --aggregation-rule="rbac.example.com/aggregate-to-audit=true" ``` 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: "...
Get the output from running the 'postgres' command in the pod named 'email-service-pod' using the first container by default
Command: ```bash kubectl exec email-service-pod -- postgres ``` 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 kubect...
Create a single ingress called 'private-service-ingress' that directs requests to website.com/input to svc1:3000 and use the tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/input=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp logging/web-app-pod-1::/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 the kubectl.kub...
Update the scaling-policy annotation of the pod identified in the "conf.json" file to "auto-horizontal-scaling"
Command: ```bash kubectl annotate -f conf.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 and...
Create an ingress with the name 'api-ingress' that directs requests from foo.com/module to the service 'svc1' on port 8010, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-ingress --rule="foo.com/module=svc1:8010,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": "...
Run the 'php --version' command inside the monitoring-pod container and get the output.
Command: ```bash kubectl exec monitoring-pod -- 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 kube...
Add a taint with the key 'special' on nodes that have the label 'app-type=microservice'.
Command: ```bash kubectl taint node -l app-type=microservice special=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": "", "us...
Delete pods and services with the names "vpn" and "email"
Command: ```bash kubectl delete pod,service vpn 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. Some ...
Forward local ports 3000 and 6000 to ports 3000 and 6000 in the pod named security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 3000 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Delete both the pod and service with the name "frontend".
Command: ```bash kubectl delete pod,service frontend frontend ``` 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 selecto...
Create a role named "bar" with the ability to list, create, and update resources for both nodes and nodes/metrics subresources.
Command: ```bash kubectl create role bar --verb=list,create,update --resource=nodes,nodes/metrics ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag":...
Create a copy of the 'proxy-server-pod', changing all container images to 'nginx' and name it 'my-debugger'
Command: ```bash kubectl debug proxy-server-pod --copy-to=my-debugger --set-image=*=nginx ``` 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 reso...
Create a service for the ubuntu deployment that listens on port 3001 and redirects traffic to the containers on port 801000.
Command: ```bash kubectl expose deployment ubuntu --port=3001 --target-port=801000 ``` 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 specifi...
Create a LoadBalancer service named log-aggregator-lb and map port 8088 on the host to port 5001 on the service.
Command: ```bash kubectl create service loadbalancer log-aggregator-lb --tcp=8088:5001 ``` 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", "...
Update the 'proxy-server' pod by setting the 'status' label to 'unhealthy', overwriting any existing value.
Command: ```bash kubectl label --overwrite pods proxy-server 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"...
Create a priority class named 'critical-priority' with a value of 10000, a description of "Highest criticality and resource allocation", and a preemption policy of "Never".
Command: ```bash kubectl create priorityclass critical-priority --value=10000 --description="Highest criticality and resource allocation" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --va...
Retrieve the snapshot logs from the specified container of the given deployment.
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c vpn-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: ...
Forward local port 8888 to port 8088 in the pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8888 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 au...
import the DEBUG_MODE key from the db-config config map and set it as an environment variable for the web-app-deployment deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/db-config deployment/web-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 definitions in on...
Create a new config map named db-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/properties/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 conf...
Forward data between local ports and a pod
Command: ```bash kubectl port-forward pod/backend-pod 9090 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 automa...
Create a job named "cleanup" using the alpine image, and execute the command "sleep 3600"
Command: ```bash kubectl create job cleanup --image=alpine -- sleep 3600 ``` 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 o...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=API_KEY --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 defin...
Update the annotation 'scaling-policy' of the pod 'auth' with the value 'auto-horizontal-scaling'
Command: ```bash kubectl annotate pods auth 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 and in...
Create a role named "admin_role" with access to execute commands on pods and specific resource names, such as "dev-database" and "machine-learning"
Command: ```bash kubectl create role admin_role --verb=exec --resource=pods --resource-name=dev-database --resource-name=machine-learning ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=serv...
Create a pod called 'hazelcast' using the 'node' image and expose port 5001
Command: ```bash kubectl run hazelcast --image=node --port=5001 ``` 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": "--fil...
create a cron job that runs the command "irb" every minute using the Ruby image
Command: ```bash kubectl create cronjob metrics-collection --image=ruby --schedule="*/1 * * * *" -- irb ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "d...
Retrieve the snapshot logs from the container named mypod-1 in the load-balancer-deployment deployment.
Command: ```bash kubectl logs deployment/load-balancer-deployment -c mypod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--...
Set resource limits for the redis container in the deployment. Set the cpu limit to "2" and memory limit to "256Mi".
Command: ```bash kubectl set resources deployment redis -c=nginx --limits=cpu=2,memory=256Mi ``` 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 it...
Forward local port 8081 to pod port 8888 in the specified deployment
Command: ```bash kubectl port-forward deployment/mydeployment 8081 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 selecte...
Forward port 5432 on your local machine to port 8088 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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 aut...
Switch to the raw terminal mode and connect to the 'bash' shell in the 'warp-drive' container of the 'chat-app-pod' pod.
Command: ```bash kubectl exec chat-app-pod -c warp-drive -i -t -- bash -il ``` 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,...
Create a copy of the 'web-app-pod' pod and start a debugging session on the 'nano-bot' container
Command: ```bash kubectl debug web-app-pod -it --copy-to=my-debugger --container=nano-bot -- sh ``` 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 n...
Scale the mysql deployment named backend-service-replicaset from the current size of 3 replicas to 7 replicas
Command: ```bash kubectl scale --current-replicas=3 --replicas=7 deployment/backend-service-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 --r...
Create a job named 'log-collection' with the image 'alpine' and the command 'sleep 3600'
Command: ```bash kubectl create job log-collection --image=alpine -- sleep 3600 ``` 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...
Create a copy of the "gateway-pod" and change all container images to "node"
Command: ```bash kubectl debug gateway-pod --copy-to=dgb-img --set-image=*=node ``` 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 resource is sp...
Set the custom TLS server name "staging-cluster" for the "moon-cluster" cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=staging-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] [--certific...
Create a pod disruption budget named 'worker-pdb' that will select all pods with the 'component=web' label and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=component=web --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 [--dr...
Change the service account of the search-engine-deployment deployment to cert-manager.
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment cert-manager ``` 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: ...
Create a service for the replication controller specified in the "python-controller.yaml" file
Command: ```bash kubectl expose -f python-controller.yaml --port=8080 --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...
Listen on port 3000 on localhost and IP address 10.19.21.23, and forward the traffic to port 8081 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 3000: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 p...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/analytics-rc pods/analytics-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...
Start a redis pod with specific overrides using JSON
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "v3.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] -- [COMMAND...
Create a new pod named "nginx" with the image "mongo", by overriding the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=mongo --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] -- [COMM...
Create a service for the 'ubuntu' deployment that serves on port 8089 and connects to the containers on port 801000.
Command: ```bash kubectl expose deployment ubuntu --port=8089 --target-port=801000 ``` 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 specifi...
Set the cluster field in the 'my-context' context to 'prod-cluster'
Command: ```bash kubectl config set contexts.service-account-context.cluster prod-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 va...
Create an ingress resource called 'api-ingress' that directs requests to 'testing.com/example' to a service named 'svc1' on port 8000, and use the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress api-ingress --rule="testing.com/example=svc1:8000,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...
Get the output of the command 'kafka-topics --list' from the pod 'gateway-pod' in the container 'nano-bot'
Command: ```bash kubectl exec gateway-pod -c nano-bot -- kafka-topics --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 name. If omitte...
Attach to a pod's container and access its terminal in raw mode
Command: ```bash kubectl attach security-service-pod -c warp-drive -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...
Create a pod disruption budget named 'ingress-controller-pdb' that will select all pods with the 'tier=frontend' label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget ingress-controller-pdb --selector=tier=frontend --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-avail...
Get the output of the command `dotnet --list-runtimes` from the `cosmic-container` container running in the `database-pod` pod.
Command: ```bash kubectl exec database-pod -c cosmic-container -- dotnet --list-runtimes ``` 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 nam...
Update the environment variable SMTP_HOST for the deployment 'user-management-deployment'
Command: ```bash kubectl set env deployment/user-management-deployment SMTP_HOST=smtp.example.com ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more ...
Import the MAX_CONNECTIONS key from the db-config config map and set it as an environment variable for the proxy-service-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/db-config deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Add a taint with key 'app' on nodes having label app=web-app
Command: ```bash kubectl taint node -l app=web-app app=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": "", "usage": "...
Listen on port 8888 locally and forward data to/from port 5432 in the frontend-pod.
Command: ```bash kubectl port-forward pod/frontend-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 autom...
Run the 'kafka-topics --list' command inside the 'stardust-shuttle' container of the 'media-stream-pod' pod and get the output
Command: ```bash kubectl exec media-stream-pod -c stardust-shuttle -- kafka-topics --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 na...