prompt
stringlengths
13
282
response
stringlengths
128
3.11k
List deployments in the "v3.0.0" version of the "prod-apps" API group in JSON format.
Command: ```bash kubectl get deployments.v3.0.0.prod-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 will ...
Create a pod disruption budget named batch-processing-pdb that will select all pods with the release=1.0.0 label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=release=1.0.0 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-availab...
Add a taint on nodes with specific label
Command: ```bash kubectl taint node -l cluster=my-cluster environment=prod-node-5: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": "", "u...
Create a cluster role named "custom_role" with permissions to list pods and specific resource names.
Command: ```bash kubectl create clusterrole custom_role --verb=list --resource=pods --resource-name=cdn-proxy --resource-name=file-uploader ``` 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...
Add a taint with key 'workload' on nodes having label app=web-app and specify the taint as PreferNoSchedule on the web-node-8 node.
Command: ```bash kubectl taint node -l app=web-app workload=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": "Out...
Taint nodes with the label 'role=database' with a taint key of 'cpu-type' and a value of 'gpu-node-12' and set the effect to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l role=database 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": "", "usage": "...
Attach to the warp-drive container inside the backend-pod to get the output
Command: ```bash kubectl attach backend-pod -c warp-drive ``` 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 t...
Auto scale the deployment named "web" with a minimum and maximum number of pods set to 7 and 8 respectively
Command: ```bash kubectl autoscale deployment web --min=7 --max=8 ``` 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 ...
Taint nodes labeled with component=proxy with a key 'app' and value 'app-node-6' indicating that no new pods should be scheduled on this node unless they have a matching toleration.
Command: ```bash kubectl taint node -l component=proxy app=app-node-6: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...
Create a new secret named api-key-secret using the profiles.env file as the source for environment variables.
Command: ```bash kubectl create secret generic api-key-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 basen...
Forward local port 8000 to port 8081 of a selected pod of the mydeployment deployment.
Command: ```bash kubectl port-forward deployment/mydeployment 8000 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 selecte...
Create a deployment named 'loadbalancer' using the 'jenkins' image and expose port 5001.
Command: ```bash kubectl create deployment loadbalancer --image=jenkins --port=5001 ``` 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. On...
Import the specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/monitoring-config 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 definit...
Add a taint with the key 'disktype' and value 'app-node-6:PreferNoSchedule' on nodes having the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy disktype=app-node-6: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": ...
Import the 'EXTERNAL_API_URL' key from the config map named 'api-config' into the deployment named 'order-processing-deployment'.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/api-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 d...
import the "debug_mode" key from the config map "app-config-prod" to the deployment "search-engine-deployment"
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod 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 defin...
Delete the pods and services named "cdn" and "gateway"
Command: ```bash kubectl delete pod,service cdn gateway ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Som...
Create a new config map named app-settings with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creat...
Set a custom TLS server name for the cluster-beta cluster entry
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=edge-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] [--certificate...
Set the CPU limits of the Kafka container in the deployment to "200m" and memory limits to "128Mi"
Command: ```bash kubectl set resources deployment kafka -c=nginx --limits=cpu=200m,memory=128Mi ``` 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...
Get output from the time-machine container in the vpn-service-pod pod.
Command: ```bash kubectl attach vpn-service-pod -c time-machine ``` 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,...
Update the annotation 'SLA' of the pod 'cdn' with the value '99.9% uptime'
Command: ```bash kubectl annotate pods cdn SLA='99.9% uptime' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary strin...
Set resource requests and limits for all containers in a deployment named "go" in the cluster.
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=1,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 requested, bu...
Create a service for a replicated php application, serving on port 3001 and connecting to the containers on port 300100
Command: ```bash kubectl expose rc php --port=3001 --target-port=300100 ``` 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 ...
Delete pods and services with the names "vpn" and "web"
Command: ```bash kubectl delete pod,service vpn web ``` 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...
Create a job named "test-job" based on the configuration of the cron job "database-maintenance"
Command: ```bash kubectl create job test-job --from=cronjob/database-maintenance ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output forma...
Add a taint with key 'special' on nodes having label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp special=prod-node-5: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...
Get the output from running the 'postgres' command in the 'stardust-shuttle' container from the 'log-aggregator-pod' pod.
Command: ```bash kubectl exec log-aggregator-pod -c stardust-shuttle -- 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 om...
Set the resource limits and requests for all containers in the python deployment to cpu=200m and memory=512Mi for limits, and cpu=10 and memory=256Mi for requests.
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=10,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 request...
Create a debug copy of the proxy-service-pod named debug-image-app, replacing all container images with hazelcast/hazelcast.
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-app --set-image=*=hazelcast/hazelcast ``` 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...
Forward local port 5432 to port 8088 in the security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 5432 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create a new ClusterIP service named api-service-clusterip
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=8088: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", "d...
Begin streaming the logs of the 'quantum-quark' container in the 'email-service-pod' pod.
Command: ```bash kubectl logs -f -c quantum-quark email-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...
Create an ingress called 'api-v2-ingress' that directs requests from 'testing.com/input' to the service 'svc1' on port 5001
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/input=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": "", "usa...
Set the custom TLS server name 'data-cluster' for the 'star-cluster' cluster entry
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=data-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] [--certificate...
Create a deployment named worker with 2 replicas, using the python image
Command: ```bash kubectl create deployment worker --image=python --replicas=2 ``` 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: ...
Create a config map named "namespace-config" using the specified keys and corresponding file paths
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/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 creating ...
Create a job named "data-migration-job" using the "python" image. The job will run the command "python".
Command: ```bash kubectl create job data-migration-job --image=python -- python ``` 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...
create an ExternalName service named external-authentication-service with an external name of dummy-website.io
Command: ```bash kubectl create service externalname external-authentication-service --external-name dummy-website.io ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to refere...
Forward data between local ports 8000 and 6000 to/from ports 9090 and 6000 in a pod selected by the 'api-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 8000 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 will b...
Add a taint with the key 'special' on nodes that have the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp special=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"...
Execute the command 'gem --version' in the cosmic-container of the frontend-pod and display the output.
Command: ```bash kubectl exec frontend-pod -c cosmic-container -- 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 omi...
List deployments in YAML output format, specifying the version and API group.
Command: ```bash kubectl get deployments.v2.1.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...
Add a taint with key 'dedicated' on nodes having label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend dedicated=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"...
Create a ClusterIP service named "database-service-clusterip" that maps port 9092 on the service to port 27017 on the pods.
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=9092:27017 ``` 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": "-...
Partially update the configuration of a node by providing a strategic merge patch in JSON format
Command: ```bash kubectl patch node gpu-node-12 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 ...
Copy the contents of the `/var/run/secrets/kubernetes.io/serviceaccount/` directory from the remote pod named `security-scanner-pod-18` in the `kube-system` namespace to the `/tmp/bar` directory locally.
Command: ```bash kubectl cp kube-system/security-scanner-pod-18:/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...
Import the keys "config_file_path" from the "env-vars" ConfigMap into the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/env-vars deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Create a pod disruption budget named worker-pdb that selects pods with the region=us-east label and ensures that at least 9 of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=region=us-east --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...
Import the 'API_KEY' key from the 'log-config' ConfigMap into the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/log-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 mor...
Create a copy of 'mypod' changing all container images to 'node'. Name the new pod 'debug-image-web'.
Command: ```bash kubectl debug mypod --copy-to=debug-image-web --set-image=*=node ``` 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 resource is ...
import the environment variables from the gcp-service-account-secret secret and update the load-balancer-deployment deployment
Command: ```bash kubectl set env --from=secret/gcp-service-account-secret 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 definitions in ...
Create a cluster role named "admin_role" with permission to connect to services and specific resource names "prod-api-gateway" and "cdn-proxy"
Command: ```bash kubectl create clusterrole admin_role --verb=connect --resource=services --resource-name=prod-api-gateway --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|...
Attach to a specific pod and interact with the terminal
Command: ```bash kubectl attach payment-gateway-pod -c stardust-shuttle -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container nam...
Forward local port 5000 to port 5000 in the pod named "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...
Create a new ExternalName service named external-ldap-service and map it to the external domain practice-online.site.
Command: ```bash kubectl create service externalname external-ldap-service --external-name practice-online.site ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Listen on a random port locally and forward the traffic to the pod named "cdn-service-pod" on port 6379
Command: ```bash kubectl port-forward pod/cdn-service-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 automa...
Get the output from running the 'irb' command on the first pod of the deployment 'log-aggregator-deployment' using the first container
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Retrieve the output of the command 'sleep 3600' executed in the warp-drive container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c warp-drive -- 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 omitted,...
Attach to the auth-service-pod container named nebula-navigator to get the output from Nebula Navigator
Command: ```bash kubectl attach auth-service-pod -c nebula-navigator ``` 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 omi...
Delete the cluster named "galaxy-cluster" from the Kubernetes configuration.
Command: ```bash kubectl config delete-cluster galaxy-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Partially update a node using a strategic merge patch with a specified JSON patch.
Command: ```bash kubectl patch node edge-node-10 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags...
Partially update a node by applying a strategic merge patch in JSON format
Command: ```bash kubectl patch node worker-node-3 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flag...
Begin streaming the logs of the "warp-drive" container in the "monitoring-pod" pod.
Command: ```bash kubectl logs -f -c warp-drive monitoring-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", "sh...
import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-settings deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Embed the certificate authority data for the "cluster-beta" cluster entry by running the command "kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/cluster-alpha/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/cluster-alpha/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...
Create a secret named docker-registry-secret with keys for each file in the specified folder
Command: ```bash kubectl create secret generic docker-registry-secret --from-file=path/to/options ``` 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 basena...
Attach to vpn-service-pod and enter raw terminal mode
Command: ```bash kubectl attach vpn-service-pod -c cyber-sleuth -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 om...
Import specific keys from a config map into an environment variable of a deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/log-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Autoscale the deployment "proxy-server" with the number of pods ranging from 2 to 13.
Command: ```bash kubectl autoscale deployment proxy-server --min=2 --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...
Create a new config map named app-settings from the env file located at path/to/configs.env
Command: ```bash kubectl create configmap app-settings --from-env-file=path/to/configs.env ``` 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 b...
Create an ingress called 'public-service-ingress' that directs requests to 'testing.com/example' to 'svc1:5432' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/example=svc1:5432,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"...
Attach to the cyber-sleuth container in the gateway-pod and get the output
Command: ```bash kubectl attach gateway-pod -c cyber-sleuth ``` 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...
Check if you have permissions to list the job named "report-generation-job" in the "kube-node-lease" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-job -n kube-node-lease ``` 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 ...
Create a single ingress named 'api-ingress' that routes requests from foo.com/module to the service named 'svc1' on port 8181
Command: ```bash kubectl create ingress api-ingress --rule="foo.com/module=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": "", "usage": "...
Create a pod named 'hazelcast' using the 'mcr.microsoft.com/dotnet/core/runtime' image, and configure the pod to expose port 8181.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=8181 ``` 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......
Import specific keys from a config map and set them as environment variables on a deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/ui-config deployment/web-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 definitions in o...
Create a service named "frontend" for the pod "chat-app-pod" that serves on port 444.
Command: ```bash kubectl expose pod chat-app-pod --port=8089 --name=frontend ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified por...
Create a single ingress called 'private-ingress' that directs requests to website.com/input to svc1:5001, using the tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="website.com/input=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": "", "us...
Import the 'debug_mode' key from the 'kube-system-config' config map and set it as an environment variable for the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-config 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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-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 variable defi...
Forward local port 5432 to port 5432 in a pod selected by the monitoring-stack-deployment deployment
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 5432 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 ...
Forward traffic from port 9090 on all addresses to port 5432 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 9090:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Forward port 5000 on all addresses to port 8000 in the pod "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 8088 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 5000: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 ...
Forward port 5432 on all addresses to port 8888 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 5432:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Execute the 'ash' command in the first container of the 'backend-microservice-deployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/backend-microservice-deployment -- ash ``` 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...
Forward data between local port 9090 and the pod's port 5000 for the 'api-service-pod' pod
Command: ```bash kubectl port-forward pod/api-service-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 pod will be selected au...
Import specific keys from a config map into environment variables for a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-settings deployment/cache-cluster-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...
Remove a taint on a specific node
Command: ```bash kubectl taint nodes monitoring-node-15 datacenter:NoExecute- ``` 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....
Create a copy of the e-commerce pod with a debug container and updated container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-debugger --image=debian --set-image=mailer=mailer:latest,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource an...
Set the cpu limit of the nginx container in the nginx deployment to "2" and the memory limit to "64Mi"
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=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 requested, but may burst up to its...
Forward local port 8080 to port 8888 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-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 a...
Create a service for the alpine replication controller specified in the "alpine-controller.yaml" file, which serves on port 3001 and connects to the containers on port 500000.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=3001 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Set the cluster field in a specific context to a specific value
Command: ```bash kubectl config set contexts.user-a-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 ...
Execute the command 'npm --version' inside the first container of the backend-microservice-deployment deployment
Command: ```bash kubectl exec deploy/backend-microservice-deployment -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. ...
Set specific environment variables from a config map for a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/monitoring-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...
List all deployments in the "dev-2.2.0" version of the "backup-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.dev-2.2.0.backup-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 ...
Import the "redis_host" key from the "app-config-dev" config map into the "frontend-deployment" deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev deployment/frontend-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...