prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the pod named 'auth' with the annotation 'description' and set its value to 'Web server for marketing site'
Command: ```bash kubectl annotate --overwrite pods auth description='Web server for marketing site' ``` 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 t...
Import environment variables from a secret for a deployment
Command: ```bash kubectl set env --from=secret/payment-gateway-secret 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 definitions in o...
Copy the file 'foo' from your local machine to the '/tmp/bar_dir' directory on the 'file-server-pod-14' pod in the 'metallb-system' namespace.
Command: ```bash kubectl cp :/tmp/foo metallb-system/file-server-pod-14:/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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/ui-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 on...
Create a new ClusterIP service named shipping-service-clusterip, mapping TCP port 8000 on the cluster IP to port 8084 on the service
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=8000:8084 ``` 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...
Import the SECRET_KEY key from the app-settings config map into the log-aggregator-deployment deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-settings 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 definit...
List the information of replication controllers, services, and pods named "web", "auth-service-rc", and "chat-app-pod".
Command: ```bash kubectl get rc/web service/auth-service-rc pods/chat-app-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 namespac...
Copy the directory /tmp/foo_dir from the pod named monitoring/load-balancer-pod-9 to the local machine at /tmp/bar_dir
Command: ```bash kubectl cp monitoring/load-balancer-pod-9:/tmp/foo_dir /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Listen on port 8080 on your local machine and forward traffic to port 8000 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 8080:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Update the 'monitoring-stack-deployment' deployment by setting the environment variable S3_BUCKET to the value my-s3-bucket
Command: ```bash kubectl set env deployment/monitoring-stack-deployment S3_BUCKET=my-s3-bucket ``` 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...
Get output from the lunar-launcher container in the monitoring-pod pod
Command: ```bash kubectl attach monitoring-pod -c lunar-launcher ``` 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...
Partially update a resource by applying a strategic merge patch from a file.
Command: ```bash kubectl patch -f 10-mynet.conf -p '{"spec":{"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]` Helpf...
Update the image of the first container in a pod using a JSON patch with positional arrays
Command: ```bash kubectl patch pod log-aggregator-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl pat...
Import the REDIS_HOST key from the config map named api-config and set it as an environment variable in the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/api-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 definition...
Update the pod named 'vpn' with the label 'release' and set the value to 'v1.0'
Command: ```bash kubectl label pods vpn release=v1.0 ``` 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 t...
Scale the replica set named 'bar' to have only 1 replica
Command: ```bash kubectl scale --replicas=1 rs/bar ``` 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 validated before...
Update the pod 'proxy-server' by adding the annotation 'app-version' with the value '2.5.1'.
Command: ```bash kubectl annotate pods proxy-server app-version=2.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 larger than labels and include arbitra...
View the resource utilization metrics of pods with the label version=v1.0.0
Command: ```bash kubectl top pod -l version=v1.0.0 ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAME | ...
Update the 'monitoring-stack-deployment' deployment by adding a new environment variable 'MONGO_URI' with the value 'mongodb://localhost:27017/mydb'
Command: ```bash kubectl set env deployment/monitoring-stack-deployment MONGO_URI=mongodb://localhost:27017/mydb ``` 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 ...
Forward traffic from port 5000 on your local machine to port 3000 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000: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 au...
Expose a replica set as a service, serving on port 8443 and targeting port 808200
Command: ```bash kubectl expose rs php --port=8443 --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 specified port. A ...
Forward the local port 6379 and the IP 10.19.21.23 to port 8000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 6379: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 criteri...
Roll back the deployment of the nginx application
Command: ```bash kubectl rollout undo deployment/nginx ``` 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 resource to get ...
Create a single ingress named 'external-ingress' with a rule that directs requests to site.com/bar to svc1:8010
Command: ```bash kubectl create ingress external-ingress --rule="site.com/bar=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Execute the 'nginx' command in the 'cyber-sleuth' container of the 'backend-pod' pod and get the output.
Command: ```bash kubectl exec backend-pod -c cyber-sleuth -- 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...
Create an ingress called 'myapp-ingress' that directs requests to website.com/bar to svc1:8082 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/bar=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": "", "usage"...
Create an ingress named 'api-v1-ingress' that directs requests from testing.com/module to svc1:9091 and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/module=svc1:9091,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 single ingress called 'external-ingress' with a rule that directs requests from foo.com/input to the service svc1 on port 8080
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/input=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": "", "usage...
Create a new config map named global-config with specified keys and file paths
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/data/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 creating a con...
Create a secret named "my-secret" using the environment variables defined in the "profiles.env" file.
Command: ```bash kubectl create secret generic my-secret --from-env-file=path/to/profiles.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 basename o...
Auto scale the replication controller "backend" based on CPU utilization, with the number of pods between 1 and 5 and target CPU utilization at 90%.
Command: ```bash kubectl autoscale rc backend --max=5 --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...
Create a new config map named app-config-dev in the current namespace using the files specified
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/configs/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 ...
Add a taint to a node to mark it as dedicated for a specific purpose.
Command: ```bash kubectl taint nodes testing-node-11 dedicated: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...
Retrieve the output of the 'pg_dump --version' command running inside the astro-container from the media-stream-pod.
Command: ```bash kubectl exec media-stream-pod -c astro-container -- pg_dump --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....
Forward traffic from port 8000 on all addresses to port 5432 inside the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Set the cluster field in the 'client-1-context' context to 'kube-cluster-1' in the kubeconfig file
Command: ```bash kubectl config set contexts.client-1-context.cluster kube-cluster-1 ``` 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...
Forward local port 8081 to port 8080 in the pod `cdn-service-pod`.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081: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 pod disruption budget named cron-jobs-pdb that selects all pods with the label release=1.0.0 and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=release=1.0.0 --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [-...
Set the resource request and limits for all containers in the 'python' deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 request...
Remove all taints with the key 'hardware' from the node 'monitoring-node-15'
Command: ```bash kubectl taint nodes monitoring-node-15 hardware- ``` 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: jso...
Edit the last-applied-configuration annotations of a deployment named "ubuntu" in YAML format.
Command: ```bash kubectl apply edit-last-applied deployment/ubuntu ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the edit...
Add a taint with key 'zone' on nodes having label role=database and value 'backup-node-14' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database zone=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": "O...
Create an ingress called 'website-ingress' that directs requests to testing.com/input to svc1:8010 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/input=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Attach to the 'nano-bot' container in the 'chat-app-pod' pod and switch to the raw terminal mode, allowing input from stdin to be sent to 'bash' in the pod and sending stdout/stderr from 'bash' back to the client.
Command: ```bash kubectl attach chat-app-pod -c nano-bot -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 omitted, ...
Expose the replication controller specified in "node-controller.yaml" as a service, serving on port 3001 and connecting to the containers on port 801000.
Command: ```bash kubectl expose -f node-controller.yaml --port=3001 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Add or update a taint on the node 'gpu-node-12' with the key 'dedicated', value 'special-user', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes gpu-node-12 dedicated=special-user: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 fo...
List deployments in YAML output format for the "custom-version" version of the "custom-deployments" API group
Command: ```bash kubectl get deployments.custom-version.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 nam...
Forward local traffic on port 5432 to the deployment's pod on port 3000
Command: ```bash kubectl port-forward deployment/mydeployment 5432 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 selecte...
Set the service account of the "web-app-deployment" deployment to "flux"
Command: ```bash kubectl set serviceaccount deployment web-app-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 set s...
Import the environment variables from the 'email-credentials-secret' secret into the 'database-deployment' deployment.
Command: ```bash kubectl set env --from=secret/email-credentials-secret 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 one or ...
Add a taint to the node 'web-node-8' with the key 'workload' and no value
Command: ```bash kubectl taint nodes web-node-8 workload: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...
Auto scale the deployment "email" with a minimum of 1 pod and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment email --min=1 --max=12 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses t...
Retrieve the previous terminated logs for the 'mycontainer' container in the 'mypod' pod.
Command: ```bash kubectl logs -p -c mycontainer 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": "-...
Forward local port 5432 to port 3000 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 5432: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 auto...
set resource requests and limits for all containers in the "runtime" deployment to cpu=500m and memory=2Gi respectively, with a limit of cpu=200m and memory=512Mi.
Command: ```bash kubectl set resources deployment runtime --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=2Gi ``` 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...
Create a service for the 'centos' deployment in the default namespace, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment centos --port=8888 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Update the label of pod 'foo' to set the role as backend
Command: ```bash kubectl label pods foo role=backend ``` 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 t...
Copy the contents of the service account folder from a remote pod to a local directory
Command: ```bash kubectl cp kube-proxy/file-server-pod-14:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "Co...
Create a copy of the 'frontend-pod' pod, adding a debug container with the image 'debian' and changing the container images to 'logging-app:debug' for the logger container and 'my-scheduler:1.0' for the scheduler container
Command: ```bash kubectl debug frontend-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,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 ide...
Import the 'REDIS_HOST' key from the 'env-vars' config map into the 'search-engine-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/env-vars 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 definitions ...
Create a new secret named docker-registry-secret, with keys for each file in the folder "path/to/properties".
Command: ```bash kubectl create secret generic docker-registry-secret --from-file=path/to/properties ``` 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...
Create a service for the php replication controller, serving on port 8080 and connecting to the containers on port 8888
Command: ```bash kubectl expose rc php --port=8080 --target-port=888800 ``` 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 ...
Import the API_KEY from the app-secrets config map and set it as an environment variable in the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-secrets deployment/analytics-platform-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 definit...
Create an ingress that directs requests to a specific service with TLS encryption.
Command: ```bash kubectl create ingress app-loadbalancer-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": ...
Use the "micro" editor to edit the configuration of the "order-service" service.
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/order-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables,...
Roll back the daemonset 'namespace-2' to revision 1
Command: ```bash kubectl rollout undo daemonset/namespace-2 --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...
Create a new config map named monitoring-config using the files file1.txt and file2.txt, and map them to the keys conf and data, respectively.
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 con...
Retrieve the snapshot logs from the container named email-server-deployment-1 in the deployment named proxy-server-pod
Command: ```bash kubectl logs deployment/email-server-deployment -c proxy-server-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: "...
Update the annotation 'compliance-level' of the 'backend' pod to 'PCI-DSS' in order to overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods backend compliance-level='PCI-DSS' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and...
Auto scale the deployment "security" with a minimum of 7 pods and a maximum of 14 pods. Use the default autoscaling policy.
Command: ```bash kubectl autoscale deployment security --min=7 --max=14 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a cluster role named "bar" with API Group specified
Command: ```bash kubectl create clusterrole bar --verb=list,create,connect --resource=replicasets.apps ``` 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...
Set the custom TLS server name "dev-cluster" for the kube-cluster-1 cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=dev-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...
Forward traffic from port 8088 of all addresses to port 9090 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8088:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Create a pod using the ethereum/client-go image, but customize the pod's specification using values parsed from a JSON file
Command: ```bash kubectl run nginx --image=ethereum/client-go --overrides='{ "apiVersion": "feature-branch-2.3.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-js...
Delete the pods and services named "cdn" in the current namespace
Command: ```bash kubectl delete pod,service cdn cdn ``` 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 re...
Switch to raw terminal mode and attach to the nano-bot container in the proxy-service-pod.
Command: ```bash kubectl attach proxy-service-pod -c nano-bot -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 omit...
Delete the pods and services with the names "security" and "cdn"
Command: ```bash kubectl delete pod,service security cdn ``` 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. So...
Add a taint with the key 'dedicated' on nodes having the label 'role=database', and set the value to 'worker-node-3:PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database dedicated=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Listen on port 9090 locally and forward it to port 8081 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 9090:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Add a taint with the key 'datacenter' on nodes having the label role=database.
Command: ```bash kubectl taint node -l role=database datacenter=dev-node-4: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": ...
Set the custom TLS server name to 'staging-cluster' for the 'cluster-gamma' cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --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] [--certifi...
Retrieve the logs from the previous terminated container 'cyber-sleuth' in the 'e-commerce-pod' pod.
Command: ```bash kubectl logs -p -c cyber-sleuth 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", "...
Forward local port 3000 to port 5432 in a pod selected by the mydeployment deployment
Command: ```bash kubectl port-forward deployment/mydeployment 3000 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 selecte...
Deny the Certificate Signing Request with the name 'csr-frontend-4'
Command: ```bash kubectl certificate deny csr-frontend-4 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kubect...
Create a pod disruption budget named statefulset-pdb that will select all pods with the app=rails label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=app=rails --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--d...
Copy the ~/.config/kube file from a remote pod to the /tmp/bar_dir directory on your local machine.
Command: ```bash kubectl cp monitoring/message-broker-pod-15:~/.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,...
Create an ingress called 'public-api-ingress' that directs requests to 'testing.com/module' to service 'svc1:8010' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/module=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Create a cluster role named "custom_role" with the following permissions for the specified resource names: - "exec" verb for all pods - "order-fulfillment" and "search-elasticsearch" resource names for pods
Command: ```bash kubectl create clusterrole custom_role --verb=exec --resource=pods --resource-name=order-fulfillment --resource-name=search-elasticsearch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=s...
Create a deployment called "registry" with the image "ruby" and 6 replicas.
Command: ```bash kubectl create deployment registry --image=ruby --replicas=6 ``` 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: ...
Return logs from container "proxy-service-pod-1" in deployment "frontend-deployment"
Command: ```bash kubectl logs deployment/frontend-deployment -c proxy-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "fla...
Import the specific keys from the "monitoring-config" ConfigMap into the environment variables of the "log-aggregator-deployment" deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/monitoring-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 ...
Run the command 'redis-server --version' in the time-machine container of the proxy-service-pod pod and print the output
Command: ```bash kubectl exec proxy-service-pod -c time-machine -- 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 na...
Remove the label named 'bar' from the 'payment' pod
Command: ```bash kubectl label pods payment component- ``` 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...
List the replication controller with the name 'web', the service with the name 'web-app-rc', and the pod with the name 'monitoring-pod'
Command: ```bash kubectl get rc/web service/web-app-rc pods/monitoring-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced ...
Listen on port 8080 on your local machine and forward the traffic to port 3000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-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 automa...
Get the output of the 'elasticsearch-plugin --list' command from the first container in the first pod of the 'gateway-service' service.
Command: ```bash kubectl exec svc/gateway-service -- elasticsearch-plugin --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Display the most recent 31 lines of logs from the mypod pod
Command: ```bash kubectl logs --tail=31 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": "-c", "def...
Retrieve the output of the `composer --version` command from the `mycontainer` container within the `chat-app-pod` pod.
Command: ```bash kubectl exec chat-app-pod -c mycontainer -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Begin streaming the logs of the code-explorer container in the pod named api-service-pod
Command: ```bash kubectl logs -f -c code-explorer api-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",...
Forward local port 5432 to the targetPort of the 'https' port named service 'web-service' in a pod selected by the service
Command: ```bash kubectl port-forward service/web-service 5432:https ``` 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 a...