prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Copy the local file '/tmp/foo' to the remote pod 'openfaas/monitoring-agent-pod-6' in the '/tmp/bar_dir' directory
Command: ```bash kubectl cp :/tmp/foo openfaas/monitoring-agent-pod-6:/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 t...
Create a debug container by copying the gateway-pod, and change the container images
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-1 --image=debian --set-image=proxy=nginx:1.21,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 res...
Run the 'mongod' command inside the vpn-service-pod pod and get the output
Command: ```bash kubectl exec vpn-service-pod -- mongod ``` 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 kubectl.ku...
Copy the '~/.config/kube' file from your local machine to the '/etc/kubernetes' directory in the 'istio-system/database-pod-2' pod within the 'istio-system' namespace.
Command: ```bash kubectl cp ~/.config/kube istio-system/database-pod-2:/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, u...
Copy the directory "/var/run/secrets/kubernetes.io/serviceaccount/" from the pod named "cache-pod-5" in the namespace "ingress-nginx" to the local directory "/etc/kubernetes/".
Command: ```bash kubectl cp ingress-nginx/cache-pod-5:/var/run/secrets/kubernetes.io/serviceaccount/ /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": ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/namespace-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 def...
Forward local traffic on ports 5000 to the deployment 'search-engine-deployment' pods on port 9090.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 5000 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 wil...
Copy the file /tmp/foo from the load-balancer-pod-9 pod to the local machine's /tmp/bar directory
Command: ```bash kubectl cp velero/load-balancer-pod-9:/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 kubect...
Create a new ClusterIP service named my-cs with TCP port forwarding from 8088 to 5432.
Command: ```bash kubectl create service clusterip my-cs --tcp=8088:5432 ``` 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", "default": "", "us...
Create a new config map named app-config-dev using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/configs/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 creati...
Set the service account of the deployment "cache-cluster-deployment" to "argocd"
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment argocd ``` 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: `kubec...
Embed the certificate authority data for the "dev-cluster" cluster entry.
Command: ```bash kubectl config set-cluster dev-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 se...
Import the 'API_KEY' key from the 'db-config' config map into the 'web-app-deployment' deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-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 one o...
Add a taint to the 'edge-node-10' node with the key 'app' and no value.
Command: ```bash kubectl taint nodes edge-node-10 app:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json...
Retrieve the logs from the previously terminated "cyber-sleuth" container in the "analytics-pod" pod.
Command: ```bash kubectl logs -p -c cyber-sleuth analytics-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...
Start a ethereum/client-go pod named 'nginx' with a custom spec, using a partial set of values parsed from a JSON file
Command: ```bash kubectl run nginx --image=ethereum/client-go --overrides='{ "apiVersion": "alpha-2.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--comm...
Create a deployment named monitoring with the redis image
Command: ```bash kubectl create deployment monitoring --image=redis ``` 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: json|yaml|...
Set a custom TLS server name for the web-cluster cluster entry.
Command: ```bash kubectl config set-cluster web-cluster --tls-server-name=data-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-...
Create a Pod Disruption Budget named "cache-cluster-pdb" that selects all pods with the label "tier=frontend" and ensures that at least 9 of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=tier=frontend --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=...
Update the pod named 'email' by setting the label 'env' to the value 'production'
Command: ```bash kubectl label pods email env=production ``` 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": "...
Create a new ClusterIP service named my-cs that forwards traffic from port 5001 to port 3001.
Command: ```bash kubectl create service clusterip my-cs --tcp=5001:3001 ``` 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", "default": "", "us...
Create a job named "scaling-job" using the PHP image
Command: ```bash kubectl create job scaling-job --image=php -- ``` 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|ya...
Create a deployment named 'logging' using the 'alpine' image and expose port 8088.
Command: ```bash kubectl create deployment logging --image=alpine --port=8088 ``` 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: ...
Forward traffic from local port 8088 to port 8000 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Remove the 'bar' label from the 'cdn' pod
Command: ```bash kubectl label pods cdn component- ``` 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 tru...
Execute the 'nginx' command in the first container of the 'user-management-deployment' deployment's first pod, and print the output.
Command: ```bash kubectl exec deploy/user-management-deployment -- 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, u...
Get the output from running the 'kafka-console-producer --broker-list localhost:9092 --topic test' command in the 'rocket-ranger' container of the 'chat-app-pod' pod.
Command: ```bash kubectl exec chat-app-pod -c rocket-ranger -- kafka-console-producer --broker-list localhost:9092 --topic test ``` 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",...
Update the annotation "expiration-date" of pod "cdn" with the value "2024-12-31".
Command: ```bash kubectl annotate pods cdn expiration-date='2024-12-31' ``` 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 arbit...
Create an ingress called 'api-v1-ingress' that directs requests to a specific path and service, and enable TLS using a specified secret.
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/example=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 deployment named 'auth' with the 'python' image and expose port 8089
Command: ```bash kubectl create deployment auth --image=python --port=8089 ``` 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: jso...
Import specific keys from a config map into the environment variables of a deployment named payment-processor-deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-settings 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 defi...
Create a debug copy of the chat-app-pod with all container images changed to golang.
Command: ```bash kubectl debug chat-app-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 res...
Delete the pods and services with the names "media-stream" and "log-aggregator"
Command: ```bash kubectl delete pod,service media-stream 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 lab...
Create a cluster role named "admin_role" that has the ability to delete configmaps with the resource name "message-queue" and "search-elasticsearch"
Command: ```bash kubectl create clusterrole admin_role --verb=delete --resource=configmaps --resource-name=message-queue --resource-name=search-elasticsearch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-ru...
Forward local port to the 3000 port in the web-app-pod.
Command: ```bash kubectl port-forward pod/web-app-pod :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 automatica...
Forward local port 8888 to port 8888 in the pod
Command: ```bash kubectl port-forward pod/security-service-pod 8888: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 select...
Create a copy of the 'analytics-pod' pod but with a different command for the 'cosmic-container' container
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-custom-dbg --container=cosmic-container -- 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 ...
Attach to the console of the specified container in the given pod
Command: ```bash kubectl attach api-service-pod -c mycontainer ``` 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, ...
Import the key "smtp_server" from the "app-name-config" config map to the environment variables of the "analytics-platform-deployment" deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-name-config deployment/analytics-platform-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...
Copy the local file /tmp/foo to the remote pod named image-resizer-pod-20 at the location /tmp/bar, but make sure to specify the container named ingress-controller.
Command: ```bash kubectl cp /tmp/foo image-resizer-pod-20::/tmp/bar -c ingress-controller ``` 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...
Create a cron job named 'system-health-check' with the image 'php' that runs the command 'composer --version' every minute.
Command: ```bash kubectl create cronjob system-health-check --image=php --schedule="*/1 * * * *" -- composer --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", "s...
Embed certificate authority data for the on-prem-cluster cluster entry
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/sun-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 s...
Copy the local directory ~/.config/kube_dir to the remote pod named database-pod-2 in the default namespace, and place it in the directory /tmp/bar_dir.
Command: ```bash kubectl cp ~/.config/kube_dir database-pod-2::/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...
Create a new config map named global-config using the files file1.txt and file2.txt as the values for the keys conf and data, respectively.
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Update node 'dev-node-4' with a taint with key 'cpu-type' and value 'x86' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes dev-node-4 cpu-type=x86: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 o...
Forward traffic from port 8000 on all addresses to port 5000 in the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8000: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 sel...
Forward local traffic to a pod in a deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Create a deployment named "db" with the "ruby" image and expose port 5432
Command: ```bash kubectl create deployment db --image=ruby --port=5432 ``` 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: json|ya...
Set the cluster field in the context named my-context to on-prem-cluster.
Command: ```bash kubectl config set contexts.app-1-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 you...
Forward local port 5432 to port 8081 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 5432: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 select...
Create an ingress resource named 'service-ingress' with the rule that directs requests for 'website.com/module' to service 'svc1' on port 8000, and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress service-ingress --rule="website.com/module=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Update node 'node-2' with a taint having a key 'special', value 'backup', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes node-2 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. One of:...
Add a taint with the key 'hardware' on nodes that have the label service=auth
Command: ```bash kubectl taint node -l service=auth hardware=backup-node-14: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":...
Forward port 8080 on all addresses to port 3000 in the backend-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8080: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 ...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to /tmp/bar in the image-resizer-pod-20 pod, but specifically inside the database-container container.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ image-resizer-pod-20:/tmp/bar -c database-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": "",...
Create a service for the 'node' replica set, serving on port 5432 and connecting to the containers on port 808200.
Command: ```bash kubectl expose rs node --port=5432 --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...
Create a new container for debugging the log-aggregator-pod with a copy of the rocket-ranger container.
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-web --container=rocket-ranger -- 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...
Apply a taint with the key 'zone' and the value 'storage-node-13:PreferNoSchedule' on all nodes labeled with 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp zone=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": "", "usag...
Forward local port 8081 to port 8000 in the pod named analytics-pod
Command: ```bash kubectl port-forward pod/analytics-pod 8081:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Retrieve the output from running the 'irb' command in the 'code-explorer' container of the 'database-pod' pod.
Command: ```bash kubectl exec database-pod -c code-explorer -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Retrieve the logs from the container named 'e-commerce-pod-1' in the deployment 'email-server-deployment'
Command: ```bash kubectl logs deployment/email-server-deployment -c e-commerce-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: "fl...
Forward local port 5432 to port 6379 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-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...
delete both the pods and services with the names "security" and "log-aggregator"
Command: ```bash kubectl delete pod,service security 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 s...
Forward local port 6379 to port 9090 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379 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 a...
Execute the 'redis-server' command inside the first pod of the service 'logging-service', using the first container.
Command: ```bash kubectl exec svc/logging-service -- redis-server ``` 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 ...
Create a job named 'indexing' using the 'mysql' image and run the command 'mysql' within the job
Command: ```bash kubectl create job indexing --image=mysql -- mysql ``` 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: js...
Get the output from running the 'dotnet' command in the 'code-explorer' container of the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c code-explorer -- 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, u...
Get the output from running the command 'elasticsearch --version' inside the 'rocket-ranger' container of the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c rocket-ranger -- 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": "Container nam...
Partially update a resource identified by the file specified in "-f" flag using strategic merge patch.
Command: ```bash kubectl patch -f 10-mynet.conf -p '{"stringData":{"password":"new-password"}' ``` 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 FIL...
Create an ingress with the name 'www-ingress' that directs requests for 'testing.com/input' to the service 'svc1' on port 3306, using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress www-ingress --rule="testing.com/input=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a new NodePort service named database-nodeport with the TCP ports 8082 on the host and 6379 on the pods.
Command: ```bash kubectl create service nodeport database-nodeport --tcp=8082:6379 ``` 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": ""...
Partially update the settings of a node identified by the specified type and name using strategic merge patch.
Command: ```bash kubectl patch -f node-settings.json -p '{"spec":{"someField":"newValue"}' ``` 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]` ...
Create a single ingress called 'public-api-ingress' that directs requests to 'website.com/example' to the service 'svc1' on port 8000, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/example=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Create a service for the replicated wordpress with the following specifications: serves on port 80, connects to the containers on port 8000.
Command: ```bash kubectl expose rc wordpress --port=9091 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Update the pod 'frontend' with the label 'env' set to 'production'
Command: ```bash kubectl label pods frontend env=production ``` 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"...
Create a single ingress called 'default-ingress' that directs requests to website.com/bar to svc1 on port 8888 with the tls secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="website.com/bar=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": "", "usag...
Create a copy of the api-service-pod named debug-image-1 and change all container images to redis
Command: ```bash kubectl debug api-service-pod --copy-to=debug-image-1 --set-image=*=redis ``` 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...
Automatically scale the deployment "vpn" by creating a horizontal pod autoscaler
Command: ```bash kubectl autoscale deployment vpn --min=4 --max=15 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Create a new config map named db-config in the current namespace
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
get the details of a specific context in your kubeconfig file
Command: ```bash kubectl config get-contexts cloud-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Update the cluster field in the 'dev-context' context to 'cluster-alpha'
Command: ```bash kubectl config set contexts.dev-context.cluster cluster-alpha ``` 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 wan...
Import specific keys from a config map to set environment variables for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-dev 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 definition...
Create a service for a replicated node using the replica set "node"
Command: ```bash kubectl expose rs node --port=8181 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Output the modified deployment in YAML format without applying the changes to the server.
Command: ```bash kubectl set env deployment/web-app-deployment GOOGLE_API_KEY=your-google-api-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 ...
create a new config map named app-config-prod with specified keys from files
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/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 cre...
Forward port 8080 on localhost and IP 10.19.21.23 to port 5432 in the pod named api-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8080:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Create a secret named "git-credentials-secret" where each file in the "path/to/configurations" folder is a key
Command: ```bash kubectl create secret generic git-credentials-secret --from-file=path/to/configurations ``` 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...
Update the annotation 'last-deployment' of pod 'log-aggregator' by setting the value to '2023-03-15'.
Command: ```bash kubectl annotate pods log-aggregator last-deployment=2023-03-15 ``` 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...
View metrics for the pod "analytics-pod" and its containers.
Command: ```bash kubectl top pod analytics-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod...
Import the 'debug_mode' key from the 'namespace-config' config map into the 'backend-microservice-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/namespace-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 variab...
Create a new NodePort service named database-nodeport with a TCP port mapping of 8181:9090
Command: ```bash kubectl create service nodeport database-nodeport --tcp=8181:9090 ``` 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 new config map named log-config with the keys "properties" and "key1" using the respective files "/path/to/configurations/file1.txt" and "/path/to/configurations/file2.txt"
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/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. Whe...
Run the 'geth' command on the first pod of the 'gateway-deployment' deployment.
Command: ```bash kubectl exec deploy/gateway-deployment -- 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 the ku...
partially update the edge-node-10 node by applying the specified JSON patch
Command: ```bash kubectl patch node edge-node-10 -p '{"spec":{"someField":"newValue"}' ``` 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...
Import the `database_url` key from the `ui-config` ConfigMap into the `email-server-deployment` Deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/ui-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 definition...
Retrieve a list of deployments in YAML output format, specifically for the "v1.1.1" version of the "custom-deployments" API group.
Command: ```bash kubectl get deployments.v1.1.1.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 is namespaced ...
List deployments in JSON output format, in the specific version of an API group
Command: ```bash kubectl get deployments.dev-2.2.0.custom-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 ...
Add a taint with key 'workload' on nodes having label tier=frontend.
Command: ```bash kubectl taint node -l tier=frontend workload=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outpu...
Create a new config map named monitoring-config using specified keys and file paths
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Update the annotation "owner" of the pod using the specified value
Command: ```bash kubectl annotate -f options.json 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 arbitra...