prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a service for the replicated php using the replica set
Command: ```bash kubectl expose rs php --port=3001 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Create a new secret named 'api-secret-key' using the environment variables defined in the file located at 'path/to/parameters.env'
Command: ```bash kubectl create secret generic api-secret-key --from-env-file=path/to/parameters.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the bas...
Get the output of the 'geth attach' command from the first pod of the 'analytics-service' service.
Command: ```bash kubectl exec svc/analytics-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...
Update the annotation 'security-scan-status' of the pod 'api' to 'pass'
Command: ```bash kubectl annotate pods api security-scan-status=pass ``` 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 arbitrar...
List the specified resources by their types and names
Command: ```bash kubectl get rc/web service/vpn-service-rc pods/proxy-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is name...
Add a taint with key 'environment' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace environment=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Create a debug container within the proxy-server-pod and change the container images to debian for the debug container, and to mysql:5.7 for the database container and to api:v2 for the api container.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-1 --image=debian --set-image=database=mysql:5.7,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 na...
Create an ingress that directs requests to a specific service with TLS enabled.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/module=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...
Set the custom TLS server name "moon-cluster" for the cluster-gamma cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=moon-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] [--certificat...
Create a pod disruption budget that selects all pods with the env=production label and ensures that at least four of them are available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=env=production --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...
Create a new config map named 'api-config' in the current namespace using the specified files
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Update the 'proxy-server' pod with the annotation 'deployment-script' and the value 'https://example.com/deploy.sh', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server deployment-script='https://example.com/deploy.sh' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that c...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-secrets deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Execute the 'python' command inside the 'mycontainer' container of the 'media-stream-pod' pod and display the output.
Command: ```bash kubectl exec media-stream-pod -c mycontainer -- 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, us...
Scale a resource to a specific number of replicas using a YAML file
Command: ```bash kubectl scale --replicas=5 -f docker-registry.yaml ``` 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...
Forward port 6379 on all addresses to port 5000 in the cdn-service-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 6379: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 w...
create a job with a specified image and command
Command: ```bash kubectl create job audit-job --image=ethereum/client-go -- geth ``` 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...
Access the 'bash' command in the code-explorer container of the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c code-explorer -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Create a service named "frontend" for the pod "vpn-service-pod" that serves on port 444, using the command "kubectl expose pod vpn-service-pod --port=9090 --name=frontend"
Command: ```bash kubectl expose pod vpn-service-pod --port=9090 --name=frontend ``` 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 ...
Import the 'secret_key' key from the 'db-config' config map to the deployment 'mydeployment'
Command: ```bash kubectl set env --keys=secret_key --from=configmap/db-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 m...
Forward data between local port 8088 and pod port 5432 for the email-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8088 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a job named 'indexing' using the 'wordpress' image and run the 'wp' command inside the job.
Command: ```bash kubectl create job indexing --image=wordpress -- wp ``` 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: j...
create a config map named app-config-dev from specified files, using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
Autoscale the replication controller 'proxy', allowing the number of pods to scale between 1 and 7, based on target CPU utilization of 20%.
Command: ```bash kubectl autoscale rc proxy --max=7 --cpu-percent=20 ``` 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...
Auto scale the replication controller "media-stream" based on CPU utilization, with a minimum of 1 pod and a maximum of 8 pods.
Command: ```bash kubectl autoscale rc media-stream --max=8 --cpu-percent=50 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that...
Create a deployment named db using the nginx image
Command: ```bash kubectl create deployment db --image=nginx ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-...
Switch to raw terminal mode for the 'stardust-shuttle' container inside the 'e-commerce-pod' pod
Command: ```bash kubectl attach e-commerce-pod -c stardust-shuttle -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 new ClusterIP service named catalog-service-clusterip, mapping port 8088 of the service to port 8088 of the pods.
Command: ```bash kubectl create service clusterip catalog-service-clusterip --tcp=8088:8088 ``` 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"...
Execute the 'redis-server --version' command in the cyber-sleuth container within the monitoring-pod pod and print the output.
Command: ```bash kubectl exec monitoring-pod -c cyber-sleuth -- 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": "Container name....
Delete the pods and services with names "security" and "frontend"
Command: ```bash kubectl delete pod,service security 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...
Import the DATABASE_URL key from the app-config-prod config map and set it as an environment variable in the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-prod deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a debug image of auth-service-pod with all container images changed to confluentinc/cp-kafka
Command: ```bash kubectl debug auth-service-pod --copy-to=debug-image-api --set-image=*=confluentinc/cp-kafka ``` 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 b...
Scale the deployment "auth" with a minimum of 7 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment auth --min=7 --max=11 ``` 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 th...
Create a deployment named wordpress with the wordpress image
Command: ```bash kubectl create deployment wordpress --image=wordpress ``` 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|ya...
List all deployments in the "stable-2.0.0" version of the "extensions" API group and display the output in YAML format.
Command: ```bash kubectl get deployments.stable-2.0.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 yo...
Listen on port 3000 on localhost and IP address 10.19.21.23, and forward the traffic to port 8088 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 3000: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 th...
Create a role binding for app-operator, sysadmin, and security-auditors using the view cluster role
Command: ```bash kubectl create rolebinding view --clusterrole=view --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname]...
Remove all taints with the key 'app' from the node 'node-1'.
Command: ```bash kubectl taint nodes node-1 app- ``` 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: json|yaml|name|go-te...
Listen on port 6379 on localhost and IP 10.19.21.23, and forward the traffic to port 9090 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-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 cri...
Add a taint to node 'app-node-6' with the key 'environment' and no value
Command: ```bash kubectl taint nodes app-node-6 environment:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of...
Retrieve the previous terminated logs of the 'cyber-sleuth' container from the 'payment-gateway-pod' pod.
Command: ```bash kubectl logs -p -c cyber-sleuth 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": "--containe...
List the rc (replication controller) with the name "web", the service with the name "web-app-rc", and the pod with the name "auth-service-pod"
Command: ```bash kubectl get rc/web service/web-app-rc pods/auth-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Set the cluster field in a context to a specific cluster
Command: ```bash kubectl config set contexts.cluster-1-context.cluster cluster-gamma ``` 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 y...
Create an ingress called 'public-ingress' that directs requests to website.com/bar to the service 'svc1' running on port 3000, and use the TLS secret 'my-cert' to secure the connection.
Command: ```bash kubectl create ingress public-ingress --rule="website.com/bar=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": "", "usage...
Remove the taint with key 'app' and effect 'PreferNoSchedule' from the node 'db-node-7' if one exists.
Command: ```bash kubectl taint nodes db-node-7 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 of: ...
Create an ingress called 'app-loadbalancer-ingress' with a rule that directs requests from foo.com/module to svc1 on port 8082
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/module=svc1:8082,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": "...
List all deployments in the "alpha-2.0" version of the "experimental-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.alpha-2.0.experimental-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Roll back the daemonset 'test' to revision 1.
Command: ```bash kubectl rollout undo daemonset/test --to-revision=1 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the re...
Forward port 8000 on localhost and IP 10.19.21.23 to port 6379 in the analytics-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8000: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 crite...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/ui-config 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 definitions ...
Create a service for the hazelcast replication controller, which serves on port 8080 and connects to the containers on port 909100.
Command: ```bash kubectl expose rc hazelcast --port=8080 --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 specified po...
Scale the deployment named "foo" to 5 replicas if its current size is already 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=5 deployment/foo ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Create a LoadBalancer service named frontend-lb that maps traffic from port 3001 on the external IP address to port 3001 on the pods
Command: ```bash kubectl create service loadbalancer frontend-lb --tcp=3001:3001 ``` 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", "defaul...
Update the image of all containers in the daemonset 'development' to 'postgres:13.4'
Command: ```bash kubectl set image daemonset development *=postgres:13.4 ``` 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 an ingress called 'public-ingress' that directs requests to website.com/module to svc1:9090 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="website.com/module=svc1:9090,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": "", "us...
Forward port 5000 on all addresses to port 8000 in the frontend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5000: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...
Expose the replicated Wordpress service by creating a new service object, which will serve on port 5432 and connect to the containers on port 808800.
Command: ```bash kubectl expose rs wordpress --port=5432 --target-port=808800 ``` 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...
Scale the deployment named frontend-rs to 7 replicas if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=7 deployment/frontend-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...
Forward local port 8081 to port 3000 in the pod called "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 8081 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Forward traffic between local port 9090 and pod port 6379
Command: ```bash kubectl port-forward pod/mypod 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 will be selected automaticall...
Add a 'special' taint to the nodes labeled with 'zone=us-east-1', specifically the node named 'storage-node-13' with the effect of 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l zone=us-east-1 special=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...
Forward local port 5432 to port 8888 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5432: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...
Create a debug copy of the database-pod with additional containers and modified container images
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-web --image=debian --set-image=web=nginx:latest,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Update deployment 'proxy-service-deployment' by setting the environment variable 'DB_USER' to 'username'.
Command: ```bash kubectl set env deployment/proxy-service-deployment DB_USER=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 template...
Create a pod disruption budget named batch-processing-pdb that will select all pods with the role=worker label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=role=worker --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...
Get the output from running the 'postgres' command in the first container of the first pod from the 'load-balancer-deployment' deployment.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- 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, ...
Set the service account of the deployment named "api-server-deployment" to "dashboard".
Command: ```bash kubectl set serviceaccount deployment api-server-deployment dashboard ``` 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: `kubec...
List the environment variables set on a deployment named 'payment-processor-deployment'
Command: ```bash kubectl set env deployment/payment-processor-deployment --list ``` 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...
Execute the 'bash' command in the astro-container of the e-commerce-pod and get the output.
Command: ```bash kubectl exec e-commerce-pod -c astro-container -- bash ``` 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...
Add the annotation 'SLA' with the value '99.9% uptime' to the 'chat-app' pod.
Command: ```bash kubectl annotate pods chat-app 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 include arbitrary ...
Start a golang pod named nginx with the golang image, but override the pod spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "rc-1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Show the details of the replication controller named "web", the service named "cdn-service-rc", and the pod named "payment-gateway-pod"
Command: ```bash kubectl get rc/web service/cdn-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...
Add a taint with key 'app' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 app=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Import specific keys from a config map to a deployment's environment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/kube-system-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Create a pod disruption budget named elastic-search-pdb that will select all pods with the app=nginx label, and require at least 20% of the pods selected to be available at any point in time.
Command: ```bash kubectl create pdb elastic-search-pdb --selector=app=nginx --min-available=20% ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry-run=serv...
Set the service account of the deployment "notification-handler-deployment" to "kube-dns".
Command: ```bash kubectl set serviceaccount deployment notification-handler-deployment kube-dns ``` 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 Synta...
List deployments in JSON output format, in the desired version and API group.
Command: ```bash kubectl get deployments.custom-version.apps -o json ``` 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 wi...
Create an ingress called 'private-api-ingress' that directs requests to foo.com/input to the service 'svc1' running on port 3001
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/input=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": "", "us...
Start a hazelcast pod and expose port 8010
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8010 ``` 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:...
Update the pod 'chat-app' with the annotation 'env' and set its value to 'staging', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods chat-app 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...
Start a new pod named "nginx" using the "node" image, but override the pod specification using values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "hotfix-1.1.2", "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] -- [CO...
Create a job named 'deployment-rollout-job' running the 'confluentinc/cp-kafka' image
Command: ```bash kubectl create job deployment-rollout-job --image=confluentinc/cp-kafka -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful fla...
import the DEBUG_MODE key from the app-secrets config map into the api-server-deployment deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-secrets 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 definitions ...
Update the 'frontend-deployment' deployment by adding a new environment variable 'JWT_SECRET' with the value 'your-jwt-secret'
Command: ```bash kubectl set env deployment/frontend-deployment JWT_SECRET=your-jwt-secret ``` 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...
Set the container images for a deployment
Command: ```bash kubectl set image deployment/openjdk busybox=busybox openjdk=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), repl...
Create a new config map named global-config using options from a specific folder path
Command: ```bash kubectl create configmap global-config --from-file=path/to/options ``` 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 config map based on a file, the key will default to the basename...
Update the image version of the 'gateway-pod' pod to 'v4' for the container 'myimage'
Command: ```bash kubectl get pod gateway-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ k...
Execute the 'nginx' command inside the 'auth-service-pod' pod, using the first container by default, and retrieve the output.
Command: ```bash kubectl exec auth-service-pod -- 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.ku...
Create a service for a replication controller using a yaml file
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8443 --target-port=808100 ``` 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 ...
Set the CPU and memory limits for a deployment's container.
Command: ```bash kubectl set resources deployment amazonlinux -c=nginx --limits=cpu=100m,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst u...
Set the cluster field of the my-context context to on-prem-cluster.
Command: ```bash kubectl config set contexts.edge-context.cluster on-prem-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 ...
Set the cluster field in the 'my-context' context to 'galaxy-cluster'
Command: ```bash kubectl config set contexts.team-beta-context.cluster galaxy-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 ...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/namespace-config 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...
List the deployments in the "extensions" API group with the version "feature-branch-2.3.0" in JSON format
Command: ```bash kubectl get deployments.feature-branch-2.3.0.extensions -o json ``` 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...
Add a taint with key 'dedicated' on nodes having label 'myLabel'
Command: ```bash kubectl taint node -l myLabel dedicated=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Run the 'irb' command inside the email-service-pod pod and retrieve the output
Command: ```bash kubectl exec email-service-pod -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kub...
Create a single ingress called 'myapp-ingress' that directs requests to foo.com/module to svc1:8089 with a tls secret "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/module=svc1:8089,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Scale the deployment named app-v2-replicaset from its current size of 7 replicas to 5 replicas.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/app-v2-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-v...
Remove the taint with the key 'cpu-type' and effect 'NoSchedule' from the node named 'node-2'
Command: ```bash kubectl taint nodes node-2 cpu-type: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: json...
Forward local port 9090 to port 8000 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward pod/security-service-pod 9090 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...