prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Partially update the configuration of a node by applying a strategic merge patch expressed in JSON format
Command: ```bash kubectl patch node db-node-7 -p '{"spec":{"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]` Helpfu...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "jane.smith" entry
Command: ```bash kubectl config set-credentials jane.smith --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-...
Create an ingress called 'api-v1-ingress' that routes requests from testing.com/example to svc1:3000 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/example=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Create a job named "indexing" using the "mongo" image with the command "mongod".
Command: ```bash kubectl create job indexing --image=mongo -- mongod ``` 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: j...
Edit the 'user-service' service using the 'nvim' editor.
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/user-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, o...
Remove all the taints with the key 'zone' from the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 zone- ``` 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|...
Forward traffic from port 8888 on all addresses to port 8081 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 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...
Create a deployment named 'monitoring' using the 'node' image and 6 replicas
Command: ```bash kubectl create deployment monitoring --image=node --replicas=6 ``` 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...
Expose a replication controller named "ruby" as a service on port 9092, connecting to the containers on port 808200.
Command: ```bash kubectl expose rc ruby --port=9092 --target-port=808200 ``` 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...
Scale the mysql deployment to 1 replica if the current size of the deployment named payment-service-rs is 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/payment-service-rs ``` 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-...
Create a copy of the auth-service-pod with a debug container called my-debugger, using the debian image
Command: ```bash kubectl debug auth-service-pod -it --copy-to=my-debugger --image=debian --set-image=web=nginx:latest,api=api:v2 ``` 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. ...
Create a copy of the frontend-pod called debug-image-memcached with all container images changed to hazelcast/hazelcast
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-memcached --set-image=*=hazelcast/hazelcast ``` 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 b...
Update the image of a container in a pod
Command: ```bash kubectl patch pod api-service-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' ``` 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 FILE...
Forward local port 8000 to port 8080 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 8000: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 automaticall...
Add a taint with the key 'hardware' on the nodes that have the label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe hardware=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": "Outp...
Forward local port 5432 to port 6379 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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 aut...
Autoscale the deployment "media-stream" with a minimum of 3 pods and a maximum of 9 pods using the default autoscaling policy
Command: ```bash kubectl autoscale deployment media-stream --min=3 --max=9 ``` 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 ...
Import environment variables from a config map with a specific prefix
Command: ```bash kubectl set env --from=configmap/app-config-prod --prefix=MYSQL_ 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 ...
Copy the contents of the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod "web-app-pod-1" in the "istio-system" namespace, and place them in the "/tmp/bar" directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ istio-system/web-app-pod-1::/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": "Cont...
Attach to the code-explorer container in the pod "mypod" and get the output
Command: ```bash kubectl attach mypod -c code-explorer ``` 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 the ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/log-config 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 defi...
forward local port 6379 to port 5000 in the database-deployment pod
Command: ```bash kubectl port-forward deployment/database-deployment 6379 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Update the image of all deployments and replication controllers (rc) named nginx to 'nginx:1.21.3'
Command: ```bash kubectl set image deployments,rc nginx=nginx:1.21.3 --all ``` 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...
Create a deployment named mattermost running the node image and expose port 5432
Command: ```bash kubectl create deployment mattermost --image=node --port=5432 ``` 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:...
Embed certificate authority data for the moon-cluster cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/data-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...
View previous terminated logs from the "code-explorer" container in the "monitoring-pod" pod.
Command: ```bash kubectl logs -p -c code-explorer monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", ...
import the specific key 'EXTERNAL_API_URL' from the 'env-vars' config map and set it as an environment variable for the 'email-server-deployment' deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/env-vars 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 definit...
Copy the local file '/tmp/foo_dir' to '/tmp/bar' in the container 'auth-service' of the pod 'backend-pod-13'
Command: ```bash kubectl cp /tmp/foo_dir backend-pod-13:/tmp/bar -c auth-service ``` 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 role named "admin_role" with specified ResourceName
Command: ```bash kubectl create role admin_role --verb=get --resource=pods --resource-name=dev-database --resource-name=image-processor ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server...
Copy the local file `/tmp/foo_dir` to the remote pod `payment-gateway-pod-19` in the `istio-system` namespace to the directory `/tmp/bar_dir`.
Command: ```bash kubectl cp /tmp/foo_dir istio-system/payment-gateway-pod-19:/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...
Run the command 'mongo' in the first container of the 'proxy-server-pod' pod and get the output
Command: ```bash kubectl exec proxy-server-pod -- mongo ``` 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.ku...
Scale the deployment named backend-service-replicaset to 1 replica, if its current size is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/backend-service-replicaset ``` 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 --r...
Update the pod 'proxy' by setting the annotation 'custom-label' to 'my-custom-value', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods proxy custom-label='my-custom-value' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels a...
Create an ingress called 'public-service-ingress' with a rule that directs requests for foo.com/bar to svc1:8089
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.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": "", "u...
Create a job named 'deployment-rollout-job' using the image 'confluentinc/cp-kafka' and run the command 'kafka-server-start /etc/kafka/server.properties' in the job.
Command: ```bash kubectl create job deployment-rollout-job --image=confluentinc/cp-kafka -- kafka-server-start /etc/kafka/server.properties ``` 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": "--ou...
Create an ingress resource called 'external-ingress' that directs requests to foo.com/example to the service 'svc1' on port 8000
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/example=svc1:8000,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...
Remove the taint with key 'environment' and effect 'NoSchedule' from the node 'gpu-node-12'
Command: ```bash kubectl taint nodes gpu-node-12 environment:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
retrieve the information for the replication controller named "web", the service named "chat-app-rc", and the pod named "email-service-pod"
Command: ```bash kubectl get rc/web service/chat-app-rc pods/email-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespa...
Create a cron job named 'weekly-summary' that runs the command 'kafka-console-producer --broker-list localhost:9092 --topic test' using the image 'confluentinc/cp-kafka'
Command: ```bash kubectl create cronjob weekly-summary --image=confluentinc/cp-kafka --schedule="*/1 * * * *" -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- ...
Create an autoscaling policy for the deployment "frontend" with a minimum of 6 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment frontend --min=6 --max=9 ``` 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...
Listen on port 9090 locally and forward the traffic to port 8088 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 9090:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected auto...
Display the resource usage metrics for the pods that have the label instance=app-instance-1
Command: ```bash kubectl top pod -l instance=app-instance-1 ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod...
Import the REDIS_HOST key from the kube-system-config ConfigMap into the load-balancer-deployment Deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/kube-system-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 de...
Create a new ClusterIP service named cache-service-clusterip that maps port 8088 on the service to port 8088 on the backend pods
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=8088:8088 ``` 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", ...
execute the 'geth version' command inside the auth-service-pod and print the output
Command: ```bash kubectl exec auth-service-pod -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Check if I have permission to list the "notification-sender-job" in the "monitoring" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n monitoring ``` 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 par...
Update the settings of a node using the information provided in the "node-settings.json" file
Command: ```bash kubectl patch -f node-settings.json -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kube...
Create a deployment named 'wordpress' using the 'ruby' image and expose port '8081'
Command: ```bash kubectl create deployment wordpress --image=ruby --port=8081 ``` 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: ...
Copy the local directory /tmp/foo_dir_dir to /tmp/bar_dir_dir in a remote pod named load-balancer-pod-9 within the default namespace.
Command: ```bash kubectl cp /tmp/foo_dir_dir load-balancer-pod-9:/tmp/bar_dir_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...
Auto scale the deployment "api" with a minimum of 3 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment api --min=3 --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 uses the...
Get the output from running the 'jenkins-plugin-cli' command in the 'lunar-launcher' container of the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c lunar-launcher -- jenkins-plugin-cli ``` 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 an ingress named "private-api-ingress" that directs requests from "testing.com/bar" to "svc1:8083" with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/bar=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Display the most recent 12 lines of output from the 'chat-app-pod' pod.
Command: ```bash kubectl logs --tail=12 chat-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", "short": "-c...
Create a deployment named 'app' using the 'confluentinc/cp-kafka' image and expose port 8082.
Command: ```bash kubectl create deployment app --image=confluentinc/cp-kafka --port=8082 ``` 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 forma...
Execute the 'php --version' command in the first container of the 'api-service' service pod and display the output.
Command: ```bash kubectl exec svc/api-service -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Create a deployment named 'wordpress' using the 'redis' image with 4 replicas
Command: ```bash kubectl create deployment wordpress --image=redis --replicas=4 ``` 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...
Copy the directory '/tmp/foo_dir' from the remote pod 'front-end-pod-12' in the 'kube-proxy' namespace to the local directory '/tmp/bar'
Command: ```bash kubectl cp kube-proxy/front-end-pod-12:/tmp/foo_dir :/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 k...
Create an ingress named 'private-ingress' that directs requests to website.com/bar to a service named svc1 on port 9092
Command: ```bash kubectl create ingress private-ingress --rule="website.com/bar=svc1:9092,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": "", "usag...
Forward traffic from port 5000 on your local machine and IP address 10.19.21.23 to port 5432 in the backend-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 5000: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 criteri...
Return the logs of the previous terminated "stardust-shuttle" container from the "monitoring-pod" pod
Command: ```bash kubectl logs -p -c stardust-shuttle monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container...
Create a role named "reader" with ResourceName specified
Command: ```bash kubectl create role reader --verb=connect --resource=pods --resource-name=mail-server --resource-name=cache-redis ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|clie...
Forward local ports 5000 to port 6379 in the analytics-platform-deployment pod.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Forward traffic from local port 5000 to port 8000 inside the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 5000: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 select...
Display the most recent 53 lines of logs for the pod named "monitoring-pod"
Command: ```bash kubectl logs --tail=53 monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "...
Delete the pods and services with the names "email" and "analytics"
Command: ```bash kubectl delete pod,service email analytics ``` 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....
Create a pod disruption budget named "auth-service-pdb" that will select all pods with the "role=worker" label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=role=worker --min-available=9 ``` 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 [...
Update the pod 'analytics' with the annotation 'release-notes' and the value 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods analytics release-notes='https://example.com/release-notes/v2.5.1' ``` 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 la...
Update the 'storage-node-13' node by applying a strategic merge patch with the JSON provided
Command: ```bash kubectl patch node storage-node-13 -p '{"data":{"key":"new-value"}' ``` 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]` Helpf...
Update the "key" attribute in the data section of the node named "testing-node-11" by partially applying a strategic merge patch specified in YAML format
Command: ```bash kubectl patch node testing-node-11 -p $'data:\n key: new-value' ``` 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 f...
Get the output from running the 'node' command in the monitoring-pod pod
Command: ```bash kubectl exec monitoring-pod -- node ``` 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.kuber...
Apply a taint with the key 'environment' and the value 'node-2:PreferNoSchedule' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production environment=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Create a copy of the "email-service-pod" with a debug container and changed container images
Command: ```bash kubectl debug email-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=scheduler=my-scheduler:1.0,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identi...
Create a new config map named app-config-prod using the specified key-value pairs instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/options/file1.txt --from-file=key2=/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 creati...
Listen on port 8080 on all addresses, forwarding to port 8080 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a Pod Disruption Budget named `api-service-pdb` that selects all pods with the `release=1.0.0` label
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=release=1.0.0 --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 new secret named email-credentials-secret with key1=supersecret and key2=topsecret
Command: ```bash kubectl create secret generic email-credentials-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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...
List all deployments in the "rc-1.1.0" version of the "legacy-apps" API group and display the output in YAML format.
Command: ```bash kubectl get deployments.rc-1.1.0.legacy-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Get output from running the 'geth attach' command from the pod named auth-service-pod, using the first container by default
Command: ```bash kubectl exec auth-service-pod -- 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 omitted, use the kube...
Import the DEBUG_MODE key from the env-vars config map and set it as an environment variable for the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/env-vars deployment/gateway-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...
Create a cluster role named "view" with ResourceName specified
Command: ```bash kubectl create clusterrole view --verb=patch --resource=pods --resource-name=staging-app-server --resource-name=keycloak-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Create a copy of the proxy-server-pod with a debug container, and update the container images.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-app --image=debian --set-image=scheduler=my-scheduler:1.0,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects ide...
Retrieve the output of the 'mysqld' command running inside the first container of the first pod in the user-management-deployment deployment.
Command: ```bash kubectl exec deploy/user-management-deployment -- 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, ...
Forward local port 8000 to port 9090 in the chat-app-pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8000: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...
Create an ingress named ingress1 with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:8443" \ --rule="bar.com/admin*=svc2:http" ``` 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", "sh...
Forward traffic from port 8081 on all addresses to port 8888 inside the e-commerce-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8081: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 wi...
Scale the deployment named api-service-rs to be the same size as the current size of the deployment named api-service-rs
Command: ```bash kubectl scale --current-replicas=5 --replicas=5 deployment/api-service-rs ``` 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-vers...
Embed client certificate data for the "developer" entry.
Command: ```bash kubectl config set-credentials developer --client-certificate=~/.kube/admin.crt --embed-certs=true ``` 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...
Forward the requests coming to port 9090 on all addresses to the 'chat-app-pod' pod's port 5000
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 9090: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...
Update the 'api' pod with the annotation 'scaling-policy' and the value 'auto-horizontal-scaling', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods api scaling-policy='auto-horizontal-scaling' ``` 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 ...
Get the output from running the 'nginx' command inside the 'nebula-navigator' container of the 'security-service-pod' pod.
Command: ```bash kubectl exec security-service-pod -c nebula-navigator -- nginx ``` 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 omi...
Create an ingress called 'api-v1-ingress' that directs requests from foo.com/example to svc1:8080 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="foo.com/example=svc1:8080,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...
Delete both the 'security' pod and service, as well as the 'web' pod and service.
Command: ```bash kubectl delete pod,service security web ``` 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. So...
Start a centos pod with custom spec values provided in JSON format
Command: ```bash kubectl run nginx --image=centos --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] -- [COM...
Create a pod named "hazelcast" using the "wordpress" container image, and expose port 8081.
Command: ```bash kubectl run hazelcast --image=wordpress --port=8081 ``` 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": "...
Set the Google Compute Platform auth provider for the "app-service" entry
Command: ```bash kubectl config set-credentials app-service --auth-provider=gcp ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags: -...
Forward local port 9090 to pod port 6379
Command: ```bash kubectl port-forward pod/e-commerce-pod 9090: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 aut...
Copy the ~/.config/kube directory from the 'worker-pod-4' pod in the 'kube-node-lease' namespace to the /tmp/bar directory locally.
Command: ```bash kubectl cp kube-node-lease/worker-pod-4:~/.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, use the...
Forward local ports to a pod
Command: ```bash kubectl port-forward pod/chat-app-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...
Start a pod named "hazelcast" using the image "mcr.microsoft.com/dotnet/core/runtime" and expose port 8443
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=8443 ``` 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......
Create a new generic secret named jwt-secret using the options specified in the options.env file
Command: ```bash kubectl create secret generic jwt-secret --from-env-file=path/to/options.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 the basename o...