prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the annotation 'env' of the 'email' pod to 'staging', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods email 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 arbitr...
Copy the local file at /var/run/secrets/kubernetes.io/serviceaccount/ to the remote pod with name 'backend-pod-13' in the 'kube-dns' namespace at the destination path /tmp/bar.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-dns/backend-pod-13::/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...
Forward traffic from port 8080 on localhost and IP address 10.19.21.23 to port 5000 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8080: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 criteri...
Set resource limits for a specific container in a deployment.
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=cpu=500m,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, but may burst up...
create a new ExternalName service named 'external-authentication-service' with an external name of 'documentation-tech.tech'
Command: ```bash kubectl create service externalname external-authentication-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 to...
Create a debug image of the 'frontend-pod' with all container images changed to 'ethereum/client-go'
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-web --set-image=*=ethereum/client-go ``` 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 defau...
Create a new config map named "api-config" by reading key=value pairs from the file located at "path/to/options"
Command: ```bash kubectl create configmap api-config --from-file=path/to/options ``` 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 basename of...
Listen on ports 8000 and 6000 locally, forwarding data to/from ports 8081 and 6000 in a pod selected by the notification-handler-deployment deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 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 ...
Partially update the backup-node-14 node by setting the 'unschedulable' field to true
Command: ```bash kubectl patch node backup-node-14 -p '{"spec":{"unschedulable":true}}' ``` 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]` He...
Listen on port 3000 on localhost and IP address 10.19.21.23, and forward the traffic to port 3000 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-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 crit...
Copy the file '/tmp/foo' from your local machine to the '/etc/kubernetes' directory in the 'message-broker-pod-15' pod in the 'kube-flannel' namespace.
Command: ```bash kubectl cp :/tmp/foo kube-flannel/message-broker-pod-15:/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,...
Copy the file '/tmp/foo' from the 'monitoring-agent-pod-6' pod in the 'kube-proxy' namespace to the '/etc/kubernetes' directory locally.
Command: ```bash kubectl cp kube-proxy/monitoring-agent-pod-6::/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, ...
Create a copy of the payment-gateway-pod adding a debug container and changing container images
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-1 --image=debian --set-image=scheduler=my-scheduler:1.0,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 reso...
Update the pod 'chat-app' by assigning the label 'tier' with the value 'backend'
Command: ```bash kubectl label pods chat-app tier=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": ...
import the SMTP_SERVER key from the config map 'app-config-dev' and set it as an environment variable in the 'search-engine-deployment' deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-dev deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Apply the JSON content from the `pod.json` file to a pod.
Command: ```bash cat pod.json | kubectl apply -f - ``` 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 'create --save-config'....
Import the environment variables from the 'cert-manager-secret' secret into the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --from=secret/cert-manager-secret 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 definitions in one or mor...
Create an ingress with multiple hosts and the pathType as Prefix.
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:8080" \ --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",...
Partially update the containerd configuration by applying a strategic merge patch from the "containerd-config.toml" file, with the new password specified as "new-password".
Command: ```bash kubectl patch -f containerd-config.toml -p '{"stringData":{"password":"new-password"}' ``` 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...
Create an ingress called 'api-v2-ingress' that directs requests from site.com/input to svc1:8081 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/input=svc1:8081,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"...
Copy the local file ~/.config/kube to the /tmp/bar directory inside the security-scanner-pod-18 pod in the kube-public namespace.
Command: ```bash kubectl cp ~/.config/kube kube-public/security-scanner-pod-18::/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,...
Return the snapshot logs from the container 'media-stream-pod-1' of the deployment named 'search-engine-deployment'.
Command: ```bash kubectl logs deployment/search-engine-deployment -c media-stream-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 cron job named 'weekly-summary' using the 'ruby' image, with a schedule to run every minute
Command: ```bash kubectl create cronjob weekly-summary --image=ruby --schedule="*/1 * * * *" -- gem --version ``` 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": "-...
Execute the 'mongod' command in the first container of the 'backend-microservice-deployment' deployment and get the output.
Command: ```bash kubectl exec deploy/backend-microservice-deployment -- 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 omit...
create a config map named db-config from specified files
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/configs/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...
Add a taint to the node 'edge-node-10' with key 'environment' and no value
Command: ```bash kubectl taint nodes edge-node-10 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 ...
import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/db-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 definiti...
Execute the 'ash' command in the warp-drive container of the mypod pod and capture the output
Command: ```bash kubectl exec mypod -c warp-drive -- 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 kubectl.k...
Create a service for the replication controller specified in the "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8000 --target-port=8000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Copy a local file to a remote pod in a specific namespace
Command: ```bash kubectl cp /tmp/foo prometheus/front-end-pod-12:/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 kubect...
Set the resource request and limits for all containers in a deployment named "python" for CPU and memory.
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=4Gi ``` 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 request...
Auto scale the 'gateway' deployment with a minimum of 4 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment gateway --min=4 --max=13 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Return the logs of the previously terminated "stardust-shuttle" container from the "vpn-service-pod" pod.
Command: ```bash kubectl logs -p -c stardust-shuttle vpn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Auto scale the replication controller "proxy" with a target CPU utilization of 50% and a range of 1 to 3 pods.
Command: ```bash kubectl autoscale rc proxy --max=3 --cpu-percent=50 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses t...
Remove the taint on node 'node-2' if it exists
Command: ```bash kubectl taint nodes node-2 dedicated:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Create a pod disruption budget named database-pdb that will select pods with the project=my-project label, ensuring at least 9 of them are available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=project=my-project --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=...
Forward local port 6379 to port 8080 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-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 will be selected...
Create a new ClusterIP service named 'security-service-clusterip' that maps port 8083 on the service to port 8000 on the backend
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=8083:8000 ``` 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 port 9090 to port 8888 of a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 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 selecte...
run the command 'mysql' in the nebula-navigator container of the backend-pod and retrieve the output
Command: ```bash kubectl exec backend-pod -c nebula-navigator -- mysql ``` 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...
List all deployments in the "v2.1.0" version of the "api-v2" API group and display the output in YAML format.
Command: ```bash kubectl get deployments.v2.1.0.api-v2 -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 will onl...
Set environment variables from a secret for a specific deployment
Command: ```bash kubectl set env --from=secret/password-secret deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one ...
Create a cluster role named "admin_role" with permissions to use the specified non-resource URL.
Command: ```bash kubectl create clusterrole "admin_role" --verb=use --non-resource-url=/watch/* ``` 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", "sh...
Remove the taint with key 'dedicated' and effect 'NoSchedule' from the node 'app-node-6' if it exists
Command: ```bash kubectl taint nodes app-node-6 dedicated:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Create a new NodePort service named proxy-server-nodeport and map port 3001 on the host to port 8083 on the service
Command: ```bash kubectl create service nodeport proxy-server-nodeport --tcp=3001:8083 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default"...
Create an ingress named "internal-ingress" that maps requests from foo.com/example to the service "svc1" on port 8080, using the TLS secret "my-cert".
Command: ```bash kubectl create ingress internal-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": "", "usa...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/db-config deployment/mydeployment ``` 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...
Forward port 8081 on all addresses to port 6379 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8081: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 ...
Create a new config map named global-config with key1=config1 and key2=config2.
Command: ```bash kubectl create configmap global-config --from-literal=properties=config1 --from-literal=key1=config2 ``` 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, th...
Import environment variables from a config map with a specific prefix for a deployment.
Command: ```bash kubectl set env --from=configmap/global-config --prefix=MYSQL_ deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Set the cluster field in the "app-2-context" context to "cluster-gamma"
Command: ```bash kubectl config set contexts.app-2-context.cluster cluster-gamma ``` 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...
Start streaming the logs of the "code-explorer" container in the "frontend-pod" pod
Command: ```bash kubectl logs -f -c code-explorer frontend-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", "s...
Create a new NodePort service named backend-nodeport that maps port 3000 on all nodes to port 3001 on the backend service
Command: ```bash kubectl create service nodeport backend-nodeport --tcp=3000:3001 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Return snapshot logs from container 'analytics-pod-1' of a deployment named 'user-management-deployment'.
Command: ```bash kubectl logs deployment/user-management-deployment -c analytics-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: "...
Get the output of the 'gem --version' command from the first pod of the 'payment-processor-deployment' deployment
Command: ```bash kubectl exec deploy/payment-processor-deployment -- gem --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 ...
Create a copy of the cdn-service-pod with the name 'dgb-img' and change all container images to use the 'hazelcast/hazelcast' image.
Command: ```bash kubectl debug cdn-service-pod --copy-to=dgb-img --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 by default i...
Retrieve the output of the command 'python --version' from the first container of the first pod in the deployment 'scheduler-app-deployment'
Command: ```bash kubectl exec deploy/scheduler-app-deployment -- python --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Remove exec auth plugin environment variables for a specific service account
Command: ```bash kubectl config set-credentials service-account --exec-env=var-to-remove- ``` 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 ...
Scale the replica set named 'frontend-rs' to have only 1 replica.
Command: ```bash kubectl scale --replicas=1 rs/frontend-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-version is specified, it is validate...
Return the snapshot logs from container named auth-service-pod-1 in the deployment/notification-handler-deployment
Command: ```bash kubectl logs deployment/notification-handler-deployment -c auth-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 ...
Update the annotation of the pod named 'monitoring' with the key 'SLA' and the value '99.9% uptime', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods monitoring SLA='99.9% uptime' ``` 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 incl...
Create a cluster role named "admin_role" with the API Group "tokenreviews.authentication.k8s.io" specified
Command: ```bash kubectl create clusterrole admin_role --verb=use,proxy,delete --resource=tokenreviews.authentication.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|none]` Helpful f...
Remove the taint with key 'disktype' from the node 'gpu-node-12'
Command: ```bash kubectl taint nodes gpu-node-12 disktype- ``` 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|...
Create a job named "log-processing-job" using the Alpine image and the command "ash"
Command: ```bash kubectl create job log-processing-job --image=alpine -- ash ``` 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. O...
Check if you have permission to list the jobs with the name "image-processing-job" in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-job -n kube-system ``` 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 parti...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-settings 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 definitions...
Create a pod disruption budget named "messaging-pdb" that selects all pods with the "owner=team-1" label and requires at least one of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=owner=team-1 --min-available=1 ``` 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 [--...
Get the output from running the 'psql' command in the 'nebula-navigator' container of the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c nebula-navigator -- psql ``` 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...
display the resource usage metrics for the email-service-pod and its containers
Command: ```bash kubectl top pod email-service-pod --containers ``` 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...
Run the 'mongod' command on the first container of the 'email-service' pod and capture the output.
Command: ```bash kubectl exec svc/email-service -- mongod ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Create a role named "view" with the ability to proxy to pods and specifically to the "notification-service" resource name
Command: ```bash kubectl create role view --verb=proxy --resource=pods --resource-name=notification-service --resource-name=notification-service ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-r...
Create a new config map named "app-name-config" using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/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 creatin...
Create an ingress named 'api-v2-ingress' with a rule that directs requests from foo.com/example to svc1:8181, using the tls secret "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="foo.com/example=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
List deployments in YAML output format for the "feature-branch-2.3.0" version of the "prod-apps" API group.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.prod-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 namesp...
List the replication controller named 'web', the service named 'media-stream-rc', and the pod named 'web-app-pod'.
Command: ```bash kubectl get rc/web service/media-stream-rc pods/web-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespace...
Check if you have permission to list a specific job in a namespace
Command: ```bash kubectl auth can-i list jobs.batch/backup-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 URL that st...
Start a pod named "hazelcast" using the Redis image and set the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default".
Command: ```bash kubectl run hazelcast --image=redis --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] -- [COMM...
Create a job to run a security scan, using the Ethereum client image and attaching to geth.
Command: ```bash kubectl create job security-scan-job --image=ethereum/client-go -- geth attach ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
start a node pod with a container that exposes port 9090
Command: ```bash kubectl run hazelcast --image=node --port=9090 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fil...
view the detailed config of pods that have the label version=v1.0.0
Command: ```bash kubectl describe po -l version=v1.0.0 ``` 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, provid...
Update the 'search-engine-deployment' deployment by setting the environment variable SECRET_KEY to 'your-secret-key'
Command: ```bash kubectl set env deployment/search-engine-deployment SECRET_KEY=your-secret-key ``` 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 po...
Update the image of all containers in the 'services' daemonset to 'python:3.9.7'.
Command: ```bash kubectl set image daemonset services *=python:3.9.7 ``` 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: `ku...
Retrieve the snapshot logs from the container named 'api-server-deployment-1' of the 'frontend-pod' deployment.
Command: ```bash kubectl logs deployment/api-server-deployment -c frontend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag":...
Forward port 6379 on all addresses to port 8088 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 6379: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 ...
Forward local port 6379 to the pod's port 6379.
Command: ```bash kubectl port-forward pod/e-commerce-pod 6379 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...
Auto scale the deployment "log-aggregator" with a minimum of 1 and maximum of 10 pods. Use the default autoscaling policy.
Command: ```bash kubectl autoscale deployment log-aggregator --min=1 --max=10 ``` 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 th...
Remove all taints with the key 'zone' from the node 'node-1'
Command: ```bash kubectl taint nodes node-1 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|name|go-t...
Delete pods and services with the names "database" and "log-aggregator"
Command: ```bash kubectl delete pod,service database log-aggregator ``` 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 s...
Get the output from running the 'mysql --version' command in the cosmic-container from the api-service-pod pod
Command: ```bash kubectl exec api-service-pod -c cosmic-container -- mysql --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. I...
Forward ports locally to a pod
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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 wil...
Taint the node 'storage-node-13' with a key 'cpu-type', value 'x86', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes storage-node-13 cpu-type=x86: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. ...
Create an ingress called 'api-v2-ingress' that directs requests to website.com/module to a service named svc1 running on port 8081
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/module=svc1:8081,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": "", "us...
Create a deployment named 'mattermost' using the 'node' image and expose port 3000
Command: ```bash kubectl create deployment mattermost --image=node --port=3000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Create a new config map named "app-settings" using files from specific paths as values for keys
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/configs/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 c...
Execute the 'geth' command on the first container of the 'search-service' service and get the output.
Command: ```bash kubectl exec svc/search-service -- geth ``` 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.k...
Update the 'web-app-deployment' deployment by adding a new environment variable 'DB_PASSWORD' with the value 'secretpassword'
Command: ```bash kubectl set env deployment/web-app-deployment DB_PASSWORD=secretpassword ``` 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 temp...
Import the environment variables from the 'password-secret' secret into the 'email-server-deployment' deployment
Command: ```bash kubectl set env --from=secret/password-secret deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more ...
Create a new ExternalName service named 'external-ldap-service' with the external name 'example-domain.com'
Command: ```bash kubectl create service externalname external-ldap-service --external-name example-domain.com ``` 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 serv...
List deployments in YAML output format using the "extensions" API group and filter by the "hotfix-1.1.2" version.
Command: ```bash kubectl get deployments.hotfix-1.1.2.extensions -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 yo...
Update the node specified in "node.json" by applying the strategic merge patch in the 10-mynet.conf file
Command: ```bash kubectl patch -f 10-mynet.conf -p '{"spec":{"unschedulable":true}}' ``` 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...