prompt
stringlengths
13
282
response
stringlengths
128
3.11k
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/web-app-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 namespaced you...
Create an ingress called 'private-ingress' that redirects requests from testing.com/input to svc1:5000, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="testing.com/input=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": "", "us...
Attach to a specific container in a pod and interact with its terminal
Command: ```bash kubectl attach e-commerce-pod -c cosmic-container -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. If...
Retrieve the password for the "data-cluster" user
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "data-cluster")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpful...
import the DEBUG_MODE key from the global-config config map into the database-deployment deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/global-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
List all deployments in the "v1.1.1" version of the "apps" API group and display the output in JSON format.
Command: ```bash kubectl get deployments.v1.1.1.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 will only ...
Open a raw terminal to interact with a pod
Command: ```bash kubectl attach auth-service-pod -c cosmic-container -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. ...
Import the 'debug_mode' key from the 'app-config' config map into the 'scheduler-app-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Remove the label named 'component' from the 'gateway' pod
Command: ```bash kubectl label pods gateway component- ``` 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...
Set the CPU limit of the nginx container in the wordpress deployment to "10" and the memory limit to "512Mi".
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=10,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up ...
Scale a resource to 1 based on the settings specified in "settings.json"
Command: ```bash kubectl scale --replicas=1 -f settings.json ``` 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 valida...
Create a pod disruption budget named 'database-pdb' that will select all pods with the 'release=1.0.0' label and require at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=release=1.0.0 --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 [--...
Set up horizontal autoscaling for the "web" deployment with a minimum of 1 and maximum of 13 pods.
Command: ```bash kubectl autoscale deployment web --min=1 --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 uses the...
Remove the context for the 'team-alpha-context' cluster
Command: ```bash kubectl config delete-context team-alpha-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Forward the local port 5000 to the port 5000 of the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5000: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 aut...
Forward traffic from local port 8888 to port 8080 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888: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...
Set the service account of the deployment authentication-service-deployment to kube-scheduler
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment kube-scheduler ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulse...
Create a deployment named 'monitoring' using the 'mongo' image with 4 replicas.
Command: ```bash kubectl create deployment monitoring --image=mongo --replicas=4 ``` 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 o...
Forward traffic from localhost and IP 10.19.21.23 on port 8888 to port 3000 in the pod named "cdn-service-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8888: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 cri...
Forward local ports to a pod
Command: ```bash kubectl port-forward pod/analytics-pod 6379 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 auto...
Interact with the lunar-launcher application in the gateway-pod by attaching to it.
Command: ```bash kubectl attach gateway-pod -c lunar-launcher ``` 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, u...
Set the environment variable SECRET_KEY to 'your-secret-key' for all containers in all replication controllers in the project.
Command: ```bash kubectl set env rc --all SECRET_KEY=your-secret-key ``` 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 (within replica...
Copy the file ~/.config/kube from the remote pod "file-server-pod-14" in the "kube-system" namespace to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kube-system/file-server-pod-14:~/.config/kube /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Create a new ExternalName service named 'external-payment-gateway-service' that resolves to the external DNS name 'news-demo.news'
Command: ```bash kubectl create service externalname external-payment-gateway-service --external-name news-demo.news ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to referen...
Import specific keys from a config map into an environment variable
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/kube-system-config deployment/log-aggregator-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 vari...
Set the service account of the deployment named proxy-service-deployment to fluentd
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment fluentd ``` 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...
Add a taint to node 'node-1' with the key 'zone', value 'us-west-1a', and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes node-1 zone=us-west-1a: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 format. ...
Output the modified gateway-deployment object in YAML format after setting the environment variable DB_HOST to localhost
Command: ```bash kubectl set env deployment/gateway-deployment DB_HOST=localhost -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 templ...
Get the output from running the 'node' command in the warp-drive container of the proxy-service-pod.
Command: ```bash kubectl exec proxy-service-pod -c warp-drive -- 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, use ...
Update the pod 'log-aggregator' with the label 'role' and the value 'frontend'
Command: ```bash kubectl label pods log-aggregator role=frontend ``` 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", "u...
Create a new config map named app-config-dev using the files file1.txt and file2.txt for the keys conf and data respectively
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/configs/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 config...
Copy the ~/.config/kube local file to /tmp/bar_dir in the message-broker-pod-15 pod in the rook-ceph namespace.
Command: ```bash kubectl cp ~/.config/kube rook-ceph/message-broker-pod-15:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Forward the traffic from all addresses on port 8088 to the pod named "mypod" on port 8080.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 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 sel...
Forward port 8080 on all addresses to port 3000 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8080: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 ...
Import the 'external_api_url' key from the 'env-vars' config map and set it as an environment variable in the 'web-app-deployment' deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/env-vars deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create a deployment named 'sonarqube' with the image 'confluentinc/cp-kafka' and expose port 8010
Command: ```bash kubectl create deployment sonarqube --image=confluentinc/cp-kafka --port=8010 ``` 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...
Set the cluster field of a context to a specified value
Command: ```bash kubectl config set contexts.cluster-2-context.cluster cluster-alpha ``` 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 y...
Create a new ExternalName service named external-security-service that maps to the external DNS name travel-sample.travel.
Command: ```bash kubectl create service externalname external-security-service --external-name travel-sample.travel ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to referenc...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l app=web-app dedicated=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": "", "usage": "O...
Set resource requests and limits for all containers in the specified deployment during runtime.
Command: ```bash kubectl set resources deployment runtime --limits=cpu=200m,memory=512Mi --requests=cpu=5,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 requested...
Forward local ports 8081 to the pod's port 8088
Command: ```bash kubectl port-forward pod/analytics-pod 8081 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...
Add a taint with the key 'environment' and value 'backup-node-14:PreferNoSchedule' on nodes having the label 'service=auth'
Command: ```bash kubectl taint node -l service=auth environment=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": "", "usag...
Create a role named "foo" with the verb "watch" and the resource "pods"
Command: ```bash kubectl create role foo --verb=watch --resource=pods --resource-name=app-worker-1 --resource-name=monitoring-prometheus ``` 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=serve...
Forward traffic from port 8081 on the local machine to port 8081 in the pod named "mypod", and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8081: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 sel...
Create a new config map named app-config-dev with specific keys from files.
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/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. When crea...
Forward local port 9090 to port 3000 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 9090: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 select...
Retrieve the output of the 'kafka-topics --list' command being executed inside the 'cyber-sleuth' container in the 'security-service-pod' pod.
Command: ```bash kubectl exec security-service-pod -c cyber-sleuth -- 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 na...
List the replication controller with the name "web", the service with the name "auth-service-rc", and the pod with the name "api-service-pod"
Command: ```bash kubectl get rc/web service/auth-service-rc pods/api-service-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 names...
Import the 'MAX_CONNECTIONS' key from the 'app-config-dev' ConfigMap and set it as an environment variable in the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config-dev 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 d...
Allow scheduling of pods on the node "monitoring-node-15"
Command: ```bash kubectl uncordon monitoring-node-15 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Import environment variables from a config map with a specific prefix into a deployment.
Command: ```bash kubectl set env --from=configmap/kube-system-config --prefix=MYSQL_ deployment/database-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...
Create a new config map named env-vars with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/settings/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 creating a...
Enable a new exec auth plugin for the "system" entry
Command: ```bash kubectl config set-credentials system --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: --cl...
Add a taint on nodes with a specific label
Command: ```bash kubectl taint node -l app=web-app environment=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": "", "usag...
Forward traffic from local port 8088 to the targetPort of the "https" port in a pod selected by the "email-service" service
Command: ```bash kubectl port-forward service/email-service 8088:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Create a cluster role binding for multiple users and groups using a custom role
Command: ```bash kubectl create clusterrolebinding custom_role --clusterrole=custom_role --user=jane.doe --user=bob.smith --group=developers ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=grou...
Update the last-deployment annotation of the pod specified in "settings.json" with the value "2023-03-15".
Command: ```bash kubectl annotate -f settings.json 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 include...
Fetch and print the logs from the first container of the cleanup-job job
Command: ```bash kubectl logs job/cleanup-job ``` 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", "def...
Add a taint with key 'datacenter' on nodes having label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha datacenter=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": "", "usag...
Copy the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod "metrics-exporter-pod-10" under the "/tmp/bar_dir" directory, specifically in the "worker-container" container.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ metrics-exporter-pod-10:/tmp/bar_dir -c worker-container ``` 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"...
Get the output from running the 'psql' command in the 'stardust-shuttle' container in the 'proxy-server-pod' pod.
Command: ```bash kubectl exec proxy-server-pod -c stardust-shuttle -- psql ``` 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,...
Create a deployment named 'mattermost' using the 'ethereum/client-go' image and expose port 3000.
Command: ```bash kubectl create deployment mattermost --image=ethereum/client-go --port=3000 ``` 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 f...
Forward local port 3000 to port 8888 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 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 selected autom...
Forward local ports 8081 and 6000 to ports 8088 and 6000 in a pod selected by the database-deployment deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 8081 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 ...
Create a config map named app-config from the key=value pairs in a file
Command: ```bash kubectl create configmap app-config --from-file=path/to/configs ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename of...
Set the cluster field in the team-alpha-context context to edge-cluster
Command: ```bash kubectl config set contexts.team-alpha-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 y...
Enable OpenID Connect auth provider for "web-app" entry with additional arguments
Command: ```bash kubectl config set-credentials web-app --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: --cli...
Run the 'mongod' command inside the 'astro-container' from the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c astro-container -- mongod ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Start a php pod with a container that exposes port 8082
Command: ```bash kubectl run hazelcast --image=php --port=8082 ``` 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": "--file...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-settings deployment/database-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...
Create a new config map with specific key-value pairs
Command: ```bash kubectl create configmap namespace-config --from-literal=settings=config1 --from-literal=key2=config2 ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, t...
Copy the ~/.config/kube directory from the remote pod file-server-pod-14 to the local directory /tmp/bar
Command: ```bash kubectl cp kube-public/file-server-pod-14:~/.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, use ...
Retrieve the previous terminated logs of the 'ruby' container from the 'email-service-pod' pod
Command: ```bash kubectl logs -p -c ruby email-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", "short...
Retrieve the previous terminated logs of the "astro-container" container from the pod "log-aggregator-pod"
Command: ```bash kubectl logs -p -c astro-container 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": "--contai...
Set up the OpenID Connect authentication provider for the "cluster-admin" entry with additional arguments
Command: ```bash kubectl config set-credentials cluster-admin --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: ...
Embed the certificate authority data for the data-cluster cluster entry using the command 'kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/cloud-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/cloud-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...
Create a Pod Disruption Budget named "critical-services-pdb" that selects all pods with the "tier=frontend" label and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=tier=frontend --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-availa...
Forward local port 9090 to port 9090 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 9090: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 select...
Create a single ingress called 'private-service-ingress' that directs requests to site.com/bar to svc1:8088 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="site.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": "", ...
Check if you have permission to list the job named "data-synchronization-job" in the "namespace-1" namespace
Command: ```bash kubectl auth can-i list jobs.batch/data-synchronization-job -n namespace-1 ``` 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 p...
Create a new ExternalName service named 'external-logging-service' with the external name 'demo-service.dev'
Command: ```bash kubectl create service externalname external-logging-service --external-name demo-service.dev ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference ser...
Forward local ports to pod ports
Command: ```bash kubectl port-forward pod/api-service-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 will be selected au...
Forward local traffic on port 8888 to a pod selected by the 'email-server-deployment' deployment on port 8888.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8888 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...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/global-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 var...
Update the pod 'auth' by adding the annotation 'description' with the value 'Web server for marketing site'
Command: ```bash kubectl annotate pods auth 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 a...
Create a job named 'report-generation-job' with the 'node' image and run the 'node --version' command
Command: ```bash kubectl create job report-generation-job --image=node -- node --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Update the label of the pod 'cdn' to set the role as 'frontend'
Command: ```bash kubectl label pods cdn role=frontend ``` 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 ...
Create a new config map named app-config-dev with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/path/to/preferences/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 disruption budget named cron-jobs-pdb that will select all pods with the tier=frontend label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=tier=frontend --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 [-...
Display the last 20 lines of logs from the 'e-commerce-pod' pod.
Command: ```bash kubectl logs --tail=20 e-commerce-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": "...
Create an ingress called 'app-gateway-ingress' with a rule that directs requests from foo.com/module to svc1:6379
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/module=svc1:6379,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...
Create an ingress resource with the name 'web-ingress' and define a rule that directs requests from foo.com/input to the service 'svc1' on port 5000
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/input=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": "", "usage": "O...
Create a config map named app-config-prod from the key=value pairs in the specified file
Command: ```bash kubectl create configmap app-config-prod --from-file=path/to/configs ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basena...
Retrieve the YAML representation of the 'backend-pod' pod.
Command: ```bash kubectl get -o yaml pod 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 you will only see resu...
Execute the command 'sleep 3600' in the container 'rocket-ranger' of the pod 'vpn-service-pod' and display the output.
Command: ```bash kubectl exec vpn-service-pod -c rocket-ranger -- sleep 3600 ``` 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 omitte...
Embed the certificate authority data for the 'staging-cluster' cluster entry by running the command 'kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/data-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 ...
Forward traffic from port 8080 on all addresses to port 5432 in the 'web-app-pod' pod using the command 'kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8080:5432'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8080:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Add a taint to nodes with the label "zone=us-east-1" and the taint key "datacenter" with value "k8s-node-1:PreferNoSchedule"
Command: ```bash kubectl taint node -l zone=us-east-1 datacenter=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":...
Create a job named "certificate-renewal" using the Postgres image and run the "psql" command
Command: ```bash kubectl create job certificate-renewal --image=postgres -- psql ``` 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 forma...
Add a taint with key 'workload' and no value to the node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 workload: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...