prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the custom TLS server name to 'star-cluster' for the 'galaxy-cluster' cluster entry.
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=star-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 local port 8888 to port 5000 in the pod `api-service-pod`
Command: ```bash kubectl port-forward pod/api-service-pod 8888: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...
Delete the pods and services with the names "vpn" and "vpn"
Command: ```bash kubectl delete pod,service vpn 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. Some re...
Retrieve the phase value of a specific pod
Command: ```bash kubectl get -o template pod/e-commerce-pod --template={{.status.phase}} ``` 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 ...
Create an ingress named 'private-api-ingress' with a rule that directs requests from testing.com/bar to svc1:8089
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/bar=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": "", "...
Create a new config map named env-vars with the specified keys and files
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/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 cre...
Create a cron job named "email-notifications" using the MongoDB image, with a schedule of running every minute, and pass the command "mongo".
Command: ```bash kubectl create cronjob email-notifications --image=mongo --schedule="*/1 * * * *" -- mongo ``` 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"...
Return the snapshot logs from the container named "mypod-1" in the deployment named "scheduler-app-deployment"
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c mypod-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": "--...
Add a taint with key 'workload' on nodes having label component=proxy
Command: ```bash kubectl taint node -l component=proxy workload=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...
Set the custom TLS server name to 'e2e' for the 'dev-cluster' cluster entry
Command: ```bash kubectl config set-cluster dev-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-authority...
Update the label of the pod 'frontend' to 'role=backend'
Command: ```bash kubectl label pods frontend 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": ...
Retrieve information about specific resources by specifying their names and types
Command: ```bash kubectl get rc/web service/proxy-server-rc pods/log-aggregator-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 na...
Remove the "client-secret" config value for the OpenID Connect auth provider of the "k8s-admin" entry
Command: ```bash kubectl config set-credentials k8s-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 --client-k...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/ui-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 variable definit...
Forward local ports 3000 and 6000 to ports 3000 and 6000 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000 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...
Forward local port 6379 to port 8081 in the web-app-pod pod
Command: ```bash kubectl port-forward pod/web-app-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 will be selected automa...
Create a cron job called "cron-task" that runs the command "dotnet --list-runtimes" every minute.
Command: ```bash kubectl create cronjob cron-task --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-runtimes ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful f...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/log-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
In the testing-context, set the cluster field to cloud-cluster.
Command: ```bash kubectl config set contexts.testing-context.cluster cloud-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...
Show the supported API resources for the "events.k8s.io" API group
Command: ```bash kubectl api-resources --api-group=events.k8s.io ``` 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. "
Create a new generic secret named 'email-credentials-secret' with keys for each file inside the 'path/to/settings' folder.
Command: ```bash kubectl create secret generic email-credentials-secret --from-file=path/to/settings ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the bas...
Copy the file "/tmp/foo" from the remote pod "default/database-pod-2" to the local directory "/tmp/bar".
Command: ```bash kubectl cp default/database-pod-2::/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.ku...
Start a pod named "hazelcast" using the "ubuntu" image and expose port 9092.
Command: ```bash kubectl run hazelcast --image=ubuntu --port=9092 ``` 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 deployment named 'cache' using the 'amazonlinux' image and expose port 3306
Command: ```bash kubectl create deployment cache --image=amazonlinux --port=3306 ``` 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...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=log_level --from=configmap/ui-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 defin...
Create a role named "admin_role" with specific resource names
Command: ```bash kubectl create role admin_role --verb=connect --resource=pods --resource-name=dashboard-ui --resource-name=monitoring-prometheus ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-...
Create a copy of the 'proxy-service-pod' and change all container images to 'busybox' for debugging purposes.
Command: ```bash kubectl debug proxy-service-pod --copy-to=my-custom-dbg --set-image=*=busybox ``` 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...
Update the image of all containers in the 'namespace-3' daemonset to 'mysql:5.7.35'
Command: ```bash kubectl set image daemonset namespace-3 *=mysql:5.7.35 ``` 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 'email' pod by setting the annotation 'git-repo' to 'https://github.com/example/my-app', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods email git-repo='https://github.com/example/my-app' ``` 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...
Get the output from running the 'jenkins --version' command in the nano-bot container of the database-pod pod.
Command: ```bash kubectl exec database-pod -c nano-bot -- jenkins --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...
Create a cluster role named "bar" with the ability to watch pods and access the log-aggregator and document-storage resources.
Command: ```bash kubectl create clusterrole bar --verb=watch --resource=pods --resource-name=log-aggregator --resource-name=document-storage ``` 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...
Open the cache-service resource for editing using the nvim editor
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/cache-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, ...
Listen on port 9090 on all addresses, forwarding to port 9090 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Create an ingress called 'private-api-ingress' that directs requests from 'testing.com/input' to the service 'svc1' running on port '8888', using the TLS secret "my-cert".
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/input=svc1:8888,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 local port 9090 to port 8888 in the chat-app-pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 9090: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...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp kube-dns/worker-pod-4::/tmp/foo /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 kubectl...
Remove the 'env' label from the 'cdn' pod
Command: ```bash kubectl label pods cdn env- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, che...
Listen on port 5432 on all addresses, forwarding to port 8888 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 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...
Create a cluster role named "bar" with the specified non-resource URL of "/proxy/*" and the verb "list".
Command: ```bash kubectl create clusterrole "bar" --verb=list --non-resource-url=/proxy/* ``` 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": ...
Create a service for a replicated Python using a replica set, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rs python --port=80 --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 port. A...
Set the annotation 'env' with the value 'staging' for the pod 'analytics'
Command: ```bash kubectl annotate pods analytics 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 arbitrary string...
Remove the taint with key 'datacenter' and effect 'NoExecute' from the node 'db-node-7', if it exists
Command: ```bash kubectl taint nodes db-node-7 datacenter:NoExecute- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Get the snapshot logs from the container scheduler-app-deployment-1 of the deployment named cdn-service-pod.
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c cdn-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: "...
Update the service account of the deployment "proxy-service-deployment" to "kube-controller-manager".
Command: ```bash kubectl set serviceaccount deployment proxy-service-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), statefulse...
Listen on local port 8888 and forward data to/from port 5432 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 8888 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 auto...
Forward traffic from port 3000 on localhost and IP address 10.19.21.23 to port 5432 in the pod named api-service-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 3000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Interact with the cyber-sleuth container in the auth-service-pod and get the output
Command: ```bash kubectl attach auth-service-pod -c cyber-sleuth ``` 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...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-name-config deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Create a new ClusterIP service named "security-service-clusterip" that forwards traffic from port 3306 to port 9000
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=3306:9000 ``` 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...
Forward local traffic from port 3000 to port 5432 in the 'analytics-platform-deployment' deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 3000 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Set a custom TLS server name for validation for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --tls-server-name=data-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] [--certificate-authorit...
Add a taint with key 'cpu-type' and value 'edge-node-10:PreferNoSchedule' on nodes having label 'myLabel'
Command: ```bash kubectl taint node -l myLabel cpu-type=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": "", "usage": "Outpu...
Set a custom TLS server name for the cluster-beta cluster entry.
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=testing-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Get output from running the 'mongod' command in nebula-navigator from pod gateway-pod
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- 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, us...
Start a pod named nginx with the mongo image, but customize the pod specification using values parsed from a JSON override file
Command: ```bash kubectl run nginx --image=mongo --overrides='{ "apiVersion": "v1.1.1", "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...
Get the output from running the 'go' command in the pod 'web-app-pod'
Command: ```bash kubectl exec web-app-pod -- go ``` 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.kubernetes...
Listen on port 8081 locally and forward traffic to port 8081 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a new config map named "app-name-config" with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-name-config --from-file=settings=/path/to/parameters/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 deployment named sonarqube with the ruby image, and expose port 8088
Command: ```bash kubectl create deployment sonarqube --image=ruby --port=8088 ``` 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: ...
Forward local port 9090 to pod port 8000
Command: ```bash kubectl port-forward pod/proxy-server-pod 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 will be selected a...
Update the cluster field in the 'app-1-context' context to 'galaxy-cluster'
Command: ```bash kubectl config set contexts.app-1-context.cluster galaxy-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 ...
Edit the deployment 'proxy-service-deployment' by opening it in YAML format, make the necessary changes, and save the modified configuration in its annotation.
Command: ```bash kubectl edit deployment/proxy-service-deployment -o yaml --save-config ``` 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 en...
Copy the ~/.config/kube file from the pod named velero/image-resizer-pod-20 to the /etc/kubernetes directory on your local machine
Command: ```bash kubectl cp velero/image-resizer-pod-20:~/.config/kube /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Get the output from running the 'go version' command on the first pod of the 'database-deployment' deployment, using the first container by default.
Command: ```bash kubectl exec deploy/database-deployment -- go 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...
Output the modified deployment in YAML format without making changes on the server
Command: ```bash kubectl set env deployment/search-engine-deployment API_KEY=your-api-key -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 deployment named my-dep that runs the alpine image
Command: ```bash kubectl create deployment my-dep --image=alpine ``` 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|yaml|nam...
Edit the last-applied-configuration annotations of the resource specified in the file "parameters.yaml" using JSON output format.
Command: ```bash kubectl apply edit-last-applied -f parameters.yaml -o json ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open...
Import environment variables from the 'tls-certificate-secret' secret and set them for the 'user-management-deployment' deployment
Command: ```bash kubectl set env --from=secret/tls-certificate-secret deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Add a taint with key 'zone' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp zone=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": ...
Retrieve the snapshot logs from the container 'database-pod-1' of the 'cache-cluster-deployment' deployment
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c database-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: "fla...
Import specific keys from a config map into an environment variable of a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-dev deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Check if you have permissions to list the "log-rotation-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n kube-ingress ``` 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 ...
Configure an autoscaling policy for the deployment "frontend", with a minimum of 4 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment frontend --min=4 --max=8 ``` 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...
Start a pod named 'hazelcast' using the 'wordpress' image and expose port 3306
Command: ```bash kubectl run hazelcast --image=wordpress --port=3306 ``` 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": "...
Execute the 'pip --version' command inside the 'astro-container' in the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c astro-container -- pip --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...
Forward traffic from local port 9090 to port 8081 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 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 au...
Embed the certificate authority data for the entry of the 'cluster-gamma' cluster
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/staging-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...
Import the 'REDIS_HOST' key from the 'env-vars' config map and set it as an environment variable in the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/env-vars deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
List the replication controller 'web', service 'e-commerce-rc', and pod 'proxy-service-pod'
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/proxy-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is names...
Create a deployment named wordpress with the image amazonlinux and expose port 9090
Command: ```bash kubectl create deployment wordpress --image=amazonlinux --port=9090 ``` 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. O...
forward local traffic on port 5000 to port 6379 in the 'api-service-pod' pod
Command: ```bash kubectl port-forward pod/api-service-pod 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 au...
Add a taint with key 'workload' on nodes having label environment=production.
Command: ```bash kubectl taint node -l environment=production workload=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": "...
Set the service account of the deployment "analytics-platform-deployment" to "elasticsearch"
Command: ```bash kubectl set serviceaccount deployment analytics-platform-deployment elasticsearch ``` 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 cluster role named "default_role" with specified API Group, verbs, and resources
Command: ```bash kubectl create clusterrole default_role --verb=proxy,update,patch --resource=certificatesigningrequests.certificates.k8s.io ``` 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...
Partially update the specified node 'gpu-node-12' using a strategic merge patch, with the 'someField' value set to 'newValue'
Command: ```bash kubectl patch node gpu-node-12 -p $'spec:\n someField: newValue' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful ...
Create a new config map named env-vars using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/configs/file1.txt --from-file=data=/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 a config ma...
Add a taint to nodes with the label "instance=app-instance-1" to indicate that they are dedicated for a specific purpose, namely "monitoring".
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=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", "defaul...
Retrieve snapshot logs from container "log-aggregator-pod-1" of a deployment named "search-engine-deployment"
Command: ```bash kubectl logs deployment/search-engine-deployment -c log-aggregator-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...
Create a new config map named 'app-config-dev' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creat...
Create a job called 'audit-job' with an image 'jenkins' and run the command 'jenkins --version'
Command: ```bash kubectl create job audit-job --image=jenkins -- jenkins --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 for...
Create a new ExternalName service named external-cloud-storage-service pointing to the external domain test-site.org.
Command: ```bash kubectl create service externalname external-cloud-storage-service --external-name test-site.org ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference ...
Forward local port 6379 to port 9090 in the web-app-pod pod
Command: ```bash kubectl port-forward pod/web-app-pod 6379: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...
Create an ingress named 'myapp-ingress' that routes requests with the host 'testing.com/module' to the service named 'svc1' on port '6379'
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.com/module=svc1:6379,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Update the pod identified by the type and name in the "setup.json" file with the annotation "env=staging"
Command: ```bash kubectl annotate -f setup.json 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 arbitrary string ...
Create a new config map named env-vars using specified keys and file paths
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
Auto scale the replication controller "gateway" with a minimum of 1 pod, a maximum of 8 pods, and a target CPU utilization of 81%.
Command: ```bash kubectl autoscale rc gateway --max=8 --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...
Add a taint to nodes with the label 'component=proxy' with the taint key 'datacenter' and value 'node-1:PreferNoSchedule'.
Command: ```bash kubectl taint node -l component=proxy datacenter=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
create a new ExternalName service named external-identity-provider-service
Command: ```bash kubectl create service externalname external-identity-provider-service --external-name documentation-tech.tech ``` 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...
Update the annotation 'last-deployment' of pod 'analytics' with the value '2023-03-15', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods analytics 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...
Copy a file named "foo" from the "/tmp" directory of a remote pod to the "/tmp" directory locally.
Command: ```bash kubectl exec -n kube-public file-server-pod-14 -- tar cf - :/tmp/foo | tar xf - -C /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": "Contain...