prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward port 8080 on localhost and IP address 10.19.21.23 to port 8080 in the mypod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Add a taint with key 'hardware' on nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice hardware=prod-node-5: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...
Import the API_KEY value from the config map named 'api-config' into the deployment named 'proxy-service-deployment'
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/api-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 definitions i...
Create a new NodePort service named cdn-service-nodeport
Command: ```bash kubectl create service nodeport cdn-service-nodeport --tcp=8000:9091 ``` 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":...
Auto scale the replication controller "security" based on CPU utilization, with the number of pods between 1 and 8 and target CPU utilization at 20%
Command: ```bash kubectl autoscale rc security --max=8 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Expose the hazelcast replication controller as a service, serving on port 7000 and forwarding traffic to the containers on port 9092
Command: ```bash kubectl expose rc hazelcast --port=7000 --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 po...
Forward all traffic on port 5432 from any address to port 6379 inside the 'analytics-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-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 wil...
Create a config map named kube-system-config using specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/settings/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. Whe...
Create a copy of the web-app-pod by adding a debug container and changing the container images.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-api --image=debian --set-image=web=nginx:latest,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name...
Get the output from running the 'geth attach' command in the first container of the first pod of the 'gateway-service' service.
Command: ```bash kubectl exec svc/gateway-service -- geth attach ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Add a taint with the key 'cpu-type' on nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel cpu-type=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": "Output ...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=log_level --from=configmap/env-vars 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...
Add a taint with key 'hardware' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha hardware=dev-node-4:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Copy the ~/.config/kube local file to the /etc/kubernetes directory of the database-pod-2 pod in the logging namespace.
Command: ```bash kubectl cp ~/.config/kube logging/database-pod-2:/etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Copy the file "/tmp/foo" from the remote pod "metallb-system/load-balancer-pod-9" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp metallb-system/load-balancer-pod-9:/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, ...
Create a NodePort service named frontend-nodeport with the TCP port mapping 8443 to port 8080
Command: ```bash kubectl create service nodeport frontend-nodeport --tcp=8443:8080 ``` 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": ""...
Copy the directory "/tmp/foo_dir" from the remote pod "front-end-pod-12" to the local directory "/etc/kubernetes"
Command: ```bash kubectl cp prometheus/front-end-pod-12:/tmp/foo_dir /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...
Forward local port 8080 to port 8081 in the pod named "e-commerce-pod", accepting connections on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8080: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...
Copy a file from local to a remote pod
Command: ```bash kubectl cp /tmp/foo kube-flannel/logging-agent-pod-7:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Create a pod disruption budget named cache-cluster-pdb that will select all pods with the env=production label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=env=production --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...
Create a deployment with the name "drupal" that runs the "ethereum/client-go" image and has 7 replicas.
Command: ```bash kubectl create deployment drupal --image=ethereum/client-go --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 form...
Create a copy of the 'database-pod' pod, changing the command of the 'lunar-launcher' container
Command: ```bash kubectl debug database-pod -it --copy-to=my-custom-dbg --container=lunar-launcher -- 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 def...
Get the output from running the 'postgres' command in the first container of the 'analytics-pod' pod
Command: ```bash kubectl exec analytics-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.ku...
Scale the replica set 'foo' to 7 replicas
Command: ```bash kubectl scale --replicas=7 rs/foo ``` 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 is validated before...
set the resource requests and limits for all containers in the Hazelcast deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource request...
Import the specific key `my-example-key` from the `global-config` ConfigMap into the `load-balancer-deployment` deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/global-config deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
import the LOG_LEVEL key from the app-config-dev config map and set it as an environment variable in the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-dev deployment/search-engine-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...
Forward local port 5432 to port 5000 in the pod 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 5432 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Forward local ports 5432 and 6000 to ports 6379 and 6000 respectively, for the selected pod by the deployment named "api-server-deployment"
Command: ```bash kubectl port-forward deployment/api-server-deployment 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 b...
Add a taint to a specific node with a given key, value, and effect
Command: ```bash kubectl taint nodes monitoring-node-15 hardware=gpu: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...
Open the search-service service for editing using the vim editor
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/search-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, ...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/env-vars deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Forward local port 8080 to port 6379 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-pod 8080: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 automa...
Set the resource request and limits for all containers in the hazelcast deployment to a CPU limit of 200 milliCPU and memory limit of 512MiB, and a CPU request of 5 milliCPU and memory request of 64MiB.
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=5,memory=64Mi ``` 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 reques...
Create a pod disruption budget named cache-cluster-pdb that selects pods with the version=v2 label and requires at least 9 of them to be available at any given time
Command: ```bash kubectl create poddisruptionbudget cache-cluster-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 [...
Change the service account of the deployment "api-server-deployment" to "jenkins"
Command: ```bash kubectl set serviceaccount deployment api-server-deployment jenkins ``` 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...
Execute the 'redis-cli' command on the first pod of the 'email-server-deployment' deployment.
Command: ```bash kubectl exec deploy/email-server-deployment -- 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, ...
Set the service account of the 'log-aggregator-deployment' deployment to 'istio'
Command: ```bash kubectl set serviceaccount deployment log-aggregator-deployment istio ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubec...
Check the rollout status of a daemonset
Command: ```bash kubectl rollout status daemonset/staging ``` What it does: Manage the rollout of a resource. Valid resource types include: Syntax: `kubectl rollout SUBCOMMAND`
Create a deployment named 'mattermost' with 2 replicas using the 'docker.elastic.co/elasticsearch/elasticsearch' image.
Command: ```bash kubectl create deployment mattermost --image=docker.elastic.co/elasticsearch/elasticsearch --replicas=2 ``` 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", "defa...
Update the 'proxy-service-deployment' deployment by setting a new environment variable 'MAX_CONNECTIONS' with the value of 100.
Command: ```bash kubectl set env deployment/proxy-service-deployment MAX_CONNECTIONS=100 ``` 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 templ...
Retrieve the snapshot logs from the container named web-app-pod-1 of the deployment named authentication-service-deployment.
Command: ```bash kubectl logs deployment/authentication-service-deployment -c web-app-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 fla...
Create a pod disruption budget named "load-balancer-pdb" that will select all pods with the "project=my-project" label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=project=my-project --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-avail...
Start a pod named "hazelcast" using the "mongo" image and expose port 8888
Command: ```bash kubectl run hazelcast --image=mongo --port=8888 ``` 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...
Forward local port 5432 to port 5000 in the security-service-pod pod
Command: ```bash kubectl port-forward pod/security-service-pod 5432:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Disable certificate checking for the entry of the testing-cluster in the Kubernetes configuration
Command: ```bash kubectl config set-cluster testing-cluster --insecure-skip-tls-verify=true ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifi...
Create a service for a replicated hazelcast, which serves on port 5001 and connects to the containers on port 700000
Command: ```bash kubectl expose rc hazelcast --port=5001 --target-port=700000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Create a secret named payment-gateway-secret using environment variables from the specified file
Command: ```bash kubectl create secret generic payment-gateway-secret --from-env-file=path/to/parameters.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...
Execute the 'php --version' command in the 'nebula-navigator' container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c nebula-navigator -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Remove the label 'app' from the pod named 'foo'
Command: ```bash kubectl label pods foo app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, che...
Add a taint with key 'app' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster app=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": "", "usage": "O...
Create a deployment named gateway using the amazonlinux image
Command: ```bash kubectl create deployment gateway --image=amazonlinux ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|ya...
Return snapshot logs from container 'chat-app-pod-1' of a deployment named 'monitoring-stack-deployment'
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c chat-app-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: "...
Partially update a resource using a strategic merge patch.
Command: ```bash kubectl patch -f machine-configuration.yaml -p '{"spec":{"someField":"newValue"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file...
Add a taint with key 'app' on nodes having label cluster=my-cluster, specifically on the node monitoring-node-15, with the taint effect PreferNoSchedule
Command: ```bash kubectl taint node -l cluster=my-cluster app=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Update the annotation of a pod with a new value
Command: ```bash kubectl annotate --overwrite pods api 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 labels an...
Set up auto scaling for the "vpn" deployment with a minimum of 1 pod and a maximum of 14 pods
Command: ```bash kubectl autoscale deployment vpn --min=1 --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...
Copy the file "/tmp/foo" from the "monitoring-agent-pod-6" pod in the "velero" namespace to the local directory "/tmp/bar"
Command: ```bash kubectl cp velero/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 kub...
List the replication controller named "web", the service named "api-service-rc", and the pod named "e-commerce-pod".
Command: ```bash kubectl get rc/web service/api-service-rc pods/e-commerce-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...
Forward traffic from port 3000 on localhost and IP 10.19.21.23 to port 5432 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 3000: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 cri...
Create an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="website.com/=svc:https,tls" \ --rule="testing.com/path/subpath*=othersvc:8081" ``` 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"...
Create a new config map named 'api-config' using the specified keys with the corresponding file paths
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/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...
Copy the local directory ~/.config/kube_dir to the remote pod api-server-pod-3 in the default namespace at the path /etc/kubernetes_dir
Command: ```bash kubectl cp ~/.config/kube_dir api-server-pod-3:/etc/kubernetes_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Retrieve output from running the 'ash' command in the container named 'mycontainer' from the pod named 'email-service-pod'
Command: ```bash kubectl exec email-service-pod -c mycontainer -- ash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Update the cluster field in the my-context context to app-cluster
Command: ```bash kubectl config set contexts.cloud-context.cluster app-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...
Create a new secret named ssh-key-secret with keys for each file in the specified folder
Command: ```bash kubectl create secret generic ssh-key-secret --from-file=path/to/properties ``` 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...
Automatically scale the replication controller named "security" to have a maximum of 7 pods and target a CPU utilization of 20%.
Command: ```bash kubectl autoscale rc security --max=7 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create an ingress called 'private-api-ingress' that directs requests for 'foo.com/bar' to the service 'svc1' on port '8088', using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/bar=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a pod disruption budget named auth-service-pdb that will select all pods with the region=us-east label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=region=us-east --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=...
Create a new config map named "app-config-prod" using files from disk with specified keys
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/options/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 local port 8081 to port 9090 on the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8081 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 aut...
Create a pod disruption budget named statefulset-pdb that will select all pods with the project=my-project label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-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-availab...
Create a copy of the 'mypod' resource, changing the command of the 'lunar-launcher' container.
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-memcached --container=lunar-launcher -- 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 de...
Attach to the running pod named 'monitoring-pod' and get output from it.
Command: ```bash kubectl attach monitoring-pod ``` 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....
Set the custom TLS server name 'testing-cluster' to use for validation for the 'staging-cluster' cluster entry
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=testing-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] [--certi...
Create a service for the replicated ubuntu containers, which will serve on port 8081 and connect to the container's port 900000.
Command: ```bash kubectl expose rc ubuntu --port=8081 --target-port=900000 ``` 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 a cron job to run the Elasticsearch container every minute
Command: ```bash kubectl create cronjob data-processing --image=docker.elastic.co/elasticsearch/elasticsearch --schedule="*/1 * * * *" -- elasticsearch ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Help...
Check if the authenticated user has permission to list the "log-analysis-job" job in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-analysis-job -n staging ``` 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...
Apply the last configuration from each file in a directory.
Command: ```bash kubectl apply set-last-applied -f dir/ ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of the obje...
Listen on port 8000 locally, forwarding to port 8888 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000: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...
Run the specified command in warp-drive container of the pod api-service-pod and get the output.
Command: ```bash kubectl exec api-service-pod -c warp-drive -- nginx -g "daemon off;" ``` 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. ...
Create a pod disruption budget named auth-service-pdb that will select all pods with the component=web label and require a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=component=web --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...
Update the environment variable of a deployment to "prod" and output the modified deployment in YAML format without actually applying the changes to the object on the server.
Command: ```bash kubectl set env deployment/email-server-deployment ENV=prod -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 templates...
Create a new config map named 'db-config' using the files '/path/to/configs/file1.txt' and '/path/to/properties/file2.txt', where 'properties' will be the key for '/path/to/configs/file1.txt' and 'key1' will be the key for '/path/to/properties/file2.txt'.
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/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 creating a...
Forward port 6379 from the pod named "cdn-service-pod" to your local machine's port 6379
Command: ```bash kubectl port-forward pod/cdn-service-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 pod will be selected au...
Update the cluster field in the app-2-context context to "edge-cluster".
Command: ```bash kubectl config set contexts.app-2-context.cluster edge-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Forward local port 3000 to port 8888 in a pod selected by the web-app-deployment
Command: ```bash kubectl port-forward deployment/web-app-deployment 3000 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 s...
show the differences between current resources and the ones specified in the options.yaml file
Command: ```bash kubectl diff -f options.yaml ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff comman...
expose a replication controller as a service on a specified port
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8083 --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 s...
Import the specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/namespace-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 definit...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/monitoring-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 varia...
Set the resource request and limits for all containers in the 'postgres' deployment
Command: ```bash kubectl set resources deployment postgres --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=4Gi ``` 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 reque...
Return the logs of container "auth-service-pod-1" from the deployment "user-management-deployment"
Command: ```bash kubectl logs deployment/user-management-deployment -c auth-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 flags...
Check if you have permission to list the job named "report-generation-job" in the "kube-public" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-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 part...
Forward traffic from local port 6379 to port 8888 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 6379: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 wil...
Create an ingress called "website-ingress" that directs requests from "testing.com/example" to the service "svc1" on port 8084, using the TLS secret "my-cert".
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/example=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Retrieve the previous terminated logs of the "warp-drive" container from the "backend-pod" pod
Command: ```bash kubectl logs -p -c warp-drive backend-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...
Embed the certificate authority data for the 'kube-cluster-1' cluster entry using the command 'kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/web-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster kube-cluster-1 --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 se...
Update the annotation of a pod by applying a deployment script from a specified URL
Command: ```bash kubectl annotate -f conf.json deployment-script='https://example.com/deploy.sh' ``` 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...
Listen locally on port 6379, forwarding data to/from port 3000 in the 'web-app-deployment' pod.
Command: ```bash kubectl port-forward deployment/web-app-deployment 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 s...