prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a job named 'deployment-rollout-job' using the 'alpine' image
Command: ```bash kubectl create job deployment-rollout-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 forma...
Execute the 'bash' command in the 'rocket-ranger' container of the 'frontend-pod' pod and get the output.
Command: ```bash kubectl exec frontend-pod -c rocket-ranger -- 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 th...
Create a service for the replication controller specified in "php-controller.yaml" which serves on port 5432 and connects to the containers on port 808400
Command: ```bash kubectl expose -f php-controller.yaml --port=5432 --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 sp...
Copy the file "/tmp/foo" from the pod "kube-node-lease/message-broker-pod-15" to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp kube-node-lease/message-broker-pod-15::/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,...
Update the 'payment' pod with the label 'role' set as 'frontend'
Command: ```bash kubectl label pods payment role=frontend ``` 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": ...
Set the service account of the deployment "web-app-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment web-app-deployment fluentd ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl se...
Create a new NodePort service named 'frontend-nodeport' that maps traffic from port 3001 on the node to port 7000 on the service
Command: ```bash kubectl create service nodeport frontend-nodeport --tcp=3001:7000 ``` 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": ""...
Set the service account of the deployment named "proxy-service-deployment" to the default service account.
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment default ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kube...
Create a service for the replicated php pods, serving on port 8084 and connecting to the containers on port 637900
Command: ```bash kubectl expose rc php --port=8084 --target-port=637900 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Set the cluster field in the team-beta-context context to on-prem-cluster.
Command: ```bash kubectl config set contexts.team-beta-context.cluster on-prem-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...
Copy the local file `~/.config/kube` to the remote pod `task-processor-pod-17` in the `kube-flannel` namespace, and place it in the `/tmp/bar_dir` directory.
Command: ```bash kubectl cp ~/.config/kube kube-flannel/task-processor-pod-17:/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 omitte...
Rename the context in your kubeconfig file
Command: ```bash kubectl config rename-context local-context new-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 also be...
Output the modified deployment "order-processing-deployment" with the environment variable "ENV" set to "prod" in YAML format without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/order-processing-deployment ENV=prod -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 templ...
Add a taint with key 'workload' and no value to node 'node-2'
Command: ```bash kubectl taint nodes node-2 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 of: json|...
Retrieve snapshot logs from the container "vpn-service-pod-1" of the deployment named "frontend-deployment"
Command: ```bash kubectl logs deployment/frontend-deployment -c vpn-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 flags: "flag"...
Add a taint with the key 'hardware' on nodes that have the label namespace=mynamespace.
Command: ```bash kubectl taint node -l namespace=mynamespace hardware=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Set the service account of the deployment "backend-microservice-deployment" to "flux"
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment flux ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `...
Create a new config map named "ui-config" with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/properties/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 ...
Create a cluster role named "view" with an AggregationRule specified
Command: ```bash kubectl create clusterrole view --aggregation-rule="rbac.example.com/aggregate-to-security=true" ``` 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...
Run the 'jenkins-plugin-cli' command in the code-explorer container of the media-stream-pod pod.
Command: ```bash kubectl exec media-stream-pod -c code-explorer -- jenkins-plugin-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. ...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/namespace-config 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 defin...
Import the keys 'redis_host' from the 'ui-config' config map and set them as environment variables in the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/ui-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Import the MAX_CONNECTIONS key from the monitoring-config ConfigMap into the email-server-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/monitoring-config 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...
Forward local port 5000 to the pod's port 5432, listening on both localhost and IP address 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 5000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Set the CPU and memory resource requests and limits for all containers in the alpine deployment
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=512Mi ``` 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 reque...
Create a role named "foo" with verb "connect" and resources "pods" with resource names "search-elasticsearch" and "database-master"
Command: ```bash kubectl create role foo --verb=connect --resource=pods --resource-name=search-elasticsearch --resource-name=database-master ``` 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=s...
List all deployments in the "sandbox-apps" API group with the version "custom-version" and display the output in YAML format.
Command: ```bash kubectl get deployments.custom-version.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 namespace...
Copy a file named "foo" located in the "/tmp" directory of the remote pod "worker-pod-4" in the "ingress-nginx" namespace to the "/tmp" directory locally, and name it "bar".
Command: ```bash kubectl cp ingress-nginx/worker-pod-4::/tmp/foo :/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 kubec...
view the environment variables defined on the 'log-aggregator-deployment' deployment
Command: ```bash kubectl set env deployment/log-aggregator-deployment --list ``` 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...
Execute the 'geth' command in the 'quantum-quark' container from the 'frontend-pod' pod and retrieve the output
Command: ```bash kubectl exec frontend-pod -c quantum-quark -- 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 th...
List deployments in YAML output format for the "feature-branch-2.3.0" version of the "custom-apps" API group
Command: ```bash kubectl get deployments.feature-branch-2.3.0.custom-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 name...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/kube-system-config 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...
Attach to the log-aggregator-pod and open a raw terminal session
Command: ```bash kubectl attach log-aggregator-pod -c warp-drive -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 a new config map named 'namespace-config' using the specified keys and corresponding file paths for 'settings' and 'key2' files
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/configurations/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 c...
Set the annotation 'custom-label' to 'my-custom-value' for the pod 'backend'
Command: ```bash kubectl annotate pods backend custom-label=my-custom-value ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include a...
Forward local port 8088 to the targetPort of the "https" service port in a pod selected by the "scheduler-service" service
Command: ```bash kubectl port-forward service/scheduler-service 8088: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 sele...
Check whether you have permission to list the "backup-job" job in the "logging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/backup-job -n logging ``` 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...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to the /tmp/bar directory in the file-server-pod-14 pod in the ingress-nginx namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ ingress-nginx/file-server-pod-14::/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":...
Execute the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' inside the pod vpn-service-pod and retrieve the output
Command: ```bash kubectl exec vpn-service-pod -- /bin/bash -c "echo 'Hello, Amazon Linux'" ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container n...
Create a cron job named 'metrics-collection' with the command 'php', scheduled to run every minute
Command: ```bash kubectl create cronjob metrics-collection --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", "defaul...
Set the service account of the deployment named "order-processing-deployment" to "gitlab-runner"
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment gitlab-runner ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Synt...
Check if the current user has permission to list the job named "cleanup-job" in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-job -n staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that s...
Create a service for a WordPress deployment that serves on port 8089 and connects to the containers on port 808200.
Command: ```bash kubectl expose deployment wordpress --port=8089 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Forward local port 3000 to port 8888 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-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 autom...
Update the server field for the galaxy-cluster cluster entry to "https://1.2.3.4" without modifying any other values.
Command: ```bash kubectl config set-cluster galaxy-cluster --server=https://1.2.3.4 ``` 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-aut...
Get the specified resources by their type and names
Command: ```bash kubectl get rc/web service/chat-app-rc pods/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 ...
Copy the ~/.config/kube file from a remote pod named argocd/web-app-pod-1 to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp argocd/web-app-pod-1:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl...
Apply a taint with the key 'special' on nodes that have the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy special=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": "O...
Create a job named monitoring-job using the mcr.microsoft.com/dotnet/core/runtime image
Command: ```bash kubectl create job monitoring-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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": ...
Show the resource utilization metrics for the payment-gateway-pod pod and its containers.
Command: ```bash kubectl top pod payment-gateway-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 t...
Create a pod disruption budget named monitoring-pdb that selects all pods with the label "project=my-project" and ensures that at least one of these pods is always available.
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=project=my-project --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-availabl...
Forward local port 3000 to port 3000 in the pod
Command: ```bash kubectl port-forward pod/api-service-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 criteria, a pod will be selected au...
Create a deployment named "my-dep" using the image "mcr.microsoft.com/dotnet/core/runtime"
Command: ```bash kubectl create deployment my-dep --image=mcr.microsoft.com/dotnet/core/runtime ``` 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": "Outpu...
update the pod named 'foo' with the annotation 'compliance-level' and the value 'PCI-DSS', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods foo 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 inc...
Forward traffic from port 8000 on all addresses to port 3000 in the backend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Forward traffic from port 3000 on all addresses to port 3000 in the 'backend-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-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 criteria, a pod will ...
Set resource requests and limits for all containers in the Mongo deployment
Command: ```bash kubectl set resources deployment mongo --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=2Gi ``` 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, ...
Embed certificate authority data for the web-cluster cluster entry:
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/cluster-beta/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-...
Import environment variables from a config map into a deployment, with a prefix for the variable names
Command: ```bash kubectl set env --from=configmap/app-config-dev --prefix=MYSQL_ 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 definiti...
Add a taint with key 'zone' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz zone=kube-master-9: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...
Deny a Certificate Signing Request (CSR) with the name 'csr-kubelet-14'
Command: ```bash kubectl certificate deny csr-kubelet-14 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kubect...
Create a new config map named app-config using the specified files as key-value pairs
Command: ```bash kubectl create configmap app-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...
set environment variables from config map keys
Command: ```bash kubectl set env --keys=redis_host --from=configmap/kube-system-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment vari...
Create a cluster role named "admin_role" with specific resource names
Command: ```bash kubectl create clusterrole admin_role --verb=patch --resource=services --resource-name=cache-redis --resource-name=load-balancer ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Create a cluster role named "admin_role" with SubResource specified
Command: ```bash kubectl create clusterrole admin_role --verb=patch,watch,exec --resource=secrets,secrets/status ``` 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"...
Display the container and image information for the 'e-commerce-pod' pod
Command: ```bash kubectl get pod e-commerce-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image ``` 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 --...
Create a pod disruption budget named database-pdb that will select all pods with the env=production label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget database-pdb --selector=env=production --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 [-...
Create a deployment called "worker" using the Centos image and expose port 8081
Command: ```bash kubectl create deployment worker --image=centos --port=8081 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Add a taint with key 'hardware' on nodes having label app=web-app, and value 'testing-node-11' with effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l app=web-app hardware=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": "", "usage":...
Copy the file '/tmp/foo' from your local machine to '/tmp/bar_dir' in the 'metrics-exporter-pod-10' pod in the 'logging' namespace.
Command: ```bash kubectl cp :/tmp/foo logging/metrics-exporter-pod-10:/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 t...
Create a service for the replicated centos using replica set centos, which serves on port 9090 and connects to the containers on port 8081
Command: ```bash kubectl expose rs centos --port=9090 --target-port=808100 ``` 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....
Update the pod 'auth' by adding or updating the annotation 'security-scan-status' with the value 'pass', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods auth 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 i...
Add a taint with the key 'disktype' on nodes having the label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 disktype=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/log-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Update the annotation of pod 'web' with the key 'SLA' and the value '99.9% uptime', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods web 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 include arb...
Run the 'kafka-topics --list' command inside the nano-bot container of the chat-app-pod pod.
Command: ```bash kubectl exec chat-app-pod -c nano-bot -- 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. If omitt...
Create a new config map named "app-name-config" and populate it with specified keys and their corresponding file paths
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Create a cron job named "report-generation" with the image "node", a schedule of running every minute, and the command "node --version" as the main container command.
Command: ```bash kubectl create cronjob report-generation --image=node --schedule="*/1 * * * *" -- node --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"...
Forward local port 5000 to port 3000 in the pod
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Update the annotation 'last-deployment' of the 'backend' pod with the value '2023-03-15', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods backend 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 a...
Create a copy of the 'api-service-pod' and name it 'my-debugger', changing all container images to 'jenkins'
Command: ```bash kubectl debug api-service-pod --copy-to=my-debugger --set-image=*=jenkins ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no res...
Copy a file named "foo" from the remote pod "metrics-exporter-pod-10" in the "prometheus" namespace to a directory named "bar" locally.
Command: ```bash kubectl cp prometheus/metrics-exporter-pod-10:/tmp/foo /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...
Set the cluster field in the 'my-context' context to 'testing-cluster'
Command: ```bash kubectl config set contexts.cluster-2-context.cluster testing-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...
Create a job named 'data-migration-job' with the image 'jenkins' and run the command 'java -jar /usr/share/jenkins/jenkins.war'
Command: ```bash kubectl create job data-migration-job --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` 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", "de...
Forward local port 8088 to port 8000 of the pod selected by the 'notification-handler-deployment' deployment
Command: ```bash kubectl port-forward deployment/notification-handler-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 ...
Execute the 'wp' command inside the first container of the 'web-app-deployment' deployment and display the output.
Command: ```bash kubectl exec deploy/web-app-deployment -- wp ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Create an ingress called 'myapp-ingress' that directs requests from website.com/input to the service 'svc1' on port 8084, and use a TLS secret called 'my-cert' to secure the connection.
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/input=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a debug image of the 'api-service-pod' with all container images changed to 'jenkins'
Command: ```bash kubectl debug api-service-pod --copy-to=debug-image-web --set-image=*=jenkins ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no...
Get the output from running the 'composer --version' command in the rocket-ranger container of the proxy-service-pod pod.
Command: ```bash kubectl exec proxy-service-pod -c rocket-ranger -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
Update the 'admin' role binding to include the 'admin' user, 'devops-user' user, and 'operations-team' group.
Command: ```bash kubectl set subject rolebinding admin --user=admin --user=devops-user --group=operations-team ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--service...
Import the specific keys 'max_connections' from the config map 'app-config-dev' into the deployment 'database-deployment'
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-dev 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 defini...
Create a new config map named app-config using specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/profiles/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 creating ...
Set the exec auth plugin environment variables for the "developer" entry with key1=val1 and key2=val2
Command: ```bash kubectl config set-credentials developer --exec-env=key1=val1 --exec-env=key2=val2 ``` 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 Bea...
Forward local port 8080 to port 6379 in the web-app-pod pod, listening on both localhost and IP address 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-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 criteri...
Get the output from running the 'python' command in the 'cyber-sleuth' container of the 'backend-pod' pod.
Command: ```bash kubectl exec backend-pod -c cyber-sleuth -- 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, use th...
Listen on local port 8081 and forward data to port 5000 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081 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 au...
Remove the taint with key 'datacenter' and effect 'NoExecute' from node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 datacenter: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. One of:...
Retrieve the deployments in YAML format for the "feature-branch-2.3.0" version of the "my-apps" API group
Command: ```bash kubectl get deployments.feature-branch-2.3.0.my-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 namespac...
Forward local port 8080 to port 5000 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-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 criteria, a pod will be selected auto...
Output the modified deployment in YAML format without altering the object on the server
Command: ```bash kubectl set env deployment/user-management-deployment DB_PASSWORD=secretpassword -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 ...