prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Display only the most recent 12 lines of logs for the 'api-service-pod' pod.
Command: ```bash kubectl logs --tail=12 api-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": ...
Forward traffic from port 5432 on your local machine to port 8888 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod 5432: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...
Partially update the configuration of a node by applying a strategic merge patch in JSON format
Command: ```bash kubectl patch node prod-node-5 -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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 p...
Forward the traffic from all addresses on port 8080 to port 8080 in the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
List deployments in JSON output format for the specific version and API group
Command: ```bash kubectl get deployments.hotfix-1.1.2.internal-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced...
Execute the 'kafka-server-start /etc/kafka/server.properties' command inside the 'nebula-navigator' container of the 'gateway-pod' pod and display its output.
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- kafka-server-start /etc/kafka/server.properties ``` 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": "",...
Expose the replica set "wordpress" as a service on port 8010, which will connect to the containers on port 909200.
Command: ```bash kubectl expose rs wordpress --port=8010 --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...
Create an ingress named 'ingsecret' in the 'default' class with a rule that routes all requests to 'site.com' to the service 'svc:5000'
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="site.com/*=svc:5000,tls=secret1" ``` 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 a copy of the media-stream-pod with all container images changed to mysql.
Command: ```bash kubectl debug media-stream-pod --copy-to=debug-image-1 --set-image=*=mysql ``` 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 re...
Attach to the warp-drive container in the chat-app-pod pod and get the output.
Command: ```bash kubectl attach chat-app-pod -c warp-drive ``` 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 ...
Update the annotation of pod 'vpn' to 'env=staging', replacing any existing value for the 'env' key.
Command: ```bash kubectl annotate --overwrite pods vpn env='staging' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrar...
Get the output from running the 'dotnet' command on the first pod of the 'loadbalancer-service' service.
Command: ```bash kubectl exec svc/loadbalancer-service -- dotnet ``` 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...
Create an ingress resource called 'external-ingress' with a rule that directs requests to website.com/input to the svc1 service on port 5000, using the tls secret 'my-cert'.
Command: ```bash kubectl create ingress external-ingress --rule="website.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": "", "u...
Update the image of all containers in the namespace-2 daemonset to 'nginx:1.21.3'
Command: ```bash kubectl set image daemonset namespace-2 *=nginx:1.21.3 ``` 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), replicaset (rs) Syntax: ...
Update the pod with the name 'auth' by adding a label 'release' with the value 'v2.0'
Command: ```bash kubectl label pods auth release=v2.0 ``` 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 ...
forward the local port 8080 to port 5432 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-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 be selected a...
Start a pod named "hazelcast" using the "wordpress" image and expose port 9090.
Command: ```bash kubectl run hazelcast --image=wordpress --port=9090 ``` 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": "...
Forward traffic from port 3000 on all addresses to port 8000 in the analytics-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 3000: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 wil...
Create a cluster role named "foo" with permissions to access a non-resource URL
Command: ```bash kubectl create clusterrole "foo" --verb=use --non-resource-url=/healthz ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "...
Auto scale the replication controller "email" with a target CPU utilization of 40% and a minimum of 1 pod and a maximum of 3 pods.
Command: ```bash kubectl autoscale rc email --max=3 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses t...
Add or update the 'criticality' annotation of pod 'cdn' with the value 'high', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods cdn criticality='high' ``` 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 arb...
Check if you have the permission to list the "cache-warming-job" job in the "namespace-1" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cache-warming-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 partial ...
Automatically scale the replication controller "web" with the maximum number of pods set to 3, and target CPU utilization at 60%.
Command: ```bash kubectl autoscale rc web --max=3 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/api-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Run the 'nginx -t' command in the 'time-machine' container of the 'e-commerce-pod' pod to get the output
Command: ```bash kubectl exec e-commerce-pod -c time-machine -- nginx -t ``` 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...
Create a service for a Hazelcast deployment that serves on port 9091 and connects to the containers on port 909200.
Command: ```bash kubectl expose deployment hazelcast --port=9091 --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 spec...
Create a deployment named auth that runs the mysql image and exposes port 6379
Command: ```bash kubectl create deployment auth --image=mysql --port=6379 ``` 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...
Update the label of the pod 'payment' to set 'unhealthy' as 'true'
Command: ```bash kubectl label pods payment unhealthy=true ``` 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":...
Retrieve the version of npm running in the first container of the order-service service
Command: ```bash kubectl exec svc/order-service -- npm --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 omitted, use the k...
Retrieve the previous terminated logs of the "mycontainer" container from the "security-service-pod" pod
Command: ```bash kubectl logs -p -c mycontainer security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Forward traffic from local port 3000 to the target port of the "https" service port in a selected pod for the "gateway-service" service.
Command: ```bash kubectl port-forward service/gateway-service 3000: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 select...
Start streaming the logs of the 'cosmic-container' container in the 'e-commerce-pod' pod
Command: ```bash kubectl logs -f -c cosmic-container 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...
Switch to raw terminal mode and attach to the cdn-service-pod container named warp-drive
Command: ```bash kubectl attach cdn-service-pod -c warp-drive -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 omit...
Get the output from the 'mongod' command running on the first pod of the 'search-service' service.
Command: ```bash kubectl exec svc/search-service -- 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, use the kubectl...
Create an ingress resource that directs requests to a specific service on a specific port, with a TLS certificate
Command: ```bash kubectl create ingress private-service-ingress --rule="site.com/example=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Forward traffic from a local port to a specific port in a pod.
Command: ```bash kubectl port-forward pod/chat-app-pod :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 automatic...
Create a role named "view" with the ability to patch pods and specifically target the resources "nginx-proxy" and "error-logger"
Command: ```bash kubectl create role view --verb=patch --resource=pods --resource-name=nginx-proxy --resource-name=error-logger ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|...
Start a pod named hazelcast using the hazelcast/hazelcast container image and expose port 8083 on the pod.
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --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:...
import the 'external_api_url' key from the 'app-secrets' config map and set it as an environment variable for the 'email-server-deployment' deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-secrets deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Listen on port 9090 on localhost and IP address 10.19.21.23, and forward the traffic to port 8080 in the pod named 'proxy-server-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 9090:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cr...
Create an ingress with two annotations: ingress.annotation1 and ingress.annotations2
Command: ```bash kubectl create ingress annotated --class=default --rule="foo.com/module=svc:port" \ --annotation ingress.annotation1=website \ --annotation ingress.annotation2=bla ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=sec...
Apply a taint with the key 'hardware' on nodes that have the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe hardware=testing-node-11: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...
Set basic auth credentials for the "app-service" entry
Command: ```bash kubectl config set-credentials app-service --username=admin --password=uXFGweU9l35qcif ``` 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: --client-certificate=certfile --client-key=keyfile...
Create a cluster role named "bar" with specific resource names and desired permissions
Command: ```bash kubectl create clusterrole bar --verb=use --resource=services --resource-name=nginx-proxy --resource-name=identity-provider ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|n...
create a config map named namespace-config using specified key-value pairs from files
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When ...
Create a new config map named log-config using the specified files, where "conf" key represents the contents of /path/to/configurations/file1.txt and "data" key represents the contents of /path/to/configurations/file2.txt
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Update the pod specified in the "conf.json" file by adding the custom-label annotation with the value "my-custom-value"
Command: ```bash kubectl annotate -f conf.json custom-label=my-custom-value ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Import environment variables from a secret to a deployment named "scheduler-app-deployment"
Command: ```bash kubectl set env --from=secret/password-secret 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 definitions in one or more...
Apply a taint to the 'node-2' node with the key 'environment' and no value that prevents scheduling.
Command: ```bash kubectl taint nodes node-2 environment: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: js...
Copy a local file to a remote pod in a specific namespace
Command: ```bash kubectl cp /tmp/foo cert-manager/ingress-controller-pod-8:/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 local port 9090 to port 8000 in the pod selected by the deployment "search-engine-deployment"
Command: ```bash kubectl port-forward deployment/search-engine-deployment 9090 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 wil...
Create a service for the ubuntu deployment on port 9091, connecting to containers on port 808800.
Command: ```bash kubectl expose deployment ubuntu --port=9091 --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 specifi...
Copy the file "foo" from the "/tmp" directory in the remote pod named "logging-agent-pod-7" to the "/tmp" directory in your local machine
Command: ```bash kubectl cp :/tmp/foo logging-agent-pod-7::/tmp/bar -c ingress-controller ``` 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...
Copy the file /tmp/foo from the remote pod named cache-pod-5 in the kube-public namespace, and copy it to the local machine at the /tmp/bar location.
Command: ```bash kubectl cp kube-public/cache-pod-5:/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 kubectl.k...
Create a job named "log-collection" using the Ruby image, running the interactive Ruby (IRB) command.
Command: ```bash kubectl create job log-collection --image=ruby -- irb ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Listen on port 6379 on all addresses, forwarding to port 8081 in the analytics-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 6379:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Create a new config map named app-secrets using the properties file /path/to/parameters/file1.txt and the key1 file /path/to/options/file2.txt
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/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...
Create a cluster role named "admin_role" with the ability to update configmaps and specifically the configmaps with the resource names "identity-provider" and "search-elasticsearch"
Command: ```bash kubectl create clusterrole admin_role --verb=update --resource=configmaps --resource-name=identity-provider --resource-name=search-elasticsearch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dr...
Return previous terminated logs of stardust-shuttle container in media-stream-pod
Command: ```bash kubectl logs -p -c stardust-shuttle media-stream-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": "--contain...
Set a custom TLS server name for the galaxy-cluster cluster entry.
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=dev-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] [--certificat...
Start a new pod named nginx using the node image, but override the pod specification with the values provided in the given JSON file.
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "v1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND]...
Create a LoadBalancer service named database-lb
Command: ```bash kubectl create service loadbalancer database-lb --tcp=9090:8083 ``` 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", "defaul...
Create a new LoadBalancer service named web-app-lb that listens on port 8082 and forwards traffic to port 7000
Command: ```bash kubectl create service loadbalancer web-app-lb --tcp=8082:7000 ``` 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", "default...
Create a debug container based on a copy of the frontend-pod, with all container images changed to redis.
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-app --set-image=*=redis ``` 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 reso...
Start a pod named "hazelcast" with the image "ubuntu" and expose port 5432
Command: ```bash kubectl run hazelcast --image=ubuntu --port=5432 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create a role named "reader" that allows the "create" verb on the "pods" resource with the resource names "error-logger" and "web-frontend"
Command: ```bash kubectl create role reader --verb=create --resource=pods --resource-name=error-logger --resource-name=web-frontend ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|cli...
Create a deployment named "mattermost" with an image of "redis" and a command of "redis-cli"
Command: ```bash kubectl create deployment mattermost --image=redis -- redis-cli ``` 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...
Set the CPU and memory limits and requests for all containers in the elasticsearch deployment.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=1,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 re...
Create a LoadBalancer service named gateway-lb for routing traffic from port 8443 externally to port 3001 internally.
Command: ```bash kubectl create service loadbalancer gateway-lb --tcp=8443: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", "default...
Create a service for a replicated alpine container, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc alpine --port=8088 --target-port=808100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a new LoadBalancer service named 'frontend-lb' that maps port 7000 to port 3001.
Command: ```bash kubectl create service loadbalancer frontend-lb --tcp=7000: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", "defaul...
Autoscale the 'payment' replication controller with a minimum of 1 pod, a maximum of 7 pods, and a target CPU utilization of 40%
Command: ```bash kubectl autoscale rc payment --max=7 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Create a new pod named 'hazelcast' using the 'docker.elastic.co/elasticsearch/elasticsearch' image and expose port 3001.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=3001 ``` 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] ...
Create a service using the configuration in the "ubuntu-controller.yaml" file, which exposes port 8081 and connects to the containers on port 700000
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8081 --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...
Create an ingress called 'internal-ingress' with the following rules: direct requests to site.com/module to svc1:8181 and use the tls secret "my-cert"
Command: ```bash kubectl create ingress internal-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": "", "usa...
Listen on port 3000 locally, forwarding data to/from port 8888 in the authentication-service-deployment pod.
Command: ```bash kubectl port-forward deployment/authentication-service-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, ...
Copy the /tmp/foo_dir directory from the remote 'database-pod-2' pod in the 'default' namespace to the /tmp/bar_dir directory locally.
Command: ```bash kubectl cp default/database-pod-2:/tmp/foo_dir /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, use the kub...
Retrieve the logs of the previous terminated 'nano-bot' container from the 'security-service-pod' pod
Command: ```bash kubectl logs -p -c nano-bot security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Update the annotation 'env' of the pod 'monitoring' to 'staging', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods monitoring env='staging' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Set up autoscaling for the deployment "payment" with a minimum of 6 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment payment --min=6 --max=13 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Forward all traffic from port 8080 of any address to port 8888 of the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8080: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 ...
Create an ingress resource named 'private-ingress' with a rule that directs requests to foo.com/module and forwards them to the service 'svc1' on port 3306
Command: ```bash kubectl create ingress private-ingress --rule="foo.com/module=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
List multiple resources by their types and names
Command: ```bash kubectl get rc/web service/chat-app-rc pods/vpn-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 namespace...
Listen on port 8000 locally and forward the traffic to port 3000 in the pod named 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 8000: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 selected au...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/email-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 nam...
Create a new ingress called 'api-v2-ingress' with the following rule: site.com/input should be directed to svc1:8084
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/input=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": "", "usage"...
Get output from the astro-container in the chat-app-pod by attaching to it.
Command: ```bash kubectl attach chat-app-pod -c astro-container ``` 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,...
Update the environment variable 'MAX_CONNECTIONS' for the deployment 'email-server-deployment'
Command: ```bash kubectl set env deployment/email-server-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 templa...
Create a new config map named ui-config with the specified keys and their corresponding values from the provided files
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/properties/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 creati...
Start streaming the logs of the "cyber-sleuth" container in the "e-commerce-pod" pod
Command: ```bash kubectl logs -f -c cyber-sleuth 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", "...
Retrieve the logs of the previous terminated time-machine container from the e-commerce-pod pod.
Command: ```bash kubectl logs -p -c time-machine 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", "...
Forward local port 5000 to port 6379 in the pod named 'mypod'.
Command: ```bash kubectl port-forward pod/mypod 5000: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 automaticall...
Attach to the pod "log-aggregator-pod" and get the output from the "cosmic-container"
Command: ```bash kubectl attach log-aggregator-pod -c cosmic-container ``` 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 o...
Auto scale the deployment "media-stream" with a minimum of 4 pods and a maximum of 15 pods.
Command: ```bash kubectl autoscale deployment media-stream --min=4 --max=15 ``` 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...
Return the snapshot of the previous terminated logs from the 'nano-bot' container inside the 'monitoring-pod' pod.
Command: ```bash kubectl logs -p -c nano-bot monitoring-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", "shor...
Add a taint on nodes with a specific label
Command: ```bash kubectl taint node -l namespace=mynamespace disktype=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...
Retrieve the previous logs of the terminated nebula-navigator container from the cdn-service-pod pod
Command: ```bash kubectl logs -p -c nebula-navigator cdn-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": "--containe...
Attach to the cosmic-container in the e-commerce-pod and receive its output.
Command: ```bash kubectl attach e-commerce-pod -c cosmic-container ``` 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 omitt...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=database_url --from=configmap/env-vars 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 taint with key 'app' from node 'monitoring-node-15'
Command: ```bash kubectl taint nodes monitoring-node-15 app- ``` 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|yam...