prompt
stringlengths
13
282
response
stringlengths
128
3.11k
List the replication controller 'web', service 'api-service-rc', and pod 'payment-gateway-pod'
Command: ```bash kubectl get rc/web service/api-service-rc pods/payment-gateway-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is na...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/kube-system-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 ...
Run the command 'gem --version' in the pod named 'database-pod' and retrieve the output.
Command: ```bash kubectl exec database-pod -- gem --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 kubect...
Expose the replication controller "php" as a service, so that it can serve on port 3001 and connect to the containers on port 637900.
Command: ```bash kubectl expose rc php --port=3001 --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 specified port. A ...
Create a new config map named app-settings and populate it with data from specified files
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Start a pod named "hazelcast" using the php image and have the container inside the pod expose port 9092.
Command: ```bash kubectl run hazelcast --image=php --port=9092 ``` 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": "--file...
Create a service for the replicated nginx with the default port of 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose rc nginx --port=5001 --target-port=500100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Listen on the local ports 8081 and 6000, and forward data to/from ports 8088 and 6000 in the 'security-service-pod'.
Command: ```bash kubectl port-forward pod/security-service-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 select...
Create a single ingress called 'app2-ingress' that directs requests to site.com/module to svc1 on port 8000 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/module=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": "", "usage":...
Create a role named "custom_role" that allows using the "pods" resource with the resource names "app-worker-1" and "nginx-proxy"
Command: ```bash kubectl create role custom_role --verb=use --resource=pods --resource-name=app-worker-1 --resource-name=nginx-proxy ``` 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|cl...
Delete pods and services named "analytics" and "monitoring"
Command: ```bash kubectl delete pod,service analytics 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 sele...
Copy the ~/.config/kube directory from the remote pod "database-pod-2" to the /tmp/bar_dir directory locally
Command: ```bash kubectl cp kube-flannel/database-pod-2:~/.config/kube /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Listen on local port 5432 and forward data to/from port 8081 in a pod selected by the monitoring-stack-deployment deployment
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 5432 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Create a new LoadBalancer service named web-app-lb and map port 3001 of the LoadBalancer to port 8000 of the target application
Command: ```bash kubectl create service loadbalancer web-app-lb --tcp=3001:8000 ``` 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...
Update the "cluster-beta" cluster entry's "server" field to use the URL "https://1.2.3.4", without modifying any other values.
Command: ```bash kubectl config set-cluster cluster-beta --server=https://1.2.3.4 ``` 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-autho...
Return the previous terminated container logs named 'time-machine' from the 'log-aggregator-pod' pod.
Command: ```bash kubectl logs -p -c time-machine log-aggregator-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...
Forward traffic from port 3000 on all addresses to port 8081 in the analytics-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 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 pod wil...
Execute the command 'mongo --version' inside the 'astro-container' of the 'email-service-pod' pod
Command: ```bash kubectl exec email-service-pod -c astro-container -- mongo --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. ...
Get the output from running the command 'nginx -g "daemon off;"' in the first pod of the service 'api-service', using the first container by default.
Command: ```bash kubectl exec svc/api-service -- nginx -g "daemon off;" ``` 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, us...
Update the annotation 'env' of the pod 'database' with the value 'staging'.
Command: ```bash kubectl annotate pods database env=staging ``` 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 arbitrary string ...
Update the release notes of the pod identified in the "pod.json" file by annotating it with the URL 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate -f pod.json release-notes='https://example.com/release-notes/v2.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 large...
Create a deployment named 'mattermost' using the MySQL image and the command 'mysql'
Command: ```bash kubectl create deployment mattermost --image=mysql -- mysql ``` 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...
Approve the CSR (Certificate Signing Request) with the name 'csr-def456'.
Command: ```bash kubectl certificate approve csr-def456 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attribu...
Auto scale the replication controller "gateway" with a maximum of 2 pods and a target CPU utilization of 60%
Command: ```bash kubectl autoscale rc gateway --max=2 --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...
Create an ingress named 'api-v2-ingress' that routes requests from 'website.com/example' to 'svc1:3306' with TLS certificate 'my-cert'.
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/example=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
List the deployments in the "alpha-2.0" version of the "custom-deployments" API group in YAML format
Command: ```bash kubectl get deployments.alpha-2.0.custom-deployments -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespac...
Create a new LoadBalancer service named my-lbs with a mapping of port 8443 on the external IP to port 8081 of the pods
Command: ```bash kubectl create service loadbalancer my-lbs --tcp=8443:8081 ``` 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": "...
Specify the keys to import from a config map and set them as environment variables for a specific deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/api-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 definitions i...
Get the output from running the 'docker run ubuntu echo "Hello, World"' command in the rocket-ranger container of the proxy-server-pod.
Command: ```bash kubectl exec proxy-server-pod -c rocket-ranger -- docker run ubuntu echo "Hello, World" ``` 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"...
Get output from running the 'npm --version' command in pod backend-pod with container name nano-bot.
Command: ```bash kubectl exec backend-pod -c nano-bot -- npm --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...
Add a taint to nodes with the label 'tier=frontend' and key 'cpu-type'
Command: ```bash kubectl taint node -l tier=frontend cpu-type=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Delete the pods and services named "auth" and "vpn"
Command: ```bash kubectl delete pod,service auth vpn ``` 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 r...
Copy the local file '/tmp/foo_dir' to the '/etc/kubernetes' directory in the remote pod 'backend-pod-13' in the 'istio-system' namespace.
Command: ```bash kubectl cp /tmp/foo_dir istio-system/backend-pod-13:/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...
Forward traffic from local port 9090 to port 8080 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 9090: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 autom...
Execute 'node --version' command in the security-service-pod and retrieve the output.
Command: ```bash kubectl exec security-service-pod -- node --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Show the last 12 lines of logs for the 'cdn-service-pod' pod
Command: ```bash kubectl logs --tail=12 cdn-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": ...
List the specified resources by their respective types and names.
Command: ```bash kubectl get rc/web service/auth-service-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 names...
Create a deployment named "jenkins" using the "ethereum/client-go" image and expose port 8088.
Command: ```bash kubectl create deployment jenkins --image=ethereum/client-go --port=8088 ``` 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...
Forward local port 3000 to port 8888 in the pod/api-service-pod pod
Command: ```bash kubectl port-forward pod/api-service-pod 3000 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...
Add a taint with the key 'workload' on nodes having the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel workload=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Forward local ports 8081 and 6000 to ports 8081 and 6000 in the pod
Command: ```bash kubectl port-forward pod/security-service-pod 8081 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Taint a specific node by adding a taint with a key and no value.
Command: ```bash kubectl taint nodes k8s-node-1 hardware: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: j...
Set the service account for the deployment named "email-server-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment email-server-deployment my-service-account ``` 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 Syn...
Create an ingress called 'api-v2-ingress' with a rule that directs requests from 'testing.com/input' to 'svc1:5000'
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/input=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create an ingress called 'app-ingress' that directs requests to testing.com/bar to a service named svc1 on port 3001, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/bar=svc1:3001,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 specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/api-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Start streaming the logs of the "cosmic-container" container in the "security-service-pod" pod.
Command: ```bash kubectl logs -f -c cosmic-container security-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": "--con...
Apply a taint with key 'app' and value 'k8s-node-1:PreferNoSchedule' on all nodes labeled with 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha app=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Scale the dev-environment-rs deployment to 1 replica, if its current size is 3
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/dev-environment-rs ``` 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-...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the mycontainer container of the gateway-pod pod
Command: ```bash kubectl exec gateway-pod -c mycontainer -- kafka-server-start /etc/kafka/server.properties ``` 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": "", "usa...
Run the command 'kafka-server-start /etc/kafka/server.properties' inside the 'mypod' pod and display the output
Command: ```bash kubectl exec mypod -- kafka-server-start /etc/kafka/server.properties ``` 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....
Return the logs for the previous terminated rocket-ranger container from the pod named mypod.
Command: ```bash kubectl logs -p -c rocket-ranger 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 service for the 'hazelcast' deployment, exposing port 8010 and connecting to the containers on port 808200
Command: ```bash kubectl expose deployment hazelcast --port=8010 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Start a Jenkins pod and expose port 27017.
Command: ```bash kubectl run hazelcast --image=jenkins --port=27017 ``` 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": "-...
Create a new config map named db-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/options/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 a conf...
Partially update a node using a strategic merge patch specified as YAML
Command: ```bash kubectl patch node node-2 -p $'spec:\n type: LoadBalancer' ``` 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 FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags:...
Create a service for a replicated Ruby using replica set
Command: ```bash kubectl expose rs ruby --port=3000 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Enable autoscaling for the "api" deployment with a minimum of 6 pods and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment api --min=6 --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 uses the...
Display the metrics for the 'worker-node-3' node.
Command: ```bash kubectl top node worker-node-3 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector ...
Forward local port 9090 to port 8888 in the mypod pod
Command: ```bash kubectl port-forward pod/mypod 9090: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 automaticall...
Import the 'SECRET_KEY' key from the 'ui-config' config map into the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/ui-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 definitions...
Add a label to the pod 'cdn' with the label 'unhealthy' and the value 'true'
Command: ```bash kubectl label pods cdn unhealthy=true ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If...
Set the service account of the deployment named api-server-deployment to flux
Command: ```bash kubectl set serviceaccount deployment api-server-deployment flux ``` 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...
Start a new ubuntu pod with the name 'nginx', using the 'ubuntu' image
Command: ```bash kubectl run nginx --image=ubuntu --overrides='{ "apiVersion": "dev-2.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] -- [COM...
Create a deployment named 'my-dep' using the mysql image and expose port 8088
Command: ```bash kubectl create deployment my-dep --image=mysql --port=8088 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Set resource requests and limits for all containers in the Redis deployment.
Command: ```bash kubectl set resources deployment redis --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 reques...
Display the most recent 23 lines of output from the logs of the proxy-service-pod pod
Command: ```bash kubectl logs --tail=23 proxy-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"...
List deployments in YAML format for the "v2.1.0" version of the "alpha-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.alpha-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will...
Create a deployment named jenkins-x using the redis image and expose port 3001
Command: ```bash kubectl create deployment jenkins-x --image=redis --port=3001 ``` 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:...
Retrieve the output from executing the 'python' command in the 'cosmic-container' within the 'monitoring-pod' pod
Command: ```bash kubectl exec monitoring-pod -c cosmic-container -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Import the "log_level" key from the "app-settings" ConfigMap into the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-settings deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Create a copy of the log-aggregator-pod, adding a debug container, and changing the container images to debian for the debug container, logging-app to debug image, and nginx for the web image
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identif...
Update the annotation value for the pod 'email' with the key 'contact-email' to 'support@example.com', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods email contact-email='support@example.com' ``` 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...
Scale a replica set named 'dev-environment-rs' to 3 replicas
Command: ```bash kubectl scale --replicas=3 rs/dev-environment-rs ``` 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 v...
Create a priority class named 'medium-priority' with a value of 50, a description of "Moderate, standard resource allocation", and a preemption policy of "Never".
Command: ```bash kubectl create priorityclass medium-priority --value=50 --description="Moderate, standard 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 --value=VALUE ...
Add a taint to nodes with the label 'cluster=my-cluster' to mark them as preferring no scheduling
Command: ```bash kubectl taint node -l cluster=my-cluster workload=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": "", "usa...
delete pods and services named "payment" and "vpn"
Command: ```bash kubectl delete pod,service payment vpn ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Som...
Import the SECRET_KEY from the config map called namespace-config and set it as an environment variable in the notification-handler-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/namespace-config 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 variab...
Import the 'my-example-key' keys from the 'ui-config' config map into the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/ui-config deployment/backend-microservice-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 ...
Create a job named "certificate-renewal" using the "busybox" image.
Command: ```bash kubectl create job certificate-renewal --image=busybox ``` 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...
Create a new NodePort service named auth-service-nodeport that maps port 27017 on the cluster nodes to port 6379 on the service endpoints.
Command: ```bash kubectl create service nodeport auth-service-nodeport --tcp=27017:6379 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default...
Delete the pods and services with the names "foo" and "gateway"
Command: ```bash kubectl delete pod,service foo 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. Som...
Create a service to expose the replicated ubuntu pods, which will listen on port 8089 and forward traffic to the pods on port 637900.
Command: ```bash kubectl expose rs ubuntu --port=8089 --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 specified port....
Expose a replication controller named "nginx" as a service, with the service listening on port 8088 and forwarding traffic to the containers on port 500100.
Command: ```bash kubectl expose rc nginx --port=8088 --target-port=500100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Output the modified deployment/database-deployment in YAML format, adding the environment variable SECRET_KEY with the value "your-secret-key"
Command: ```bash kubectl set env deployment/database-deployment SECRET_KEY=your-secret-key -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more...
Open the 'security-scan-job' in JSON format using the v1 API version
Command: ```bash kubectl edit job.v1.batch/security-scan-job -o json ``` 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...
Taint the nodes with the label 'team=devops' by adding a taint with the key 'app' and value 'k8s-node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l team=devops app=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output f...
Start streaming the logs of the "warp-drive" container in the "payment-gateway-pod" pod.
Command: ```bash kubectl logs -f -c warp-drive payment-gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Forward local traffic from port 5000 to port 8080 in a specific pod
Command: ```bash kubectl port-forward pod/cdn-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 debug copy of the cdn-service-pod, with a debug container and updated container images.
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-api --image=debian --set-image=scheduler=my-scheduler:1.0,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 i...
Create a new secret named ssl-key-secret and include keys for each file in the folder 'bar' that is located at the 'path/to/parameters'
Command: ```bash kubectl create secret generic ssl-key-secret --from-file=path/to/parameters ``` 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...
Forward local port 9090 to port 5432 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-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 au...
Disable certificate checking for the 'kube-cluster-1' dev cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --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] [--certific...
Retrieve the snapshot logs from the first container of the job named "report-generation-job"
Command: ```bash kubectl logs job/report-generation-job ``` 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 new config map named global-config using the specified files as values for each key
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/configurations/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 crea...
Set the runtime container CPU limits to "50m" and memory to "512Mi" in the deployment named "runtime", for the container named "nginx".
Command: ```bash kubectl set resources deployment runtime -c=nginx --limits=cpu=50m,memory=512Mi ``` 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 t...
List deployments in YAML format, specifically for the "dev-2.2.0" version of the "extensions" API group
Command: ```bash kubectl get deployments.dev-2.2.0.extensions -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Create a job named data-migration-job using the Python image, and run the command "pip --version" inside the job.
Command: ```bash kubectl create job data-migration-job --image=python -- pip --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...
Create a job named 'testing' using the 'redis' image, and run the command 'redis-server --version' within the job
Command: ```bash kubectl create job testing --image=redis -- redis-server --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 fo...
Update the pod 'security' with the annotation 'env' and the value 'staging', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods security env='staging' ``` 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...