prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a role named "default_role" that allows users to perform "use", "get", and "patch" operations on configmaps.
Command: ```bash kubectl create role default_role --verb=use --verb=get --verb=patch --resource=configmaps ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags...
Copy the service account secret file to a specific pod in a given namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ 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": "", "u...
import the database_url key from the monitoring-config config map and set it as an environment variable in the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/monitoring-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Update the pod 'database' with the annotation 'custom-label' and the value 'my-custom-value'
Command: ```bash kubectl annotate pods database custom-label=my-custom-value ``` 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 ...
Update the 'proxy-server' pod with the annotation 'last-deployment' and set its value to '2023-03-15'.
Command: ```bash kubectl annotate pods proxy-server last-deployment=2023-03-15 ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and includ...
Forward local port 5432 to port 9090 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-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 automa...
Create a new nginx pod with the php image, but override the pod's spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=php --overrides='{ "apiVersion": "legacy-1.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COM...
Create a new LoadBalancer service named log-aggregator-lb
Command: ```bash kubectl create service loadbalancer log-aggregator-lb --tcp=5000:8084 ``` 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", "...
Update the label of a pod to "status=unhealthy" using the information provided in "params.json"
Command: ```bash kubectl label -f params.json status=unhealthy ``` 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", "usa...
Copy a file from a local directory to a remote pod
Command: ```bash kubectl cp :/tmp/foo kube-node-lease/metrics-exporter-pod-10:/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, u...
Forward all incoming traffic from port 9090 on any IP address to port 8080 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-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 ...
Add a taint to the worker-node-3 node with the key 'hardware' and no value that prevents scheduling new pods on it
Command: ```bash kubectl taint nodes worker-node-3 hardware:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of...
Delete a pod using the specified configuration file
Command: ```bash kubectl delete -f ./docker-registry.yaml ``` 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. S...
Create an ingress called 'internal-ingress' that routes requests from website.com/input to svc1:8089 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/input=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": "", "u...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-secrets deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Start a pod named "hazelcast" using the "centos" image and expose port 8010.
Command: ```bash kubectl run hazelcast --image=centos --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": "--f...
import specific keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/api-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Create a new config map named app-config-dev with specified keys and file paths
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When ...
Create a service for the 'python' deployment, which serves on port 9000 and connects to the containers on port 700000
Command: ```bash kubectl expose deployment python --port=9000 --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 specifi...
Copy the local file '/tmp/foo' to the remote pod 'payment-gateway-pod-19' in the namespace 'openfaas', and save it as '/tmp/bar'.
Command: ```bash kubectl cp :/tmp/foo openfaas/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 ...
Create a job called 'report-generation-job' using the 'busybox' image
Command: ```bash kubectl create job report-generation-job --image=busybox ``` 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 ...
Get the logs from the pod named "log-aggregator-pod" with only one container
Command: ```bash kubectl logs log-aggregator-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 an ingress with specific rules and TLS secret to direct requests to a service
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.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": "...
Taint nodes with the label 'stack=tech-stack' with a taint key of 'special' and a value of 'storage-node-13', and set the effect to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l stack=tech-stack special=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Forward traffic from port 8888 on all addresses to port 6379 in the pod named "log-aggregator-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8888: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 po...
Apply a taint with key 'environment' on the nodes that have label release=beta
Command: ```bash kubectl taint node -l release=beta environment=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 5000 in the pod named "backend-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8088: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 criteri...
Forward ports 6379 and 6000 locally to ports 8080 and 6000 of a pod selected by the deployment "log-aggregator-deployment"
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 6379 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 wi...
Update the 'kubernetes-serve-hostname' container's image to 'new image' in the 'security-service-pod' pod
Command: ```bash kubectl patch pod security-service-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' ``` 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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Create a new secret named ldap-credentials-secret with the content of an environment file
Command: ```bash kubectl create secret generic ldap-credentials-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 t...
Start a pod with the specified image and set environment variables in the container.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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=i...
Copy the local file "/tmp/foo_dir" to the remote pod "auth-service-pod-11" in the "kube-flannel" namespace, and place it in the location "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo_dir kube-flannel/auth-service-pod-11:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Create a new config map named app-config-prod using the files file1.txt and file2.txt from the specified paths
Command: ```bash kubectl create configmap app-config-prod --from-file=conf=/path/to/data/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 creating a conf...
Create a service for the replication controller specified in "alpine-controller.yaml" that serves on port 8084 and connects to the containers on port 909100.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=8084 --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...
Create a python pod named "nginx" with custom specifications, using a JSON file to override the default values.
Command: ```bash kubectl run nginx --image=python --overrides='{ "apiVersion": "v1.1.1", "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] -- [COMMAN...
create a job named "monitoring-job" using the "golang" image, and run the command "go run hello.go" inside the job container
Command: ```bash kubectl create job monitoring-job --image=golang -- go run hello.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 f...
Create a new ClusterIP service named log-service-clusterip with the following configuration:
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=3001:6379 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Create a pod disruption budget named elastic-search-pdb that will select all pods with the role=worker label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=role=worker --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...
Forward the local machine's port to port 8000 in the web-app-pod pod
Command: ```bash kubectl port-forward pod/web-app-pod :8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automatica...
Create a single ingress called 'public-service-ingress' that directs requests to website.com/bar to service 'svc1' on port '9092' and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/bar=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Forward local port 9090 to port 8088 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward pod/analytics-pod 9090 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...
Execute the 'node' command in the 'stardust-shuttle' container of the 'monitoring-pod' pod and get the output.
Command: ```bash kubectl exec monitoring-pod -c stardust-shuttle -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Execute the 'redis-cli' command inside the 'mycontainer' container in the 'frontend-pod' pod and retrieve the output.
Command: ```bash kubectl exec frontend-pod -c mycontainer -- redis-cli ``` 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...
Get the output from running the 'bash' command in the first container of the 'gateway-pod'.
Command: ```bash kubectl exec gateway-pod -- bash ``` 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.kubernet...
Create a new secret named 'monitoring-credentials-secret' by reading environment variables from the file located at 'path/to/preferences.env'
Command: ```bash kubectl create secret generic monitoring-credentials-secret --from-env-file=path/to/preferences.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 de...
Forward traffic from localhost port 9090 to port 8888 in the backend-pod pod
Command: ```bash kubectl port-forward pod/backend-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 pod will be selected automa...
Create a single ingress called 'app-ingress' that directs requests to foo.com/example to the service 'svc1' on port 9090 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="foo.com/example=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": "", "usage": ...
Check if you have permission to list the job named "data-migration-job" in the "kube-public" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n kube-public ``` 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...
Create an ingress called 'web-ingress' that directs requests to foo.com/bar to svc1:3306 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/bar=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Execute the 'geth' command within the 'mycontainer' container of the 'analytics-pod' pod
Command: ```bash kubectl exec analytics-pod -c mycontainer -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Forward local port 8888 to port 9090 in the `proxy-server-pod` pod
Command: ```bash kubectl port-forward pod/proxy-server-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 a...
Begin streaming logs of the "cyber-sleuth" container in the "proxy-service-pod" pod
Command: ```bash kubectl logs -f -c cyber-sleuth proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Auto scale the deployment named "database" with the number of pods ranging from 6 to 13.
Command: ```bash kubectl autoscale deployment database --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 use...
Attach to the first pod of the replica set named "wordpress" and get its output.
Command: ```bash kubectl attach rs/wordpress ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Add a taint with key 'disktype' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha disktype=worker-node-3: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 specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config 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 definiti...
Forward local ports 8088 and 6000 to ports 8080 and 6000 in the pod
Command: ```bash kubectl port-forward pod/web-app-pod 8088 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 automa...
retrieve information about the rc/web, service/chat-app-rc, and pods/backend-pod resources
Command: ```bash kubectl get rc/web service/chat-app-rc pods/backend-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 yo...
Forward port 8081 on localhost and IP 10.19.21.23 to port 3000 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8081: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 criteri...
Enable the OpenID Connect auth provider for the "prod-user" entry with additional arguments by setting the credentials
Command: ```bash kubectl config set-credentials prod-user --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: --c...
Copy the file '/tmp/foo' from the 'front-end-pod-12' pod in the 'kube-server' namespace to the local '/tmp/bar' directory.
Command: ```bash kubectl cp kube-server/front-end-pod-12::/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 kube...
Add a taint to nodes with the label 'instance=app-instance-1' specifying the 'zone' key with the value 'kube-master-9:PreferNoSchedule'
Command: ```bash kubectl taint node -l instance=app-instance-1 zone=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": "", "u...
Copy the kube config file from the local machine to the /etc/kubernetes directory in a remote pod named "database-pod-2" in the "ingress-nginx" namespace.
Command: ```bash kubectl cp ~/.config/kube ingress-nginx/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, ...
Update the cluster field for a specific context
Command: ```bash kubectl config set contexts.app-1-context.cluster my-k8s-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 ...
List deployments in JSON output format for the "dev-2.2.0" version of the "internal-apps" API group
Command: ```bash kubectl get deployments.dev-2.2.0.internal-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 yo...
Create an ingress resource named 'ingress1' in the default class with two rules
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:3000" \ --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...
import the specific key "config_file_path" from the "app-name-config" config map and set it as an environment variable for the "web-app-deployment" deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-name-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 defin...
Auto scale the "database" deployment with a minimum of 5 pods and a maximum of 12 pods, using the default autoscaling policy.
Command: ```bash kubectl autoscale deployment database --min=5 --max=12 ``` 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 service for the 'nginx' deployment, exposing it on port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment nginx --port=9091 --target-port=808400 ``` 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 specifie...
Set resource limits and requests for all containers in the Elasticsearch deployment.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource r...
Create a pod disruption budget named load-balancer-pdb that selects all pods with the project=my-project label and requires a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=project=my-project --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-avail...
Set a custom TLS server name for the testing-cluster cluster entry.
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=prod-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] [--certific...
Expose the replication controller specified in the "centos-controller.yaml" file as a service, which will serve on port 9000 and connect to the containers on port 844300.
Command: ```bash kubectl expose -f centos-controller.yaml --port=9000 --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...
List the deployments in the "beta-1.0" version of the "mobile-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.beta-1.0.mobile-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 w...
Forward port 6379 locally to port 5000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 6379: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 automa...
Add a taint with key 'zone' on nodes having the label environment=production
Command: ```bash kubectl taint node -l environment=production zone=app-node-6: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...
Set the new exec auth plugin for the "saas-admin" entry
Command: ```bash kubectl config set-credentials saas-admin --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: ...
update the node named 'node-2' by applying a strategic merge patch with the JSON patch {"data":{"key":"new-value"}}
Command: ```bash kubectl patch node node-2 -p '{"data":{"key":"new-value"}' ``` 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 flags:...
Delete the pods and services with the names "email" and "proxy"
Command: ```bash kubectl delete pod,service email proxy ``` 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...
Delete both the pods and services named "chat-app" and "cdn"
Command: ```bash kubectl delete pod,service chat-app cdn ``` 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. So...
Create a pod disruption budget named "database-pdb" that selects all pods with the label "env=production" and ensures that at least one of them is available at any given time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=env=production --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 [-...
Start a pod named 'nginx' using the 'confluentinc/cp-kafka' image, but customize the pod spec by overriding some of the values using a JSON file.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "alpha-2.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--c...
Forward port 5432 locally to port 6379 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5432:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Auto scale the 'vpn' deployment with the number of pods ranging from 3 to 14.
Command: ```bash kubectl autoscale deployment vpn --min=3 --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 uses the...
Update the node 'dev-node-4' by adding a taint with the key 'disktype', value 'ssd', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes dev-node-4 disktype=ssd:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Create a copy of the 'security-service-pod' pod, with all container images changed to 'postgres', and name the copy 'my-debugger'.
Command: ```bash kubectl debug security-service-pod --copy-to=my-debugger --set-image=*=postgres ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if ...
Create a new ClusterIP service named messaging-service-clusterip, mapping port 9090 on the host to port 6379 on the service
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=9090:6379 ``` 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": "-...
Automatically scale the replication controller "proxy-server" to have a minimum of 1 pod and a maximum of 4 pods, based on the CPU utilization target of 40%.
Command: ```bash kubectl autoscale rc proxy-server --max=4 --cpu-percent=40 ``` 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...
Create a job with a specific command to run
Command: ```bash kubectl create job monitoring-job --image=confluentinc/cp-kafka -- kafka-server-start /etc/kafka/server.properties ``` 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", "...
Create a service for the replicated hazelcast with the following configuration:
Command: ```bash kubectl expose rc hazelcast --port=8443 --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 po...
Create a new secret named docker-registry-secret with two key-value pairs
Command: ```bash kubectl create secret generic docker-registry-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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, ...
Create a pod disruption budget named frontend-pdb that will select all pods with the env=production label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=env=production --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 [-...
Forward traffic from port 6379 on localhost and IP 10.19.21.23 to port 8081 in the frontend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 6379: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 criter...
Import the 'external_api_url' key from the 'monitoring-config' ConfigMap and set it as an environment variable for the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/monitoring-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 definitio...
Create an ingress with multiple hosts and the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:8888" \ --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",...
Start a pod named 'nginx' with the 'alpine' image, but override the spec with a partial set of values parsed from JSON using the 'kubectl run' command.
Command: ```bash kubectl run nginx --image=alpine --overrides='{ "apiVersion": "hotfix-1.1.2", "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] -- [...
Create an ingress called 'private-api-ingress' that routes requests to site.com/bar to svc1:8080 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="site.com/bar=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Embed the certificate authority data for the cluster-alpha cluster entry by running the command:
Command: ```bash kubectl config set-cluster cluster-alpha --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 ...
Create an ingress that directs requests to a specific service and port, and uses a TLS secret for secure communication.
Command: ```bash kubectl create ingress myapp-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": "", "usa...