prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Delete the pods and services with the names "vpn" and "backend"
Command: ```bash kubectl delete pod,service vpn backend ``` 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. Som...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-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...
Create an ingress named 'web-ingress' with a rule that maps requests from testing.com/input to svc1:3000
Command: ```bash kubectl create ingress web-ingress --rule="testing.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": "", "usage"...
Forward the local port 8000 to port 8081 in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 8000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Auto scale the replication controller "monitoring" with a minimum of 1 pod, and a maximum of 7 pods, targeting a CPU utilization of 90%
Command: ```bash kubectl autoscale rc monitoring --max=7 --cpu-percent=90 ``` 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 u...
Set the environment variable 'API_KEY' with the value 'your-api-key' in the 'database-deployment' deployment.
Command: ```bash kubectl set env deployment/database-deployment API_KEY=your-api-key ``` 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 templates...
Forward traffic from local port 8000 to the pod's port 8080
Command: ```bash kubectl port-forward pod/frontend-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 be selected autom...
Forward local port to a pod port
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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 wil...
Create a cluster role named "bar" with the ability to list pods and specify the resource names "auth-service" and "app-analytics".
Command: ```bash kubectl create clusterrole bar --verb=list --resource=pods --resource-name=auth-service --resource-name=app-analytics ``` 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]` ...
Attach to the 'astro-container' inside the 'backend-pod' pod and view the output
Command: ```bash kubectl attach backend-pod -c astro-container ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Create an ingress named 'public-ingress' that routes requests for 'site.com/example' to the service 'svc1:8081' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress public-ingress --rule="site.com/example=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": "", "usag...
Create a service to expose the replicated wordpress application on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose rs wordpress --port=9000 --target-port=300100 ``` 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...
Forward port 5432 from localhost and IP 10.19.21.23 to port 5000 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 5432:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Update the cluster field in the admin-context context to "edge-cluster"
Command: ```bash kubectl config set contexts.admin-context.cluster edge-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 wa...
import the log_level key from the config map named namespace-config and set it as an environment variable in the log-aggregator-deployment deployment
Command: ```bash kubectl set env --keys=log_level --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 defi...
Autoscale the replication controller "api" with a minimum of 1 pod, a maximum of 3 pods, and a target CPU utilization of 90%
Command: ```bash kubectl autoscale rc api --max=3 --cpu-percent=90 ``` 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...
Edit the service "logging-service" using the "micro" editor.
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/logging-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variable...
Add a taint with key 'datacenter' on nodes having label release=beta.
Command: ```bash kubectl taint node -l release=beta datacenter=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": "", "usag...
Create a new ClusterIP service named inventory-service-clusterip that maps port 9090 of the service to port 8081 of the pod.
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=9090:8081 ``` 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": "-...
Show all logs from the monitoring-pod pod written in the last hour
Command: ```bash kubectl logs --since=1h 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 an autoscaling policy for the deployment "cdn"
Command: ```bash kubectl autoscale deployment cdn --min=6 --max=13 ``` 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 'app-config-dev' in the current namespace
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/profiles/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 resource limits and requests for all containers in the "hazelcast" deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=2,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 request...
Get the output from running the 'geth version' command in code-explorer from the pod api-service-pod
Command: ```bash kubectl exec api-service-pod -c code-explorer -- geth 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...
List deployments in JSON output format for the "v2.0.0" version of the "legacy-apps" API group
Command: ```bash kubectl get deployments.v2.0.0.legacy-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 wil...
Forward local port 5432 to port 9090 in the cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5432: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 au...
Forward port 8088 on all addresses to port 3000 in the pod "cdn-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-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 criteria, a pod w...
Copy the file "foo" from the "/tmp" directory of the "task-processor-pod-17" pod in the "kubeapps" namespace to the "/etc/kubernetes" directory locally.
Command: ```bash kubectl cp kubeapps/task-processor-pod-17:/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Update the image version (tag) of a single-container pod to v4.
Command: ```bash kubectl get pod web-app-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ k...
Output the modified 'log-aggregator-deployment' deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/log-aggregator-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 ...
Create a deployment named 'my-dep' using the 'node' image and command 'node'.
Command: ```bash kubectl create deployment my-dep --image=node -- node ``` 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...
Copy a local file to a remote pod in a given namespace
Command: ```bash kubectl cp :/tmp/foo kubeapps/payment-gateway-pod-19:/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 k...
Open the "notification-service" service for editing using the "nvim" editor
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/notification-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment vari...
Create a new ClusterIP service named messaging-service-clusterip that listens on port 9090 and forwards traffic to port 8443.
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=9090:8443 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-...
Print the list of supported namespaced resources
Command: ```bash kubectl api-resources --kindspaced=true ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Execute the 'elasticsearch' command in the first container of the logging-service pod and display the output.
Command: ```bash kubectl exec svc/logging-service -- elasticsearch ``` 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...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 5000 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 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 crit...
import the 'secret_key' key from the 'app-config' config map and set it as an environment variable in the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-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 definiti...
Create an ingress resource named 'ingress1' with the following rules:
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8089" \ --rule="module.com/admin*=svc2:http" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--outpu...
Forward port 9090 on all addresses to port 8888 in the pod named log-aggregator-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 9090: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 po...
Create a service for the replication controller specified in "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=7000 --target-port=800000 ``` 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...
Forward traffic from local port 8080 to port 8080 in the pod
Command: ```bash kubectl port-forward pod/api-service-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 au...
Set the cluster field in the my-context context to galaxy-cluster
Command: ```bash kubectl config set contexts.cluster-2-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value ...
Create a copy of the 'gateway-pod' by adding a 'debug' container, changing the 'gateway-pod' container image to 'debian', and changing the images for the 'database' container to 'mysql:5.7' and the 'cache' container to 'redis:alpine'.
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-memcached --image=debian --set-image=database=mysql:5.7,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by reso...
Add a taint to nodes with the label "team=devops"
Command: ```bash kubectl taint node -l team=devops hardware=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": "", "usage":...
Create a copy of the log-aggregator-pod with a debug container and change the container images to debian, database=mysql:5.7, and app=app:debug.
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-app --image=debian --set-image=database=mysql:5.7,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 resource...
Scale the 'backend-service-replicaset' replica set to 7 replicas
Command: ```bash kubectl scale --replicas=7 rs/backend-service-replicaset ``` 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,...
Create a new secret named 'tls-certificate-secret' and populate it with keys for each file in the 'path/to/parameters' folder.
Command: ```bash kubectl create secret generic tls-certificate-secret --from-file=path/to/parameters ``` 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 bas...
Create an ingress called 'private-service-ingress' that directs requests to website.com/bar to a service named svc1 listening on port 8443, and use a TLS secret named "my-cert" to secure the connection.
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/bar=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": "...
Create a copy of the gateway-pod and change all container images to mongo, then launch a debug container inside the copy.
Command: ```bash kubectl debug gateway-pod --copy-to=debug-image-app --set-image=*=mongo ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resou...
Run the 'wp' command inside the 'log-aggregator-pod' pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -- wp ``` 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.kub...
Set the resource request and limits for all containers in the 'centos' deployment, with a limit of 200m CPU and 512Mi memory, and a request of 2 CPU and 512Mi memory.
Command: ```bash kubectl set resources deployment centos --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=512Mi ``` 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 requeste...
Create a new secret named database-secret with keys for each file in the specified folder
Command: ```bash kubectl create secret generic database-secret --from-file=path/to/settings ``` 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 basename of ...
Expose the deployment 'php' as a service on port 80, connecting to the containers on port 8000
Command: ```bash kubectl expose deployment php --port=80 --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 po...
Get the output from rocket-ranger from the pod proxy-service-pod
Command: ```bash kubectl attach proxy-service-pod -c rocket-ranger ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Create a copy of the security-service-pod pod with the name my-debugger, and change all container images to mysql
Command: ```bash kubectl debug security-service-pod --copy-to=my-debugger --set-image=*=mysql ``` 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 ...
Update the service account of the "load-balancer-deployment" deployment to "vault"
Command: ```bash kubectl set serviceaccount deployment load-balancer-deployment vault ``` 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: `kubect...
Set the cpu and memory resource limits for the nginx container in the 'wordpress' deployment to "500m" and "512Mi" respectively.
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=500m,memory=512Mi ``` 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 u...
Create an ingress called 'service-ingress' with a rule that directs requests from testing.com/example to svc1:8083
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/example=svc1:8083,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": "", "...
exec into the pod named "proxy-server-pod" and execute the command "geth" using the container "time-machine"
Command: ```bash kubectl exec proxy-server-pod -c time-machine -- 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...
Create a job named "backup" using the golang image and run the command "go"
Command: ```bash kubectl create job backup --image=golang -- go ``` 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|y...
Listen on port 8088 on all addresses and forward the traffic to port 6379 inside the api-service-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8088: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 w...
Open the 'authentication-service' service for editing using the 'sublime' editor
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/authentication-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment...
Get the output from running the 'elasticsearch-plugin --list' command in the stardust-shuttle container of the media-stream-pod pod
Command: ```bash kubectl exec media-stream-pod -c stardust-shuttle -- elasticsearch-plugin --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Cont...
Add a taint to the 'backup-node-14' node with the key 'dedicated', value 'special-user', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes backup-node-14 dedicated=special-user: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...
Update the annotation 'security-scan-status' of the 'monitoring' pod to 'pass'
Command: ```bash kubectl annotate pods monitoring security-scan-status=pass ``` 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 a...
Deny the Certificate Signing Request with the name "csr-worker-3"
Command: ```bash kubectl certificate deny csr-worker-3 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kubectl ...
Expose a deployment named "python" as a service, serving on port 3001 and connecting to the containers on port 300000
Command: ```bash kubectl expose deployment python --port=3001 --target-port=300000 ``` 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 specifi...
Remove the 'description' annotation from the 'proxy' pod
Command: ```bash kubectl annotate pods proxy description- ``` 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 string va...
Set the environment variables with the prefix RAILS_ from your local shell into the deployment named analytics-platform-deployment on the server
Command: ```bash env | grep RAILS_ | kubectl set env -e - 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 definitions in one or more...
Get the output from running the 'npm --version' command inside the astro-container of the database-pod pod.
Command: ```bash kubectl exec database-pod -c astro-container -- 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 omit...
Display the resource usage metrics for all pods in the 'external-caching-service' namespace.
Command: ```bash kubectl top pod --namespace=external-caching-service ``` 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: `kubec...
Create a new NodePort service named api-service-nodeport that maps port 8888 on all cluster nodes to port 8010 on the service.
Command: ```bash kubectl create service nodeport api-service-nodeport --tcp=8888:8010 ``` 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":...
Set the service account of the deployment named "notification-handler-deployment" to "kube-proxy"
Command: ```bash kubectl set serviceaccount deployment notification-handler-deployment kube-proxy ``` 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 Syn...
Create a job named indexing using the amazonlinux image with the command "/bin/bash -c 'echo Hello'"
Command: ```bash kubectl create job indexing --image=amazonlinux -- /bin/bash -c "echo 'Hello ``` 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": ...
delete the pods and services with the names "chat-app" and "monitoring"
Command: ```bash kubectl delete pod,service chat-app monitoring ``` 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 selec...
Import specific keys from a config map into environment variables for a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --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 var...
Create a new config map named app-config-prod based on the settings folder located at path/to/settings.
Command: ```bash kubectl create configmap app-config-prod --from-file=path/to/settings ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basen...
Update the annotation 'release-notes' of the pod named 'foo' with the value 'https://example.com/release-notes/v2.5.1', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods foo release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can...
Copy the local file /tmp/foo to the /etc/kubernetes directory of the pod named database-pod-2 in the monitoring namespace.
Command: ```bash kubectl cp /tmp/foo monitoring/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, use the k...
Display metrics for the specified pod and its containers.
Command: ```bash kubectl top pod chat-app-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 redis_host key from the app-config config map to the mydeployment deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config 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 or ...
Create a pod disruption budget named auth-service-pdb that will select all pods with the project=my-project label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=project=my-project --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-availa...
Set the resource request and limits for all containers in the go deployment.
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=50m,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, b...
Create a cluster role named "bar" with the ability to update services resources, specifically the "mail-server" and "api-server" resources.
Command: ```bash kubectl create clusterrole bar --verb=update --resource=services --resource-name=mail-server --resource-name=api-server ``` 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]...
Set the TLS server name for the cloud-cluster cluster entry to "staging-cluster"
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=staging-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifi...
import the EXTERNAL_API_URL key from the log-config config map and set it as an environment variable for the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/log-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Add a taint with key 'disktype' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice disktype=dev-node-4:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Get output from running the 'geth attach' command from the e-commerce-pod.
Command: ```bash kubectl exec e-commerce-pod -- 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 omitted, use the kubect...
Forward port 8000 on all addresses to port 3000 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 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 po...
Create a new config map named app-secrets and populate it with specified keys and files
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/options/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 creating a ...
Copy the directory /tmp/foo_dir from the remote pod named ingress-controller-pod-8 in the kubeapps namespace to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp kubeapps/ingress-controller-pod-8:/tmp/foo_dir /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, ...
Approve CSR 'csr-node-2' by running the command 'kubectl certificate approve csr-node-2'
Command: ```bash kubectl certificate approve csr-node-2 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attribu...
Create a pod disruption budget that selects pods with a specific label and requires a minimum number of them to be available at all times.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=component=web --min-available=4 ``` 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 ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/db-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a cluster role named "custom_role" with specific resource names allowed
Command: ```bash kubectl create clusterrole custom_role --verb=list --resource=services --resource-name=app-worker-1 --resource-name=web-frontend ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Forward port 8888 on your local machine to port 9090 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888: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...
Show the resource utilization metrics for the monitoring-pod and its containers
Command: ```bash kubectl top pod monitoring-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 po...
Get output from running the 'geth attach' command inside the monitoring-pod
Command: ```bash kubectl exec monitoring-pod -- 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 omitted, use the kubect...
Roll back to the previous deployment of a resource
Command: ```bash kubectl rollout undo deployment/services ``` What it does: Manage the rollout of a resource. Valid resource types include: Syntax: `kubectl rollout SUBCOMMAND`