prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the 'web' pod by setting the annotation 'alert-email' with the value 'alerts@example.com'
Command: ```bash kubectl annotate pods web 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 arb...
List the deployments in the "feature-branch-2.3.0" version of the "custom-deployments" API group in YAML output format.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.custom-deployments -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 ...
Create a secret named "ldap-credentials-secret" from an environment file
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-env-file=path/to/settings.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 ...
Copy the /tmp/foo_dir directory from the local machine to the /etc/kubernetes_dir directory in the load-balancer-pod-9 pod in the default namespace.
Command: ```bash kubectl cp :/tmp/foo_dir load-balancer-pod-9:/etc/kubernetes_dir ``` 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 th...
Create a deployment named jenkins using the nginx image and expose port 8443.
Command: ```bash kubectl create deployment jenkins --image=nginx --port=8443 ``` 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...
Execute the 'mysql --version' command on the first pod of the service 'notification-service'.
Command: ```bash kubectl exec svc/notification-service -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Start a pod with node image and expose port 8080
Command: ```bash kubectl run hazelcast --image=node --port=8080 ``` 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": "--fil...
Create a job named "backup" using the CentOS image and execute the "bash" command.
Command: ```bash kubectl create job backup --image=centos -- 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: json...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-settings 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 o...
Import specific keys from a config map into specified deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-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 definit...
Forward port 8888 on localhost and IP 10.19.21.23 to port 8088 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8888: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 crite...
Partially update the 'backup-node-14' node by applying the provided strategic merge patch in JSON format
Command: ```bash kubectl patch node backup-node-14 -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: `kubect...
Forward local ports 8088 and 6000 to ports 8081 and 6000 in the specified deployment
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8088 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, ...
Create a pod disruption budget named logging-pdb that will select all pods with the tier=frontend label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=tier=frontend --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 [--d...
Copy the ~/.config/kube directory from the remote pod named "openfaas/task-processor-pod-17" to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp openfaas/task-processor-pod-17:~/.config/kube /tmp/bar_dir ``` 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, u...
Import the LOG_LEVEL key from the kube-system-config config map and set it as an environment variable for the order-processing-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/kube-system-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Forward local port 8088 to port 5432 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 8088: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 will be selected au...
Create a copy of the vpn-service-pod pod and change all container images to golang using the command "kubectl debug vpn-service-pod --copy-to=my-debugger --set-image=*=golang".
Command: ```bash kubectl debug vpn-service-pod --copy-to=my-debugger --set-image=*=golang ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Forward port 5432 on your local machine to port 6379 in the pod named "web-app-pod".
Command: ```bash kubectl port-forward pod/web-app-pod 5432:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Set up autoscaling for the "analytics" deployment with a minimum of 6 pods and a maximum of 8 pods.
Command: ```bash kubectl autoscale deployment analytics --min=6 --max=8 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/api-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Copy the '~/.config/kube' local file to the '/tmp/bar' directory in the 'auth-service-pod-11' pod, specifically in the 'backend-container' container.
Command: ```bash kubectl cp ~/.config/kube auth-service-pod-11::/tmp/bar -c backend-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Execute the 'geth attach' command in the nebula-navigator container of the gateway-pod pod and retrieve the output.
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- geth attach ``` 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...
Execute the 'postgres' command inside the pod named 'payment-gateway-pod'
Command: ```bash kubectl exec payment-gateway-pod -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Enable the Google Compute Platform auth provider for the "system" entry.
Command: ```bash kubectl config set-credentials system --auth-provider=gcp ``` 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: --client-certificate=certfile --client-key=keyfile Bearer token flags: --toke...
Create a cluster role named "bar" with specific resource names
Command: ```bash kubectl create clusterrole bar --verb=use --resource=pods --resource-name=billing-service --resource-name=content-delivery ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|no...
Create a Pod Disruption Budget (PDB) named messaging-pdb that selects all pods with the app=nginx label and ensures that at least 50% of the selected pods are available at any given time.
Command: ```bash kubectl create pdb messaging-pdb --selector=app=nginx --min-available=50% ``` 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-run=server|cl...
Import the "external_api_url" key from the "log-config" ConfigMap and set it as an environment variable for the "scheduler-app-deployment" deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/log-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Change the name of a context in your kubeconfig file from 'old-name' to 'app-2-context'
Command: ```bash kubectl config rename-context old-name 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 be up...
Forward traffic from localhost port 5000 to port 3000 in the backend-pod pod
Command: ```bash kubectl port-forward pod/backend-pod 5000: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 automa...
Create an ingress called 'website-ingress' that directs requests from foo.com/module to a service at svc1:9091, and use a TLS secret named "my-cert".
Command: ```bash kubectl create ingress website-ingress --rule="foo.com/module=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": "", "usage...
Forward local port 5000 to port 5000 of pod/mypod and listen for data
Command: ```bash kubectl port-forward pod/mypod 5000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
import the specific key CONFIG_FILE_PATH from the api-config config map and set it as an environment variable for the database-deployment deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/api-config 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 definitio...
Forward local port 8080 to the targetPort of the service's port named "https" in a selected pod.
Command: ```bash kubectl port-forward service/api-service 8080: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...
Update the deployment 'log-aggregator-deployment' by setting a new environment variable 'DB_USER' with the value 'username'
Command: ```bash kubectl set env deployment/log-aggregator-deployment DB_USER=username ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templat...
forward traffic from local ports 8081 and 6000 to ports 8080 and 6000 respectively in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 8081 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 be selected automa...
Create a new ExternalName service named external-email-service with the external name test-site.org
Command: ```bash kubectl create service externalname external-email-service --external-name test-site.org ``` 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...
Copy the file "/tmp/foo" from your local machine to "/tmp/bar_dir" inside a remote pod in the "argocd/message-broker-pod-15" namespace.
Command: ```bash kubectl cp :/tmp/foo argocd/message-broker-pod-15:/tmp/bar_dir ``` 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 ...
Import the LOG_LEVEL key from the namespace-config ConfigMap into the payment-processor-deployment Deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/namespace-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 d...
Create a new secret named 'git-credentials-secret' using the values from the 'path/to/settings.env' file
Command: ```bash kubectl create secret generic git-credentials-secret --from-env-file=path/to/settings.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 t...
Get the documentation of the pods resource and its fields
Command: ```bash kubectl explain resource=pods ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag to display all of th...
Increase the number of replicas in the 'frontend-rs' replica set to 5.
Command: ```bash kubectl scale --replicas=5 rs/frontend-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validate...
Create a deployment named sonarqube that uses the wordpress image and exposes port 9092
Command: ```bash kubectl create deployment sonarqube --image=wordpress --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...
Execute the 'nginx' command in pod 'backend-pod' using the container 'quantum-quark' and retrieve the output
Command: ```bash kubectl exec backend-pod -c quantum-quark -- nginx ``` 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 th...
Forward local port 8081 to pod port 5432 and port 6000 to port 6000.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8081 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Create an ingress called 'www-ingress' that directs requests to site.com/module to svc1:8443 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="site.com/module=svc1:8443,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Add an annotation to the pod 'payment'. Set the annotation 'owner' to the value 'alice smith'.
Command: ```bash kubectl annotate pods payment 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 arbitrary ...
Remove all taints with the key 'environment' from the node 'db-node-7'
Command: ```bash kubectl taint nodes db-node-7 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: json|yaml...
Create a new ExternalName service named external-metrics-service with an external name of sample-domain.net
Command: ```bash kubectl create service externalname external-metrics-service --external-name sample-domain.net ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Listen on port 8080 locally and forward traffic to port 8080 in the chat-app-pod
Command: ```bash kubectl port-forward pod/chat-app-pod 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 be selected autom...
Execute the command 'gem --version' on the first pod of the deployment 'cache-cluster-deployment' and retrieve the output.
Command: ```bash kubectl exec deploy/cache-cluster-deployment -- gem --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Create an ingress called 'website-ingress' with a rule that directs requests for site.com/module to the service called svc1 on port 3000
Command: ```bash kubectl create ingress website-ingress --rule="site.com/module=svc1:3000,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...
Copy the file "/tmp/foo" from the remote pod "kube-node-lease/task-processor-pod-17" to the local directory "/tmp/bar".
Command: ```bash kubectl cp kube-node-lease/task-processor-pod-17::/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, us...
Get the output of the 'pip --version' command from the nano-bot container running in the cdn-service-pod pod.
Command: ```bash kubectl exec cdn-service-pod -c nano-bot -- pip --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create an ingress named "web-ingress" that directs requests for "foo.com/example" to the service "svc1" on port 8088, and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/example=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": "", "usage": ...
Scale the deployment named 'staging-app-rs' to 3 replicas if its current size is already 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/staging-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/monitoring-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Watch the rollout status of the 'prod' deployment
Command: ```bash kubectl rollout status deployment/prod ``` What it does: Show the status of the rollout. By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts in-bet...
Create a cron job called "metrics-collection" that runs the command "node --version" every minute.
Command: ```bash kubectl create cronjob metrics-collection --image=node --schedule="*/1 * * * *" -- node --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", "short...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/monitoring-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 d...
Create a new NodePort service named media-stream-nodeport and map port 8084 on the host to port 8000 on the service.
Command: ```bash kubectl create service nodeport media-stream-nodeport --tcp=8084:8000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default"...
Create a copy of web-app-pod with all container images changed to nginx for debugging purposes
Command: ```bash kubectl debug web-app-pod --copy-to=dgb-img --set-image=*=nginx ``` 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...
Get resource(s) by their type and names
Command: ```bash kubectl get rc/web service/backend-rc pods/api-service-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...
Get the output of the 'python --version' command in pod email-service-pod, container warp-drive.
Command: ```bash kubectl exec email-service-pod -c warp-drive -- python --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 new secret named tls-certificate-secret with keys for each file in the folder bar
Command: ```bash kubectl create secret generic tls-certificate-secret --from-file=path/to/configs ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basena...
Add a taint with the key 'zone' on nodes that have the label 'myLabel', and set the taint value to 'edge-node-10:PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel zone=edge-node-10: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 fo...
Output the modified deployment in YAML format without making changes to the object on the server
Command: ```bash kubectl set env deployment/monitoring-stack-deployment SECRET_KEY=your-secret-key -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...
Taint nodes with the label 'zone=us-east-1' using a taint key 'hardware' and value 'monitoring-node-15:PreferNoSchedule'
Command: ```bash kubectl taint node -l zone=us-east-1 hardware=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Scale a resource defined in the "pod.json" file to a replica count of 3.
Command: ```bash kubectl scale --replicas=3 -f pod.json ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated b...
Listen on port 3000 locally and forward the traffic to the targetPort of the "https" service port in a pod selected by the "payment-service" service.
Command: ```bash kubectl port-forward service/payment-service 3000:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Forward the local port 8000 to the port 8088 in the chat-app-pod pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 8000 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 autom...
Create a debug container image 'debug-image-1' that is a copy of 'mypod' with all container images changed to 'wordpress'
Command: ```bash kubectl debug mypod --copy-to=debug-image-1 --set-image=*=wordpress ``` 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 job named batch-processing with the image docker.elastic.co/elasticsearch/elasticsearch
Command: ```bash kubectl create job batch-processing --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch-plugin --list ``` 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": "--outp...
Set the CPU limit of the Hazelcast container in the deployment to "10" and the memory limit to "2Gi".
Command: ```bash kubectl set resources deployment hazelcast -c=nginx --limits=cpu=10,memory=2Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to...
Create a copy of the auth-service-pod with the name debug-image-web, replacing all container images with the golang image.
Command: ```bash kubectl debug auth-service-pod --copy-to=debug-image-web --set-image=*=golang ``` 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...
Retrieve the list of topics from running the command 'kafka-topics --list' in the 'mycontainer' container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c mycontainer -- kafka-topics --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": "Container name. I...
Create a cluster role named "custom_role" with ResourceName specified as "backup-service" and "audit-logger" for the configmaps resource.
Command: ```bash kubectl create clusterrole custom_role --verb=patch --resource=configmaps --resource-name=backup-service --resource-name=audit-logger ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serve...
Copy the file '/tmp/foo' from the local machine to the '/tmp/bar' directory in the 'file-server-pod-14' pod
Command: ```bash kubectl cp :/tmp/foo file-server-pod-14:/tmp/bar -c front-end-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Retrieve the output from running the 'elasticsearch --version' command inside the cosmic-container of the media-stream-pod.
Command: ```bash kubectl exec media-stream-pod -c cosmic-container -- elasticsearch --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": "Containe...
Begin streaming the logs from all containers in the pods that have the label 'environment=production'
Command: ```bash kubectl logs -f -l environment=production --all-containers=true ``` 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":...
Import the 'DATABASE_URL' key from the 'app-name-config' config map into the 'email-server-deployment' deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-name-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 defi...
Create an ingress that redirects requests from foo.com/bar to svc1:8080 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/bar=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": "", "usag...
Delete the pods and services with the names "email" and "log-aggregator"
Command: ```bash kubectl delete pod,service email log-aggregator ``` 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 sele...
Set a custom TLS server name for the "cloud-cluster" cluster entry.
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=app-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...
Display the last 20 lines of logs for a specific pod
Command: ```bash kubectl logs --tail=20 monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "...
Create a role named "reader" with specific resource names
Command: ```bash kubectl create role reader --verb=patch --resource=pods --resource-name=error-logger --resource-name=identity-provider ``` 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...
Update the pod named 'database' by adding the annotation 'scaling-policy' with the value 'auto-horizontal-scaling'.
Command: ```bash kubectl annotate pods database scaling-policy=auto-horizontal-scaling ``` 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...
Create a cron job called "backup-job" with the image "node" and a schedule of running every minute
Command: ```bash kubectl create cronjob backup-job --image=node --schedule="*/1 * * * *" -- npm --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", "short": "-o", ...
Listen on port 8088 locally and forward traffic to port 8000 inside the 'security-service-pod' pod
Command: ```bash kubectl port-forward pod/security-service-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 be select...
Get the output from running the 'apache2ctl -D FOREGROUND' command inside the 'cosmic-container' in the 'proxy-server-pod' pod
Command: ```bash kubectl exec proxy-server-pod -c cosmic-container -- apache2ctl -D FOREGROUND ``` 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": "Contain...
Create a new ClusterIP service named notification-service-clusterip
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=8083:8082 ``` 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":...
Listen on port 8088 on localhost and IP 10.19.21.23, forwarding traffic to port 3000 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8088: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 crite...
Listen on port 8888 on localhost and IP address 10.19.21.23, forwarding to port 3000 in the pod named log-aggregator-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8888: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 ...
Copy the file /tmp/foo from the pod named 'admin-dashboard-pod-16' in the 'monitoring' namespace to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp monitoring/admin-dashboard-pod-16:/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 the ...
Add a taint with key 'zone' on nodes having label 'namespace=mynamespace' and the value 'testing-node-11' and setting it to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l namespace=mynamespace zone=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Open a bash shell in the cosmic-container of the analytics-pod and get its output.
Command: ```bash kubectl exec analytics-pod -c cosmic-container -- bash ``` 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...
Forward local ports to a pod's ports for data exchange
Command: ```bash kubectl port-forward pod/api-service-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 be selected au...
Copy the file /tmp/foo from the pod web-app-pod-1 in the kube-server cluster to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp kube-server/web-app-pod-1:/tmp/foo /tmp/bar_dir ``` 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 kube...
Delete the pods and services named "media-stream"
Command: ```bash kubectl delete pod,service media-stream media-stream ``` 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...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/frontend-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 namespac...