prompt
stringlengths
13
282
response
stringlengths
128
3.11k
View the last-applied-configuration annotations of the settings.yaml file in JSON format.
Command: ```bash kubectl apply view-last-applied -f settings.yaml -o json ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-...
Execute 'yum install -y wget' command in the 'astro-container' from the 'analytics-pod' and get the output
Command: ```bash kubectl exec analytics-pod -c astro-container -- yum install -y wget ``` 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. ...
Add a taint with key 'workload' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 workload=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":...
Open the 'notification-service' service for editing using the 'notepad' editor
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/notification-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 v...
List deployments from the "internal-apps" API group in the "v1.1.1" version, and display the output in JSON format
Command: ```bash kubectl get deployments.v1.1.1.internal-apps -o json ``` 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...
Check if you have the permission to list the job named "content-import-job" in the "namespace-1" namespace
Command: ```bash kubectl auth can-i list jobs.batch/content-import-job -n namespace-1 ``` 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...
Run the 'bash' command in the 'nano-bot' container of the 'vpn-service-pod' pod and get the output.
Command: ```bash kubectl exec vpn-service-pod -c nano-bot -- bash ``` 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 ...
Forward local port 5000 to port 3000 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 5000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Read the documentation of the "replicas" field in the "spec" section of the "configmaps" resource.
Command: ```bash kubectl explain resource=configmaps.spec.replicas ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag ...
Apply a taint with the key 'dedicated' on nodes that have the label project=project-alpha
Command: ```bash kubectl taint node -l project=project-alpha dedicated=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": "...
Scale the deployment "dev-environment-rs" to 7 replicas when the current number of replicas is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=7 deployment/dev-environment-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-...
Remove a taint from a specific node
Command: ```bash kubectl taint nodes k8s-node-1 cpu-type: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: ...
Forward local port 8080 to pod port 8000
Command: ```bash kubectl port-forward pod/e-commerce-pod 8080 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...
Set the custom TLS server name to use for validation for the e2e cluster entry by running the command "kubectl config set-cluster e2e --tls-server-name=web-cluster"
Command: ```bash kubectl config set-cluster e2e --tls-server-name=web-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-authority...
Update the label of the pod named 'vpn' to have the key 'release' and the value 'v2.0'
Command: ```bash kubectl label pods vpn release=v2.0 ``` 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 t...
Create a config map named app-secrets using specific keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Execute the command 'dotnet --list-runtimes' in the code-explorer container of the mypod pod and display the output.
Command: ```bash kubectl exec mypod -c code-explorer -- dotnet --list-runtimes ``` 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...
Set the service account of the deployment "payment-processor-deployment" to "kube-controller-manager"
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment kube-controller-manager ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statef...
Import the 'my-example-key' key from the config map 'env-vars' into the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/env-vars 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 definiti...
View metrics for all pods with the label "tier=frontend"
Command: ```bash kubectl top pod -l tier=frontend ``` 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 [NAME | -...
Forward local port 9090 to port 5432 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 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 selected...
Create an ingress resource with a rule that directs requests from foo.com/input to a service named svc1 on port 8000, using a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-v1-ingress --rule="foo.com/input=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": "", "usage":...
Set the last-applied-configuration of a resource from a file
Command: ```bash kubectl apply set-last-applied -f params.yaml ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of t...
Create a copy of the mypod pod, adding a debug container and changing the container images
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and na...
Output the modified deployment in YAML format without making changes to the object on the server
Command: ```bash kubectl set env deployment/database-deployment DEBUG=true -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (...
List deployments in YAML output format for a specific version of an API group
Command: ```bash kubectl get deployments.hotfix-1.1.2.sandbox-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 ...
Set the CPU and memory limits for the Nginx container in the deployment "nginx" to 5 and 256Mi respectively.
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=5,memory=256Mi ``` 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 it...
Start a new CentOS pod and expose port 9092
Command: ```bash kubectl run hazelcast --image=centos --port=9092 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create a NodePort service named monitoring-nodeport that maps port 8081 on the host machine to port 9091 on the service.
Command: ```bash kubectl create service nodeport monitoring-nodeport --tcp=8081:9091 ``` 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": ...
edit the configuration of the 'authentication-service' service
Command: ```bash kubectl edit svc/authentication-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 fall ba...
Display resource usage metrics for all pods in the "external-file-storage-service" namespace.
Command: ```bash kubectl top pod --namespace=external-file-storage-service ``` 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: `...
Taint nodes labeled with 'environment=production' with a 'datacenter' taint using the command 'kubectl taint node -l environment=production datacenter=db-node-7:PreferNoSchedule'
Command: ```bash kubectl taint node -l environment=production datacenter=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Create a single ingress called 'api-gateway-ingress' with a rule that directs requests to testing.com/bar to the service 'svc1' on port 7000
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/bar=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Forward local port 3000 to port 9090 in the search-engine-deployment pod
Command: ```bash kubectl port-forward deployment/search-engine-deployment 3000 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 wil...
Create an ingress resource called 'rontend-ingress' with a rule that directs requests from foo.com/module to the service 'svc1' on port 27017
Command: ```bash kubectl create ingress rontend-ingress --rule="foo.com/module=svc1:27017,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...
Copy the /tmp/foo_dir directory from the task-processor-pod-17 pod to the /tmp/bar_dir directory locally.
Command: ```bash kubectl cp prometheus/task-processor-pod-17:/tmp/foo_dir /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Return the snapshot logs from the container "gateway-pod-1" of the deployment named "analytics-platform-deployment".
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c gateway-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: ...
Copy the file '/tmp/foo' from the 'backend-pod-13' pod in the 'kube-node-lease' namespace to the local directory '/tmp/bar_dir'
Command: ```bash kubectl cp kube-node-lease/backend-pod-13::/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Forward the local port 9090 to the port 5000 inside the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward 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 be selected autom...
Add an annotation to the 'monitoring' pod with the key 'last-deployment' and the value '2023-03-15'
Command: ```bash kubectl annotate pods monitoring last-deployment=2023-03-15 ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ...
Create a single ingress called 'app2-ingress' that directs requests to website.com/input to a service named 'svc1' on port 27017, and use the TLS secret named "my-cert" for secure communication.
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/input=svc1:27017,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...
Execute the 'postgres' command inside the 'web-app-pod' pod, using the first container by default, and show the output.
Command: ```bash kubectl exec web-app-pod -- postgres ``` 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.kube...
Retrieve the last 31 lines of logs for the pod named proxy-server-pod.
Command: ```bash kubectl logs --tail=31 proxy-server-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":...
Import the keys "smtp_server" from the config map "app-settings" and set them as environment variables for the "order-processing-deployment" deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-settings deployment/order-processing-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...
Create a pod disruption budget for pods with a specific label, ensuring that at least four of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=project=my-project --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 --mi...
Open the 'monitoring-service' service for editing using the nano editor instead of the default editor
Command: ```bash KUBE_EDITOR="nano" kubectl edit svc/monitoring-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...
Rename the context 'cluster-1-context' to 'user-b-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context cluster-1-context user-b-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will ...
Execute the command 'dotnet --list-runtimes' in the first container of the 'database-service' pod and retrieve the output.
Command: ```bash kubectl exec svc/database-service -- dotnet --list-runtimes ``` 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 omitte...
Forward local port 6379 to port 8088 in the 'api-service-pod' pod
Command: ```bash kubectl port-forward pod/api-service-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 au...
Attach to the code-explorer container in the e-commerce-pod pod and get the output.
Command: ```bash kubectl attach e-commerce-pod -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,...
Update the pod named 'frontend' with the annotation 'team' and the value 'frontend-team', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods frontend 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 incl...
Update the pod 'gateway' with the annotation 'deployment-script' and set the value as 'https://example.com/deploy.sh', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods gateway deployment-script='https://example.com/deploy.sh' ``` 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...
create a service for the replicated centos pods, which serves on port 5000 and connects to the containers on port 8080
Command: ```bash kubectl expose rc centos --port=5000 --target-port=808000 ``` 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....
Embed certificate authority data for the "moon-cluster" cluster entry.
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/staging-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Create a new LoadBalancer service named email-service-lb that maps port 8084 of the service to port 8089 of the pods.
Command: ```bash kubectl create service loadbalancer email-service-lb --tcp=8084:8089 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Create a new secret named payment-gateway-secret from an env file
Command: ```bash kubectl create secret generic payment-gateway-secret --from-env-file=path/to/preferences.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 t...
Update the label of the pod 'database' to 'env=production'
Command: ```bash kubectl label pods database env=production ``` 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"...
Create a new config map named app-secrets with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/configurations/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 cre...
Listen to port 3000 locally and forward the traffic to port 5000 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 3000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Update the label of pod 'auth' with the value 'unhealthy', overwriting any existing value
Command: ```bash kubectl label --overwrite pods auth status=unhealthy ``` 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...
Add a taint to nodes with label 'release=beta' with the key 'cpu-type' and the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l release=beta cpu-type=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": "", "usage": "Output...
Execute the 'go version' command on the cdn-service-pod pod and retrieve the output
Command: ```bash kubectl exec cdn-service-pod -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Listen on port 6379 on localhost and IP address 10.19.21.23, and forward the traffic to port 8888 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 6379: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 crite...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/global-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a cron job that runs a command every minute
Command: ```bash kubectl create cronjob monthly-audit --image=alpine --schedule="*/1 * * * *" -- ash ``` 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...
Create a new secret named my-secret using the files in the specified folder
Command: ```bash kubectl create secret generic my-secret --from-file=path/to/configs ``` 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 of the fil...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-config deployment/frontend-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...
Launch a debug container in the backend-pod, create a copy of the pod named dgb-img, and change the container images to debian for the debug container, nginx:1.21 for the proxy container, and my-scheduler:1.0 for the scheduler container.
Command: ```bash kubectl debug backend-pod -it --copy-to=dgb-img --image=debian --set-image=proxy=nginx:1.21,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 identified by resource and...
Create an autoscaler for the replication controller "proxy" with a maximum of 8 pods and a target CPU utilization of 20%.
Command: ```bash kubectl autoscale rc proxy --max=8 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses t...
View the list of all allowed actions in the "kube-system" namespace
Command: ```bash kubectl auth can-i --list --namespace=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 partial URL that starts wi...
Taint a node with key 'zone' and no value
Command: ```bash kubectl taint nodes node-1 zone: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: json|yaml...
Add a taint with key 'workload' on nodes having the label region=eu-west-2, specifically on the node 'db-node-7', with the taint effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l region=eu-west-2 workload=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Create an ingress named 'public-ingress' that directs requests for website.com/example to svc1:3000 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="website.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...
Interact with the pod's shell in raw terminal mode
Command: ```bash kubectl attach database-pod -c stardust-shuttle -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
create an ingress named 'web-ingress' that routes requests from foo.com/bar to svc1:8082 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/bar=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": "Out...
Create a service for the 'alpine' deployment, which serves on port 8088 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment alpine --port=8088 --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 specifi...
Create a new secret named aws-credentials-secret with keys for each file in the folder bar, where the path to the files is specified as the value for the --from-file parameter and should be set to path/to/options.
Command: ```bash kubectl create secret generic aws-credentials-secret --from-file=path/to/options ``` 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 basena...
Create a new config map using the key=value pairs in a file
Command: ```bash kubectl create configmap app-name-config --from-file=path/to/configs ``` 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 basena...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-dev deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
List the replication controller with the name "web", the service with the name "log-aggregator-rc", and the pod with the name "auth-service-pod"
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/auth-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 na...
Add a taint with key 'environment' and value 'backup-node-14:PreferNoSchedule' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 environment=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Create an ingress called 'api-v1-ingress' that routes requests from 'website.com/bar' to 'svc1:8181' with a TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/bar=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...
Create a copy of the "analytics-pod" pod by running a debugging container with the command "sh".
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-debugger --container=mycontainer -- sh ``` 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...
Create an ingress named 'app-ingress' with a rule that directs requests to site.com/module, and routes them to svc1:8083
Command: ```bash kubectl create ingress app-ingress --rule="site.com/module=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": "", "usage": ...
Retrieve information about the single pod named "analytics-pod" in JSON format
Command: ```bash kubectl get -o json pod analytics-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 namespaced you will only see re...
Set the annotation 'security-scan-status' to 'pass' on pod 'gateway'
Command: ```bash kubectl annotate pods gateway security-scan-status=pass ``` 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 arbi...
Retrieve the previous terminated container logs for the 'rocket-ranger' container in the 'security-service-pod' pod.
Command: ```bash kubectl logs -p -c rocket-ranger 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": "--contai...
Add a taint with the key 'disktype' on nodes having the label tier=frontend, specifically on the node with the label k8s-node-1, and set the taint to PreferNoSchedule.
Command: ```bash kubectl taint node -l tier=frontend disktype=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Listen locally on port 9090, forwarding data to/from port 5000 in the pod selected by the analytics-platform-deployment deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Get the output from running 'bash' command from the first pod of the scheduler-app-deployment deployment using the first container by default.
Command: ```bash kubectl exec deploy/scheduler-app-deployment -- bash ``` 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 ...
create a service for the replicated 'php' replication controller, serving on port 3001 and connecting to the containers on port 8084
Command: ```bash kubectl expose rc php --port=3001 --target-port=808400 ``` 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 ...
Create a job named "audit-job" using the image "postgres" and run the command "pg_dump --version" as its main task.
Command: ```bash kubectl create job audit-job --image=postgres -- pg_dump --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output fo...
Create an autoscaler for the replication controller "cdn" with the following configuration:
Command: ```bash kubectl autoscale rc cdn --max=5 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Create a cluster role named "foo" with specific API Group permissions
Command: ```bash kubectl create clusterrole foo --verb=use,delete,connect --resource=clusterrolebindings.rbac.authorization.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]` Hel...
Create an ingress called 'myapp-ingress' with a rule that routes requests from 'testing.com/input' to 'svc1:8080' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress myapp-ingress --rule="testing.com/input=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": "", "usag...
Set the resource requests and limits for all containers in the nginx deployment to 100m cpu, 1Gi memory for requests, and 200m cpu, 512Mi memory for limits.
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=1Gi ``` 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 requeste...
Import the SECRET_KEY key from the kube-system-config config map and set it as an environment variable in the proxy-service-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/kube-system-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 de...
Forward port 8888 on all addresses to port 9090 in the analytics-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8888: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 wil...
Add an annotation to the 'vpn' pod with the description 'my frontend running nginx' but only if the resource is unchanged from version 1.
Command: ```bash kubectl annotate pods vpn 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...
Forward traffic from your local port 8080 to port 6379 in the 'security-service-pod'.
Command: ```bash kubectl port-forward pod/security-service-pod 8080 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 select...