prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the custom TLS server name to "kube-cluster-2" for the "app-cluster" cluster entry
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=kube-cluster-2 ``` 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 local port 8080 to port 6379 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 8080: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 automa...
Execute the 'irb' command inside the nebula-navigator container of the payment-gateway-pod and get the output.
Command: ```bash kubectl exec payment-gateway-pod -c nebula-navigator -- 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 omitte...
Create a copy of the backend-pod with the name debug-image-app
Command: ```bash kubectl debug backend-pod --copy-to=debug-image-app --set-image=*=alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Forward local port 8088 to port 5000 inside the 'api-service-pod' pod
Command: ```bash kubectl port-forward pod/api-service-pod 8088: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 will be selected au...
Create a pod disruption budget named 'database-pdb' that will select all pods with the 'release=1.0.0' label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=release=1.0.0 --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=N [--...
Execute the 'dotnet --list-sdks' command in the 'warp-drive' container of the 'backend-pod' pod and retrieve the output.
Command: ```bash kubectl exec backend-pod -c warp-drive -- dotnet --list-sdks ``` 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...
Update the annotation 'custom-label' of pod 'database' with the value 'my-custom-value', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods database custom-label='my-custom-value' ``` 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 label...
Start a pod using the "node" image with a different command and custom arguments
Command: ```bash kubectl run nginx --image=node --command -- <cmd> <arg1> ... <argN> ``` 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 ...
Set the CPU and memory limits for a container in a deployment named "postgres" to "50m" and "256Mi" respectively
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=50m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up ...
Assign a taint to the node 'db-node-7' with the key 'dedicated' and no value
Command: ```bash kubectl taint nodes db-node-7 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 of: j...
Update the label of the 'gateway' pod to 'release=v1.0'
Command: ```bash kubectl label pods gateway 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": "...
Dump the cluster information for the specified namespaces to the /tmp/foo directory
Command: ```bash kubectl cluster-info dump --namespaces default,kube-system --output-directory=:/tmp/foo ``` What it does: Dump cluster information out suitable for debugging and diagnosing cluster problems. By default, dumps everything to stdout. You can optionally specify a directory with --output-directory. If yo...
Import the value for the 'secret_key' key from the 'env-vars' config map into the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/env-vars deployment/authentication-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 def...
Get the output of the 'geth version' command from the first container in the 'payment-gateway-pod' pod
Command: ```bash kubectl exec payment-gateway-pod -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Set the environment variable in the monitoring-stack-deployment deployment using the encryption-key-secret secret.
Command: ```bash kubectl set env --from=secret/encryption-key-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 on...
Create a new ClusterIP service named cache-service-clusterip
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=5000:5000 ``` 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", ...
Return the snapshot logs from the container order-processing-deployment-1 of the deployment named proxy-service-pod
Command: ```bash kubectl logs deployment/order-processing-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 fla...
Begin streaming the logs of the 'quantum-quark' container in the 'payment-gateway-pod' pod.
Command: ```bash kubectl logs -f -c quantum-quark 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": "--contain...
Update the pod 'web' by adding or updating the annotation 'contact-email' with the value 'support@example.com', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods web 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 label...
Create a service for a replicated alpine and expose it on port 9092
Command: ```bash kubectl expose rc alpine --port=9092 --target-port=543200 ``` 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....
Forward data between ports 8888 on your local machine and port 6379 in the api-service-pod pod.
Command: ```bash kubectl port-forward pod/api-service-pod 8888 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 au...
Forward traffic from port 8080 on all addresses to port 8000 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-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 po...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l team=devops hardware=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Forward port 3000 on localhost and IP address 10.19.21.23 to port 8000 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 3000: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 th...
Execute the 'postgres' command in the first pod of the deployment 'cache-cluster-deployment' and retrieve the output.
Command: ```bash kubectl exec deploy/cache-cluster-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, ...
Update the node 'gpu-node-12' by adding a taint with key 'disktype' and value 'ssd'
Command: ```bash kubectl taint nodes gpu-node-12 disktype=ssd: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 ...
Expose a replica set called "php" on port 5432, connecting to the containers on port 8000.
Command: ```bash kubectl expose rs php --port=5432 --target-port=8000 ``` 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 de...
Create a cluster role named "foo" with "list" verb and resources "configmaps" with resource_names "image-processor" and "cdn-proxy"
Command: ```bash kubectl create clusterrole foo --verb=list --resource=configmaps --resource-name=image-processor --resource-name=cdn-proxy ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|no...
Update the cluster field in the "my-context" context to "prod-cluster"
Command: ```bash kubectl config set contexts.edge-context.cluster prod-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 wan...
Create an ingress resource named 'web-ingress' that will direct requests for site.com/bar to the service 'svc1' running on port 8081
Command: ```bash kubectl create ingress web-ingress --rule="site.com/bar=svc1:8081,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": "Ou...
Create a service for the replication controller specified in "hazelcast-controller.yaml", with port 80 serving the containers on port 8000.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=9000 --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 ...
Import the 'database_url' key from the 'app-config' config map into the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Import the SMTP_SERVER key from the app-config-dev config map and set it as an environment variable for the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-dev 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...
Port forward from local port 9090 to port 8088 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 9090: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...
Execute a 'dotnet' command inside the first pod of the 'api-service' service.
Command: ```bash kubectl exec svc/api-service -- 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 omitted, use the kubectl.ku...
Create a new config map named "namespace-config" from the key=value pairs in the file located at "path/to/configurations"
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/configurations ``` 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 th...
Forward local port 9090 to port 5000 in a pod selected by the 'web-app-deployment' deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 9090 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 will be s...
create a service for a replicated ubuntu using replica set, connecting to containers on port 8000 and serving on port 80
Command: ```bash kubectl expose rs ubuntu --port=8089 --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 specified port....
Get the output from running the 'redis-server' command on the first pod of the 'load-balancer-deployment' deployment.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- redis-server ``` 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...
Retrieve the snapshot logs from the container named cache-cluster-deployment-1 of the deployment named analytics-pod
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c analytics-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: "fl...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Start streaming the logs of the 'warp-drive' container in the 'web-app-pod' pod.
Command: ```bash kubectl logs -f -c warp-drive web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short...
Create a new secret named monitoring-credentials-secret with keys for each file in the path/to/properties folder
Command: ```bash kubectl create secret generic monitoring-credentials-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 ...
Forward local port 6379 to port 8088 in the email-server deployment pod
Command: ```bash kubectl port-forward deployment/email-server-deployment 6379 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...
Edit the db-service using Atom as the editor
Command: ```bash KUBE_EDITOR="atom" kubectl edit svc/db-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or ...
Create a configmap named monitoring-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/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 cre...
Set the CPU limit for the nginx container in the ubuntu deployment to "500m" and the memory limit to "512Mi"
Command: ```bash kubectl set resources deployment ubuntu -c=nginx --limits=cpu=500m,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up t...
Import the 'api_key' key from the 'db-config' config map into the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=api_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 more...
Create a new secret named git-credentials-secret and add keys for each file in the folder path/to/profiles.
Command: ```bash kubectl create secret generic git-credentials-secret --from-file=path/to/profiles ``` 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 basen...
List the deployments in YAML output format, specifically in the "v2.1.0" version of the "web-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.web-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will o...
Scale the deployment named prod-app-rs to 1 replica if its current size is 3
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/prod-app-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...
Update the annotation of the pod named 'analytics' with the key 'SLA' and the value '99.9% uptime', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods analytics 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 inclu...
Add a label 'unhealthy' with the value 'true' to the pod 'media-stream'
Command: ```bash kubectl label pods media-stream unhealthy=true ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "us...
Update the deployment 'proxy-service-deployment' by adding a new environment variable with the key 'DB_PASSWORD' and the value 'secretpassword'.
Command: ```bash kubectl set env deployment/proxy-service-deployment DB_PASSWORD=secretpassword ``` 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 po...
Set the CPU limits for the 'ruby' deployment's 'nginx' container to 10 and the memory limits to 2Gi
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=10,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 requested, but may burst up to its ...
Attach to a specific container in a pod to get the output
Command: ```bash kubectl attach frontend-pod -c nano-bot ``` 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 th...
Create a single ingress named 'api-v2-ingress' that directs requests to website.com/bar to the service 'svc1' on port 8443
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/bar=svc1:8443,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...
Embed the certificate authority data for the "cloud-cluster" cluster entry by running the command `kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt`
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/data-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 se...
View the supported API resources for the specified APIGroup.
Command: ```bash kubectl api-resources --api-group=coordination.k8s.io ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Set the environment variable 'DB_USER' to 'username' in the 'payment-processor-deployment' deployment
Command: ```bash kubectl set env deployment/payment-processor-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 temp...
Add a taint with key 'app' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe app=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Set the resource limits and requests for all containers in the 'hazelcast' deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=64Mi ``` 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...
Add a taint with key 'environment' on nodes having the label myLabel
Command: ```bash kubectl taint node -l myLabel environment=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 f...
Auto scale the "vpn" deployment with a minimum of 7 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment vpn --min=7 --max=13 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Create a new config map named env-vars by reading files from the path/to/profiles folder.
Command: ```bash kubectl create configmap env-vars --from-file=path/to/profiles ``` 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 of ...
Start forwarding traffic from port 9090 on all addresses to port 5000 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 9090: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 po...
Forward local port 8088 to port 8888 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 8088: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 autom...
Import the secret_key key from the api-config config map into the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/api-config 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 definition...
Set the service account for the deployment "email-server-deployment" to "prometheus".
Command: ```bash kubectl set serviceaccount deployment email-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: `ku...
Approve the Certificate Signing Request (CSR) with the name 'csr-prometheus-8'.
Command: ```bash kubectl certificate approve csr-prometheus-8 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the a...
Import the secret_key key from the log-config ConfigMap and set it as an environment variable in the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/log-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Roll back the daemonset 'test' to revision 3.
Command: ```bash kubectl rollout undo daemonset/test --to-revision=3 ``` 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...
Create a new NodePort service named 'database-nodeport' that will route traffic from port 8010 on all nodes to port 8083 on the pods.
Command: ```bash kubectl create service nodeport database-nodeport --tcp=8010:8083 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Roll back a daemonset to a specific revision
Command: ```bash kubectl rollout undo daemonset/development --to-revision=3 ``` 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...
Forward the local port 3000 to the target port of the "https" service port in a selected pod for the "analytics-service" service.
Command: ```bash kubectl port-forward service/analytics-service 3000: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 sele...
create a job called deployment-rollout-job using the mongo image and run the command "mongo" as the job's main process
Command: ```bash kubectl create job deployment-rollout-job --image=mongo -- mongo ``` 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 form...
Listen on local ports 8080 and 6000, and forward data to/from ports 8888 and 6000 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-pod 8080 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 auto...
Forward local traffic on port 5000 to port 5000 on the pod 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 5000 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 will be selected autom...
edit the 'api-service' service
Command: ```bash kubectl edit svc/api-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to 'vi' ...
Forward traffic from all addresses on port 9090 to port 8000 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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...
Create a new NodePort service named gateway-nodeport
Command: ```bash kubectl create service nodeport gateway-nodeport --tcp=9091:3001 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Create a pod disruption budget named 'monitoring-pdb' that will select all pods with the 'env=production' label and require a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=env=production --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 mongo deployment
Command: ```bash kubectl set resources deployment mongo --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource reques...
Create an ingress named 'api-gateway-ingress' with a rule that directs requests to the service 'svc1:8084' for the host 'foo.com/example', and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/example=svc1:8084,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": "", "...
Partially update a node using a strategic merge patch
Command: ```bash kubectl patch node storage-node-13 -p '{"spec":{"someField":"newValue"}' ``` 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]` ...
Set the resource request and limits for all containers in the alpine deployment
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource reque...
Retrieve the password for the "galaxy-cluster" user.
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "galaxy-cluster")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpf...
Create a new config map named monitoring-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When c...
Copy the local file /tmp/foo to the /etc/kubernetes directory in the load-balancer-pod-9 pod, specifically in the backend-container container
Command: ```bash kubectl cp :/tmp/foo load-balancer-pod-9:/etc/kubernetes -c backend-container ``` 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 om...
Create a cluster role named "reader" with the verbs "create" and the resources "configmaps" and the resource names "file-processing" and "auth-service".
Command: ```bash kubectl create clusterrole reader --verb=create --resource=configmaps --resource-name=file-processing --resource-name=auth-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|c...
Execute the 'mysql' command in the first container of the first pod of the 'monitoring-service' service.
Command: ```bash kubectl exec svc/monitoring-service -- mysql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Create a job named 'scaling-job' using the 'redis' image and run the command 'redis-cli'
Command: ```bash kubectl create job scaling-job --image=redis -- redis-cli ``` 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...
Forward port 3000 on all addresses to port 5432 in the e-commerce-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 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 wi...
Connect to the chat-app-pod pod and execute the 'redis-cli' command.
Command: ```bash kubectl exec chat-app-pod -- redis-cli ``` 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...
Output the modified proxy-service-deployment deployment in YAML format after setting the environment variable DB_PASSWORD to "secretpassword"
Command: ```bash kubectl set env deployment/proxy-service-deployment DB_PASSWORD=secretpassword -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or...
Forward port 8080 on all addresses to port 5432 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8080: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 wil...
Edit the YAML configuration of the 'database-deployment' deployment and save the modified configuration in its annotation.
Command: ```bash kubectl edit deployment/database-deployment -o yaml --save-config ``` 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 environ...
Begin streaming the logs of the `cyber-sleuth` container in the `vpn-service-pod` pod.
Command: ```bash kubectl logs -f -c cyber-sleuth vpn-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", ...
Add a taint with key 'dedicated' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database 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": "Outp...