prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set resource requests and limits for all containers in the Elasticsearch deployment.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource r...
Create a role named "default_role" with the ability to list pods and specify two specific resource names: "dev-database" and "mail-server"
Command: ```bash kubectl create role default_role --verb=list --resource=pods --resource-name=dev-database --resource-name=mail-server ``` 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|...
Retrieve the logs from the container proxy-service-deployment-1 of the log-aggregator-pod deployment.
Command: ```bash kubectl logs deployment/proxy-service-deployment -c log-aggregator-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags...
Forward traffic from local ports 8088 and 6000 to the corresponding ports 8088 and 6000 in the backend pod
Command: ```bash kubectl port-forward pod/backend-pod 8088 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a new config map named ui-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a con...
Import environment variables from a config map with a specific prefix for a deployment
Command: ```bash kubectl set env --from=configmap/kube-system-config --prefix=MYSQL_ 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...
Execute the command 'gem --version' in the 'nebula-navigator' container of the 'auth-service-pod' pod and display the output
Command: ```bash kubectl exec auth-service-pod -c nebula-navigator -- 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...
Auto scale the "media-stream" deployment with a minimum of 7 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment media-stream --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...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/monitoring-config deployment/search-engine-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 an ingress called 'app-ingress' that directs requests from testing.com/example to the service `svc1` running on port 8181
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/example=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a new secret named encryption-key-secret with keys for each file in folder bar
Command: ```bash kubectl create secret generic encryption-key-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 basenam...
Autoscale the replication controller "proxy" to have a minimum of 1 pod and a maximum of 2 pods, with a target CPU utilization of 20%
Command: ```bash kubectl autoscale rc proxy --max=2 --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...
Update the pod 'foo' by setting the annotation 'scaling-policy' to 'auto-horizontal-scaling', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods foo scaling-policy='auto-horizontal-scaling' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than ...
Create an ingress called 'app2-ingress' that directs requests from website.com/input to svc1:8088, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/input=svc1:8088,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 pod named "hazelcast" using the "mongo" image and expose port 7000 from the container
Command: ```bash kubectl run hazelcast --image=mongo --port=7000 ``` 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": "--fi...
Forward local port 5000 to port 8888 in the pod
Command: ```bash kubectl port-forward pod/web-app-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 pod will be selected automa...
Set the cluster field in the prod-context context to cluster-gamma.
Command: ```bash kubectl config set contexts.prod-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 you wa...
List the replication controller named "web", the service named "proxy-service-rc", and the pods named "proxy-service-pod".
Command: ```bash kubectl get rc/web service/proxy-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 na...
Create a copy of the frontend-pod named debug-image-1, replacing the existing time-machine container, and launch an interactive shell in the debug-image-1 container.
Command: ```bash kubectl debug frontend-pod -it --copy-to=debug-image-1 --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 defau...
Begin streaming the logs of the specified container in the specified pod
Command: ```bash kubectl logs -f -c stardust-shuttle e-commerce-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...
Create a cluster role named "default_role" that allows the user to perform "patch", "proxy", and "delete" operations on services
Command: ```bash kubectl create clusterrole default_role --verb=patch,proxy,delete --resource=services ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--outpu...
Embed the certificate authority data for the "cluster-alpha" cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/my-k8s-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Set the custom TLS server name "staging-cluster" to use for validation for the "cluster-beta" cluster entry in the kubectl configuration.
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=staging-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Create a new config map called 'global-config' with the specified keys instead of using file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/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 c...
Listen on a random local port and forward the traffic to port 6379 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod :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 aut...
Create a new secret named payment-gateway-secret with the keys and their values
Command: ```bash kubectl create secret generic payment-gateway-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, ...
Create a single ingress called 'public-service-ingress' that directs requests to site.com/example to svc1:7000 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="site.com/example=svc1:7000,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": "...
Create an ingress named "ingress1" with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:8081" \ --rule="example.com/admin*=svc2:http" ``` 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": "--outp...
Open a local port 3000 and forward incoming traffic to port 8081 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward pod/cdn-service-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 will be selected au...
import specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-config-prod 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...
Forward traffic from local port 8081 to port 8088 in pod 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-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 selected au...
Create a new ClusterIP service named 'payment-service-clusterip' with the rule that maps TCP port 6379 on the service's IP address to port 8081 on the pods
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=6379:8081 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Create an ingress called 'app2-ingress' that directs requests to 'website.com/module' to 'svc1:5001' and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/module=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a job named "log-collection" with the image "ethereum/client-go" and the command "geth attach"
Command: ```bash kubectl create job log-collection --image=ethereum/client-go -- geth attach ``` 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": "...
Create a copy of the 'gateway-pod' pod and add a debug container to it
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-memcached --image=debian --set-image=worker=my-custom-worker:1.2.3,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 obje...
Create a new config map named app-config-prod with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/preferences/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 creat...
Add an annotation "contact-email" with the value "support@example.com" to the pod specified in the "params.json" file.
Command: ```bash kubectl annotate -f params.json 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 labels and in...
Listen on port 8088 locally and forward data to/from port 8080 in the analytics-pod pod
Command: ```bash kubectl port-forward pod/analytics-pod 8088 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...
Autoscale a deployment named "payment" to have a minimum of 5 pods and a maximum of 10 pods
Command: ```bash kubectl autoscale deployment payment --min=5 --max=10 ``` 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 a config map named monitoring-config with specified keys from files
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/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 ...
Create an ingress called 'public-service-ingress' with the following rule: "foo.com/example" should be directed to svc1:7000 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/example=svc1:7000,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": ""...
Import the 'redis_host' key from the 'namespace-config' configmap into the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --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...
Forward traffic from port 6379 on localhost and IP '10.19.21.23' to port 5432 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 6379: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 p...
Get the output from running the command 'docker run ubuntu echo "Hello, World"' in the pod vpn-service-pod, specifically in the container named nebula-navigator.
Command: ```bash kubectl exec vpn-service-pod -c nebula-navigator -- 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": "", "usag...
Create a service for the ruby deployment, which serves on port 9000 and connects to the containers on port 8083
Command: ```bash kubectl expose deployment ruby --port=9000 --target-port=808300 ``` 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...
Remove all the taints with the key 'zone' from the node 'app-node-6'
Command: ```bash kubectl taint nodes app-node-6 zone- ``` 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|...
set the resource requests and limits for the elasticsearch deployment
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=2,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 req...
Attach to the proxy-server-pod and get output from it
Command: ```bash kubectl attach proxy-server-pod ``` 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, use the kubect...
List the deployments in the "v3.0.0" version of the "internal-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.v3.0.0.internal-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 w...
Create a new ClusterIP service named my-cs that maps port 8000 on the service to port 8000 on the pods.
Command: ```bash kubectl create service clusterip my-cs --tcp=8000:8000 ``` 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", "default": "", "us...
Forward local port 8080 and IP address 10.19.21.23 to port 8088 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 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 ...
Create a single ingress called 'internal-ingress' that directs requests to website.com/module to svc1 on port 8000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="website.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": "", "...
Forward local port 8080 to the pod port 3000 and keep it running.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8080 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...
Access the container named "stardust-shuttle" inside the pod "cdn-service-pod" and run the "psql" command.
Command: ```bash kubectl exec cdn-service-pod -c stardust-shuttle -- psql ``` 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, ...
Start an nginx pod by running the command "kubectl run nginx --image=nginx" but override the spec with a partial set of values parsed from JSON using the "--overrides" flag.
Command: ```bash kubectl run nginx --image=nginx --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] -- [COMMA...
Inspect the last-applied-configuration annotations for a specific deployment in YAML format.
Command: ```bash kubectl apply view-last-applied deployment/centos ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-applied...
Expose a replica set named "ruby" as a service
Command: ```bash kubectl expose rs ruby --port=8084 --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. A...
Start a node pod with the image "hazelcast" and have the container within the pod expose port 6379.
Command: ```bash kubectl run hazelcast --image=node --port=6379 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fil...
import specific keys from a config map for a deployment named "proxy-service-deployment" and update the environment variables by setting the value of the key "SMTP_SERVER" to the corresponding value from the config map.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-secrets 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 definiti...
Create an ingress with multiple hosts and the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:8080" \ --rule="module.com/admin*=svc2:http" ``` 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": "--outpu...
Auto scale the "chat-app" replication controller with a minimum of 1 and a maximum of 7 pods, setting the target CPU utilization at 81%
Command: ```bash kubectl autoscale rc chat-app --max=7 --cpu-percent=81 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a deployment named drupal with the ubuntu image and expose port 8443
Command: ```bash kubectl create deployment drupal --image=ubuntu --port=8443 ``` 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...
Create a cron job with the provided command to install aws-cli and run it every minute
Command: ```bash kubectl create cronjob email-notifications --image=amazonlinux --schedule="*/1 * * * *" -- yum install -y aws-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": "-...
Auto scale the replication controller "backend" in order to maintain a target CPU utilization of 90%
Command: ```bash kubectl autoscale rc backend --max=2 --cpu-percent=90 ``` 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...
Set the custom TLS server name "my-k8s-cluster" to use for validation for the "web-cluster" cluster entry.
Command: ```bash kubectl config set-cluster web-cluster --tls-server-name=my-k8s-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...
Execute the command "docker run -d ubuntu sleep 3600" in the container "cyber-sleuth" inside the pod "web-app-pod" and get the output.
Command: ```bash kubectl exec web-app-pod -c cyber-sleuth -- docker run -d ubuntu 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...
List deployments in JSON format for a specific version of the API group.
Command: ```bash kubectl get deployments.v1.1.1.mobile-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 wil...
Start a Ubuntu pod with customized specifications parsed from JSON
Command: ```bash kubectl run nginx --image=ubuntu --overrides='{ "apiVersion": "v1.1.1", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAN...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-dev 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 ...
Add a taint with key 'dedicated' on nodes having the label region=eu-west-2 with the value 'backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l region=eu-west-2 dedicated=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...
Add a taint with the key 'datacenter' and value 'web-node-8:PreferNoSchedule' on nodes that have the label 'role=database'
Command: ```bash kubectl taint node -l role=database datacenter=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": "", "usage": ...
Create a 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/preferences/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 creati...
Execute the command 'nginx -g "daemon off;"' in the first container of the 'user-management-deployment' deployment and get the output.
Command: ```bash kubectl exec deploy/user-management-deployment -- 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 na...
Import the "database_url" key from the "ui-config" ConfigMap to the deployment named "mydeployment".
Command: ```bash kubectl set env --keys=database_url --from=configmap/ui-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or...
Set the cluster field of a context to a specific cluster
Command: ```bash kubectl config set contexts.client-1-context.cluster web-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 ...
Create a new secret named 'email-credentials-secret' from an env file located at 'path/to/configurations.env'
Command: ```bash kubectl create secret generic email-credentials-secret --from-env-file=path/to/configurations.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 defa...
Forward traffic from port 8888 on all addresses to port 5432 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Forward local port 5000 to the pod's port 8081 and listen on port 5000.
Command: ```bash kubectl port-forward pod/web-app-pod 5000 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 selected automa...
Set the service account for the deployment 'api-server-deployment' to 'prometheus'.
Command: ```bash kubectl set serviceaccount deployment api-server-deployment prometheus ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kube...
Update the image of all containers in the daemonset "namespace-" to "postgres:13.4"
Command: ```bash kubectl set image daemonset namespace-3 *=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 a role named "view" with the verb "create" and resources "pods", with specific resource names "identity-provider" and "payment-processor"
Command: ```bash kubectl create role view --verb=create --resource=pods --resource-name=identity-provider --resource-name=payment-processor ``` 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=se...
Update the 'frontend-deployment' by adding a new environment variable SMTP_USERNAME with the value of 'your-username'
Command: ```bash kubectl set env deployment/frontend-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 te...
Start a nginx pod with specific overrides parsed from a JSON file in the stable-2.0.0 API version. Specify the image as nginx.
Command: ```bash kubectl run nginx --image=nginx --overrides='{ "apiVersion": "stable-2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [C...
Check if you have permission to list the job named "content-import-job" in the "default" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/content-import-job -n default ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL...
Switch to raw terminal mode and attach to the frontend-pod in the nebula-navigator container, allowing for interactive communication with the pod.
Command: ```bash kubectl attach frontend-pod -c nebula-navigator -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 o...
Create an ingress named 'api-v2-ingress' that routes requests to website.com/module to the service named 'svc1' on port 9090
Command: ```bash kubectl create ingress api-v2-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...
Create a new secret named gcp-service-account-secret from an environment file
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-env-file=path/to/preferences.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 defau...
Create a new config map named 'app-config-dev' with two key-value pairs, key1=config1 and key2=config2.
Command: ```bash kubectl create configmap app-config-dev --from-literal=settings=config1 --from-literal=key2=config2 ``` 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...
List all allowed actions in the "staging" namespace
Command: ```bash kubectl auth can-i --list --namespace=staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that starts with "...
Run the 'dotnet' command in the cosmic-container of the proxy-service-pod and get the output
Command: ```bash kubectl exec proxy-service-pod -c cosmic-container -- dotnet ``` 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 omitt...
Import specific keys from a configmap into a deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/global-config deployment/database-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 ...
Drain "node-2" by evicting all pods, including those not managed by a replication controller, replica set, job, daemon set, or stateful set.
Command: ```bash kubectl drain node-2 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, it wi...
Get the output from running the 'sleep 3600' command in the code-explorer container of the email-service-pod.
Command: ```bash kubectl exec email-service-pod -c code-explorer -- 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...
Get the output from running the 'nginx' command in the payment-gateway-pod pod.
Command: ```bash kubectl exec payment-gateway-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...
Create a cron job named "weekly-summary" using the "php" image, scheduled to run every minute, and execute the command "php --version".
Command: ```bash kubectl create cronjob weekly-summary --image=php --schedule="*/1 * * * *" -- php --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l instance=app-instance-1 cpu-type=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": "", ...
Copy the file '/tmp/foo' from the '/tmp' directory inside the 'monitoring-agent-pod-6' pod in the 'ingress-nginx' namespace to the '/tmp/bar_dir' directory on the local system.
Command: ```bash kubectl cp ingress-nginx/monitoring-agent-pod-6:/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
List deployments in the specified API group and version in JSON output format
Command: ```bash kubectl get deployments.v2.1.0.custom-deployments -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 ...
Copy the file ~/.config/kube from the remote pod kube-node-lease/admin-dashboard-pod-16 to the local directory /tmp/bar.
Command: ```bash kubectl cp kube-node-lease/admin-dashboard-pod-16:~/.config/kube :/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 omitt...
import the "MAX_CONNECTIONS" key from the "app-config" ConfigMap to the "database-deployment" Deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config deployment/database-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...