prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/api-config deployment/load-balancer-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...
List deployments in YAML output format for the "custom-apps" API group with the version "legacy-1.0.0"
Command: ```bash kubectl get deployments.legacy-1.0.0.custom-apps -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 y...
Set the CPU limits to "2" and memory limits to "1Gi" for the "mongo" container in the "nginx" deployment.
Command: ```bash kubectl set resources deployment mongo -c=nginx --limits=cpu=2,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its ...
Set the service account of the deployment named "proxy-service-deployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment kube-dns ``` 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: `kub...
Configure a new exec auth plugin for the "jane.smith" entry
Command: ```bash kubectl config set-credentials jane.smith --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: ...
Set the resource request and limits for all containers in the "php" deployment
Command: ```bash kubectl set resources deployment php --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=128Mi ``` 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, ...
Create a new ingress resource called 'public-api-ingress' with a rule that directs requests for 'website.com/module' to the service 'svc1:8083'
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/module=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": "",...
list the replication controller named "web", the service named "frontend-rc", and the pod named "chat-app-pod"
Command: ```bash kubectl get rc/web service/frontend-rc pods/chat-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced y...
Autoscale the "analytics" deployment with a minimum of 3 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment analytics --min=3 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that us...
Create a pod disruption budget named messaging-pdb that selects pods with the app=rails label and requires at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=app=rails --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 [--dry...
Create a copy of the api-service-pod pod and name it my-debugger, changing all the container images to nginx
Command: ```bash kubectl debug api-service-pod --copy-to=my-debugger --set-image=*=nginx ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resou...
Create a service for the replicated Wordpress using a ReplicaSet
Command: ```bash kubectl expose rs wordpress --port=5001 --target-port=330600 ``` 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...
Execute the command 'elasticsearch --version' within the 'cyber-sleuth' container of the 'database-pod' pod
Command: ```bash kubectl exec database-pod -c cyber-sleuth -- 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. ...
Partially update a node using a strategic merge patch, providing the patch in JSON format.
Command: ```bash kubectl patch node node-1 -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]` Helpful f...
import the LOG_LEVEL key from the app-config ConfigMap and set it as an environment variable in the gateway-deployment deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Forward traffic from port 8081 on all addresses to port 5432 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 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 ...
Add a taint with key 'zone' and value 'web-node-8:PreferNoSchedule' on nodes having label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha zone=web-node-8: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"...
Update the label of a pod to mark it as unhealthy
Command: ```bash kubectl label pods email unhealthy=true ``` 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": "...
Add a taint with the key 'cpu-type' and value 'kube-master-9:PreferNoSchedule' on nodes that have the label 'tier=frontend'.
Command: ```bash kubectl taint node -l tier=frontend cpu-type=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Update the 'monitoring' pod by adding the annotation 'monitoring-tool' with the value 'Prometheus'.
Command: ```bash kubectl annotate pods monitoring monitoring-tool=Prometheus ``` 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 ...
Create a service for a pod named "vpn-service-pod" with the name "frontend" that serves on port 444.
Command: ```bash kubectl expose pod vpn-service-pod --port=3000 --name=frontend ``` 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 ...
Create an ingress called 'api-gateway-ingress' that directs requests to site.com/bar to svc1:8181 with a tls secret called "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="site.com/bar=svc1:8181,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": "", "usa...
Start a port-forwarding service to listen on port 9090 locally, and forward data between port 9090 and port 8080 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 9090 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 a...
Create a NodePort service named auth-service-nodeport that maps port 8082 on all cluster nodes to port 9090 on the service.
Command: ```bash kubectl create service nodeport auth-service-nodeport --tcp=8082: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"...
Use the "emacs" editor instead of the default editor to edit the "email-service" service
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/email-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 variables,...
Create a copy of the payment-gateway-pod and open a shell in the debug-image-1 container with the command "sh"
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-1 --container=warp-drive -- 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 ...
Set the CPU limit to 200m and memory limit to 512Mi, and set the CPU request to 100m and memory request to 512Mi for all containers in the 'runtime' deployment.
Command: ```bash kubectl set resources deployment runtime --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 requ...
Create a debug copy of web-app-pod by adding a debug container and changing container images
Command: ```bash kubectl debug web-app-pod -it --copy-to=my-custom-dbg --image=debian --set-image=worker=my-custom-worker:1.2.3,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 r...
Execute the 'go version' command inside the web-app-pod pod.
Command: ```bash kubectl exec web-app-pod -- go 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 kubectl.ku...
Start a pod named 'hazelcast' using the 'confluentinc/cp-kafka' image and expose port 8010
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8010 ``` 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 flag...
Forward local port 5000 to port 8088 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 5000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
import the `debug_mode` key from the `app-secrets` config map and apply it to the `frontend-deployment` deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-secrets deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Edit the search-engine-deployment YAML configuration and save the modified config in its annotation
Command: ```bash kubectl edit deployment/search-engine-deployment -o yaml --save-config ``` 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 en...
Update the 'analytics' pod with the label 'role' and set it to 'cache'
Command: ```bash kubectl label pods analytics role=cache ``` 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 secret named jwt-secret with keys for each file in the folder path/to/preferences
Command: ```bash kubectl create secret generic jwt-secret --from-file=path/to/preferences ``` 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 th...
Copy the directory "/tmp/foo_dir" from the local machine to the directory "/etc/kubernetes_dir" in a remote pod named "message-broker-pod-15" in the default namespace.
Command: ```bash kubectl cp :/tmp/foo_dir message-broker-pod-15:/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 ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/ui-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 ...
Import the 'external_api_url' key from the 'api-config' ConfigMap and set it as an environment variable for the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/api-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...
Remove all the taints with the key 'zone' from the 'gpu-node-12' node.
Command: ```bash kubectl taint nodes gpu-node-12 zone- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name...
Open the 'docker-registry' service for editing
Command: ```bash kubectl edit svc/docker-registry ``` 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 variables, or fall back to '...
Set the service account of the deployment "web-app-deployment" to "istio"
Command: ```bash kubectl set serviceaccount deployment web-app-deployment istio ``` 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: `kubectl set ...
Expose a replicated hazelcast as a service on port 80 connecting to containers on port 8000.
Command: ```bash kubectl expose rc hazelcast --port=8088 --target-port=700000 ``` 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 8000 on your local machine to port 8081 in the pod named "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 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 automa...
Rename a context in your kubeconfig file.
Command: ```bash kubectl config rename-context prod-context team-alpha-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will a...
Execute the 'ash' command inside the security-service-pod container named time-machine and get the output.
Command: ```bash kubectl exec security-service-pod -c time-machine -- 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, ...
Copy the ~/.config/kube file from the backend-pod-13 pod in the ingress-nginx namespace to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp ingress-nginx/backend-pod-13:~/.config/kube /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, ...
Create an ingress resource called 'public-api-ingress' with a routing rule that directs requests from testing.com/module to a service named 'svc1' on port 9090
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/module=svc1:9090,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": "",...
Retrieve the previous terminated logs of the "nebula-navigator" container from the "database-pod" pod.
Command: ```bash kubectl logs -p -c nebula-navigator database-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",...
Embed the certificate authority data for the app-cluster cluster entry and specify the path to the certificate authority file as ~/.kube/kube-cluster-2/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config se...
Forward local port 5432 to port 5000 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-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 criteria, a pod will be selected autom...
execute the 'mysql' command inside the frontend-pod pod
Command: ```bash kubectl exec frontend-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...
Set up automatic scaling for the deployment named "api"
Command: ```bash kubectl autoscale deployment api --min=5 --max=10 ``` 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...
Set the cluster field in the 'app-1-context' context to 'prod-cluster'
Command: ```bash kubectl config set contexts.app-1-context.cluster prod-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...
Partially update the gpu-node-12 node by specifying the patch as JSON. Set the value of "someField" to "newValue".
Command: ```bash kubectl patch node gpu-node-12 -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]` Help...
update the security scan status annotation of the pod specified in the "setup.json" file to "pass"
Command: ```bash kubectl annotate -f setup.json 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 arb...
Create a new ExternalName service named 'external-geolocation-service' with the external name 'document-company.com'
Command: ```bash kubectl create service externalname external-geolocation-service --external-name document-company.com ``` 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 refer...
Output the modified frontend-deployment deployment in YAML format, with the SMTP_USERNAME environment variable set to "your-username", without altering the object on the server.
Command: ```bash kubectl set env deployment/frontend-deployment SMTP_USERNAME=your-username -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 mor...
Change the size of the 'bar' deployment to 5 by scaling it from the current size of 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/bar ``` 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...
Forward local port 8081 to port 5000 in a pod selected by the 'web-app-deployment' deployment
Command: ```bash kubectl port-forward deployment/web-app-deployment 8081 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 s...
Create an ingress named 'ingress1' with two rules:
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8084" \ --rule="bar.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": "--output",...
Create a cluster role named "view" with the ability to list configmaps and access specific configmaps named "machine-learning" and "app-worker-1"
Command: ```bash kubectl create clusterrole view --verb=list --resource=configmaps --resource-name=machine-learning --resource-name=app-worker-1 ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Return the logs of the previous terminated "quantum-quark" container from the "vpn-service-pod" pod.
Command: ```bash kubectl logs -p -c quantum-quark vpn-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",...
Create an autoscaling policy for the 'monitoring' deployment with a minimum of 5 pods and a maximum of 15 pods.
Command: ```bash kubectl autoscale deployment monitoring --min=5 --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 u...
Create a service for a replicated nginx using replica set, which serves on port 8081 and connects to the containers on port 8443
Command: ```bash kubectl expose rs nginx --port=8081 --target-port=844300 ``` 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. ...
Copy the directory "/tmp/foo_dir" from a remote pod to the local directory "/tmp/bar"
Command: ```bash kubectl cp kube-system/monitoring-agent-pod-6:/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...
Update the 'proxy' pod with the label 'app' and the value 'myapp'
Command: ```bash kubectl label pods proxy app=myapp ``` 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 tr...
Forward traffic from port 8888 on all addresses to port 5000 in the 'api-service-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8888: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 w...
Create a cluster role named "foo" with permissions to use, delete and connect to services
Command: ```bash kubectl create clusterrole foo --verb=use,delete,connect --resource=services ``` 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": "--output", "shor...
Create a service for the ruby deployment, which serves on port 9091 and connects to the containers on port 330600
Command: ```bash kubectl expose deployment ruby --port=9091 --target-port=330600 ``` 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...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/monitoring-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
Taint nodes with the label version=v1.0.0 and add a taint with the key 'dedicated' and value 'monitoring-node-15:PreferNoSchedule'.
Command: ```bash kubectl taint node -l version=v1.0.0 dedicated=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Set the service account of the deployment named "monitoring-stack-deployment" to "argocd".
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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: `ku...
Update all the containers of the "development" DaemonSet to use the "mysql:5.7.35" image.
Command: ```bash kubectl set image daemonset development *=mysql:5.7.35 ``` 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: ...
Create a cluster role binding named 'bar' that assigns the 'bar' cluster role to the 'app-operator' user, 'sysadmin' user, and 'security-auditors' group.
Command: ```bash kubectl create clusterrolebinding bar --clusterrole=bar --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname]...
Forward local port 8888 to port 8088 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8888 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new LoadBalancer service named gateway-lb that forwards traffic from port 5432 to port 8181
Command: ```bash kubectl create service loadbalancer gateway-lb --tcp=5432:8181 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default...
Import the 'my-example-key' keys from the 'app-secrets' config map to the 'cache-cluster-deployment' deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-secrets 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 defin...
Forward data between ports 8888 and 5000 in a local machine and a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8888 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 po...
Update the pod 'log-aggregator' with the annotation 'team' and the value 'frontend team'
Command: ```bash kubectl annotate pods log-aggregator 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 ar...
Create a deployment named 'gateway' using the 'redis' image and the command 'redis-cli'
Command: ```bash kubectl create deployment gateway --image=redis -- redis-cli ``` 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: ...
Create a debug image of the proxy-server-pod with the container named warp-drive and change the command to `sh`
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-api --container=warp-drive -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by d...
Add a taint with key 'environment' on nodes having label app=web-app
Command: ```bash kubectl taint node -l app=web-app environment=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...
Expose a replication controller by creating a service based on the configuration file "hazelcast-controller.yaml", with the service serving on port 5001 and the pods targeted on port 909100.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=5001 --target-port=909100 ``` 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 ...
Add a taint with key 'hardware' on nodes having label cluster=my-cluster and the node name hardware=testing-node-11 with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l cluster=my-cluster 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": "", "...
import the 'log_level' key from the 'monitoring-config' config map to the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-config deployment/load-balancer-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 service for the 'alpine' replicated controller, serving on port 5000 and connecting to the containers on port 637900.
Command: ```bash kubectl expose rc alpine --port=5000 --target-port=637900 ``` 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....
Scale up the replication controller "backend" and set the maximum number of pods to 8
Command: ```bash kubectl autoscale rc backend --max=8 --cpu-percent=20 ``` 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...
Get the output from the quantum-quark container in the analytics-pod pod.
Command: ```bash kubectl attach analytics-pod -c quantum-quark ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Create a service for a Wordpress deployment, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment wordpress --port=80 --target-port=637900 ``` 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 specif...
Attach to the time-machine container in pod mypod to get the output.
Command: ```bash kubectl attach mypod -c time-machine ``` 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 k...
Forward local ports 5432 and 6000 to ports 8081 and 6000 in the pod selected by the deployment "email-server-deployment"
Command: ```bash kubectl port-forward deployment/email-server-deployment 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...
Auto scale the replication controller "database" with the desired number of pods between 1 and 5, and a target CPU utilization of 50%.
Command: ```bash kubectl autoscale rc database --max=5 --cpu-percent=50 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a LoadBalancer service named "proxy-service-lb" that maps port 8888 on the external IP to port 8888 on the pod
Command: ```bash kubectl create service loadbalancer proxy-service-lb --tcp=8888:8888 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Copy the local file ".config/kube" to the remote pod "worker-pod-4" in the namespace "logging" and place it in the "/tmp/bar" directory.
Command: ```bash kubectl cp ~/.config/kube logging/worker-pod-4::/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 service for the 'hazelcast' replica set, which serves on port 9000 and connects to the containers on port 909100
Command: ```bash kubectl expose rs hazelcast --port=9000 --target-port=909100 ``` 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...
Delete pods and services with the names "gateway" and "proxy-server"
Command: ```bash kubectl delete pod,service gateway proxy-server ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label sele...
Update the label of the pod 'chat-app' with the key 'release' and the value 'v2.0'
Command: ```bash kubectl label pods chat-app release=v2.0 ``` 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 an ingress called 'app-proxy-ingress' with a rule that directs requests from foo.com/bar to svc1:8088
Command: ```bash kubectl create ingress app-proxy-ingress --rule="foo.com/bar=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Remove the 'dedicated' taint from the 'kube-master-9' node.
Command: ```bash kubectl taint nodes kube-master-9 dedicated- ``` 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|ya...
Forward traffic from port 6379 on localhost and IP address 10.19.21.23 to port 9090 on the pod named proxy-server-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 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 cr...