prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Copy the local file /tmp/foo_dir to the remote pod argocd/metrics-exporter-pod-10 in the /etc/kubernetes directory
Command: ```bash kubectl cp /tmp/foo_dir argocd/metrics-exporter-pod-10:/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, ...
Import the "database_url" key from the config map "app-settings" into the "order-processing-deployment" deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-settings 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...
Partially update the configuration of a node by applying a strategic merge patch in JSON format.
Command: ```bash kubectl patch node dev-node-4 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags: ...
Create a deployment named "ingress" with 5 replicas, using the "confluentinc/cp-kafka" image.
Command: ```bash kubectl create deployment ingress --image=confluentinc/cp-kafka --replicas=5 ``` 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 ...
Get the output from running a command inside a pod
Command: ```bash kubectl exec deploy/notification-handler-deployment -- 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", "defaul...
Execute the command 'apk add curl' inside the 'warp-drive' container of the 'api-service-pod' pod and display the output.
Command: ```bash kubectl exec api-service-pod -c warp-drive -- apk add curl ``` 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...
import the specific key 'secret_key' from the 'ui-config' ConfigMap into the 'notification-handler-deployment' deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/ui-config deployment/notification-handler-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...
Import the environment variables from the `email-credentials-secret` secret and set them in the `frontend-deployment` deployment.
Command: ```bash kubectl set env --from=secret/email-credentials-secret deployment/frontend-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 ...
Add a taint with the key 'zone' and value 'db-node-7:PreferNoSchedule' on nodes having the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel zone=db-node-7: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 forma...
Forward traffic from local port 9090 to port 8081 in the pod
Command: ```bash kubectl port-forward pod/mypod 9090:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Taint the nodes with the label "version=v1.0.0" by adding a taint with the key "disktype" and value "db-node-7:PreferNoSchedule"
Command: ```bash kubectl taint node -l version=v1.0.0 disktype=db-node-7: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...
Add a taint on nodes labeled component=proxy with the key 'cpu-type' and the value 'node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l component=proxy cpu-type=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": "Out...
Get interactive shell access to the cdn-service-pod container named quantum-quark and run the 'geth attach' command to interact with the geth Ethereum client in the pod.
Command: ```bash kubectl exec cdn-service-pod -c quantum-quark -- geth attach ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Create a copy of the 'security-service-pod' pod and change all container images to 'docker.elastic.co/elasticsearch/elasticsearch'
Command: ```bash kubectl debug security-service-pod --copy-to=debug-image-app --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Create a cluster role named "default_role" with the ability to perform the "delete" verb on non-resource URLs starting with "/apis/*".
Command: ```bash kubectl create clusterrole "default_role" --verb=delete --non-resource-url=/apis/* ``` 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",...
Create a new LoadBalancer service named auth-service-lb that maps port 8000 on the service to port 8081 on the pod.
Command: ```bash kubectl create service loadbalancer auth-service-lb --tcp=8000:8081 ``` 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", "de...
Wait for the pod "payment-gateway-pod" to be in the "Ready" state
Command: ```bash kubectl wait --for=condition=Ready pod/payment-gateway-pod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the comman...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "cluster-admin" entry.
Command: ```bash kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-secret- ``` 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 --clie...
Add a taint with key 'cpu-type' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack cpu-type=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Add a taint with the key 'datacenter' and value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend datacenter=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 new config map named 'app-name-config' by using the key=value pairs in the file located at 'path/to/profiles'
Command: ```bash kubectl create configmap app-name-config --from-file=path/to/profiles ``` 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 basen...
Copy the local file '/tmp/foo' to the '/tmp/bar_dir' directory in the remote pod 'backend-pod-13' in the 'kube-public' namespace.
Command: ```bash kubectl cp /tmp/foo kube-public/backend-pod-13:/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...
Add a taint to the node 'kube-master-9' with the key 'special', value 'backup', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes kube-master-9 special=backup: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. ...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp velero/admin-dashboard-pod-16:/var/run/secrets/kubernetes.io/serviceaccount/ :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "C...
listen on port 8088 on your local machine and forward traffic to port 5000 in the pod named 'e-commerce-pod'
Command: ```bash kubectl port-forward pod/e-commerce-pod 8088:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Add a taint with key 'disktype' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster 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": "", "usage...
Create a deployment named 'web' with the image 'ruby' and pass the command 'ruby --version'
Command: ```bash kubectl create deployment web --image=ruby -- ruby --version ``` 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: ...
Create a new config map named app-secrets using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a co...
create a service for the replication controller specified in "ruby-controller.yaml" file, serving on port 8888 and connecting to the containers on port 801000
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8888 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Embed the certificate authority data for the testing-cluster cluster entry by running the command "kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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...
Configure the replication controller "web" to automatically scale the number of pods between 1 and 4 based on CPU utilization, with a target utilization of 81%.
Command: ```bash kubectl autoscale rc web --max=4 --cpu-percent=81 ``` 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...
Retrieve the snapshot log from the container web-app-deployment-1 in the deployment named e-commerce-pod.
Command: ```bash kubectl logs deployment/web-app-deployment -c e-commerce-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": ...
Import specific keys from a config map into an environment variable in a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-secrets 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 def...
Create a new ClusterIP service named 'billing-service-clusterip' that maps TCP port 8010 to port 5001.
Command: ```bash kubectl create service clusterip billing-service-clusterip --tcp=8010:5001 ``` 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"...
Copy the local directory "/tmp/foo_dir_dir" to "/tmp/bar_dir" inside the "monitoring-agent-pod-6" pod in the "default" namespace.
Command: ```bash kubectl cp /tmp/foo_dir_dir monitoring-agent-pod-6::/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 th...
Import environment variables from a config map with a prefix
Command: ```bash kubectl set env --from=configmap/env-vars --prefix=MYSQL_ 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 definitions in ...
Forward traffic from port 8888 to port 9090 on the pod, listening on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8888: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 w...
Create a copy of the pod "api-service-pod" with a debug container, changing container images to "debian"
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=database=mysql:5.7,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by re...
Remove the label 'tier' from pod 'media-stream'
Command: ```bash kubectl label pods media-stream tier- ``` 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...
Get the output from running the 'dotnet --list-sdks' command in the cyber-sleuth container of the payment-gateway-pod pod
Command: ```bash kubectl exec payment-gateway-pod -c cyber-sleuth -- 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 name...
Create a new config map named log-config using properties from the file '/path/to/configs/file1.txt' and key1 from the file '/path/to/preferences/file2.txt'
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/configs/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 creating...
Add a taint to the 'storage-node-13' node with the key 'workload' and no value
Command: ```bash kubectl taint nodes storage-node-13 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 ...
Create a service for a replication controller using the specifications in the "python-controller.yaml" file
Command: ```bash kubectl expose -f python-controller.yaml --port=9000 --target-port=888800 ``` 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...
Set the environment variables in the 'cache-cluster-deployment' deployment by importing them from the 'jwt-secret' secret.
Command: ```bash kubectl set env --from=secret/jwt-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 pod ...
Retrieve the output from running the 'mongo --version' command in the 'stardust-shuttle' container from the 'chat-app-pod' pod.
Command: ```bash kubectl exec chat-app-pod -c stardust-shuttle -- mongo --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 o...
Forward local port 5432 to port 8888 in the pod
Command: ```bash kubectl port-forward pod/web-app-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 automa...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/namespace-config deployment/notification-handler-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 variab...
Create a new config map called "global-config" with specified keys and their corresponding values from different files
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/options/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 creating a...
Create an ingress resource named 'internal-ingress' that directs requests for foo.com/example to the service 'svc1' on port 7000, and use the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress internal-ingress --rule="foo.com/example=svc1:7000,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...
Add label 'role=backend' to the pod 'vpn'
Command: ```bash kubectl label pods vpn role=backend ``` 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 t...
Add a taint with key 'zone' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace zone=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Assign a service account called "metrics-server" to the deployment named "payment-processor-deployment"
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment metrics-server ``` 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...
Create a pod using the Ruby image and expose port 9091
Command: ```bash kubectl run hazelcast --image=ruby --port=9091 ``` 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...
Create a new config map named monitoring-config using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/data/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 creati...
List the resources of different types by their names
Command: ```bash kubectl get rc/web service/security-service-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 n...
Create a cron job with a given image and schedule.
Command: ```bash kubectl create cronjob weekly-summary --image=nginx --schedule="*/1 * * * *" -- nginx ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "de...
Create a Pod Disruption Budget named 'cache-cluster-pdb' that will select all pods with the label 'app=rails' and ensure that at least four of them are available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=app=rails --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 [-...
create a job called 'database-seeding-job' using the ethereum/client-go image, and execute the command 'geth attach' inside the job container.
Command: ```bash kubectl create job database-seeding-job --image=ethereum/client-go -- geth attach ``` 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": "", "usa...
Execute the command 'yum install -y wget' inside the 'code-explorer' container in the 'web-app-pod' pod and retrieve the output.
Command: ```bash kubectl exec web-app-pod -c code-explorer -- yum install -y wget ``` 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 o...
Create a secret named docker-registry-secret from an environment file.
Command: ```bash kubectl create secret generic docker-registry-secret --from-env-file=path/to/settings.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to t...
Get the previous terminated logs of the warp-drive container from the mypod pod
Command: ```bash kubectl logs -p -c warp-drive mypod ``` 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 an ingress called 'internal-ingress' that directs requests to foo.com/example to a specific service with tls encryption
Command: ```bash kubectl create ingress internal-ingress --rule="foo.com/example=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": "", "usa...
Create a hazelcast pod with custom specifications provided in a JSON file
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "beta-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] [--comm...
Create a copy of the "gateway-pod" with all container images changed to "golang"
Command: ```bash kubectl debug gateway-pod --copy-to=debug-image-1 --set-image=*=golang ``` 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 resour...
Set the custom TLS server name to "e2e" for the "star-cluster" cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=e2e ``` 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] [--certificate-authorit...
Output the modified deployment in YAML format without actually making any changes to the object on the server.
Command: ```bash kubectl set env deployment/gateway-deployment ENV=prod -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (wit...
Remove taints from node
Command: ```bash kubectl taint nodes edge-node-10 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|yaml|name...
Start streaming the logs from the "nebula-navigator" container in the "proxy-service-pod" pod.
Command: ```bash kubectl logs -f -c nebula-navigator proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--contai...
Create a debug container named dgb-img from the vpn-service-pod with all container images changed to "redis"
Command: ```bash kubectl debug vpn-service-pod --copy-to=dgb-img --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 resource ...
Auto scale the replication controller "auth" based on CPU utilization
Command: ```bash kubectl autoscale rc auth --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 th...
Create a new config map named env-vars using specific files as input
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/data/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 confi...
Print the supported API resources sorted by a specific column
Command: ```bash kubectl api-resources --sort-by=version ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Forward local port 3000 to port 8080 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000: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 certificate authority data for the 'cloud-cluster' cluster entry in the kubeconfig file.
Command: ```bash kubectl config set-cluster cloud-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 s...
Set the environment variable "max_connections" from the values in the config map "global-config" for the deployment "search-engine-deployment"
Command: ```bash kubectl set env --keys=max_connections --from=configmap/global-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 de...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-name-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Copy the directory "/tmp/foo_dir" from the remote pod "backend-pod-13" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp kube-dns/backend-pod-13:/tmp/foo_dir /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Create a cluster role named "admin_role" with the ResourceName specified as "keycloak-server" and "payment-processor" for the "services" resource
Command: ```bash kubectl create clusterrole admin_role --verb=proxy --resource=services --resource-name=keycloak-server --resource-name=payment-processor ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=se...
Apply a taint with the key 'environment' and the value 'k8s-node-1:PreferNoSchedule' on all nodes that have the label 'instance=app-instance-1'.
Command: ```bash kubectl taint node -l instance=app-instance-1 environment=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": ""...
Add a taint with the key 'environment' and value 'kube-master-9:PreferNoSchedule' on nodes having the label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 environment=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a LoadBalancer service named analytics-lb
Command: ```bash kubectl create service loadbalancer analytics-lb --tcp=8888:8181 ``` 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", "defau...
Create a job named "scaling-job" with the image "php" and the command "composer --version"
Command: ```bash kubectl create job scaling-job --image=php -- composer --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": "Output form...
Update the environment variables of the 'search-engine-deployment' deployment by importing the 'REDIS_HOST' key from the 'app-config-prod' config map.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-config-prod 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 defin...
import the SMTP_SERVER key from the global-config config map and set it as an environment variable in the web-app-deployment deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-config 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 ...
Listen on port 3000 on your local machine and forward traffic to port 5000 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 3000: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 auto...
Create an ingress resource called 'public-api-ingress' with a rule that directs requests for 'testing.com/module' to the service 'svc1' on port 5432
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/module=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Update the image of all containers in a daemonset to 'java:11.0.12'
Command: ```bash kubectl set image daemonset namespace-3 *=java:11.0.12 ``` 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: ...
Create an ingress called 'app-gateway-ingress' that directs requests from foo.com/example to svc1:5432, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/example=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
forward the traffic coming to all addresses on port 8080 to port 9090 inside the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8080: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 sel...
Embed the certificate authority data for the cluster named "prod-cluster" by running the provided command.
Command: ```bash kubectl config set-cluster prod-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 set...
Return the snapshot logs from the container named "vpn-service-pod-1" of the deployment named "web-app-deployment".
Command: ```bash kubectl logs deployment/web-app-deployment -c vpn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag":...
Execute the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' in the proxy-server-pod and retrieve the output from the first container.
Command: ```bash kubectl exec proxy-server-pod -- /bin/bash -c "echo 'Hello, Amazon Linux'" ``` 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 ...
Create a debug container in auth-service-pod with updated container images
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=web=nginx:latest,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource an...
Retrieve the previous terminated logs of the code-explorer container from the e-commerce-pod
Command: ```bash kubectl logs -p -c code-explorer 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", ...
Add the annotation "monitoring-tool=Prometheus" to the pod specified in the "conf.json" file.
Command: ```bash kubectl annotate -f conf.json monitoring-tool=Prometheus ``` 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...
Start streaming the logs of the 'cosmic-container' container within the 'web-app-pod' pod.
Command: ```bash kubectl logs -f -c cosmic-container web-app-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", ...
Create a cron job named 'alerts-cleanup' using the 'alpine' image, with a schedule of running every minute, and the command being 'sleep 3600'
Command: ```bash kubectl create cronjob alerts-cleanup --image=alpine --schedule="*/1 * * * *" -- sleep 3600 ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o...
Import the specific keys REDIS_HOST from the config map ui-config into the frontend-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/ui-config deployment/frontend-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 o...
Update the image of all containers in the 'namespace-1' daemonset to 'wordpress:5.8.1'.
Command: ```bash kubectl set image daemonset namespace-1 *=wordpress:5.8.1 ``` 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) Synta...
Autoscale the deployment "analytics" with a minimum of 1 pod and a maximum of 11 pods
Command: ```bash kubectl autoscale deployment analytics --min=1 --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 us...