prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Change the service account of the load-balancer-deployment deployment to "elasticsearch"
Command: ```bash kubectl set serviceaccount deployment load-balancer-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 Syntax:...
Attach to the 'stardust-shuttle' container in the 'gateway-pod', allowing direct interaction with the container's bash terminal
Command: ```bash kubectl attach gateway-pod -c stardust-shuttle -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 om...
Forward local port 3000 to port 5432 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-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 criteria, a pod will be selected auto...
List resources of different types using their names
Command: ```bash kubectl get rc/web service/media-stream-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 nam...
Set the cluster field in a specific context to a given value
Command: ```bash kubectl config set contexts.user-a-context.cluster edge-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you w...
Create a debug container in the e-commerce-pod and change its container image
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-memcached --image=debian --set-image=proxy=nginx:1.21,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 resou...
Forward local traffic to/from a pod's ports
Command: ```bash kubectl port-forward pod/analytics-pod 8888 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Copy the file 'foo' from the '/tmp' directory of the 'load-balancer-pod-9' pod in the 'istio-system' namespace to '/etc/kubernetes' locally
Command: ```bash kubectl cp istio-system/load-balancer-pod-9::/tmp/foo /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...
Create a new nginx pod using the alpine image, but customize the pod's specifications by providing a partial set of values parsed from the given JSON string.
Command: ```bash kubectl run nginx --image=alpine --overrides='{ "apiVersion": "rc-1.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] -- [COMM...
Create a new config map named app-config-prod using the files file1.txt and file2.txt for keys conf and data respectively.
Command: ```bash kubectl create configmap app-config-prod --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/profiles/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 c...
Forward port 8000 on your local machine to port 8081 on the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 8000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Attach to a specific container in a pod and get its output
Command: ```bash kubectl attach gateway-pod -c mycontainer ``` 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 ...
Copy the local file /tmp/foo_dir to the remote pod worker-pod-4 in the namespace prometheus, placing it at /tmp/bar_dir.
Command: ```bash kubectl cp /tmp/foo_dir prometheus/worker-pod-4:/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 ku...
Set the service account of the deployment "proxy-service-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment my-service-account ``` 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...
Retrieve the output from running the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' inside the pod named email-service-pod, using the default first container.
Command: ```bash kubectl exec email-service-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...
View the detailed information of a specific pod named "image-resizer-pod-20"
Command: ```bash kubectl describe pods/image-resizer-pod-20 ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, p...
Forward local ports to a pod
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 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 ...
Apply the configuration in manifest.yaml that has the label "zone=us-east-1" and delete any other resources that are not present in the file and have the label "app=nginx".
Command: ```bash kubectl apply --prune -f manifest.yaml -l zone=us-east-1 ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or ...
set a custom TLS server name for the testing-cluster cluster entry
Command: ```bash kubectl config set-cluster testing-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-autho...
Import the REDIS_HOST key from the 'app-config-dev' config map and set it as an environment variable for the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-config-dev deployment/api-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 definitio...
Create a cron job named 'email-notifications' that runs the 'php' image every minute
Command: ```bash kubectl create cronjob email-notifications --image=php --schedule="*/1 * * * *" -- ``` 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", "defau...
Import a specific key from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/namespace-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 va...
Get detailed information about all pods
Command: ```bash kubectl describe pods ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a name prefix,...
Check if you have the permission to list the "image-processing-job" job in the "testing" namespace
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-job -n testing ``` 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 U...
Import environment variables from the azure-storage-secret secret into the search-engine deployment
Command: ```bash kubectl set env --from=secret/azure-storage-secret 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 definitions in one or...
Execute the 'mysqld' command in the 'time-machine' container of the 'media-stream-pod' pod and print the output.
Command: ```bash kubectl exec media-stream-pod -c time-machine -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Create an ingress called 'api-v2-ingress' that routes requests from foo.com/module to svc1:9091 using the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="foo.com/module=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a new config map named "namespace-config" with the specified keys "conf" and "data" using the corresponding files "/path/to/data/file1.txt" and "/path/to/data/file2.txt" respectively.
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 config ...
Set up auto scaling for the "gateway" deployment with a minimum of 3 pods and a maximum of 8 pods.
Command: ```bash kubectl autoscale deployment gateway --min=3 --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 ...
Create a port forwarding from your local machine's port 8888 to port 8081 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 8888: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 autom...
Get output from running the 'kafka-topics --list' command in the container named 'mycontainer' from the pod named 'security-service-pod'
Command: ```bash kubectl exec security-service-pod -c mycontainer -- kafka-topics --list ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container nam...
Create a service for the 'node' replica set, which serves on port 8082 and connects to the containers on port 637900.
Command: ```bash kubectl expose rs node --port=8082 --target-port=637900 ``` 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...
Forward traffic from all addresses on port 6379 to the pod 'analytics-pod' on port 8080
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 6379: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 wil...
Update the label of the pod 'backend' to have the key 'env' and the value 'staging'
Command: ```bash kubectl label pods backend env=staging ``` 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": "I...
Start a pod named 'hazelcast' using the 'mongo' container image and expose port 5000
Command: ```bash kubectl run hazelcast --image=mongo --port=5000 ``` 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": "--fi...
Copy the ~/.config/kube local file to /tmp/bar_dir directory inside the message-broker-pod-15 pod in the kube-dns namespace
Command: ```bash kubectl cp ~/.config/kube kube-dns/message-broker-pod-15:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Set the custom TLS server name to 'cloud-cluster' for the 'cluster-gamma' cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=cloud-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...
Create a new config map named app-secrets using the key=value pairs specified in the file located at path/to/properties.
Command: ```bash kubectl create configmap app-secrets --from-file=path/to/properties ``` 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 basenam...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "developer" entry
Command: ```bash kubectl config set-credentials developer --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...
Describe the details of a specific context in your kubeconfig file
Command: ```bash kubectl config get-contexts staging-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Add a 'PreferNoSchedule' taint with the key 'environment' on nodes having the label 'instance=app-instance-1'.
Command: ```bash kubectl taint node -l instance=app-instance-1 environment=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default"...
Forward the local port 9090 and the IP 10.19.21.23 to the port 3000 of the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 9090:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a p...
Open a raw terminal connection to the 'cyber-sleuth' container in the 'media-stream-pod' pod and interact with the bash shell.
Command: ```bash kubectl attach media-stream-pod -c cyber-sleuth -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 o...
Execute the 'go' command inside the container of the pod named vpn-service-pod and retrieve the output.
Command: ```bash kubectl exec vpn-service-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.kubern...
Set the custom TLS server name to 'cloud-cluster' for the 'kube-cluster-1' cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=cloud-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...
Embed certificate authority data for the edge-cluster cluster entry
Command: ```bash kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/my-k8s-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...
Create a new config map named log-config by specifying keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/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 con...
Scale the deployment 'foo' with the minimum number of pods set to 3 and the maximum number of pods set to 15.
Command: ```bash kubectl autoscale deployment foo --min=3 --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 uses the...
Apply a taint to nodes labeled with namespace=mynamespace, with the key 'app' and value 'db-node-7:PreferNoSchedule'
Command: ```bash kubectl taint node -l namespace=mynamespace app=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": ...
Start a pod named 'nginx' using the 'amazonlinux' image, but specify a partial set of values for the pod's specification using the JSON object provided in the 'overrides' flag.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "alpha-2.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] --...
Set the service account of the deployment "gateway-deployment" to "cert-manager"
Command: ```bash kubectl set serviceaccount deployment gateway-deployment cert-manager ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubec...
Create an ingress called 'private-api-ingress' that directs requests to 'foo.com/example' to the service 'svc1:7000' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress private-api-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": "", "...
Display the most recent 31 lines of logs for the pod named 'email-service-pod'
Command: ```bash kubectl logs --tail=31 email-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short"...
Forward local traffic from port 8080 to port 8088 in a pod selected by the email-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8080 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a new ClusterIP service named log-service-clusterip with port mapping from port 7000 to port 8181
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=7000:8181 ``` 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", "d...
Create a new config map named app-settings with the specified keys and files as the values
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/data/file1.txt --from-file=key2=/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 conf...
Create a copy of a pod and add a debug container with a different image
Command: ```bash kubectl debug backend-pod -it --copy-to=my-debugger --image=debian --set-image=web=nginx:latest,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Copy the kubeconfig file from the remote pod with the name 'monitoring-agent-pod-6' in the 'monitoring' namespace to the local directory '/tmp/bar'
Command: ```bash kubectl cp monitoring/monitoring-agent-pod-6:~/.config/kube :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Set the resource request and limits for all containers in the node deployment
Command: ```bash kubectl set resources deployment node --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested,...
Update the label of the pod named 'database' to set the label 'unhealthy' with the value 'true'
Command: ```bash kubectl label pods database 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"...
Configure the cluster field for a specific context to a given cluster
Command: ```bash kubectl config set contexts.admin-context.cluster prod-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 wa...
Get the output from running the 'composer --version' command in the 'code-explorer' container of the 'gateway-pod' pod.
Command: ```bash kubectl exec gateway-pod -c code-explorer -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Edit the job 'batch-processing-job' in JSON format using the v1 API.
Command: ```bash kubectl edit job.v1.batch/batch-processing-job -o json ``` 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 variab...
Create a deployment named "my-dep" with 3 replicas running the "wordpress" image
Command: ```bash kubectl create deployment my-dep --image=wordpress --replicas=3 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Forward local port 6379 to port 9090 in the pod "chat-app-pod" to enable data forwarding.
Command: ```bash kubectl port-forward pod/chat-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 autom...
Scale the stateful set named 'web' to have 7 replicas.
Command: ```bash kubectl scale --replicas=7 statefulset/web ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validat...
Apply a taint with key 'dedicated' on nodes that have the label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 dedicated=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"...
Import the environment variables from the 'ssl-key-secret' secret and apply them to the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --from=secret/ssl-key-secret deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod te...
Forward local port 8888 to port 8080 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 8888:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Display the modified scheduler-app-deployment deployment with the DB_HOST environment variable set to localhost, without making any changes to the deployment on the server
Command: ```bash kubectl set env deployment/scheduler-app-deployment DB_HOST=localhost -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod...
Forward local port 5000 to port 9090 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 5000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Get the output from running the 'ash' command in the 'stardust-shuttle' container from the 'mypod' pod.
Command: ```bash kubectl exec mypod -c stardust-shuttle -- ash ``` 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 kub...
Update the annotation 'alert-email' of pod 'database' with the value 'alerts@example.com', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods database alert-email='alerts@example.com' ``` 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 lab...
Auto scale the "vpn" replication controller, with the number of pods ranging from 1 to 6, based on a target CPU utilization of 20%.
Command: ```bash kubectl autoscale rc vpn --max=6 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Copy the file "foo" from the remote pod "admin-dashboard-pod-16" in the container "payment-gateway" to the local file "bar" in the same directory ("/tmp")
Command: ```bash kubectl cp :/tmp/foo admin-dashboard-pod-16::/tmp/bar -c payment-gateway ``` 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 traffic from port 8000 on all addresses to port 3000 in the pod named "chat-app-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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...
Create a job with a command to run a database seeding task
Command: ```bash kubectl create job database-seeding-job --image=ethereum/client-go -- geth ``` 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": "O...
Get the output from running the 'dotnet --list-sdks' command from the first pod of the 'mydeployment' deployment
Command: ```bash kubectl exec deploy/mydeployment -- 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. If omitted, us...
Create a service for the replicated wordpress application using the replica set called "wordpress"
Command: ```bash kubectl expose rs wordpress --port=8083 --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 specified po...
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 8081 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Create a job named "certificate-renewal" using the php image.
Command: ```bash kubectl create job certificate-renewal --image=php -- ``` 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:...
Update the 'frontend' pod only if it hasn't been changed from version 1 and label it as 'unhealthy'
Command: ```bash kubectl label pods frontend status=unhealthy --resource-version=1 ``` 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", "def...
Wait until the pod named "database-pod" is in the ready state.
Command: ```bash kubectl wait --for=condition=Ready pod/database-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 command can w...
Print the list of supported namespaced resources
Command: ```bash kubectl api-resources --singularNamespaced=true ``` 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. "
Attach to a pod and interact with the bash terminal
Command: ```bash kubectl attach payment-gateway-pod -c cyber-sleuth -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. I...
Return the snapshot of the previous terminated mycontainer container logs from the log-aggregator-pod.
Command: ```bash kubectl logs -p -c mycontainer log-aggregator-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Remove a specific label from a pod
Command: ```bash kubectl label pods auth app- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, ch...
Create an ingress configuration called 'internal-ingress' to route requests from site.com/module to svc1:8084, using the tls secret "my-cert".
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/module=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a new ClusterIP service named catalog-service-clusterip
Command: ```bash kubectl create service clusterip catalog-service-clusterip --tcp=8084:3306 ``` 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"...
Update the client-key-data field of the service-account user with the provided certificate data using the --set-raw-bytes=true option
Command: ```bash kubectl config set users.service-account.client-key-data cert_data_here --set-raw-bytes=true ``` 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...
Add a taint with key 'workload' on nodes having label cluster=my-cluster, specify the node 'storage-node-13' as the target node, and set the taint effect as PreferNoSchedule.
Command: ```bash kubectl taint node -l cluster=my-cluster workload=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Delete both the pod and service resources named "cdn" and "api"
Command: ```bash kubectl delete pod,service cdn api ``` 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...
Start a pod named 'hazelcast' using the 'python' image, and set the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container.
Command: ```bash kubectl run hazelcast --image=python --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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] -- [COM...
Scale the replica set named 'foo' to 1 replica
Command: ```bash kubectl scale --replicas=1 rs/foo ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated before...
Set the service account of the search-engine-deployment deployment to prometheus.
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment prometheus ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `k...
Return the snapshot logs from the container "chat-app-pod-1" of the deployment "scheduler-app-deployment".
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c chat-app-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...
Check if you have permission to list the "backup-job" job in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/backup-job -n staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that st...
Get output from running the 'docker run -it ubuntu' command from pod web-app-pod.
Command: ```bash kubectl exec web-app-pod -- docker run -it ubuntu ``` 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...
Create a copy of the gateway-pod and change all container images to "redis".
Command: ```bash kubectl debug gateway-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 resou...
Scale the pod specified in the "pod.json" file to 5 replicas
Command: ```bash kubectl scale --replicas=5 -f pod.json ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated b...