prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a taint with the key 'disktype' on nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack disktype=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": "Ou...
Return snapshot logs from the 'cdn-service-pod' pod, only for the 'cdn-service-container' container.
Command: ```bash kubectl logs cdn-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", "short": "-c", "def...
Update the backup strategy annotation of the pod specified in the "params.json" file to 'daily backups'
Command: ```bash kubectl annotate -f params.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 incl...
Create a new ClusterIP service named payment-service-clusterip that maps port 8088 on the service to port 9091 on the target
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=8088:9091 ``` 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"...
Copy the directory "/tmp/foo_dir" from the remote pod "kube-dns/message-broker-pod-15" to the directory "/tmp/bar" on your local machine.
Command: ```bash kubectl cp kube-dns/message-broker-pod-15:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
create a deployment named "grafana" with the image "amazonlinux" and execute the command "yum install -y aws-cli"
Command: ```bash kubectl create deployment grafana --image=amazonlinux -- yum install -y aws-cli ``` 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": "Outp...
Execute the 'node' command in the 'rocket-ranger' container within the 'mypod' pod and retrieve the output.
Command: ```bash kubectl exec mypod -c rocket-ranger -- 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 kubec...
create a new config map with key-value pairs from a file
Command: ```bash kubectl create configmap ui-config --from-file=path/to/properties ``` 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 ...
Expose a replication controller as a service, serving on port 8088 and forwarding to containers on port 808200
Command: ```bash kubectl expose rc php --port=8088 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Execute the 'node' command in the 'lunar-launcher' container running in the 'proxy-service-pod' pod
Command: ```bash kubectl exec proxy-service-pod -c lunar-launcher -- 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, ...
Return the snapshot of the previous terminated ruby container logs from the payment-gateway-pod pod
Command: ```bash kubectl logs -p -c ruby 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": "--container", "sho...
Import specific keys from a config map into a deployment's environment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-secrets 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 defi...
Start a pod named 'hazelcast' using the 'docker.elastic.co/elasticsearch/elasticsearch' image and have the container expose port 3000
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=3000 ``` 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] ...
Create a copy of the 'vpn-service-pod' by adding a debug container and changing container images
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=logger=logging-app:debug,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Remove the taint with key 'environment' and effect 'NoSchedule' from the node 'storage-node-13'
Command: ```bash kubectl taint nodes storage-node-13 environment: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. ...
Import environment variables from a secret into a deployment
Command: ```bash kubectl set env --from=secret/cert-manager-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 one or ...
Create a debug copy of 'mypod' and change the images of all containers to 'mongo'
Command: ```bash kubectl debug mypod --copy-to=debug-image-1 --set-image=*=mongo ``` 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 s...
Add the taint with key 'datacenter' and no value to the node 'dev-node-4'.
Command: ```bash kubectl taint nodes dev-node-4 datacenter: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:...
Create an ingress called 'ingtls' with TLS enabled using the default ingress certificate
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="testing.com/=svc:https,tls" \ --rule="foo.com/path/subpath*=othersvc:3001" ``` 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": "-...
Auto scale the 'proxy-server' replication controller with the number of pods between 1 and 4, and a target CPU utilization of 81%
Command: ```bash kubectl autoscale rc proxy-server --max=4 --cpu-percent=81 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that...
Set a custom TLS server name for the "data-cluster" cluster entry
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=kube-cluster-1 ``` 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] [--certifica...
Import the REDIS_HOST key from the kube-system-config config map into the email-server-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/kube-system-config deployment/email-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 def...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev deployment/email-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 definit...
View the details of the revision 7 of the 'test' daemonset
Command: ```bash kubectl rollout history daemonset/test --revision=7 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to fi...
Create a new ExternalName service named my-ns with the external name sandbox-site.co
Command: ```bash kubectl create service externalname my-ns --external-name sandbox-site.co ``` 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 services that exist off...
Copy the local file "/tmp/foo" to the remote pod "web-app-pod-1" in the "prometheus" namespace, with the destination file path set to "/tmp/bar".
Command: ```bash kubectl cp :/tmp/foo prometheus/web-app-pod-1::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl...
Create a single ingress called 'app-ingress' that directs requests to foo.com/example to service 'svc1' on port 8084, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-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": "", "usage": ...
Add a taint with key 'cpu-type' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 cpu-type=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Get the logs from container named "email-service-pod-1" in deployment named "proxy-service-deployment"
Command: ```bash kubectl logs deployment/proxy-service-deployment -c email-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags:...
Create a job named "audit-job" using the image "mcr.microsoft.com/dotnet/core/runtime", and running the command "dotnet".
Command: ```bash kubectl create job audit-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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": "", "...
List the container names and images of a specific pod in custom columns
Command: ```bash kubectl get pod proxy-service-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image ``` 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...
Import the REDIS_HOST key from the global-config ConfigMap into the gateway-deployment Deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/global-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 i...
Output the modified deployment in YAML format without making any changes on the server
Command: ```bash kubectl set env deployment/notification-handler-deployment CACHE_SIZE=64MB -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 mor...
Run the 'docker run -d ubuntu sleep 3600' command inside the 'time-machine' container in the 'frontend-pod' pod and get the output.
Command: ```bash kubectl exec frontend-pod -c time-machine -- docker run -d ubuntu sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Containe...
Embed the certificate authority data for the 'prod-cluster' cluster entry by running the command:
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-1/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 s...
Create a deployment named "jenkins-x" using the image "php" and specifying the command "php --version"
Command: ```bash kubectl create deployment jenkins-x --image=php -- php --version ``` 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 ...
create a cron job named "data-processing" that runs the "python --version" command every minute
Command: ```bash kubectl create cronjob data-processing --image=python --schedule="*/1 * * * *" -- python --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", "shor...
Set the cluster field in a specific context to a specified cluster
Command: ```bash kubectl config set contexts.cluster-2-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...
Create a new config map named app-settings using the files file1.txt and file2.txt
Command: ```bash kubectl create configmap app-settings --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 a co...
Execute the command "yum install -y aws-cli" inside the container "rocket-ranger" of the pod "log-aggregator-pod", and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c rocket-ranger -- yum install -y aws-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 ...
Create a pod disruption budget named 'elastic-search-pdb' that will select all pods with the 'env=production' label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-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-availabl...
Forward local port 6379 to pod port 3000
Command: ```bash kubectl port-forward pod/e-commerce-pod 6379 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Create a deployment named mattermost running the amazonlinux image with 7 replicas.
Command: ```bash kubectl create deployment mattermost --image=amazonlinux --replicas=7 ``` 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....
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/env-vars 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 definition...
Update the label of the pod 'vpn' to have the key 'role' and the value 'frontend'
Command: ```bash kubectl label pods vpn role=frontend ``` 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 ...
Create a new job named "test-job" based on the configuration of the cron job "alerts-cleanup"
Command: ```bash kubectl create job test-job --from=cronjob/alerts-cleanup ``` 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...
Set the service account of the deployment 'payment-processor-deployment' to 'kube-scheduler'
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment kube-scheduler ``` 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 Sy...
Output the modified deployment configuration in YAML format without making changes on the server.
Command: ```bash kubectl set env deployment/monitoring-stack-deployment SMTP_HOST=smtp.example.com -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...
Update the pod 'foo' with the annotation 'env' and the value 'staging' by running the command "kubectl annotate --overwrite pods foo env='staging'"
Command: ```bash kubectl annotate --overwrite pods foo env='staging' ``` 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 arbitrar...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the 'cosmic-container' container of the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c cosmic-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 local traffic to a specific port inside the pod
Command: ```bash kubectl port-forward pod/web-app-pod :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 automatica...
Create a copy of the "proxy-service-pod" with a debug container and change the container images.
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-app --image=debian --set-image=worker=my-custom-worker:1.2.3,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster obje...
Update the pod identified by type and name in the "config.json" file with the annotation "deployment-script" set to "https://example.com/deploy.sh"
Command: ```bash kubectl annotate -f config.json deployment-script='https://example.com/deploy.sh' ``` 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 th...
Create a debug copy of the frontend-pod named debug-image-api, changing all container images to centos.
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-api --set-image=*=centos ``` 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...
import the REDIS_HOST key from the app-config config map and set it as an environment variable in the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-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 o...
Forward traffic from port 9090 on all addresses to port 8080 in the pod called log-aggregator-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 9090: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 po...
Create a new ClusterIP service named 'notification-service-clusterip' listening on port 9091 and forwarding traffic to port 8443
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=9091:8443 ``` 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":...
Create a cluster role named "admin_role" with the following parameters:
Command: ```bash kubectl create clusterrole admin_role --verb=use --resource=configmaps --resource-name=payment-processor --resource-name=report-generator ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=s...
Create a pod named hazelcast with the ubuntu image and expose port 8083
Command: ```bash kubectl run hazelcast --image=ubuntu --port=8083 ``` 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...
Listen locally on ports 9090 and 6000, and forward data between those ports and ports 8000 and 6000 in the pod 'frontend-pod'.
Command: ```bash kubectl port-forward pod/frontend-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 be selected autom...
Copy the local file "/tmp/foo" to the remote pod "worker-pod-4" in the namespace "kube-flannel" at the path "/etc/kubernetes".
Command: ```bash kubectl cp /tmp/foo kube-flannel/worker-pod-4:/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": "Container name. If omitted, use the k...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/ui-config 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 defin...
Set the annotation 'alert-email' with the value 'alerts@example.com' for the pod 'gateway'
Command: ```bash kubectl annotate pods gateway alert-email=alerts@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include...
Create a new ExternalName service named external-third-party-api-service linked to the domain document-company.com
Command: ```bash kubectl create service externalname external-third-party-api-service --external-name document-company.com ``` 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 r...
Set the custom TLS server name to "galaxy-cluster" for the "star-cluster" cluster entry
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=galaxy-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] [--certifica...
Attach to the code-explorer container in the frontend-pod and get the output.
Command: ```bash kubectl attach frontend-pod -c code-explorer ``` 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, u...
Retrieve the output of the 'ash' command from the pod named 'api-service-pod' using the container named 'nebula-navigator'
Command: ```bash kubectl exec api-service-pod -c nebula-navigator -- 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, u...
Specify the cluster for a particular context in the kubeconfig file.
Command: ```bash kubectl config set contexts.edge-context.cluster web-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you want...
list the replication controllers with the name "web", the services with the name "chat-app-rc", and the pods with the name "gateway-pod"
Command: ```bash kubectl get rc/web service/chat-app-rc pods/gateway-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced yo...
Create an ingress called 'private-ingress' with a rule that directs requests for 'testing.com/bar' to the service 'svc1' on port 6379
Command: ```bash kubectl create ingress private-ingress --rule="testing.com/bar=svc1:6379,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...
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/moon-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/moon-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...
Forward the traffic from port 8080 on localhost and IP address 10.19.21.23 to port 5000 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-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 cri...
Forward traffic between local port 8000 and pod port 9090 in a chat app pod
Command: ```bash kubectl port-forward pod/chat-app-pod 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 be selected autom...
Set custom TLS server name for a Kubernetes cluster
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=galaxy-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifi...
Set the service account of the deployment `monitoring-stack-deployment` to `kube-dns`.
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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: `...
Create a pod named "hazelcast" using the nginx image and expose port 5000 in the pod container.
Command: ```bash kubectl run hazelcast --image=nginx --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": "--fi...
Import the 'external_api_url' key from the 'env-vars' config map and set it as an environment variable for the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/env-vars 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...
Forward traffic from port 8081 on all addresses to port 8088 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8081:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Create a new config map named app-config-dev using the key=value pairs found in the specified file.
Command: ```bash kubectl create configmap app-config-dev --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 the ...
Create a service for the 'alpine' replicated using a replica set, which serves on port 8080 and connects to the containers on port 844300
Command: ```bash kubectl expose rs alpine --port=8080 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a pod disruption budget named "logging-pdb" that selects all pods with the label "env=production" and ensures that a minimum of 9 pods are always available.
Command: ```bash kubectl create poddisruptionbudget logging-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 [--...
Create a deployment named "worker" using the "python" image and expose port 9092.
Command: ```bash kubectl create deployment worker --image=python --port=9092 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Update the 'web-app-deployment' deployment by adding a new environment variable, MONGO_URI with the value mongodb://localhost:27017/mydb.
Command: ```bash kubectl set env deployment/web-app-deployment MONGO_URI=mongodb://localhost:27017/mydb ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or...
Expose a replication controller as a service, serving on port 8084 and connecting to the containers on port 9092
Command: ```bash kubectl expose rc wordpress --port=8084 --target-port=909200 ``` 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...
Create a copy of the 'e-commerce-pod' by adding a debug container and changing the container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-1 --image=debian --set-image=api=api:v2,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 resour...
Forward local ports 8080 to port 5432 in a pod selected by the search-engine-deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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...
Set the service account of the deployment "frontend-deployment" to "elasticsearch"
Command: ```bash kubectl set serviceaccount deployment frontend-deployment elasticsearch ``` 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: `kub...
Create a new ClusterIP service named 'log-service-clusterip' that listens on port 9092 and forward traffic to port 9092.
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=9092:9092 ``` 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...
Create a pod disruption budget named auth-service-pdb that will select all pods with the role=worker label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=role=worker --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 [...
Start a pod named "hazelcast" with the image "wordpress" and expose port 9000
Command: ```bash kubectl run hazelcast --image=wordpress --port=9000 ``` 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": "...
Create a copy of the `api-service-pod` with a debug container and change the container images.
Command: ```bash kubectl debug api-service-pod -it --copy-to=my-debugger --image=debian --set-image=api=api:v2,database=mysql:5.7 ``` 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....
Delete pods and services with the names "cdn" and "security"
Command: ```bash kubectl delete pod,service cdn security ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. So...
taint the 'worker-node-3' node with a key 'special', value 'backup' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes worker-node-3 special=backup: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. ...
Execute the 'npm --version' command in rocket-ranger container of the analytics-pod pod
Command: ```bash kubectl exec analytics-pod -c rocket-ranger -- 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 omitt...
Create a deployment named loadbalancer using the confluentinc/cp-kafka image and expose port 7000
Command: ```bash kubectl create deployment loadbalancer --image=confluentinc/cp-kafka --port=7000 ``` 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": "Out...
Apply the set-last-applied action to each configuration file in the config/ directory.
Command: ```bash kubectl apply set-last-applied -f config/ ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of the o...
Add or update the annotation 'backup-strategy' with the value 'daily-backups' for the pod 'vpn', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods vpn 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 an...
Execute the command 'dotnet --list-sdks' in the container 'rocket-ranger' of the pod 'payment-gateway-pod'
Command: ```bash kubectl exec payment-gateway-pod -c rocket-ranger -- 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 nam...
Create an ingress called 'internal-ingress' that directs requests for 'testing.com/example' to the service 'svc1' on port 5001
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/example=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": "", ...
Retrieve the output of the 'geth' command from the astro-container running in the chat-app-pod pod.
Command: ```bash kubectl exec chat-app-pod -c astro-container -- geth ``` 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 ...