prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set up auto scaling for the 'log-aggregator' replication controller with a maximum of 6 pods and a target CPU utilization of 60%
Command: ```bash kubectl autoscale rc log-aggregator --max=6 --cpu-percent=60 ``` 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...
List the replication controller named "web", the service named "payment-gateway-rc", and the pod named "gateway-pod"
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/gateway-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 namesp...
Create a new secret named my-secret using the data from the path/to/data.env file
Command: ```bash kubectl create secret generic my-secret --from-env-file=path/to/data.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 of th...
Return the previous terminated logs of the quantum-quark container from the security-service-pod pod
Command: ```bash kubectl logs -p -c quantum-quark security-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": "--contai...
Retrieve the list of deployments in YAML format for the "v1.0.0" version of the "web-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.web-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 you will o...
Create a pod disruption budget named frontend-pdb that will select all pods with the project=my-project label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=project=my-project --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=...
Create a service for the replicated php deployment exposing port 9000 and targeting port 543200
Command: ```bash kubectl expose rc php --port=9000 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Update the annotation of pod 'frontend' with the key 'backup-strategy' and the value 'daily-backups', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods frontend backup-strategy='daily-backups' ``` 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 labe...
Taint the nodes with the label "component=proxy" by adding a taint with the key "dedicated" and the value "edge-node-10" with the effect "PreferNoSchedule".
Command: ```bash kubectl taint node -l component=proxy dedicated=edge-node-10: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...
Start a pod with the confluentinc/cp-kafka image and customize the command arguments by providing arg1, arg2, and so on.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka -- <arg1> <arg2> ... <argN> ``` 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...]` ...
Listen on all addresses on port 9090 and forward the traffic to port 8081 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 9090: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...
Check if the current user has permission to list the "cleanup-job" job resource in the "monitoring" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-job -n monitoring ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL tha...
Output the modified gateway-deployment deployment in YAML format with the QUEUE_NAME environment variable set to "task-queue", without modifying the object on the server.
Command: ```bash kubectl set env deployment/gateway-deployment QUEUE_NAME=task-queue -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod t...
Set the resource request and limits for all containers in the python deployment to cpu=5, memory=256Mi for requests and cpu=200m, memory=512Mi for limits
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=5,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 requeste...
Create an ingress called 'app-loadbalancer-ingress' with a rule that directs requests from 'testing.com/example' to 'svc1:9090' using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.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", "defaul...
Create a deployment named "cache" that uses the "php" image and exposes port 8081.
Command: ```bash kubectl create deployment cache --image=php --port=8081 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|...
Execute the 'go run hello.go' command in the nebula-navigator container of the gateway-pod pod and retrieve the output.
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- go run hello.go ``` 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 om...
Create a new config map named "app-config-prod" with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/profiles/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 creat...
Start a pod with custom overrides specified in a JSON format
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "v1.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] -- [COMMAND...
Open a raw terminal connection to the log-aggregator-pod container using the lunar-launcher container
Command: ```bash kubectl attach log-aggregator-pod -c lunar-launcher -i -t ``` 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. ...
Enable the new exec auth plugin for the "service-account" entry by setting the exec-command to /path/to/the/executable and the exec-api-version to client.authentication.k8s.io/v1beta1.
Command: ```bash kubectl config set-credentials service-account --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 flag...
Update the 'proxy-server' pod with the annotation 'env' and the value 'staging'
Command: ```bash kubectl annotate pods proxy-server env=staging ``` 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 str...
Add a taint to node 'kube-master-9' with the key 'dedicated', value 'special-user', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes kube-master-9 dedicated=special-user:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output ...
Start a pod named 'hazelcast' using the 'postgres' image and expose port 9000 in the container.
Command: ```bash kubectl run hazelcast --image=postgres --port=9000 ``` 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": "-...
Copy data from a remote pod to a local directory
Command: ```bash kubectl cp default/metrics-exporter-pod-10:/var/run/secrets/kubernetes.io/serviceaccount/ :/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": ...
Set the service account of the deployment "email-server-deployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment email-server-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: `kube...
Remove all taints with the key 'zone' from the node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 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|n...
Create a service for a replicated Python server using a replica set, which serves on port 5000 and connects to the containers on port 8080
Command: ```bash kubectl expose rs python --port=5000 --target-port=808100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
create an ingress named 'service-ingress' with a rule that routes requests from testing.com/example to svc1:3306, using the tls secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/example=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": "", "...
Add a taint to nodes in a specific zone with a specific key-value pair
Command: ```bash kubectl taint node -l zone=us-east-1 environment=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": "", "usage"...
Expose the service for a replication controller specified in "alpine-controller.yaml" file on port 8089, connecting to the containers on port 808000.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=8089 --target-port=808000 ``` 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 service for a replicated Ubuntu using a replica set, which serves on port 8089 and connects to the containers on port 909200.
Command: ```bash kubectl expose rs ubuntu --port=8089 --target-port=909200 ``` 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 file ~/.config/kube from the local machine to the /tmp/bar directory in the pod named task-processor-pod-17 in the kube-node-lease namespace.
Command: ```bash kubectl cp ~/.config/kube kube-node-lease/task-processor-pod-17:/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...
Listen on port 5000 locally, forwarding data to port 8081 in the security-service-pod.
Command: ```bash kubectl port-forward pod/security-service-pod 5000 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 select...
Start a new pod named hazelcast using the postgres image, and expose port 5001
Command: ```bash kubectl run hazelcast --image=postgres --port=5001 ``` 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": "-...
Create an ingress named 'public-service-ingress' that routes requests from site.com/example to the service named 'svc1' on port '5000' using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress public-service-ingress --rule="site.com/example=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Create an ingress named 'internal-ingress' that routes requests for 'foo.com/bar' to the service 'svc1' on port 8080, and configure it to use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress internal-ingress --rule="foo.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": "", "usage":...
Create an ingress named 'service-ingress' with a rule that directs requests from 'website.com/module' to a service called 'svc1' on port '5432', and use a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress service-ingress --rule="website.com/module=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Forward traffic from port 6379 on all addresses to port 6379 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 6379: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...
Listen on port 6379 on localhost and IP address 10.19.21.23, and forward the traffic to port 8080 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 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 cri...
Check if you have permission to list the job named "load-testing-job" in the "testing" namespace
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n testing ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL t...
Update the annotation of pod 'api' with the value 'Web server for marketing site'.
Command: ```bash kubectl annotate pods api 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 be larger than labels an...
Get the snapshot logs from the container "web-app-deployment-1" of the deployment named "proxy-server-pod"
Command: ```bash kubectl logs deployment/web-app-deployment -c proxy-server-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: "flag"...
Begin streaming the logs of a specific container in a pod
Command: ```bash kubectl logs -f -c cosmic-container analytics-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"...
Copy the kube configuration file from the "~/.config/kube" directory of the "payment-gateway-pod-19" pod in the "kube-flannel" namespace to the "/tmp/bar" directory locally.
Command: ```bash kubectl cp kube-flannel/payment-gateway-pod-19:~/.config/kube :/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,...
apply a taint on nodes with a specific label
Command: ```bash kubectl taint node -l customer=acme-corp hardware=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": "", "usag...
Add a taint with key 'datacenter' on nodes having label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend datacenter=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...
Delete all resources specified in the kustomization.yaml file located in the options directory
Command: ```bash kubectl delete -k options/ ``` 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 resources,...
Forward traffic from port 9090 on all addresses to port 6379 in the 'e-commerce-pod' pod, allowing remote access
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-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 criteria, a pod wi...
Delete the pod and service resources named "api" and "log-aggregator"
Command: ```bash kubectl delete pod,service api log-aggregator ``` 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 select...
Copy the file /tmp/foo from the pod 'metrics-exporter-pod-10' in the kube-server namespace to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kube-server/metrics-exporter-pod-10::/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Return the logs snapshot from the user-management-deployment-1 container of the proxy-service-pod deployment
Command: ```bash kubectl logs deployment/user-management-deployment -c proxy-service-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 flag...
Set the user field for a specific context entry without modifying other configurations
Command: ```bash kubectl config set-context client-2-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nickn...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=SMTP_SERVER --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 d...
Increase the number of replicas for the 'db-migration-replicaset' replica set to 7.
Command: ```bash kubectl scale --replicas=7 rs/db-migration-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it...
Update the 'user-management-deployment' deployment by adding a new environment variable named 'ENV' with the value 'prod'.
Command: ```bash kubectl set env deployment/user-management-deployment ENV=prod ``` 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 (wit...
Create a new config map named "app-settings" using files as the source for the data
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/configs/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 co...
Forward traffic from port 8888 on localhost and IP address 10.19.21.23 to port 5432 on the pod named "web-app-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Add a taint with key 'zone' on nodes having label owner=john-doe with the value 'backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe zone=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create a new config map named app-config-prod with the keys 'properties' and 'key1' instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When c...
Create a pod using the configuration provided in the settings.json file
Command: ```bash kubectl create -f ./settings.json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use to crea...
Get the list of kafka topics by executing the 'kafka-topics --list' command inside the cdn-service-pod container.
Command: ```bash kubectl exec cdn-service-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 t...
Forward local port 8080 to port 8088 in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod 8080 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 automaticall...
Forward traffic from local port 6379 to port 8088 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 6379: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...
Retrieve the logs from the container `vpn-service-pod-1` in the deployment `notification-handler-deployment`.
Command: ```bash kubectl logs deployment/notification-handler-deployment -c vpn-service-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 f...
Start a pod named hazelcast using the postgres image, and expose port 8081 on the container.
Command: ```bash kubectl run hazelcast --image=postgres --port=8081 ``` 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": "-...
Delete pods and services named "analytics" and "proxy"
Command: ```bash kubectl delete pod,service analytics 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....
Expose a replication controller using a YAML file with specific ports
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8082 --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 ...
Create a new config map named "namespace-config" using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/configurations/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...
Forward traffic from port 5000 on all addresses to port 3000 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 5000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
create an ingress called 'public-api-ingress' that routes requests from testing.com/bar to a service named svc1:27017 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/bar=svc1:27017,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": "", "...
Remove the taint with the key 'hardware' and effect 'NoExecute' from the node named 'app-node-6' if it exists.
Command: ```bash kubectl taint nodes app-node-6 hardware:NoExecute- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Create an ingress resource called 'website-ingress' that will direct requests for site.com/module to the service 'svc1' on port 5000
Command: ```bash kubectl create ingress website-ingress --rule="site.com/module=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config deployment/order-processing-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 port 8088 to port 5000 in a pod selected by the deployment "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 criteria, a po...
Expose the replica set "ubuntu" as a service on port 8082, connecting to container port 909100.
Command: ```bash kubectl expose rs ubuntu --port=8082 --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 port....
Forward traffic from port 8088 on all addresses to port 6379 in the backend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8088:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/db-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or m...
Forward local ports 8080 and 6000 to ports 8080 and 6000 of a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 8080 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selecte...
Listen on the local ports 6379 and 6000, and forward data to/from the ports 5000 and 6000 in a pod selected by the log-aggregator-deployment deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 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 wi...
Create a secret named "ssl-key-secret" from an environment file
Command: ```bash kubectl create secret generic ssl-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...
Run the 'postgres' command in the pod named vpn-service-pod
Command: ```bash kubectl exec vpn-service-pod -- postgres ``` 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....
Use the values from the 'oauth-secret' secret to set environment variables for the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --from=secret/oauth-secret deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more ...
Add a taint with the key 'workload' on nodes that have the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops workload=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": "", "usage":...
Create a cluster role named "default_role" with the ability to watch services, and with specific resource names "notification-service" and "machine-learning"
Command: ```bash kubectl create clusterrole default_role --verb=watch --resource=services --resource-name=notification-service --resource-name=machine-learning ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-...
Scale the deployment named api-service-rs from 3 replicas to 5 replicas
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/api-service-rs ``` 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-vers...
Set the cluster field in a specific context to a given cluster name
Command: ```bash kubectl config set contexts.edge-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you w...
Delete the pods and services with the names "security" and "foo"
Command: ```bash kubectl delete pod,service security foo ``` 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...
Start a pod named "hazelcast" using the image "docker.elastic.co/elasticsearch/elasticsearch" and expose port 8084
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8084 ``` 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] ...
Listen on port 9090 locally and forward data to/from port 8080 in a pod selected by the search-engine-deployment deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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 wil...
Edit the 'email-server-deployment' deployment in YAML format and save the modified configuration in its annotation.
Command: ```bash kubectl edit deployment/email-server-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 env...
Check if the current user has permission to list the job named "data-migration-job" in the "cert-manager" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n cert-manager ``` 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 partia...
Create a new ClusterIP service named 'notification-service-clusterip' that maps port 8089 to port 8443.
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=8089:8443 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short":...
Create a new config map named monitoring-config using specified files as the values for the keys.
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/settings/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 creat...
Set the service account for the 'database-deployment' deployment to 'kube-dns'
Command: ```bash kubectl set serviceaccount deployment database-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: `kubectl ...
Create a role named "bar" with the ability to update pods and access specific resource names
Command: ```bash kubectl create role bar --verb=update --resource=pods --resource-name=database-master --resource-name=machine-learning ``` 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...
Forward port 8888 on all addresses to port 8000 in the "chat-app-pod" pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8888: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...
Check if you have permission to list the "batch-processing-job" job in the "default" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n default ``` 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...
Make the "web-cluster" cluster the current cluster for the "admin-context" context
Command: ```bash kubectl config set contexts.admin-context.cluster web-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wan...
Retrieve the list of deployments in the "legacy-1.0.0" version of the "third-party-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.legacy-1.0.0.third-party-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 namespa...