prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the 'frontend-deployment' deployment by adding a new environment variable 'MONGO_URI' with the value 'mongodb://localhost:27017/mydb'.
Command: ```bash kubectl set env deployment/frontend-deployment MONGO_URI=mongodb://localhost:27017/mydb ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
Create a port forwarding from port 9090 on localhost and IP address 10.19.21.23 to port 6379 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 9090: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 ...
Set the environment variables on a deployment based on the local shell environment variables that match a certain pattern.
Command: ```bash env | grep RAILS_ | kubectl set env -e - deployment/proxy-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 variable definitions in one or more pod ...
Forward port 5432 from your local machine to port 9090 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Create a Pod Disruption Budget named api-service-pdb that will select all pods with the label version=v2 and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=version=v2 --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 pod disruption budget named statefulset-pdb that will select all pods with the app=nginx label and require at minimum 70% of the pods selected to be available at any point in time
Command: ```bash kubectl create pdb statefulset-pdb --selector=app=nginx --min-available=70% ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry-run=server|...
Forward port 6379 from the local machine to port 3000 in the pod named "security-service-pod", allowing access from both localhost and IP address 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 6379: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 th...
Listen on port 8088 locally and forward data to/from port 8081 in the pod selected by the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 8088 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Create a copy of the chat-app-pod adding a debug container and changing container images
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-memcached --image=debian --set-image=proxy=nginx:1.21,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Update the pod 'gateway' by adding or updating the annotation 'owner' with the value 'alice smith'
Command: ```bash kubectl annotate pods gateway owner='alice smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary ...
delete the pods and services with the names "foo" and "email"
Command: ```bash kubectl delete pod,service foo email ``` 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. Some ...
Get the output from running the 'kafka-console-producer --broker-list localhost:9092 --topic test' command in the warp-drive container of the backend-pod pod.
Command: ```bash kubectl exec backend-pod -c warp-drive -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "de...
Update the image of all containers in a daemonset named "test" to "openjdk:16.0.2"
Command: ```bash kubectl set image daemonset test *=openjdk:16.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: `kube...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/properties/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...
Create a deployment named 'registry' using the 'ethereum/client-go' image and expose port 7000.
Command: ```bash kubectl create deployment registry --image=ethereum/client-go --port=7000 ``` 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 for...
Open the "analytics-service" service for editing using the emacs editor
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/analytics-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 variab...
Partially update the edge-node-10 node by changing the password to "new-password" using a strategic merge patch in YAML format.
Command: ```bash kubectl patch node edge-node-10 -p $'stringData:\n password: new-password' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]`...
Create a job named "log-processing-job" using the Python image and running the command "pip --version"
Command: ```bash kubectl create job log-processing-job --image=python -- pip --version ``` 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...
Get output from running the 'irb' command from pod auth-service-pod
Command: ```bash kubectl exec auth-service-pod -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kube...
List the replication controller 'web', the service 'monitoring-rc', and the pod 'log-aggregator-pod'
Command: ```bash kubectl get rc/web service/monitoring-rc pods/log-aggregator-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 name...
Get the output of the 'npm --version' command from the container named 'mycontainer' running in the pod named 'payment-gateway-pod'.
Command: ```bash kubectl exec payment-gateway-pod -c mycontainer -- 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 o...
Create a job that runs a specific command
Command: ```bash kubectl create job scaling-job --image=ethereum/client-go -- geth version ``` 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": "Ou...
List the rc/web resource, the service/proxy-service-rc resource, and the pods/frontend-pod resource by their names
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/frontend-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespa...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl exec -n istio-system web-app-pod-1 -- tar cf - /tmp/foo_dir | tar xf - -C /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": "Cont...
Create a new LoadBalancer service named 'my-lbs' that maps port 3001 on the ClusterIP to port 8181 on the pods.
Command: ```bash kubectl create service loadbalancer my-lbs --tcp=3001: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": "...
Create a job named "certificate-renewal" using the "mongo" image, and run the "mongo --version" command inside the job.
Command: ```bash kubectl create job certificate-renewal --image=mongo -- mongo --version ``` 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": "Outp...
Forward local traffic from port 5000 to port 8888 in the pod 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 5000 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 au...
Create a new NodePort service named vpn-service-nodeport with the mapping of port 8081 on the node to port 8083 on the pod
Command: ```bash kubectl create service nodeport vpn-service-nodeport --tcp=8081:8083 ``` 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":...
Forward traffic from a local port to port 5432 in the backend-pod.
Command: ```bash kubectl port-forward pod/backend-pod :5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automatica...
Create an ingress called 'rontend-ingress' that routes requests from website.com/input to svc1:8443 with a tls secret 'my-cert'
Command: ```bash kubectl create ingress rontend-ingress --rule="website.com/input=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": "", "us...
Execute the 'mongo' command inside the 'analytics-pod' and retrieve the output
Command: ```bash kubectl exec analytics-pod -- mongo ``` 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.kuber...
Set the service account of the deployment "notification-handler-deployment" to "tekton"
Command: ```bash kubectl set serviceaccount deployment notification-handler-deployment tekton ``` 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:...
Update the annotation 'scaling-policy' for pod 'email' with the value 'auto-horizontal-scaling', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods email scaling-policy='auto-horizontal-scaling' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger tha...
Retrieve all deployments in the "feature-branch-2.3.0" version of the "backup-apps" API group in YAML format
Command: ```bash kubectl get deployments.feature-branch-2.3.0.backup-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 name...
Display only the most recent 3 lines of output for a specific pod
Command: ```bash kubectl logs --tail=3 web-app-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": "-c",...
Create a new config map named 'ui-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/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 creatin...
Use kubectl to forward local traffic from port 8081 to port 8888 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8081 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...
Create a role named "custom_role" with the following permissions:
Command: ```bash kubectl create role custom_role --verb=get --resource=pods --resource-name=mail-server --resource-name=auth-proxy ``` 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|clie...
Update the image of all deployments and replication controllers with the name 'amazonlinux' to 'amazonlinux:2'
Command: ```bash kubectl set image deployments,rc amazonlinux=amazonlinux:2 --all ``` 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)...
Create a cluster role binding with the name 'default_role' using the 'default_role' cluster role, and include 'user1', 'user2', and 'group1' as users and group.
Command: ```bash kubectl create clusterrolebinding default_role --clusterrole=default_role --user=user1 --user=user2 --group=group1 ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [-...
Create a new secret named 'my-secret' using the properties.env file.
Command: ```bash kubectl create secret generic my-secret --from-env-file=path/to/properties.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename...
Execute the 'mongo' command in the 'warp-drive' container of the 'database-pod' pod.
Command: ```bash kubectl exec database-pod -c warp-drive -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Create a new secret named api-key-secret from the settings.env file located at the path/to directory.
Command: ```bash kubectl create secret generic api-key-secret --from-env-file=path/to/settings.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basen...
Start a pod named "hazelcast" with the nginx image and expose port 8010.
Command: ```bash kubectl run hazelcast --image=nginx --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 flags: "flag": "--fi...
Embed the certificate authority data for the "app-cluster" cluster entry by running the `kubectl config set-cluster` command with the `--embed-certs` flag and specifying the path to the certificate authority file using the `--certificate-authority` flag.
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/web-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-c...
Begin streaming the logs of the "cosmic-container" container in the "api-service-pod" pod
Command: ```bash kubectl logs -f -c cosmic-container api-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": "--containe...
Forward local port 5000 to port 8088 in the analytics-pod pod
Command: ```bash kubectl port-forward pod/analytics-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 auto...
Expose a service for a replication controller specified in a file, with a specific target port for connecting to containers
Command: ```bash kubectl expose -f centos-controller.yaml --port=7000 --target-port=8000 ``` 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 s...
Update the pod 'log-aggregator' by setting the annotation 'description' to 'Web server for marketing site', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods log-aggregator description='Web server for marketing site' ``` 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 b...
Update the server field for the cluster "cluster-alpha" to "https://1.2.3.4"
Command: ```bash kubectl config set clusters.cluster-alpha.server https://1.2.3.4 ``` 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 ...
Retrieve the output of the 'kafka-topics --list' command from the analytics-pod using the first container.
Command: ```bash kubectl exec analytics-pod -- kafka-topics --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Create a Pod Disruption Budget named worker-pdb that selects all pods with the component=web label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget worker-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 [--dr...
Create a service for the replicated php pod, which serves on port 8082 and connects to the containers on port 637900
Command: ```bash kubectl expose rc php --port=8082 --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. A ...
Delete the pods and services with the names "chat-app" and "proxy-server"
Command: ```bash kubectl delete pod,service chat-app 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 sel...
Use the Micro editor to edit the configuration of the "db-service" service
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/db-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, or...
Expose the deployment named "ruby" as a service, serving on port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment ruby --port=7000 --target-port=808800 ``` 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 a pod disruption budget named logging-pdb that selects all pods with the region=us-east label and requires a minimum of one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=region=us-east --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 [--...
Create a new config map named app-config-dev using the files in the folder specified by the path/to/data.
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/data ``` 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 basename o...
Copy the local file /tmp/foo to the remote pod auth-service-pod-11 in the namespace cert-manager, and place it in the directory /etc/kubernetes.
Command: ```bash kubectl cp /tmp/foo cert-manager/auth-service-pod-11:/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, us...
Remove the environment variable ENV from the container 'cyber-sleuth' in all deployment configurations.
Command: ```bash kubectl set env deployments --all --containers="cyber-sleuth" ENV- ``` 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 ...
Create a single ingress named 'app2-ingress' that routes requests for 'testing.com/bar' to service 'svc1' at port '8089' and uses the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/bar=svc1:8089,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":...
Start port forwarding from local port 3000 to port 8088 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Start a centos pod and expose port 8089
Command: ```bash kubectl run hazelcast --image=centos --port=8089 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Configure auto scaling for the deployment "analytics" with a minimum of 7 pods and a maximum of 14 pods.
Command: ```bash kubectl autoscale deployment analytics --min=7 --max=14 ``` 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...
Add a taint with the key 'datacenter' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha datacenter=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": "", "...
Add a taint with the key 'datacenter' to nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice datacenter=gpu-node-12: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": "", ...
Create a new config map named 'app-secrets' using the files '/path/to/properties/file1.txt' and '/path/to/parameters/file2.txt' as the values for the keys 'conf' and 'data', respectively.
Command: ```bash kubectl create configmap app-secrets --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Create a copy of the "web-app-pod" pod, changing the command of the "cyber-sleuth" container.
Command: ```bash kubectl debug web-app-pod -it --copy-to=my-custom-dbg --container=cyber-sleuth -- 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 defaul...
Start a postgres pod named 'nginx' with the postgres image, but override the spec with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "rc-1.1.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] -- [CO...
Create a new config map named app-settings with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/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...
taint the node labeled with 'namespace=mynamespace' with the 'hardware' key and the value 'k8s-node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l namespace=mynamespace 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": "", "us...
Update the pod 'payment' with the annotation 'team' and the value 'frontend-team', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods payment 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 inclu...
Copy a file from a pod to a local directory
Command: ```bash kubectl cp kubeapps/monitoring-agent-pod-6::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Create a deployment named "wordpress" using the "hazelcast" image and configure it to have 7 replicas
Command: ```bash kubectl create deployment wordpress --image=hazelcast/hazelcast --replicas=7 ``` 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 ...
Begin streaming the logs of the cosmic-container container in the gateway-pod pod
Command: ```bash kubectl logs -f -c cosmic-container gateway-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", ...
Listen on port 6379 locally and forward it to port 3000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-pod 6379:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a debug copy of the "email-service-pod" by changing all container images to "confluentinc/cp-kafka"
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-app --set-image=*=confluentinc/cp-kafka ``` 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 ...
Scale the 'monitoring' deployment, with a minimum of 2 pods and a maximum of 9 pods
Command: ```bash kubectl autoscale deployment monitoring --min=2 --max=9 ``` 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...
Set up autoscaling for the 'foo' replication controller with a maximum of 6 pods and a target CPU utilization of 90%.
Command: ```bash kubectl autoscale rc foo --max=6 --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...
Return the snapshot logs from the 'frontend-pod-1' container of the 'payment-processor-deployment' deployment.
Command: ```bash kubectl logs deployment/payment-processor-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: ...
Get the output from running the 'mongo --version' command in the lunar-launcher container of the auth-service-pod pod.
Command: ```bash kubectl exec auth-service-pod -c lunar-launcher -- mongo --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...
Forward all traffic from port 5432 to port 8080 in the 'backend-pod' pod, listening on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 5432: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 ...
Import the environment variables from a secret into a deployment named "scheduler-app-deployment"
Command: ```bash kubectl set env --from=secret/private-key-secret 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 definitions in one or m...
Check if the current user has permission to list the "image-processing-job" job in the "logging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-job -n logging ``` 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 U...
Copy the local file '/tmp/foo' to the '/etc/kubernetes' directory in a remote pod named 'logging-agent-pod-7' located in the 'kube-system' namespace.
Command: ```bash kubectl cp /tmp/foo kube-system/logging-agent-pod-7:/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...
Autoscale the 'chat-app' replication controller with the target CPU utilization set to 50%
Command: ```bash kubectl autoscale rc chat-app --max=6 --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...
Get output from running the `mongod` command in container `time-machine` within the `backend-pod` pod.
Command: ```bash kubectl exec backend-pod -c time-machine -- mongod ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Create a new config map named log-config from an env file
Command: ```bash kubectl create configmap log-config --from-env-file=path/to/profiles.env ``` 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 ba...
Update the annotation 'alert-email' of pod 'email' with the value 'alerts@example.com', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods email alert-email='alerts@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=database_url --from=configmap/kube-system-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 ...
Import the 'config_file_path' key from the 'app-config-dev' config map into the 'authentication-service-deployment' deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-dev 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 ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-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...
Execute the 'mongo --version' command in the 'mycontainer' container of the 'vpn-service-pod' pod and retrieve the output
Command: ```bash kubectl exec vpn-service-pod -c mycontainer -- mongo --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 omi...
Create a deployment with specific image and replica count
Command: ```bash kubectl create deployment mattermost --image=mcr.microsoft.com/dotnet/core/runtime --replicas=5 ``` 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": ""...
Set up autoscaling for the deployment "log-aggregator". The minimum number of pods is set to 2 and the maximum is set to 15.
Command: ```bash kubectl autoscale deployment log-aggregator --min=2 --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 th...
Forward port 3000 on both localhost and the IP address 10.19.21.23 to port 6379 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 3000: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 p...
Copy the local file "/tmp/foo_dir" to the remote pod "load-balancer-pod-9" at the "/tmp/bar" location, specifically in the container named "payment-gateway".
Command: ```bash kubectl cp /tmp/foo_dir load-balancer-pod-9::/tmp/bar -c payment-gateway ``` 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...
Forward traffic from port 8000 on your local machine to port 5432 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Set the service account of the deployment named "authentication-service-deployment" to "metrics-server"
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment metrics-server ``` 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), statefulse...
Create a new ExternalName service named external-dns-service that points to example-domain.com
Command: ```bash kubectl create service externalname external-dns-service --external-name example-domain.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 reference servi...