prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Expose the replicated nginx resource as a service, serving on port 8181 and connecting to the containers on port 909000
Command: ```bash kubectl expose rc nginx --port=8181 --target-port=909000 ``` 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. ...
Apply a taint with the key 'disktype' and the value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops disktype=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": "Ou...
Create a cluster role named "custom_role" with access to specific pod resources named "document-storage" and "auth-service" and permission to execute actions on them.
Command: ```bash kubectl create clusterrole custom_role --verb=exec --resource=pods --resource-name=document-storage --resource-name=auth-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Forward local traffic from port 5000 to port 8080 in the email-server-deployment pod using the kubectl port-forward command.
Command: ```bash kubectl port-forward deployment/email-server-deployment 5000 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...
Forward local port 6379 to pod port 8000
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Create a copy of the 'proxy-server-pod', adding a debug container and changing container images
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=my-custom-dbg --image=debian --set-image=app=app:debug,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
Create an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="foo.com/=svc:https,tls" \ --rule="site.com/path/subpath*=othersvc:9092" ``` 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": "--ou...
Expose the replication controller named "python" on port 8888, redirecting traffic to the containers on port 500000
Command: ```bash kubectl expose rc python --port=8888 --target-port=500000 ``` 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....
Update the 'proxy-server' pod by setting the annotation 'backup-strategy' to 'daily-backups', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server 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 ...
Create a new config map named api-config using specified files as the key-value pairs.
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/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 creating a...
Create an ingress rule called 'myapp-ingress' that directs requests to site.com/module to the service 'svc1' on port 8181
Command: ```bash kubectl create ingress myapp-ingress --rule="site.com/module=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Start a postgres pod with some custom specifications provided in JSON format
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "stable-2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] --...
Forward local port 6379 to pod port 5000
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Embed the certificate authority data for the "testing-cluster" cluster entry
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/prod-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 ...
Listen on all addresses for incoming traffic on port 8080 and forward it to port 8081 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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...
Retrieve information about the following resources: the replication controller named web, the service named cdn-service-rc, and the pod named database-pod
Command: ```bash kubectl get rc/web service/cdn-service-rc pods/database-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 namespace...
Forward local port 8888 to port 8888 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 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 be selected autom...
Create a pod named 'hazelcast' using the 'ruby' image and expose port 8089.
Command: ```bash kubectl run hazelcast --image=ruby --port=8089 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fil...
Set the CPU limits of the ruby container in the deployment named "ruby" to "100m" and the memory limits to "1Gi"
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=100m,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 requested, but may burst up to it...
Listen locally on port 5000 and forward traffic to the backend-pod's port 9090
Command: ```bash kubectl port-forward pod/backend-pod 5000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Get the output from running the 'node --version' command inside the 'stardust-shuttle' container in the 'database-pod' pod.
Command: ```bash kubectl exec database-pod -c stardust-shuttle -- node --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 om...
Add a taint with key 'hardware' and value 'dev-node-4' on nodes that have the label 'version=v1.0.0' and assign it the effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l version=v1.0.0 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": "", "usage": "...
Print the result of updating the nginx container image to 'java:11.0.12' from the local file 'path/to/file.yaml' in YAML format, without hitting the server.
Command: ```bash kubectl set image -f path/to/file.yaml java=java:11.0.12 --local -o yaml ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replica...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config-dev deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Create an ingress resource called 'service-ingress' with a rule that directs requests from foo.com/input to svc1:5001
Command: ```bash kubectl create ingress service-ingress --rule="foo.com/input=svc1:5001,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"...
Display the last 5 lines of logs for a specific pod
Command: ```bash kubectl logs --tail=5 database-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c"...
Create a new ClusterIP service named order-service-clusterip with the TCP port mapping 8088:8082
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8088:8082 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
Import the environment variables from the 'docker-registry-secret' secret and set them for the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --from=secret/docker-registry-secret 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 definitions in one ...
Start streaming the logs of the "cosmic-container" container in the "backend-pod" pod.
Command: ```bash kubectl logs -f -c cosmic-container 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", ...
List all deployments in the "backup-apps" API group with the version "hotfix-1.1.2" in YAML output format.
Command: ```bash kubectl get deployments.hotfix-1.1.2.backup-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced y...
Create a LoadBalancer service named 'e-commerce-lb' that forwards traffic from port 9092 to port 3001
Command: ```bash kubectl create service loadbalancer e-commerce-lb --tcp=9092:3001 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defa...
Add a taint with key 'workload' on nodes having label component=proxy
Command: ```bash kubectl taint node -l component=proxy workload=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": ...
Add a taint with key 'hardware' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz hardware=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": "", ...
Create a new config map named namespace-config by using configurations from a specific folder
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/configurations ``` 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 th...
Create a single ingress called 'web-ingress' that directs requests to site.com/module to svc1:9091 with a tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="site.com/module=svc1:9091,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": ...
Auto scale the replication controller "proxy-server" with a minimum of 1 pod and a maximum of 7 pods, targeting a CPU utilization of 20%.
Command: ```bash kubectl autoscale rc proxy-server --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...
Forward local traffic on port 8888 to a pod selected by the web-app-deployment deployment on port 8888.
Command: ```bash kubectl port-forward deployment/web-app-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 be s...
Create a single ingress called 'app-ingress' that directs requests to foo.com/input to svc # svc1:8083 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="foo.com/input=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Create a new ExternalName service named 'external-payment-gateway-service' and map it to the external DNS name 'sandbox-site.co'
Command: ```bash kubectl create service externalname external-payment-gateway-service --external-name sandbox-site.co ``` 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 refere...
Forward local port 8000 to port 8081 in the specified pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8000 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 aut...
Add or update the 'backup-strategy' annotation of the 'media-stream' pod to 'daily-backups', overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods media-stream 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 ...
Add a taint with the key 'workload' and value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 workload=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": ...
Create a cluster role named "foo" with ResourceName specified as "blog-backend" and "prod-api-gateway"
Command: ```bash kubectl create clusterrole foo --verb=create --resource=configmaps --resource-name=blog-backend --resource-name=prod-api-gateway ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Listen on a random port locally and forward requests to port 6379 in the proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-pod :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 autom...
Set the cluster field in the 'dev-context' context to 'testing-cluster'
Command: ```bash kubectl config set contexts.dev-context.cluster testing-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...
Remove the label named 'bar' from the 'proxy' pod by running the command "kubectl label pods proxy app-".
Command: ```bash kubectl label pods proxy 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, c...
Create a new config map named "monitoring-config" with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/settings/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. When creat...
Output the modified backend-microservice-deployment YAML, with the environment variable LOG_LEVEL set to "info"
Command: ```bash kubectl set env deployment/backend-microservice-deployment LOG_LEVEL=info -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...
Create a copy of the chat-app-pod and change all container images to centos.
Command: ```bash kubectl debug chat-app-pod --copy-to=dgb-img --set-image=*=centos ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource is...
Set the custom TLS server name to use for validation for the 'dev-cluster' cluster entry as 'staging-cluster'
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=staging-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] [--certifica...
Import environment variables from a secret for the specified deployment
Command: ```bash kubectl set env --from=secret/ssl-key-secret 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 definitions in one or more ...
Begin streaming the logs of a specific container in a pod.
Command: ```bash kubectl logs -f -c nano-bot vpn-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", "sho...
Pause the nginx deployment
Command: ```bash kubectl rollout pause deployment/nginx ``` What it does: Mark the provided resource as paused. Paused resources will not be reconciled by a controller. Use "kubectl rollout resume" to resume a paused resource. Currently only deployments support being paused. Syntax: `kubectl rollout pause RESOURCE` ...
Add a taint on nodes with label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice environment=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": ""...
Forward local traffic on port 8000 to port 5000 on a pod selected by the web-app-deployment deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8000 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 s...
Update the pod 'foo' with the annotation 'last-deployment' and set the value to '2023-03-15', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods foo 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 i...
Create a debug copy of the analytics pod, changing all container images to use the postgres image.
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-memcached --set-image=*=postgres ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default ...
Forward port 5432 in the pod named "frontend-pod" to port 9090 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 9090: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...
Create a copy of the "chat-app-pod" with a debug container and change container images
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-memcached --image=debian --set-image=mailer=mailer:latest,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Output the modified YAML of the 'cache-cluster-deployment' deployment with the environment variable 'MONGO_URI' set to 'mongodb://localhost:27017/mydb' without making any changes to the deployment on the server.
Command: ```bash kubectl set env deployment/cache-cluster-deployment MONGO_URI=mongodb://localhost:27017/mydb -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 definit...
Auto scale the deployment "frontend" with the number of pods ranging from 7 to 11.
Command: ```bash kubectl autoscale deployment frontend --min=7 --max=11 ``` 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...
Execute the 'mysqld' command inside the 'log-aggregator-pod' pod and get the output
Command: ```bash kubectl exec log-aggregator-pod -- mysqld ``` 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...
Edit a service using the "micro" editor
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/proxy-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,...
Create a copy of the `backend-pod` with a debug container, and change container images to `debian`
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-app --image=debian --set-image=mailer=mailer:latest,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Expose a replication controller named "php" by creating a service that serves on port 8084 and connects to the containers on port 808100.
Command: ```bash kubectl expose rc php --port=8084 --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. A ...
Execute the 'dotnet --list-sdks' command in the pod log-aggregator-pod, specifically in the container nebula-navigator, and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c nebula-navigator -- dotnet --list-sdks ``` 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 n...
Execute the command 'geth version' in the mycontainer container of the proxy-server-pod pod and retrieve the output.
Command: ```bash kubectl exec proxy-server-pod -c mycontainer -- geth 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 omitt...
Create a cluster role named "admin_role" with specific access permissions to pods with resource names "report-generator" and "machine-learning"
Command: ```bash kubectl create clusterrole admin_role --verb=get --resource=pods --resource-name=report-generator --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-run=server|c...
Create a single ingress called 'private-service-ingress' that directs requests to site.com/example to svc1:8089 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="site.com/example=svc1:8089,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
delete pods and services with names "backend" and "vpn"
Command: ```bash kubectl delete pod,service backend vpn ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Som...
Set the service account for the deployment "scheduler-app-deployment" to "kube-proxy"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment kube-proxy ``` 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: `k...
Remove the taint with key 'disktype' from node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 disktype- ``` 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|ya...
Listen on port 5000 on all addresses and forward the traffic to port 8080 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 5000: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 ...
Update the pod named 'analytics' with the label 'component' and set its value to 'api'
Command: ```bash kubectl label pods analytics component=api ``` 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"...
forward traffic from port 8888 on all addresses to port 8088 in the web-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8888: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 ...
Retrieve the logs from container "payment-gateway-pod-1" in the deployment "mydeployment"
Command: ```bash kubectl logs deployment/mydeployment -c payment-gateway-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": "...
Use an alternative editor to edit the logging-service service configuration
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/logging-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, ...
Forward local port 8080 to port 8088 in the pod.
Command: ```bash kubectl port-forward pod/analytics-pod 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 auto...
Create a deployment named "worker" with the specified image and port.
Command: ```bash kubectl create deployment worker --image=mcr.microsoft.com/dotnet/core/runtime --port=8080 ``` 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": "", "us...
Configure the 'kube-cluster-1' cluster to use 'prod-cluster' as the custom TLS server name for validation.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=prod-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Forward the local port 8088 to port 8088 in the pod/analytics-pod, listening on the localhost and the IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8088: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 crite...
import environment variables from the config map into a deployment with a specified prefix
Command: ```bash kubectl set env --from=configmap/namespace-config --prefix=MYSQL_ 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 def...
Import environment variables from the 'tls-certificate-secret' secret into the 'web-app-deployment' deployment
Command: ```bash kubectl set env --from=secret/tls-certificate-secret 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 in one or mor...
import the specific key CONFIG_FILE_PATH from the config map 'app-config' and set it as an environment variable in the 'search-engine-deployment' deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config 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 defi...
Delete both the 'database' pod and 'database' service, as well as the 'proxy-server' pod and 'proxy-server' service.
Command: ```bash kubectl delete pod,service database proxy-server ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label sel...
Create an ingress called 'rontend-ingress' that directs requests from foo.com/bar to a service named svc1 running on port 9091
Command: ```bash kubectl create ingress rontend-ingress --rule="foo.com/bar=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Check if you have permission to list the jobs with the name "cron-job" in the "cert-manager" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/cron-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 partial URL that...
Create a pod named hazelcast using the ethereum/client-go image and expose port 8083 in the container.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=8083 ``` 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: ...
Create a single ingress called 'private-service-ingress' that directs requests to testing.com/bar to svc # svc1:3306 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/bar=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Create an ingress called 'api-gateway-ingress' that handles requests to foo.com/module and directs them to the service 'svc1' on port 8084
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/module=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": "", "u...
Create a new config map named namespace-config in the current namespace, using the contents of the files file1.txt and file2.txt, with keys conf and data respectively.
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/profiles/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...
Embed the certificate authority data for the galaxy-cluster cluster entry and specify the certificate authority file as ~/.kube/cluster-gamma/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/cluster-gamma/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Create a new config map named 'app-secrets' with the keys 'settings' and 'key2' mapped to the respective files '/path/to/configurations/file1.txt' and '/path/to/preferences/file2.txt'
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/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 cr...
Create a new pod named "hazelcast" with the centos image and set the labels "app=centos" and "env=prod"
Command: ```bash kubectl run hazelcast --image=centos --labels="app=centos,env=prod" ``` 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 ...
Add a taint with the key 'disktype' on nodes that have the label service=auth
Command: ```bash kubectl taint node -l service=auth disktype=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Import the SECRET_KEY key from the monitoring-config config map into the database-deployment deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/monitoring-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 definiti...
Begin streaming the logs of the 'nebula-navigator' container in the 'payment-gateway-pod' pod.
Command: ```bash kubectl logs -f -c nebula-navigator payment-gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--cont...
Set the service account of the deployment named "database-deployment" to "kube-controller-manager"
Command: ```bash kubectl set serviceaccount deployment database-deployment kube-controller-manager ``` 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 Sy...
Forward port 8888 on your local machine to port 8088 in a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 8888 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 selecte...
Execute the 'geth' command inside the first pod of the scheduler-app-deployment deployment.
Command: ```bash kubectl exec deploy/scheduler-app-deployment -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...