prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Port forward the pod "mypod" so that it listens on port 5432 locally and forwards the traffic to port 8088 in the pod.
Command: ```bash kubectl port-forward pod/mypod 5432: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 automaticall...
update the deployment 'database-deployment' by setting a new environment variable named PORT with the value 8080
Command: ```bash kubectl set env deployment/database-deployment PORT=8080 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (within re...
Set the cpu limits of the nginx container in the redis deployment to "500m" and set the memory limits to "4Gi"
Command: ```bash kubectl set resources deployment redis -c=nginx --limits=cpu=500m,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 requested, but may burst up to i...
Create an ingress named 'api-v1-ingress' that routes requests to 'website.com/module' to the service named 'svc1' on port 8081, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-v1-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...
Forward traffic from port 8088 on all addresses to port 6379 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8088: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 wi...
Set the environment variable "debug_mode" in the deployment "payment-processor-deployment" with the value from the "ui-config" config map.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/ui-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Forward traffic from local port 8000 to pod port 8000, listening on both ports and forwarding data between them.
Command: ```bash kubectl port-forward pod/e-commerce-pod 8000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Add a taint with key 'cpu-type' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster cpu-type=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create an ingress resource called 'public-api-ingress' that routes requests from foo.com/input to the service svc1 on port 8181
Command: ```bash kubectl create ingress public-api-ingress --rule="foo.com/input=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": "", "usa...
Create a job named "audit-job" using the specified image and running the command "elasticsearch-plugin --list"
Command: ```bash kubectl create job audit-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch-plugin --list ``` 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", "s...
Remove the taint with key 'workload' and effect 'NoSchedule' from the node 'testing-node-11' if it exists.
Command: ```bash kubectl taint nodes testing-node-11 workload:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Start a pod with the nginx name and php image, but override the spec with a partial set of values parsed from JSON.
Command: ```bash kubectl run nginx --image=php --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND...
Add an annotation to a pod identified by type and name in the "parameters.json" file.
Command: ```bash kubectl annotate -f parameters.json team='frontend team' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arb...
List deployments in YAML output format, in a specific version of a custom API group
Command: ```bash kubectl get deployments.v3.0.0.custom-deployments -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 ...
Create a role named "reader" with specific resource names specified.
Command: ```bash kubectl create role reader --verb=proxy --resource=pods --resource-name=content-delivery --resource-name=file-storage ``` 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|...
Delete the pods and services with the names "frontend" and "proxy".
Command: ```bash kubectl delete pod,service frontend proxy ``` 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. ...
Add a taint with key 'zone' on nodes having label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 zone=app-node-6: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": "", "usag...
Import the 'secret_key' key from the 'log-config' config map into the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --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 definition...
Get the output from running the 'kafka-topics --list' command in the cosmic-container from the e-commerce-pod.
Command: ```bash kubectl exec e-commerce-pod -c cosmic-container -- 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 name...
Edit the user-service service using the vi editor
Command: ```bash KUBE_EDITOR="vi" 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, or ...
Update the environment variable 'DB_HOST' for the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env deployment/load-balancer-deployment DB_HOST=localhost ``` 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 templat...
Forward traffic from port 5000 on all addresses to port 8000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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...
Copy the file `~/.config/kube` from your local machine to `/tmp/bar` in the container named `message-broker` within the pod `backend-pod-13`.
Command: ```bash kubectl cp ~/.config/kube backend-pod-13::/tmp/bar -c message-broker ``` 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, us...
Forward port 5432 on your local machine to port 9090 in the pod named e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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 aut...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/namespace-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
import the "debug_mode" key from the "monitoring-config" ConfigMap and set it as an environment variable in the "monitoring-stack-deployment" deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/monitoring-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Listen on port 8888 locally and forward it to the targetPort of the "https" service port in a pod selected by the "gateway-service" service.
Command: ```bash kubectl port-forward service/gateway-service 8888:https ``` 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...
Set the cluster field in the 'my-context' context to 'cluster-alpha'
Command: ```bash kubectl config set contexts.app-2-context.cluster cluster-alpha ``` 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...
Set a custom TLS server name for the cluster-gamma cluster.
Command: ```bash kubectl config set-cluster cluster-gamma --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-authori...
Force replace a resource by deleting and then re-creating it.
Command: ```bash kubectl replace --force -f ./config.json ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f ...
Create an ingress called 'www-ingress' with a rule to route requests for 'website.com/input' to 'svc1:8082' and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress www-ingress --rule="website.com/input=svc1:8082,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 service for a replicated alpine container
Command: ```bash kubectl expose rc alpine --port=3001 --target-port=800000 ``` 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....
Use the Sublime text editor to edit the "logging-service" service
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/logging-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 variab...
Update the label of the pod 'security' with the key 'app' and the value 'myapp'
Command: ```bash kubectl label pods security app=myapp ``` 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...
Import environment variables from a config map with a specified prefix
Command: ```bash kubectl set env --from=configmap/log-config --prefix=MYSQL_ deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Set the cluster field in the "my-context" context to "kube-cluster-1"
Command: ```bash kubectl config set contexts.on-prem-context.cluster kube-cluster-1 ``` 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 yo...
Copy the local file /tmp/foo to the /etc/kubernetes directory of the metrics-exporter-pod-10 pod in the argocd namespace.
Command: ```bash kubectl cp /tmp/foo argocd/metrics-exporter-pod-10:/etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Remove the taint with the key 'disktype' and effect 'NoSchedule' from the node 'k8s-node-1' if it exists.
Command: ```bash kubectl taint nodes k8s-node-1 disktype: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 an ingress named 'private-ingress' with the following routing rules: forward requests from foo.com/bar to the service 'svc1' on port 8088
Command: ```bash kubectl create ingress private-ingress --rule="foo.com/bar=svc1:8088,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": ...
Attach to a specific container in a pod to view its output
Command: ```bash kubectl attach frontend-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...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l project=project-alpha cpu-type=web-node-8: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...
Start a golang pod named nginx, with the golang image, but override the spec values with a partial set of values parsed from JSON.
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "v1.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] -- [COMMAN...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-name-config deployment/database-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...
Add a taint with key 'environment' on all nodes labeled with 'release=beta'
Command: ```bash kubectl taint node -l release=beta environment=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a new config map named global-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Forward local traffic on port 9090 to a pod's port 5432
Command: ```bash kubectl port-forward deployment/database-deployment 9090 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 ...
Copy the local file /tmp/foo to the remote pod named database-pod-2 in the kube-public namespace, and place it in the /tmp/bar directory.
Command: ```bash kubectl cp /tmp/foo kube-public/database-pod-2::/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...
Forward port 8081 in the 'analytics-pod' pod to port 9090 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 9090:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Forward local port 3000 to port 8888 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 3000 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a new config map named 'log-config' with the specified keys 'settings' and 'key2' by reading the content of '/path/to/parameters/file1.txt' and '/path/to/parameters/file2.txt' respectively.
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/parameters/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 creating...
Forward local traffic on port 8088 to a pod selected by the deployment named "web-app-deployment" on port 8000.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8088 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 s...
Update the compliance level of a pod identified by type and name in "options.json"
Command: ```bash kubectl annotate -f options.json compliance-level=PCI-DSS ``` 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 ar...
Import specific keys from a config map to a deployment called "monitoring-stack-deployment"
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-settings deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Add a taint with the key 'datacenter' and value 'web-node-8:PreferNoSchedule' on nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice datacenter=web-node-8: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": "", "...
List deployments in YAML output format for the "hotfix-1.1.2" version of the "beta-apps" API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.beta-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...
Create a new ExternalName service named external-geolocation-service that resolves to the external name "museum-example.museum"
Command: ```bash kubectl create service externalname external-geolocation-service --external-name museum-example.museum ``` 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 refe...
Retrieve the password for the "sun-cluster" user
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "sun-cluster")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpful ...
Create a service for the alpine deployment, serving on port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment alpine --port=9091 --target-port=300100 ``` 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 specifi...
Attach to the cosmic-container in the monitoring-pod and get the output
Command: ```bash kubectl attach monitoring-pod -c cosmic-container ``` 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 omitt...
Expose a pod as a service with a specified name and port
Command: ```bash kubectl expose pod backend-pod --port=7000 --name=frontend ``` 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...
Delete pods and services with the names "cdn" and "chat-app"
Command: ```bash kubectl delete pod,service cdn chat-app ``` 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...
Create a new cron job named log-rotation with the centos image, running the bash command, and executing every minute.
Command: ```bash kubectl create cronjob log-rotation --image=centos --schedule="*/1 * * * *" -- bash ``` 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", "defa...
Set the custom TLS server name to "app-cluster" for the "kube-cluster-2" cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=app-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] [--certificat...
Set the custom TLS server name "star-cluster" for the cluster entry "my-k8s-cluster"
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=star-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Start streaming the logs of the ruby container in the security-service-pod
Command: ```bash kubectl logs -f -c ruby security-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", "sh...
Create a Pod Disruption Budget named "database-pdb" that will select all pods with the label "tier=frontend" and require at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=tier=frontend --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 [--...
Create an ingress called 'api-v1-ingress' that maps incoming requests for 'website.com/module' to 'svc1:8888' and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/module=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Apply the taint to the node 'backup-node-14' with the key 'datacenter' and value 'dc-1', and set the effect to 'NoExecute'
Command: ```bash kubectl taint nodes backup-node-14 datacenter=dc-1:NoExecute ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format....
Create a cron job named "cleanup-task" that runs the command "redis-server --version" every minute using the Redis image.
Command: ```bash kubectl create cronjob cleanup-task --image=redis --schedule="*/1 * * * *" -- redis-server --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", "sh...
Retrieve snapshot logs from the media-stream-pod, including all containers
Command: ```bash kubectl logs media-stream-pod --all-containers=true ``` 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...
Set the cluster field in a specific context to a specific cluster
Command: ```bash kubectl config set contexts.client-1-context.cluster moon-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...
Add a taint to nodes with the label 'myLabel' and the key 'app' with the value 'web-node-8:PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel app=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output forma...
Update the description annotation for the pod 'web' only if the resource version is still 1
Command: ```bash kubectl annotate pods web description='my frontend running nginx' --resource-version=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 larg...
Copy the local file ~/.config/kube to the /tmp/bar_dir directory inside the 'task-processor-pod-17' pod in the specified container 'payment-gateway'
Command: ```bash kubectl cp ~/.config/kube task-processor-pod-17:/tmp/bar_dir -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 ...
Partially update the 'prod-node-5' node by applying the specified strategic merge patch, which is defined in YAML format
Command: ```bash kubectl patch node prod-node-5 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n 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. Sy...
Check if you have permission to list the "queue-processing-job" job in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n default ``` 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...
Embed the certificate authority data for the "staging-cluster" cluster entry
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/on-prem-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 conf...
Execute the 'python' command in the astro-container from pod chat-app-pod and get the output
Command: ```bash kubectl exec chat-app-pod -c astro-container -- python ``` 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 cluster role named "view" with the specified settings:
Command: ```bash kubectl create clusterrole view --verb=get --resource=pods --resource-name=payment-processor --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|client|...
Set up the e2e cluster entry with embedded certificate authority data.
Command: ```bash kubectl config set-cluster e2e --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 set-cluste...
Set the basic authentication for the "cloud-user" entry with the username "admin" and the password "uXFGweU9l35qcif"
Command: ```bash kubectl config set-credentials cloud-user --username=admin --password=uXFGweU9l35qcif ``` 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 ...
Embed the certificate authority data for the prod-cluster cluster entry by running the command: `kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt`
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/app-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-...
Start a nginx pod with the alpine image, but overwrite the spec field with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=alpine --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Update the pod named 'foo' with the label 'component' set to 'api'
Command: ```bash kubectl label pods foo component=api ``` 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 ...
Forward local port 6379 to pod port 8088
Command: ```bash kubectl port-forward 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 be selected automa...
Create a copy of the log-aggregator-pod and replace all container images with the mongo image.
Command: ```bash kubectl debug log-aggregator-pod --copy-to=debug-image-memcached --set-image=*=mongo ``` 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 defaul...
Create a cron job named 'data-processing' with the image 'php' to execute a command every minute
Command: ```bash kubectl create cronjob data-processing --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", "default":...
Forward port 8088 on localhost and IP 10.19.21.23 to port 8888 in the web-app-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8088: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 criteri...
Forward traffic from local port 5432 to port 8081 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5432: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...
Add a taint to nodes with the label 'component=proxy' with the key 'dedicated' and value 'gpu-node-12:PreferNoSchedule'
Command: ```bash kubectl taint node -l component=proxy dedicated=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Forward port 8081 on localhost and IP 10.19.21.23 to port 8081 in the web-app-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8081:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Import the "log_level" key from the "db-config" config map and set it as environment variable for the "scheduler-app-deployment" deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/db-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Stream the logs of the "cyber-sleuth" container in the "security-service-pod" pod
Command: ```bash kubectl logs -f -c cyber-sleuth security-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": "--contain...
Delete pods and services named "security" and "database"
Command: ```bash kubectl delete pod,service security database ``` 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 selecto...
Get the output from the 'cosmic-container' in the 'analytics-pod'
Command: ```bash kubectl attach analytics-pod -c cosmic-container ``` 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 omitte...
Forward local port 8081 to port 9090 in the api-service-pod pod.
Command: ```bash kubectl port-forward pod/api-service-pod 8081 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 au...
Create a config map named app-config-prod with specified keys and their respective values from specified files.
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When c...
Create a copy of the e-commerce pod, add a debug container, and change container images.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-app --image=debian --set-image=app=app:debug,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Add a taint with the key 'hardware' and value 'web-node-8:PreferNoSchedule' on nodes labeled with 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy hardware=web-node-8:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Create a debug container in a copy of analytics-pod, changing container images
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-web --image=debian --set-image=database=mysql:5.7,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 re...