prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a service for the replicated hazelcast using replica set, which will serve on port 7000 and connect to the containers on port 500000
Command: ```bash kubectl expose rs hazelcast --port=7000 --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 po...
Auto scale the deployment named "database" with a minimum of 4 pods and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment database --min=4 --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 an ingress called 'api-v2-ingress' that routes requests from foo.com/bar to svc1:8888 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="foo.com/bar=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Execute the 'mysql' command in the first pod of the authentication-service-deployment deployment.
Command: ```bash kubectl exec deploy/authentication-service-deployment -- mysql ``` 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 omi...
Remove a specific environment variable for the "k8s-admin" entry in the authentication configuration.
Command: ```bash kubectl config set-credentials k8s-admin --exec-env=var-to-remove- ``` 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-key=keyfile Bearer token flags:...
Add a taint with key 'workload' on nodes having label release=beta
Command: ```bash kubectl taint node -l release=beta workload=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": "", "usage": "O...
Describe pods with the label `customer=acme-corp`
Command: ```bash kubectl describe po -l customer=acme-corp ``` 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, pr...
Create a cron job named "email-notifications" that runs the command "mysqld" every minute using the mysql image.
Command: ```bash kubectl create cronjob email-notifications --image=mysql --schedule="*/1 * * * *" -- mysqld ``` 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...
Create a new deployment named 'db' that uses the 'ubuntu' image and exposes port 8089.
Command: ```bash kubectl create deployment db --image=ubuntu --port=8089 ``` 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|...
Forward local port 8000 to pod port 8000
Command: ```bash kubectl port-forward pod/security-service-pod 8000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
import the API_KEY key from the kube-system-config config map and set it as an environment variable for the user-management-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/kube-system-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Listen on port 8888 on all addresses and forward the traffic to port 8080 in the pod named 'chat-app-pod'.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8888: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...
Embed a certificate authority data for a cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config...
Use the "nvim" editor to edit the "api-service" service configuration.
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/api-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 variables, or...
Run the 'elasticsearch --version' command inside the frontend-pod and capture the output
Command: ```bash kubectl exec frontend-pod -- 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 name. If omitted, use ...
Attach to a specific container in a pod and enter raw terminal mode.
Command: ```bash kubectl attach auth-service-pod -c lunar-launcher -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Forward local traffic from port 8080 to port 8088 in the pod selected by the 'authentication-service-deployment' deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8080 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, ...
Execute the 'node' command in the 'nano-bot' container of the 'frontend-pod' pod and retrieve the output
Command: ```bash kubectl exec frontend-pod -c nano-bot -- node ``` 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 kub...
Update the image of all containers in the 'namespace-3' daemonset to 'openjdk:16.0.2'.
Command: ```bash kubectl set image daemonset namespace-3 *=openjdk:16.0.2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax...
Create a deployment named "wordpress" that runs the "jenkins" image and expose port 8084
Command: ```bash kubectl create deployment wordpress --image=jenkins --port=8084 ``` 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 o...
Execute the 'nginx' command inside the first container of the 'gateway-service' service and retrieve the output.
Command: ```bash kubectl exec svc/gateway-service -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl...
Remove the taint with key 'app' and effect 'PreferNoSchedule' from the node named 'kube-master-9'
Command: ```bash kubectl taint nodes kube-master-9 app:PreferNoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Return the logs of a specific container from a deployment
Command: ```bash kubectl logs deployment/search-engine-deployment -c frontend-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: "fla...
Add a taint with key 'special' to nodes that have the label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha special=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create a new config map named monitoring-config with the files file1.txt and file2.txt as the values for keys "settings" and "key2" respectively.
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/properties/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. When c...
Create a deployment named 'drupal' using the Jenkins image and expose port 8089.
Command: ```bash kubectl create deployment drupal --image=jenkins --port=8089 ``` 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: ...
Forward traffic from port 5000 on all addresses to port 8888 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 5000:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Begin streaming the logs of the 'nano-bot' container in the 'analytics-pod' pod
Command: ```bash kubectl logs -f -c nano-bot analytics-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...
Listen on port 8888 locally, forwarding the traffic to port 8000 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8888:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a job named 'test-job' using the 'cleanup-task' cron job as a template.
Command: ```bash kubectl create job test-job --from=cronjob/cleanup-task ``` 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...
Start streaming the logs of the "ruby" container in the pod named "email-service-pod"
Command: ```bash kubectl logs -f -c ruby email-service-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...
Forward traffic from all addresses on port 9090 to port 8081 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 9090:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Update the 'notification-handler-deployment' deployment by adding a new environment variable called SMTP_PASSWORD with the value 'your-password'.
Command: ```bash kubectl set env deployment/notification-handler-deployment SMTP_PASSWORD=your-password ``` 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...
Get the output from the 'cosmic-container' container in the 'frontend-pod' pod.
Command: ```bash kubectl attach frontend-pod -c cosmic-container ``` 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...
import the 'my-example-key' key from the 'app-config-dev' config map into the 'payment-processor-deployment' deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config-dev 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 variabl...
Set the service account of the deployment "notification-handler-deployment" to "spinnaker"
Command: ```bash kubectl set serviceaccount deployment notification-handler-deployment spinnaker ``` 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 Synt...
Create a role named "reader" with the ability to get pods and access them with the resource names "file-storage" and "file-processing"
Command: ```bash kubectl create role reader --verb=get --resource=pods --resource-name=file-storage --resource-name=file-processing ``` 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|cli...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/ui-config 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 definitio...
Set the service account of the 'log-aggregator-deployment' deployment to 'default'.
Command: ```bash kubectl set serviceaccount deployment log-aggregator-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: `kub...
Scale the replica set named 'app-v2-replicaset' to 7 replicas.
Command: ```bash kubectl scale --replicas=7 rs/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-version is specified, it is va...
Create an ingress called 'public-ingress' that directs requests for 'foo.com/module' to 'svc1:8083' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="foo.com/module=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Import the specific key 'my-example-key' from the 'app-settings' config map to the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-settings deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Attach to the rocket-ranger container in the chat-app-pod and get the output.
Command: ```bash kubectl attach chat-app-pod -c rocket-ranger ``` 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, u...
Create a new secret named "password-secret" with keys for each file in the "path/to/configs" folder.
Command: ```bash kubectl create secret generic password-secret --from-file=path/to/configs ``` 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 t...
Create a job named "backup" with an image "mysql" and run the command "mysql"
Command: ```bash kubectl create job backup --image=mysql -- mysql ``` 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...
Set the environment variable PORT to 8080 in the deployment 'log-aggregator-deployment'
Command: ```bash kubectl set env deployment/log-aggregator-deployment PORT=8080 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (wit...
Start a busybox pod with the wordpress image and keep it running in the foreground without restarting if it exits.
Command: ```bash kubectl run -i -t busybox --image=wordpress --restart=Never ``` 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: "...
create a service for the replication controller specified in "centos-controller.yaml" file, exposing port 9090 and connecting to the containers on port 637900
Command: ```bash kubectl expose -f centos-controller.yaml --port=9090 --target-port=637900 ``` 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...
Forward local port 5000 to port 8080 in the analytics-pod pod
Command: ```bash kubectl port-forward pod/analytics-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 auto...
Run the 'wp' command on the e-commerce pod and display the output.
Command: ```bash kubectl exec e-commerce-pod -- 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 the kubectl.kuberne...
Create an ingress called 'app-loadbalancer-ingress' that directs requests to foo.com/example to svc1:8080 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/example=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Update the label of a pod named 'chat-app' with the label 'tier' and the value 'database'
Command: ```bash kubectl label pods chat-app tier=database ``` 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":...
delete the pods and services named "security" and "gateway"
Command: ```bash kubectl delete pod,service security gateway ``` 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...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp ingress-nginx/payment-gateway-pod-19:/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...
Add a taint with the key 'disktype' and value 'kube-master-9:PreferNoSchedule' on nodes that have the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz 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": "", "u...
Create a job named "log-collection" using the image "redis" with the command "redis-server"
Command: ```bash kubectl create job log-collection --image=redis -- redis-server ``` 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 forma...
Create a config map named env-vars using specified files as key-value pairs
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/profiles/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 conf...
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to testing.com/module to svc1:8181 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/module=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...
Update the label of the pod 'database' to have the key 'tier' and the value 'database'
Command: ```bash kubectl label pods database tier=database ``` 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":...
Auto scale the deployment "auth" with a minimum of 4 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment auth --min=4 --max=8 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Retrieve the output of the 'redis-server --version' command from the log-aggregator-pod container named stardust-shuttle.
Command: ```bash kubectl exec log-aggregator-pod -c stardust-shuttle -- redis-server --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": "Contain...
Copy a directory named "foo_dir" from the remote pod named "api-server-pod-3" to your local directory "/tmp/bar_dir"
Command: ```bash kubectl cp cert-manager/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 ...
Create a new config map named log-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/profiles/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. When creating a...
Forward local port 5432 to port 5000 on the backend-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 5432: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 criteri...
Import the CONFIG_FILE_PATH key from the app-secrets config map into the deployment named mydeployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-secrets 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 ...
Forward local port 8888 to pod port 8088
Command: ```bash kubectl port-forward pod/api-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...
Delete the pods and services with the names "email" and "chat-app"
Command: ```bash kubectl delete pod,service email chat-app ``` 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 cron job named 'system-health-check' using the 'redis' image, with a schedule of running every minute and execute the command 'redis-cli'
Command: ```bash kubectl create cronjob system-health-check --image=redis --schedule="*/1 * * * *" -- redis-cli ``` 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 the 'my-example-key' keys from the 'app-name-config' config map into the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-name-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 i...
Taint nodes with label 'environment=production' using taint key 'app' with value 'backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l environment=production app=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": "", "us...
Start a pod named 'hazelcast' using the 'ubuntu' image and make the container inside the pod expose port 3001
Command: ```bash kubectl run hazelcast --image=ubuntu --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": "--f...
Execute the 'sleep 3600' command in the cosmic-container of the monitoring-pod and retrieve the output.
Command: ```bash kubectl exec monitoring-pod -c cosmic-container -- sleep 3600 ``` 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 omit...
Update the compliance level of the pod identified by type and name in the "params.json" file to "PCI-DSS"
Command: ```bash kubectl annotate -f params.json compliance-level=PCI-DSS ``` 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 arb...
Set the "client-key" field for the "deploy-bot" entry in the kubeconfig file to "~/.kube/admin.key"
Command: ```bash kubectl config set-credentials deploy-bot --client-key=~/.kube/admin.key ``` 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-key=keyfile Bearer token ...
import the "debug_mode" key from the "db-config" config map and set it as an environment variable in the "gateway-deployment" deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/db-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Create a job named 'batch-processing' with the 'redis' image and the command 'redis-server'
Command: ```bash kubectl create job batch-processing --image=redis -- redis-server ``` 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 for...
Set the service account of the deployment named "order-processing-deployment" to "spinnaker"
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment spinnaker ``` 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: ...
Partially update the 'node-1' node by applying the JSON patch provided, which specifies the strategic merge update for the 'container-name' container's resources limits CPU to "200m".
Command: ```bash kubectl patch node node-1 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 (-f FILEN...
Create a pod disruption budget named "database-pdb" that will select all pods with the "release=1.0.0" label and require at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=release=1.0.0 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--...
Set the last-applied-configuration of a resource to match the contents of the 'config.yaml' file and create the annotation if it doesn't exist
Command: ```bash kubectl apply set-last-applied -f config.yaml --create-annotation=true ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without upda...
Add a taint to the 'db-node-7' node with the key 'disktype' and no value
Command: ```bash kubectl taint nodes db-node-7 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Create a pod disruption budget named messaging-pdb that will select all pods with the project=my-project label, and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=project=my-project --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-settings deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create a new LoadBalancer service named ingress-controller-lb with a TCP forwarding from port 9091 to port 8089.
Command: ```bash kubectl create service loadbalancer ingress-controller-lb --tcp=9091:8089 ``` 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...
Delete the pods and services with the names "backend" and "media-stream"
Command: ```bash kubectl delete pod,service backend 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 sele...
Update the annotation of a pod with a new value, overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods security SLA='99.9% uptime' ``` 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 includ...
Import the 'max_connections' key from the 'log-config' ConfigMap into the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/log-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Embed the certificate authority data for the 'testing-cluster' cluster entry.
Command: ```bash kubectl config set-cluster testing-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 ...
Create a debugging session of the 'web-app-pod' container 'time-machine' and save it as 'debug-image-app'
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-app --container=time-machine -- 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 defa...
Expose a replication controller using a configuration file and specify the port numbers for service and container connections.
Command: ```bash kubectl expose -f php-controller.yaml --port=5432 --target-port=909100 ``` 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 sp...
Set the local shell environment variables with the prefix RAILS_ for a deployment named "order-processing-deployment".
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/order-processing-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 more p...
Update the 'monitoring-tool' annotation of the 'proxy-server' pod with the value 'Prometheus', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods proxy-server 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 lab...
Create an ExternalName service named external-messaging-service that points to test-site.org
Command: ```bash kubectl create service externalname external-messaging-service --external-name test-site.org ``` 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 serv...
Set the cluster field in the 'my-context' context to 'dev-cluster'
Command: ```bash kubectl config set contexts.cluster-1-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Update the 'web-app-deployment' deployment by setting the environment variable SMTP_USERNAME to your-username
Command: ```bash kubectl set env deployment/web-app-deployment SMTP_USERNAME=your-username ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod tem...
Create a pod disruption budget that ensures at least four pods with the label "region=us-east" are always available.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=region=us-east --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-av...
Retrieve the snapshot logs from the container "database-pod-1" in the deployment "search-engine-deployment".
Command: ```bash kubectl logs deployment/search-engine-deployment -c database-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "fla...
Create a copy of the analytics-pod named debug-image-api, adding a debug container and changing container images
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-api --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 resource and ...
Create a new config map named log-config with specified keys and file paths
Command: ```bash kubectl create configmap log-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 creating ...
Add a taint with the key 'environment' and value 'worker-node-3:PreferNoSchedule' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha environment=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "...