prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the 'gateway-deployment' deployment by setting the environment variable QUEUE_NAME to 'task-queue'
Command: ```bash kubectl set env deployment/gateway-deployment QUEUE_NAME=task-queue ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates...
Apply a taint on nodes with the label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 hardware=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...
Create a service for the replication controller specified in the "node-controller.yaml" file, serving on port 5001 and connecting to the containers on port 801000.
Command: ```bash kubectl expose -f node-controller.yaml --port=5001 --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...
Set the context 'testing-context' to use the cluster 'galaxy-cluster'
Command: ```bash kubectl config set contexts.testing-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/global-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...
Create a service for the specified replication controller, with the specified port and target port.
Command: ```bash kubectl expose -f centos-controller.yaml --port=9000 --target-port=330600 ``` 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...
Create a pod disruption budget named cron-jobs-pdb that will select all pods with the region=us-east label and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=region=us-east --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 [...
Set the cluster field in the 'staging-context' context to 'testing-cluster'
Command: ```bash kubectl config set contexts.staging-context.cluster testing-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 y...
Create a new config map named log-config with the keys "conf" and "data" that are sourced from file1.txt and file2.txt respectively.
Command: ```bash kubectl create configmap log-config --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 conf...
Add a taint with key 'disktype' on nodes having label tier=frontend, and set the taint value to node-2:PreferNoSchedule.
Command: ```bash kubectl taint node -l tier=frontend disktype=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": "Outpu...
List deployments in YAML output format from the "v2.0.0" version of the "internal-apps" API group.
Command: ```bash kubectl get deployments.v2.0.0.internal-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Forward port 6379 on your local machine to the targetPort of the "https" service port in a pod selected by the "web-service" service.
Command: ```bash kubectl port-forward service/web-service 6379: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...
List deployments in JSON output format for the "dev-2.2.0" version of the "external-apps" API group.
Command: ```bash kubectl get deployments.dev-2.2.0.external-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 yo...
Create a deployment named "grafana" with the specified image and port configuration.
Command: ```bash kubectl create deployment grafana --image=docker.elastic.co/elasticsearch/elasticsearch --port=8000 ``` 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"...
Get output from running a command in a pod.
Command: ```bash kubectl exec svc/search-service -- java -jar /usr/share/jenkins/jenkins.war ``` 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...
Run the command 'npm --version' in the pod 'vpn-service-pod' and retrieve the output
Command: ```bash kubectl exec vpn-service-pod -c warp-drive -- 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. If omitte...
Create a service for a replicated hazelcast using replica set.
Command: ```bash kubectl expose rs hazelcast --port=9000 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Set the resource request and limits for all containers in the nginx deployment
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested,...
import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=my-example-key --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 d...
Import the 'secret_key' key from the 'log-config' config map into the deployment 'load-balancer-deployment'
Command: ```bash kubectl set env --keys=secret_key --from=configmap/log-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 a custom TLS server name to be used for validation for the "dev-cluster" cluster entry.
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=cloud-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 cluster role named "bar" with the API Group specified as "certificatesigningrequests.certificates.k8s.io" and the verbs allowed are "exec", "list", and "delete"
Command: ```bash kubectl create clusterrole bar --verb=exec,list,delete --resource=certificatesigningrequests.certificates.k8s.io ``` 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]` Help...
Forward traffic from port 9090 on all addresses to port 6379 in the frontend-pod, and listen on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Remove all taints with key 'environment' from node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 environment- ``` 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...
Create a new config map named app-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/profiles/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 con...
Access the stardust-shuttle container in the chat-app-pod and run the 'mysql' command
Command: ```bash kubectl exec chat-app-pod -c stardust-shuttle -- 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, us...
Create a cron job called "database-maintenance" with the image "python" and a schedule of running every minute
Command: ```bash kubectl create cronjob database-maintenance --image=python --schedule="*/1 * * * *" -- pip --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "sh...
Forward local port 8080 to port 8888 in the pod selected by the 'log-aggregator-deployment' deployment
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 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 wi...
Get a list of deployments in YAML format from the "v1.1.0" version of the "external-apps" API group
Command: ```bash kubectl get deployments.v1.1.0.external-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...
Import the 'SECRET_KEY' key from the 'namespace-config' ConfigMap and set it as an environment variable for the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/namespace-config 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 defi...
Forward port 8081 on all addresses to port 8000 in the pod named e-commerce-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8081: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 wi...
Create a new secret named app-config-secret by using the id_rsa file as the ssh-privatekey and the passphrase "topsecret".
Command: ```bash kubectl create secret generic app-config-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based ...
Update the annotation 'backup-strategy' for pod 'gateway' to have the value 'daily-backups', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods gateway backup-strategy='daily-backups' ``` 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...
Forward port 8080 on all addresses to port 5432 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Create a pod disruption budget named load-balancer-pdb that will ensure at least one pod with the env=production label is available at all times.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=env=production --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...
Create a pod disruption budget named messaging-pdb, which will select all pods with the version=v2 label and require at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=version=v2 --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-available=N [--dr...
Create an ingress called 'public-api-ingress' that directs requests to website.com/bar to svc1:7000 with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/bar=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": "", "u...
Create a cluster role binding for multiple users and groups, using a specific cluster role
Command: ```bash kubectl create clusterrolebinding custom_role --clusterrole=custom_role --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--...
Set the service account of the user-management-deployment deployment to kube-dns.
Command: ```bash kubectl set serviceaccount deployment user-management-deployment kube-dns ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `k...
Create a cluster role named "reader" with the ResourceName specified
Command: ```bash kubectl create clusterrole reader --verb=connect --resource=pods --resource-name=app-worker-2 --resource-name=cache-redis ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|non...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/db-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 definitions in on...
Create a copy of the 'vpn-service-pod' pod, adding a debug container and changing the container images to 'debian' for the debug container, 'nginx:latest' for the 'web' container, and 'my-custom-worker:1.2.3' for the 'worker' container.
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=web=nginx:latest,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by...
Set the certificate authority data field for the data-cluster cluster.
Command: ```bash kubectl config set clusters.data-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) ``` 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 ...
Create a new config map named app-settings using the specified files as the values
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Create a service for the replication controller specified in the "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8080 --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...
Copy the '/var/run/secrets/kubernetes.io/serviceaccount/' local file to the '/etc/kubernetes' directory inside the 'kube-system/cache-pod-5' pod in the 'kube-system' namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-system/cache-pod-5:/etc/kubernetes ``` 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": "C...
Run the command `php --version` inside the first container of the first pod of the deployment named "order-processing-deployment"
Command: ```bash kubectl exec deploy/order-processing-deployment -- php --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 o...
Create a service for the replicated Ubuntu containers in the replica set named 'ubuntu', which will serve on port 8089 and connect to the containers on port 801000.
Command: ```bash kubectl expose rs ubuntu --port=8089 --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 specified port....
Create a new ExternalName service named external-third-party-api-service with the external name dummy-website.io
Command: ```bash kubectl create service externalname external-third-party-api-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 refer...
Update the pod in "pod.json" with the annotation backup-strategy='daily backups'
Command: ```bash kubectl annotate -f pod.json backup-strategy='daily backups' ``` 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...
Create a pod named "hazelcast" using the Python image and expose port 5000 in the container.
Command: ```bash kubectl run hazelcast --image=python --port=5000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Auto scale the "payment" deployment with the number of pods between 1 and 11
Command: ```bash kubectl autoscale deployment payment --min=1 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Set the service account of the 'mydeployment' deployment to 'flux'
Command: ```bash kubectl set serviceaccount deployment mydeployment 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 service...
Import environment variables from a secret in the specified deployment.
Command: ```bash kubectl set env --from=secret/api-key-secret deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod te...
Start a mysql pod with the name nginx and the image mysql, but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=mysql --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMA...
Set the cluster field in the my-context context to on-prem-cluster
Command: ```bash kubectl config set contexts.user-b-context.cluster on-prem-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Import the DEBUG_MODE key from the global-config config map into the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/global-config 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 ...
import the database_url key from the app-secrets config map and set it as an environment variable in the mydeployment deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-secrets 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 ...
Set the cluster field in a context to a specific cluster
Command: ```bash kubectl config set contexts.on-prem-context.cluster kube-cluster-2 ``` 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 yo...
Add a taint to node 'node-2' with the key 'disktype' and no value
Command: ```bash kubectl taint nodes node-2 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|...
Create an ingress called 'private-api-ingress' that directs requests to site.com/example to the service 'svc1' on port 8000
Command: ```bash kubectl create ingress private-api-ingress --rule="site.com/example=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Execute the 'node' command in the 'code-explorer' container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c code-explorer -- node ``` 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...
Start a hazelcast pod with the image "hazelcast/hazelcast" and expose port 8181
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --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...]` Helpful flags:...
Remove a label named 'env' from the pod 'email'
Command: ```bash kubectl label pods email env- ``` 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 true, c...
Embed the certificate authority data for the web-cluster cluster entry by running the command "kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/web-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/web-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-c...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-settings 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 definit...
import the "debug_mode" key from the "db-config" config map and set it as an environment variable in the monitoring-stack-deployment deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/db-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 definiti...
Create a new config map named global-config from an environment file
Command: ```bash kubectl create configmap global-config --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 ...
Embed the certificate authority data for the staging-cluster cluster entry by running the command "kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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 confi...
Execute the 'kafka-server-start /etc/kafka/server.properties' command in the 'astro-container' container of the 'media-stream-pod' pod and retrieve the output.
Command: ```bash kubectl exec media-stream-pod -c astro-container -- kafka-server-start /etc/kafka/server.properties ``` 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":...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 5000 in the frontend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 8080: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 criter...
Delete the pods and services with the names "gateway" and "foo"
Command: ```bash kubectl delete pod,service gateway foo ``` 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 deployment named 'gitlab' using the 'confluentinc/cp-kafka' image and expose port 8888
Command: ```bash kubectl create deployment gitlab --image=confluentinc/cp-kafka --port=8888 ``` 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 fo...
Partially update the 'dev-node-4' node by setting the 'unschedulable' field to true using the provided YAML patch.
Command: ```bash kubectl patch node dev-node-4 -p $'spec:\n unschedulable: true' ``` 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 f...
Get output from running 'mysql' command from the first pod of the deployment user-management-deployment
Command: ```bash kubectl exec deploy/user-management-deployment -- 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, u...
Start a pod named "hazelcast" using the Hazelcast image, and configure the pod container to expose port 8089.
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8089 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags:...
Update the 'database' pod with the annotation 'owner' and the value 'alice-smith', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods database owner='alice-smith' ``` 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...
Create a service for a replication controller specified in "node-controller.yaml" that connects to containers on port 8000, serving on port 80.
Command: ```bash kubectl expose -f node-controller.yaml --port=6379 --target-port=300000 ``` 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...
Create an ingress with the name 'api-v1-ingress' that directs requests for 'site.com/example' to the service 'svc1:9091', and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v1-ingress --rule="site.com/example=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": "", "usag...
Create a new ExternalName service named 'external-geolocation-service' with the external name 'blog-test.blog'
Command: ```bash kubectl create service externalname external-geolocation-service --external-name blog-test.blog ``` 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 s...
Remove the taint with the key 'cpu-type' and effect 'NoSchedule' from the node 'node-1' if it exists.
Command: ```bash kubectl taint nodes node-1 cpu-type:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json...
Forward local traffic from port 8080 to the selected pod's port 8080 in the 'api-server-deployment' deployment, and forward local traffic from port 6000 to the selected pod's port 6000 in the 'api-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/api-server-deployment 8080 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 b...
Import the "redis_host" key from the "kube-system-config" ConfigMap into the environment variables of the "cache-cluster-deployment" deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/kube-system-config 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 de...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-prod 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 definiti...
Return the snapshot of the previous terminated ruby container logs from the frontend-pod pod
Command: ```bash kubectl logs -p -c ruby frontend-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": "-...
Update the label of the pod 'web' to have the key 'env' and the value 'staging'
Command: ```bash kubectl label pods web env=staging ``` 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 tr...
Create a pod named "hazelcast" using the Alpine image and expose port 7000.
Command: ```bash kubectl run hazelcast --image=alpine --port=7000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Import environment variables from a secret into a deployment named "payment-processor-deployment"
Command: ```bash kubectl set env --from=secret/docker-registry-secret deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Create a copy of the e-commerce-pod with all container images changed to "node".
Command: ```bash kubectl debug e-commerce-pod --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 res...
Create a service for a replication controller that serves on port 8443 and connects to the containers on port 543200.
Command: ```bash kubectl expose -f php-controller.yaml --port=8443 --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 sp...
Create a service for the 'hazelcast' deployment in the default namespace
Command: ```bash kubectl expose deployment hazelcast --port=8081 --target-port=808800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Create a single ingress called 'app-gateway-ingress' that directs requests from foo.com/example to the service svc1 on port 5000, and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/example=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Forward local port 9090 to port 6379 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Update the 'container-name' container in the node specified in "node.json" with a CPU limit of 200m
Command: ```bash kubectl patch -f node-config.toml -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 (...
Create a new configmap named global-config in the current namespace, with the keys "conf" and "data" sourced from the provided files.
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/properties/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...
Create a copy of the backend-pod with a debug container and different container images
Command: ```bash kubectl debug backend-pod -it --copy-to=dgb-img --image=debian --set-image=scheduler=my-scheduler:1.0,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by...
Create a new config map named 'namespace-config' in the current namespace using the specified keys and corresponding file paths
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/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. Whe...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-secrets 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 ...
Listen on port 6379 locally and forward to port 8000 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-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 criteria, a pod will be selected aut...
List the replication controller with the name "web", the service with the name "analytics-rc", and the pod with the name "media-stream-pod".
Command: ```bash kubectl get rc/web service/analytics-rc pods/media-stream-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 namespa...