prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Display a list of deployments in the "v2.0.0" version of the "experimental-apps" API group, using JSON output format.
Command: ```bash kubectl get deployments.v2.0.0.experimental-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 y...
Create an ingress resource called 'default-ingress' with a rule that directs requests from 'foo.com/input' to 'svc1' on port '8080', using the TLS secret named "my-cert".
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/input=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": "", "usage"...
Mark the node "gpu-node-12" as unschedulable
Command: ```bash kubectl cordon gpu-node-12 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Create an ingress named 'private-service-ingress' with a rule that directs requests from website.com/example to svc1 on port 5432, using the tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/example=svc1:5432,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 traffic from local port 8000 to port 9090 of a pod selected by the "search-engine-deployment" deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 8000 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp kube-system/security-scanner-pod-18:/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...
Forward traffic from port 8000 on both localhost and the IP address '10.19.21.23' to the 'proxy-server-pod' pod's port 8000.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-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 cr...
Execute the 'mysql' command within the 'chat-app-pod' pod to get the output.
Command: ```bash kubectl exec chat-app-pod -- 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, use the kubectl.kubern...
Get the output of the 'node --version' command from the pod named gateway-pod, running the command in the warp-drive container.
Command: ```bash kubectl exec gateway-pod -c warp-drive -- node --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 a service for the replication controller specified in the "wordpress-controller.yaml" file in the current namespace
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8443 --target-port=808900 ``` 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 ...
Execute the 'ash' command in the 'astro-container' of the 'vpn-service-pod' pod and get the output.
Command: ```bash kubectl exec vpn-service-pod -c astro-container -- ash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Check if the current user has the permission to list the job named "backup-job" in the "namespace-1" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/backup-job -n namespace-1 ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL tha...
Forward local port 8000 to port 3000 in the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 8000 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 ...
Execute the command "elasticsearch --version" in the first container of the first pod of the "analytics-service" service.
Command: ```bash kubectl exec svc/analytics-service -- 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 name. If omit...
Run the 'node' command in the 'warp-drive' container of the 'payment-gateway-pod' pod and get the output.
Command: ```bash kubectl exec payment-gateway-pod -c warp-drive -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Import the 'external_api_url' key from the 'configmap/namespace-config' and set it as an environment variable for the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/namespace-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 variabl...
Update the label of the pod named 'vpn' to 'status=unhealthy' only if the pod's resource version is 1
Command: ```bash kubectl label pods vpn status=unhealthy --resource-version=1 ``` 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"...
Enable GCP auth provider for the "developer" entry
Command: ```bash kubectl config set-credentials developer --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: --t...
Begin streaming the logs of the time-machine container in the auth-service-pod pod.
Command: ```bash kubectl logs -f -c time-machine auth-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Forward local traffic on ports 9090 and 6000 to the pod named 'log-aggregator-pod', forwarding data to/from ports 9090 and 6000 in the pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 9090 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...
Create an ingress resource named 'ingsecret' with TLS enabled using the secret 'secret1' and pathType set as Prefix
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="site.com/*=svc:8083,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": "",...
Forward traffic from port 8080 on all addresses to port 8080 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-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 po...
Copy the contents of the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the "file-server-pod-14" pod to the "/tmp/bar_dir" directory on your local machine.
Command: ```bash kubectl cp logging/file-server-pod-14:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "C...
Create a new config map named env-vars with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ma...
Return the snapshot logs from the container authentication-service-deployment-1 of the deployment named database-pod
Command: ```bash kubectl logs deployment/authentication-service-deployment -c database-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 fl...
Forward port 8081 on localhost and IP 10.19.21.23 to port 8000 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-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 th...
Retrieve the logs of container 'web-app-pod-1' from the deployment 'notification-handler-deployment'
Command: ```bash kubectl logs deployment/notification-handler-deployment -c web-app-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...
Listen on a randomly assigned local port, and forward the traffic to port 8888 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward pod/web-app-pod :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 selected automatica...
Forward local traffic on port 8081 to port 5432 on a pod selected by the mydeployment deployment
Command: ```bash kubectl port-forward deployment/mydeployment 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 pod will be selecte...
Forward traffic from port 8000 on all addresses to port 8080 in the backend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8000: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 ...
Listen on a random port on your local machine and forward the traffic to the 8000 port in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod :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 automat...
View the logs from container analytics-platform-deployment-1 of the deployment analytics-pod.
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c analytics-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...
View and modify the environment variables of a deployment in YAML without applying the changes to the server
Command: ```bash kubectl set env deployment/email-server-deployment API_KEY=your-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 or more p...
Create an ingress that directs requests to a specific URL to a service with TLS encryption.
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/input=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...
Retrieve the snapshot logs from the container 'frontend-pod-1' of the 'analytics-platform-deployment' deployment
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c frontend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags:...
Create an ingress rule called 'web-ingress' that directs requests to site.com/module to svc1:8010 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="site.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": "", "usage": ...
Listen on port 8080 locally, and forward the traffic to port 6379 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8080:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named 'app-settings' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/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 crea...
Copy the local file "/tmp/foo" to the remote pod named "load-balancer-pod-9" in the "/etc/kubernetes" directory, specifically in the container named "admin-dashboard".
Command: ```bash kubectl cp :/tmp/foo load-balancer-pod-9:/etc/kubernetes -c admin-dashboard ``` 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 omit...
Create a pod disruption budget named api-service-pdb that selects pods with the region=us-east label and requires at least 9 pods to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-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...
Create a role named "custom_role" that allows the user to perform "proxy", "get", and "update" actions on pods.
Command: ```bash kubectl create role custom_role --verb=proxy --verb=get --verb=update --resource=pods ``` 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]` Helpful flags: "f...
Taint node 'storage-node-13' with key 'dedicated' and no value
Command: ```bash kubectl taint nodes storage-node-13 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...
Copy the contents of the local directory "/var/run/secrets/kubernetes.io/serviceaccount/_dir" to the remote pod "logging-agent-pod-7" in the namespace "default" to the directory "/tmp/bar_dir".
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/_dir logging-agent-pod-7::/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": "Con...
Set the cluster field in the specified context to the provided cluster name.
Command: ```bash kubectl config set contexts.app-1-context.cluster dev-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 wan...
Get output from running the 'mysql' command in lunar-launcher from pod proxy-server-pod
Command: ```bash kubectl exec proxy-server-pod -c lunar-launcher -- 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, ...
Add a taint with the key 'datacenter' and value 'db-node-7:PreferNoSchedule' on all nodes having the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp datacenter=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": "", "usag...
List the deployments in JSON output format using the "v3.0.0" version of the "extensions" API group.
Command: ```bash kubectl get deployments.v3.0.0.extensions -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...
Create a new ClusterIP service named log-service-clusterip with the tcp port mapping 5432:8089.
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=5432:8089 ``` 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...
Run the 'node --version' command inside the warp-drive container of the chat-app-pod pod
Command: ```bash kubectl exec chat-app-pod -c warp-drive -- node --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,...
Forward port 8081 locally to the targetPort of the "https" service port in a pod selected by the "email-service" service
Command: ```bash kubectl port-forward service/email-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 selected...
Delete the pods and services with the names "payment" and "security"
Command: ```bash kubectl delete pod,service payment security ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...
View the details of the daemonset revision 5 of the namespace-3 daemonset.
Command: ```bash kubectl rollout history daemonset/namespace-3 --revision=5 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Create an ingress resource named 'api-ingress' with a rule that directs requests for 'website.com/bar' to the service 'svc1' on port '3001' using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-ingress --rule="website.com/bar=svc1:3001,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 service for a replicated python using a replica set, serving on port 8888 and connecting to the containers on port 543200.
Command: ```bash kubectl expose rs python --port=8888 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a deployment named 'prometheus' using the 'amazonlinux' image and expose port '9091'
Command: ```bash kubectl create deployment prometheus --image=amazonlinux --port=9091 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. ...
Import the SMTP_SERVER key from the config map "app-secrets" into the deployment "scheduler-app-deployment"
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-secrets 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 definiti...
Create a new ingress resource that directs requests to a specific service and port, using a TLS secret for secure communication.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="website.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...
Import the 'max_connections' key from the 'app-settings' config map into the 'search-engine-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-settings deployment/search-engine-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...
Remove the taint with key 'hardware' and effect 'NoExecute' from the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 hardware: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. One ...
Forward local port 3000 to the targetPort of the "https" port in the pod selected by the "email-service" service.
Command: ```bash kubectl port-forward service/email-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 selected...
Create a cluster role named "reader" with the following permissions: delete, update, and proxy
Command: ```bash kubectl create clusterrole reader --verb=delete,update,proxy --resource=secrets,secrets/status ``` 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]` Helpful flags: "flag":...
Create a new config map named 'namespace-config' in the current namespace, using the specified keys and their corresponding values from the provided files
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/settings/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 creat...
Start a Jenkins pod and keep it running in the foreground without auto-restart
Command: ```bash kubectl run -i -t busybox --image=jenkins --restart=Never ``` 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: "fl...
Get the output of the 'jenkins --version' command from the 'gateway-pod' pod.
Command: ```bash kubectl exec gateway-pod -- jenkins --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, use the kub...
Create a copy of the auth-service-pod and name it my-debugger with all container images changed to amazonlinux.
Command: ```bash kubectl debug auth-service-pod --copy-to=my-debugger --set-image=*=amazonlinux ``` 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 n...
Remove the label named 'app' from the 'vpn' pod
Command: ```bash kubectl label pods vpn app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, che...
Import the 'CONFIG_FILE_PATH' key from the 'app-config' config map and update the environment variables of the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config deployment/notification-handler-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 copy of the 'auth-service-pod' pod with a debug container and change the container images
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=scheduler=my-scheduler:1.0,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by reso...
Forward port 9090 locally to port 3000 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 9090 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 automaticall...
Get the output from the running 'api-service-pod' pod by attaching to it
Command: ```bash kubectl attach api-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 kubectl...
Increase the number of replicas for the 'baz' replica set to 3.
Command: ```bash kubectl scale --replicas=3 rs/baz ``` 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 before...
Set the resource limits for the WordPress container in the deployment.
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=10,memory=256Mi ``` 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 ...
create a cluster role named "bar" with the verbs "connect" and resources "configmaps" and "notification-service" and "mail-server"
Command: ```bash kubectl create clusterrole bar --verb=connect --resource=configmaps --resource-name=notification-service --resource-name=mail-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server...
List the replication controllers named "web", services named "backend-rc", and pods named "media-stream-pod"
Command: ```bash kubectl get rc/web service/backend-rc pods/media-stream-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Create an ingress named 'api-v1-ingress' that directs requests from the domain 'site.com/input' to the service 'svc1' on port '3001' with TLS enabled using the secret named 'my-cert'.
Command: ```bash kubectl create ingress api-v1-ingress --rule="site.com/input=svc1:3001,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 'baz' to have 1 replica, if its current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/baz ``` 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 spec...
Copy the local directory '/tmp/foo_dir' to the '/etc/kubernetes_dir' directory in the 'admin-dashboard-pod-16' pod in the default namespace.
Command: ```bash kubectl cp /tmp/foo_dir admin-dashboard-pod-16:/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 ...
Retrieve the logs of the previous terminated "cyber-sleuth" container from the "proxy-service-pod" pod
Command: ```bash kubectl logs -p -c cyber-sleuth proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Import the "api_key" key from a config map to a deployment named "cache-cluster-deployment"
Command: ```bash kubectl set env --keys=api_key --from=configmap/env-vars 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 definitions in ...
Create a pod disruption budget named 'cron-jobs-pdb' that will select all pods with the 'role=worker' label, and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=role=worker --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 file `/var/run/secrets/kubernetes.io/serviceaccount/` from your local machine to the remote pod named `monitoring-agent-pod-6` in the `kube-system` namespace and place it in the `/etc/kubernetes` directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-system/monitoring-agent-pod-6:/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": "", ...
Create a service for the replicated 'python' resource, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc python --port=6379 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Update the 'proxy' pod by adding the annotation 'team' with the value 'frontend-team' (overwrite any existing value)
Command: ```bash kubectl annotate --overwrite pods proxy team='frontend-team' ``` 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...
Set the cluster field in the "team-alpha-context" context to "testing-cluster"
Command: ```bash kubectl config set contexts.team-alpha-context.cluster testing-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new valu...
Get the output from running the 'npm --version' command in the 'warp-drive' container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c warp-drive -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Forward local port 3000 to port 8088 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000: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...
Create a job named security-scan-job using the centos image and install wget using yum.
Command: ```bash kubectl create job security-scan-job --image=centos -- yum install -y wget ``` 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": "O...
Import the specific key "config_file_path" from the config map "app-name-config" into the environment variables of the "authentication-service-deployment" deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-name-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...
Forward traffic from port 8888 on all addresses to port 5432 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8888: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 sel...
Forward local port 5432 to the targetPort of the "https" service port in a pod selected by the "database-service" service
Command: ```bash kubectl port-forward service/database-service 5432: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 selec...
Start a pod named "nginx" using the "postgres" image, and customize the specifications by providing a partial set of values from a JSON file.
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "v1.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
create a new ExternalName service named external-ldap-service, with the external name set to "news-demo.news"
Command: ```bash kubectl create service externalname external-ldap-service --external-name news-demo.news ``` 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...
Create a debug container named "dgb-img" that is a copy of the "backend-pod" pod, but with all the container images changed to "postgres".
Command: ```bash kubectl debug backend-pod --copy-to=dgb-img --set-image=*=postgres ``` 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 i...
Copy the directory /tmp/foo_dir from the pod named 'auth-service-pod-11' in the 'monitoring' namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp monitoring/auth-service-pod-11:/tmp/foo_dir :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Add a taint with key 'hardware' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster hardware=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a single ingress called 'public-ingress' that directs requests to testing.com/bar to the service 'svc1' on port 8081 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/bar=svc1:8081,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 role named "default_role" and specify the resources and resource names for the role
Command: ```bash kubectl create role default_role --verb=list --resource=pods --resource-name=load-balancer --resource-name=message-queue ``` 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=serv...
Create a Pod Disruption Budget named "frontend-pdb" that selects all pods with the "owner=team-1" label and ensures that at least one of them is available at any given time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=owner=team-1 --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...
Create a new ClusterIP service named auth-service-clusterip that maps port 8084 of the service to port 9091 of the target pods
Command: ```bash kubectl create service clusterip auth-service-clusterip --tcp=8084:9091 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "...
Update the image of all containers in the daemonset 'namespace-2' to 'ruby:3.0.2'
Command: ```bash kubectl set image daemonset namespace-2 *=ruby:3.0.2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `k...