prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 8088 in the pod named "frontend-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-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 criter...
Create a service for a replicated node using replica set, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rs node --port=8000 --target-port=808300 ``` 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...
Create a copy of the "chat-app-pod" pod, with a modified command for the "nebula-navigator" container, and enter into an interactive shell.
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-custom-dbg --container=nebula-navigator -- sh ``` 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 d...
Set a custom TLS server name for the "sun-cluster" cluster entry
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=e2e ``` 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-authority...
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to site.com/input to the service svc1 on port 8888, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/input=svc1:8888,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": "...
Update the 'email-server-deployment' by adding a new environment variable 'SMTP_HOST' with the value 'smtp.example.com'.
Command: ```bash kubectl set env deployment/email-server-deployment SMTP_HOST=smtp.example.com ``` 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...
Retrieve the logs of the previous terminated "time-machine" container from the "gateway-pod" pod.
Command: ```bash kubectl logs -p -c time-machine 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...
Create a deployment named nats using the elasticsearch image from Docker.
Command: ```bash kubectl create deployment nats --image=docker.elastic.co/elasticsearch/elasticsearch ``` 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": ...
Create a pod disruption budget named 'messaging-pdb' that selects all pods with the 'app=rails' label and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=app=rails --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry...
Get the output from running the 'redis-server --version' command in the stardust-shuttle container inside the security-service-pod pod.
Command: ```bash kubectl exec security-service-pod -c stardust-shuttle -- redis-server --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Conta...
Create a new config map named ui-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Add a taint with key 'special' on nodes having label team=devops
Command: ```bash kubectl taint node -l team=devops special=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": "", "usage": ...
Retrieve the snapshot logs from the container "proxy-service-pod-1" in the deployment "gateway-deployment".
Command: ```bash kubectl logs deployment/gateway-deployment -c proxy-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag...
create an ingress with multiple hosts and set the pathType as Prefix.
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8083" \ --rule="example.com/admin*=svc2:http" ``` 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": "--outp...
Get the output from running the 'sleep 3600' command in the first pod of the 'email-server-deployment' deployment.
Command: ```bash kubectl exec deploy/email-server-deployment -- 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,...
Set the resource request and limits for all containers in the redis deployment.
Command: ```bash kubectl set resources deployment redis --limits=cpu=200m,memory=512Mi --requests=cpu=5,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,...
Copy the file /tmp/foo from the remote pod ingress-controller-pod-8 under the monitoring namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp monitoring/ingress-controller-pod-8:/tmp/foo :/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 t...
Add a taint with the key 'zone' on all nodes that have the label 'myLabel', specifying 'kube-master-9' as the node and setting it to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l myLabel zone=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": "Output f...
Create a Pod Disruption Budget named "frontend-pdb" that will select all pods with the label "app=rails" and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=app=rails --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 [--dry-...
Get output from cyber-sleuth in the backend-pod
Command: ```bash kubectl attach backend-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...
Update the pod named 'email' with the annotation 'release-notes' and the value 'https://example.com/release-notes/v2.5.1', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods email release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that c...
Retrieve the output from running the 'elasticsearch-plugin --list' command in the nebula-navigator container of the monitoring-pod pod.
Command: ```bash kubectl exec monitoring-pod -c nebula-navigator -- elasticsearch-plugin --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Contai...
Create a new config map named "db-config" using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/preferences/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 crea...
Update the node 'monitoring-node-15' by adding a taint with key 'zone', value 'us-west-1a' and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes monitoring-node-15 zone=us-west-1a: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...
Import specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/env-vars 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 in on...
Retrieve the logs from the previously terminated quantum-quark container in the pod "mypod"
Command: ```bash kubectl logs -p -c quantum-quark mypod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": ...
Forward port 3000 on your local machine and IP address 10.19.21.23 to port 5432 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 3000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crite...
Create a deployment with the name "auth" using the "confluentinc/cp-kafka" image, and set the number of replicas to 5.
Command: ```bash kubectl create deployment auth --image=confluentinc/cp-kafka --replicas=5 ``` 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 for...
Get the output from the running security-service-pod and attach to the default container specified in the 'kubectl.kubernetes.io/default-container' annotation
Command: ```bash kubectl attach security-service-pod ``` 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 the ku...
Create a job named 'testing' using the amazonlinux image and run the 'bash' command
Command: ```bash kubectl create job testing --image=amazonlinux -- bash ``` 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 of...
Update the 'owner' annotation for the pod identified by the type and name in the "docker-registry.yaml" file to 'alice smith'
Command: ```bash kubectl annotate -f docker-registry.yaml 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 include...
Forward local port 6379 to remote port 6379 in the pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379: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 a...
Start a postgres pod and allow the container to expose port 27017
Command: ```bash kubectl run hazelcast --image=postgres --port=27017 ``` 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": "...
Import the API_KEY key from the app-secrets config map into the api-server-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-secrets 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 ...
Import the environment variables from the secret "ssh-key-secret" into the "email-server-deployment" deployment.
Command: ```bash kubectl set env --from=secret/ssh-key-secret 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 definitions in one or more p...
Create a new ClusterIP service named api-service-clusterip that maps port 5000 on the service to port 5001 on the pod
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=5000:5001 ``` 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...
Output the modified email-server-deployment deployment with the new environment variable MONGO_URI set to mongodb://localhost:27017/mydb in YAML format
Command: ```bash kubectl set env deployment/email-server-deployment MONGO_URI=mongodb://localhost:27017/mydb -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 definiti...
Retrieve the output from running the 'dotnet' command in the 'lunar-launcher' container from the 'gateway-pod' pod.
Command: ```bash kubectl exec gateway-pod -c lunar-launcher -- dotnet ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Create a secret named "database-secret" from an environment file
Command: ```bash kubectl create secret generic database-secret --from-env-file=path/to/configs.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...
Update the node specified in the "node.json" file by partially applying the changes specified in the strategic merge patch
Command: ```bash kubectl patch -f 10-mynet.conf -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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 p...
Create a copy of the analytics-pod, name it dgb-img, and replace all container images with the busybox image
Command: ```bash kubectl debug analytics-pod --copy-to=dgb-img --set-image=*=busybox ``` 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 ...
Create a cluster role named "default_role" with resource name specified
Command: ```bash kubectl create clusterrole default_role --verb=connect --resource=configmaps --resource-name=keycloak-server --resource-name=backup-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run...
Create a new ExternalName service with the name external-authentication-service
Command: ```bash kubectl create service externalname external-authentication-service --external-name mockup-cloud.cloud ``` 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 refe...
list deployments in the "v1.1.1" version of the "prod-apps" API group in JSON format
Command: ```bash kubectl get deployments.v1.1.1.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 ...
Get the output from running the 'dotnet --list-sdks' command inside the first container of the deployment 'cache-cluster-deployment'
Command: ```bash kubectl exec deploy/cache-cluster-deployment -- dotnet --list-sdks ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Run the 'mysql' command in the cosmic-container from the auth-service-pod pod and print the output.
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- 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...
Create an ingress called 'api-gateway-ingress' that directs requests to 'testing.com/example' to 'svc1:8080' with a TLS secret "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/example=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Forward port 5432 on localhost and selected IP to port 5000 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 5432: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...
Attach to the 'rocket-ranger' container inside the 'analytics-pod' pod to get its output.
Command: ```bash kubectl attach analytics-pod -c rocket-ranger ``` 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, ...
Create a copy of the analytics pod named debug-image-api with all container images changed to node
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-api --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 reso...
Copy the local file ~/.config/kube to the remote pod named load-balancer-pod-9 in the rook-ceph namespace, and place it in the /etc/kubernetes directory.
Command: ```bash kubectl cp ~/.config/kube rook-ceph/load-balancer-pod-9:/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,...
Add a taint with key 'app' on nodes having label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend app=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Create an ingress resource named ingsecret in the default class with the rule "website.com/*" mapping to the service named svc on port 8082, and using the TLS secret named secret1
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="website.com/*=svc:8082,tls=secret1" ``` 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": ...
Add a taint with the key 'datacenter' and value 'kube-master-9:PreferNoSchedule' on nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack datacenter=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": "", "us...
Update the pod named 'media-stream' by adding the annotation 'deployment-script' with the value 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate pods media-stream 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...
Embed the certificate authority data for the "testing-cluster" cluster entry.
Command: ```bash kubectl config set-cluster testing-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...
Retrieve the previous terminated container logs named "rocket-ranger" from the "frontend-pod" pod
Command: ```bash kubectl logs -p -c rocket-ranger 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", "s...
Remove all taints with key 'hardware' from the node 'dev-node-4'.
Command: ```bash kubectl taint nodes dev-node-4 hardware- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|n...
Forward traffic from a random local port to port 8081 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward pod/web-app-pod :8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automatica...
Create a new config map named api-config using the specified files for keys instead of file basenames on disk
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/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 config map...
Forward local ports 8080 to pod ports 8888 of the specified deployment
Command: ```bash kubectl port-forward deployment/database-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 will be ...
Create a priority class named default-priority with a value of 0 and a description of "Default standard resource allocation level".
Command: ```bash kubectl create priorityclass default-priority --value=0 --description="Default standard resource allocation level" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [-...
Update the 'backup-node-14' node with a taint of key 'hardware' and value 'gpu' and effect 'NoExecute'
Command: ```bash kubectl taint nodes backup-node-14 hardware=gpu: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. On...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/global-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Forward data between ports 8000 and 6000 locally and ports 8000 and 6000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 8000 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...
Create a role with specified SubResource permissions
Command: ```bash kubectl create role reader --verb=use,delete,connect --resource=persistentvolumes,persistentvolumes/status ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none...
Set environment variables for a deployment using specific keys from a config map.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/db-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Mark the node "worker-node-3" as schedulable
Command: ```bash kubectl uncordon worker-node-3 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Import the keys 'max_connections' from the 'log-config' config map and set them as environment variables for the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/log-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Taint nodes with 'cpu-type' key on nodes labeled with 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster cpu-type=db-node-7: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"...
Delete the specified cluster from the kubeconfig file.
Command: ```bash kubectl config delete-cluster cloud-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
open a raw terminal connection to the astro-container in the cdn-service-pod
Command: ```bash kubectl attach cdn-service-pod -c astro-container -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...
Auto scale the "analytics" deployment, allowing the number of pods to be adjusted between 5 and 14
Command: ```bash kubectl autoscale deployment analytics --min=5 --max=14 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that us...
Create a job named 'certificate-renewal' using the 'wordpress' image, and run the command 'apache2ctl -D FOREGROUND' in the job.
Command: ```bash kubectl create job certificate-renewal --image=wordpress -- apache2ctl -D FOREGROUND ``` 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": "", "...
Import the 'log_level' key from the 'app-config-dev' config map into the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-dev deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Expose a replica set named php, serving on port 8443 and connecting to containers on port 808400.
Command: ```bash kubectl expose rs php --port=8443 --target-port=808400 ``` 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 ...
Enable the new exec auth plugin for the "dev-user" entry
Command: ```bash kubectl config set-credentials dev-user --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 8888 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 5000: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 criter...
Set a custom TLS server name for the staging-cluster cluster entry.
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=cluster-alpha ``` 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...
Forward port locally to access a service's targetPort in a pod
Command: ```bash kubectl port-forward service/logging-service 8081: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 select...
Remove the environment variable ENV from the container 'astro-container' in all deployment configurations
Command: ```bash kubectl set env deployments --all --containers="astro-container" ENV- ``` 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 templat...
Create a cluster role named "foo" with the ability to delete pods and access the resource names "mail-server" and "log-aggregator"
Command: ```bash kubectl create clusterrole foo --verb=delete --resource=pods --resource-name=mail-server --resource-name=log-aggregator ``` 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]...
Display the last 5 lines of logs from the 'gateway-pod' pod
Command: ```bash kubectl logs --tail=5 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", "short": "-c",...
Create an ingress called 'app-proxy-ingress' that forwards requests for 'website.com/module' to the service 'svc1' on port '8088', using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.com/module=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Create a role named "custom_role" with the specified ResourceName values
Command: ```bash kubectl create role custom_role --verb=use --resource=pods --resource-name=monitoring-prometheus --resource-name=database-master ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-...
Get the output from the "cosmic-container" inside the "gateway-pod"
Command: ```bash kubectl attach gateway-pod -c cosmic-container ``` 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,...
Create an ingress called 'public-api-ingress' to route requests from site.com/bar to svc1:7000, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress public-api-ingress --rule="site.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": "", "usag...
Rename the 'prod-context' context to 'app-2-context' in your kubeconfig file
Command: ```bash kubectl config rename-context prod-context app-2-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also b...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/log-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 definition...
Forward traffic from local ports 8088 and 6000 to ports 8088 and 6000 respectively on a pod selected by the analytics-platform-deployment deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8088 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 po...
Create a pod disruption budget named statefulset-pdb that selects all pods with the region=us-east label and requires at least 9 of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget statefulset-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...
Set the environment variable "api_key" for the deployment "log-aggregator-deployment" by importing the value from the "app-config-dev" config map for the specified keys.
Command: ```bash kubectl set env --keys=api_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 definiti...
Add a taint with the key 'dedicated' and no value to the node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 dedicated:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/monitoring-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 def...
Update the 'chat-app' pod by adding or updating the annotation 'app-version' with the value '2.5.1', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app app-version='2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and inclu...
Forward traffic from port 8088 on all addresses to port 8000 in the backend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8088: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 ...
Update the 'kube-master-9' node by applying the specified JSON patch, which sets the 'type' field to 'LoadBalancer' in the 'spec' section.
Command: ```bash kubectl patch node kube-master-9 -p '{"spec":{"type":"LoadBalancer"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Hel...
Create a deployment named "jenkins" with 5 replicas running the "node" image
Command: ```bash kubectl create deployment jenkins --image=node --replicas=5 ``` 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...
Create a single ingress called 'frontend-ingress' that directs requests to website.com/module to svc svc1:8010 using the tls secret "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="website.com/module=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Create a new ClusterIP service named 'git-service-clusterip' mapping port 6379 externally to port 9090 internally.
Command: ```bash kubectl create service clusterip git-service-clusterip --tcp=6379:9090 ``` 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...