prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a cluster role named "custom_role" with specific resource names
Command: ```bash kubectl create clusterrole custom_role --verb=get --resource=pods --resource-name=machine-learning --resource-name=image-processor ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|c...
Get the output from running the 'php --version' command inside the 'chat-app-pod' pod, using the 'rocket-ranger' container.
Command: ```bash kubectl exec chat-app-pod -c rocket-ranger -- php --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
create a deployment named nats using the hazelcast image and expose port 6379
Command: ```bash kubectl create deployment nats --image=hazelcast/hazelcast --port=6379 ``` 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...
Create a deployment named registry using the redis image, and expose port 5000.
Command: ```bash kubectl create deployment registry --image=redis --port=5000 ``` 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: ...
Set the custom TLS server name to 'edge-cluster' for the 'web-cluster' cluster entry
Command: ```bash kubectl config set-cluster web-cluster --tls-server-name=edge-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-...
Import specific keys from a config map to the environment variables of a deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-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 definitio...
Listen on port 8081 on all addresses and forward the traffic to port 8081 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-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 criteria, a pod wil...
Create a new ExternalName service named external-messaging-service with the external name education-edu.edu
Command: ```bash kubectl create service externalname external-messaging-service --external-name education-edu.edu ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference ...
Set the cluster field in the 'team-alpha-context' context to 'data-cluster'
Command: ```bash kubectl config set contexts.team-alpha-context.cluster data-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 y...
Forward local port 5432 to port 5432 in the pod
Command: ```bash kubectl port-forward pod/web-app-pod 5432: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 automa...
Forward traffic from port 8080 on all addresses to port 8888 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8080: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 wil...
Forward port 5432 on your local machine to port 9090 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-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 autom...
Get the output from running the 'elasticsearch-plugin --list' command in the first container of the 'mypod' pod.
Command: ```bash kubectl exec mypod -- elasticsearch-plugin --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 omitted, use the...
Create a cluster role named "reader" with API Group specified and set the allowed verbs and resources
Command: ```bash kubectl create clusterrole reader --verb=update,get,patch --resource=statefulsets.apps ``` 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": "--outp...
Retrieve the snapshot logs from the container named auth-service-pod-1 in the deployment named mydeployment.
Command: ```bash kubectl logs deployment/mydeployment -c auth-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--c...
Forward traffic from port 8888 on all addresses to port 5432 inside the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8888: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 wil...
Retrieve the resource configurations for the 'web' replication controller, the 'web-app-rc' service, and the 'security-service-pod' pods.
Command: ```bash kubectl get rc/web service/web-app-rc pods/security-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 names...
create a cron job with a specified schedule and command
Command: ```bash kubectl create cronjob backup-job --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", "shor...
Retrieve the output of the 'dotnet --list-runtimes' command executed in the stardust-shuttle container within the vpn-service-pod.
Command: ```bash kubectl exec vpn-service-pod -c stardust-shuttle -- 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 ...
Check if you have permission to list the job named "cron-job" in the "testing" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/cron-job -n testing ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that star...
Update the pod named 'analytics' by adding an annotation 'scaling-policy' with the value 'auto-horizontal-scaling'
Command: ```bash kubectl annotate pods analytics scaling-policy=auto-horizontal-scaling ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels a...
Retrieve snapshot logs from the 'backend-pod-1' container of the 'payment-processor-deployment' deployment.
Command: ```bash kubectl logs deployment/payment-processor-deployment -c backend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "...
Create or update the environment variables for the "app-operator" entry in the exec auth plugin
Command: ```bash kubectl config set-credentials app-operator --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 ...
Retrieve the documentation of the 'template' field in the 'spec' section of the 'configmaps' resource.
Command: ```bash kubectl explain resource=configmaps.spec.template ``` 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 ...
Create a new config map named global-config using specified keys and file paths.
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creat...
Apply a taint with key 'environment' and value 'node-1:PreferNoSchedule' on the nodes that have the label 'customer=acme-corp'.
Command: ```bash kubectl taint node -l customer=acme-corp environment=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"...
Remove all the taints with the key 'disktype' from the 'edge-node-10' node
Command: ```bash kubectl taint nodes edge-node-10 disktype- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml...
Check if you have permission to list the job named "report-generation-job" in the "logging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-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 ...
Rename the context 'staging-context' to 'admin-context' in your kubeconfig file
Command: ```bash kubectl config rename-context staging-context admin-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 als...
Retrieve the previous terminated logs of the code-explorer container from the analytics-pod
Command: ```bash kubectl logs -p -c code-explorer analytics-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", "...
Attach to a pod and enter raw terminal mode
Command: ```bash kubectl attach e-commerce-pod -c cyber-sleuth -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 omi...
Retrieve the previous terminated logs from the 'quantum-quark' container in the 'payment-gateway-pod' pod
Command: ```bash kubectl logs -p -c quantum-quark payment-gateway-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...
Create a ClusterIP service named backend-service-clusterip with TCP port mapping from 9092 to 8083
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=9092:8083 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Execute the 'composer --version' command in the warp-drive container of the web-app-pod pod and capture the output.
Command: ```bash kubectl exec web-app-pod -c warp-drive -- 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. If omitt...
import the 'log_level' key from the 'app-config-dev' ConfigMap and set it as an environment variable in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-dev 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...
Create a new ClusterIP service named 'frontend-service-clusterip' that will forward TCP traffic from port 6379 to port 8083
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=6379:8083 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Copy a local file to a remote pod and specific container
Command: ```bash kubectl cp :/tmp/foo image-resizer-pod-20:/etc/kubernetes -c database-container ``` 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 ...
Add a taint with the key 'workload' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production workload=monitoring-node-15: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 secret named database-secret with keys for each file in the specified path
Command: ```bash kubectl create secret generic database-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 basename of t...
Create a pod disruption budget named auth-service-pdb with the selector env=production and ensure that there are at least 9 pods with this label available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=env=production --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=...
Use an alternative text editor (in this case, emacs) to edit the service "order-service"
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/order-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,...
Remove all the taints with the key 'hardware' from the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 hardware- ``` 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|y...
import environment from a secret for the specified deployment
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Add a taint with key 'environment' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 environment=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Auto scale the replication controller "frontend", setting the maximum number of pods to 6 and target CPU utilization at 20%.
Command: ```bash kubectl autoscale rc frontend --max=6 --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 use...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/backend-rc pods/web-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you...
Create a new ExternalName service named my-ns that points to the external name "blog-test.blog"
Command: ```bash kubectl create service externalname my-ns --external-name blog-test.blog ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference services that exist off ...
create a job with a specific image and command
Command: ```bash kubectl create job data-migration-job --image=php -- ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Set the service account for the deployment "scheduler-app-deployment" to "metrics-server"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment metrics-server ``` 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...
Update the annotation "git-repo" of a pod with the contents of "pod.json" using the provided URL
Command: ```bash kubectl annotate -f pod.json git-repo='https://github.com/example/my-app' ``` 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 label...
Copy the local file "/tmp/foo" to the remote pod named "load-balancer-pod-9" in the container "payment-gateway" and place it at the path "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo load-balancer-pod-9::/tmp/bar -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 omitted, us...
Scale the deployment named staging-app-rs to have 5 replicas, assuming its current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/staging-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
create a role named "bar" with the specified subresources and verbs
Command: ```bash kubectl create role bar --verb=list,create,update --resource=nodes,nodes/stats ``` 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|client|none]` Helpful flags: "flag": "...
Attach to the astro-container in the mypod pod and get its output.
Command: ```bash kubectl attach mypod -c astro-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 omitted, use th...
execute the 'nginx' command in the quantum-quark container of the frontend-pod pod and get the output
Command: ```bash kubectl exec frontend-pod -c quantum-quark -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Forward port 3000 on your local machine to port 8088 on the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 3000: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 a...
Execute the command 'yum install -y aws-cli' inside the container of the pod 'chat-app-pod' and retrieve the output.
Command: ```bash kubectl exec chat-app-pod -- yum install -y aws-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. If omitted, use t...
Create a job called "scaling-job" using the "confluentinc/cp-kafka" image and run the command "kafka-server-start /etc/kafka/server.properties"
Command: ```bash kubectl create job scaling-job --image=confluentinc/cp-kafka -- kafka-server-start /etc/kafka/server.properties ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "sho...
Import the 'external_api_url' key from the 'app-config-dev' config map to the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config-dev 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 ...
Embed the certificate authority data for the 'cluster-gamma' cluster entry using the command 'kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/cluster-beta/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cluster-gamma --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 se...
Create a job named "testing" with the image "postgres" and run the command "postgres"
Command: ```bash kubectl create job testing --image=postgres -- postgres ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Update the annotation of a pod in "docker-registry.yaml" file
Command: ```bash kubectl annotate -f docker-registry.yaml backup-strategy='daily backups' ``` 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...
Create a cron job called "log-rotation" using the "wordpress" image, scheduled to run every minute, and execute the "wp" command.
Command: ```bash kubectl create cronjob log-rotation --image=wordpress --schedule="*/1 * * * *" -- wp ``` 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", "def...
Create a new config map named log-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/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 creat...
Create a pod disruption budget named 'ingress-controller-pdb' that selects all pods with the 'app=rails' label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget ingress-controller-pdb --selector=app=rails --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available...
Forward local port 8081 to port 5432 in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod 8081: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 automaticall...
Retrieve the logs from container gateway-deployment-1 of the deployment analytics-pod
Command: ```bash kubectl logs deployment/gateway-deployment -c analytics-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "...
Create a new config map named 'api-config' with the specified keys from the provided file paths
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/configs/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 ...
Import the keys REDIS_HOST from the app-config config map and set it as environment variables in the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-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 definition...
Forward local port 8088 to port 8888 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-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 criteria, a pod will be selected auto...
import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/kube-system-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 varia...
Forward port 6379 on all addresses to port 3000 in the pod "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 6379: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 sel...
Automatically scale the replication controller "frontend" based on CPU utilization, with a minimum of 1 pod and a maximum of 7 pods
Command: ```bash kubectl autoscale rc frontend --max=7 --cpu-percent=90 ``` 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 use...
Attach to a specific container in a pod in interactive mode
Command: ```bash kubectl attach email-service-pod -c time-machine -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 ...
Create a new config map named "monitoring-config" using the specified keys and file paths
Command: ```bash kubectl create configmap monitoring-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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. Whe...
create a job named "log-collection" using the "postgres" image and run the command "postgres"
Command: ```bash kubectl create job log-collection --image=postgres -- postgres ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format...
Create a pod disruption budget named batch-processing-pdb that selects all pods with the app=rails label and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=app=rails --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...
Use the kubectl command to listen on port 6379 on localhost and IP 10.19.21.23, forwarding the traffic to port 8000 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 6379: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 p...
Set the resource request and limits for all containers in the 'hazelcast' deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=5,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 request...
Create a pod disruption budget named ingress-controller-pdb that will select all pods with the tier=frontend label and require a minimum of four pods being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget ingress-controller-pdb --selector=tier=frontend --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-avail...
Create a role named "bar" with the specified SubResource for the "persistentvolumeclaims" resource
Command: ```bash kubectl create role bar --verb=list,create,update --resource=persistentvolumeclaims,persistentvolumeclaims/status ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|clie...
Update the 'auth' pod with the annotation 'monitoring-tool' set to 'Prometheus', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods auth monitoring-tool='Prometheus' ``` 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 ...
Forward port 5432 on localhost and IP 10.19.21.23 to port 8000 in the pod "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 5432: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 cri...
Scale the replica set named 'dev-environment-rs' to 1 replica
Command: ```bash kubectl scale --replicas=1 rs/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-version is specified, it is v...
Create a new config map with specified keys from files in a directory
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 ...
Update the annotation 'monitoring-tool' of the pod 'frontend' to 'Prometheus', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods frontend monitoring-tool='Prometheus' ``` 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 ...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/ui-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Create a single ingress called 'app2-ingress' that directs requests to website.com/example to svc1:8000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/example=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a service for the hazelcast deployment
Command: ```bash kubectl expose deployment hazelcast --port=8010 --target-port=909000 ``` 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...
Create a cron job named backup-job with the specified schedule and command
Command: ```bash kubectl create cronjob backup-job --image=golang --schedule="*/1 * * * *" -- go run hello.go ``` 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": "-...
Apply a taint with key 'zone' and value 'node-1:PreferNoSchedule' on all nodes that have the label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice zone=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...
Import the LOG_LEVEL key from the log-config config map and set it as an environment variable in the order-processing-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/log-config 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 definiti...
Listen on port 5432 locally and forward the traffic to port 9090 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward pod/api-service-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 au...
Create a service for the replication controller specified in "ubuntu-controller.yaml"
Command: ```bash kubectl expose -f ubuntu-controller.yaml --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...
Set up autoscaling for a replication controller named "email" with a minimum of 1 pod and a maximum of 6 pods, targeting a CPU utilization of 90%.
Command: ```bash kubectl autoscale rc email --max=6 --cpu-percent=90 ``` 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...
Update node 'node-2' with a taint that has the key 'hardware', value 'gpu', and effect 'NoExecute'
Command: ```bash kubectl taint nodes node-2 hardware=gpu: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: js...
Create a new ClusterIP service named git-service-clusterip, mapping port 5000 externally to port 8089 internally.
Command: ```bash kubectl create service clusterip git-service-clusterip --tcp=5000:8089 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Import the environment variables from the 'azure-storage-secret' secret into the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --from=secret/azure-storage-secret deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more ...
Execute the 'wp' command in the first container of the cache-service pod
Command: ```bash kubectl exec svc/cache-service -- 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 kubectl.kube...
Set the container images of a deployment
Command: ```bash kubectl set image deployment/node busybox=busybox node=node:14.17.3 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (...