prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create an ingress called 'external-ingress' that directs requests to a specific path of a website to a service with a specific port, and configure TLS using a specific secret.
Command: ```bash kubectl create ingress external-ingress --rule="site.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"...
Expose the deployment "alpine" as a service on port 8088, connecting to the containers on port 500000.
Command: ```bash kubectl expose deployment alpine --port=8088 --target-port=500000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Attach to the container named "quantum-quark" in the pod named "mypod" and get the output
Command: ```bash kubectl attach mypod -c quantum-quark ``` 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 the ...
Use a specific text editor (micro) to edit a service resource
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/scheduler-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...
List deployments in JSON format in specific version of API group
Command: ```bash kubectl get deployments.rc-1.1.0.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 will onl...
Forward local port 8081 to port 5432 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 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 auto...
Create a service for the 'ubuntu' deployment, serving on port 8888 and connecting to the containers on port 700000.
Command: ```bash kubectl expose deployment ubuntu --port=8888 --target-port=700000 ``` 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 golang pod named "hazelcast" and expose port 27017
Command: ```bash kubectl run hazelcast --image=golang --port=27017 ``` 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": "--...
Create a pod named 'hazelcast' using the 'ethereum/client-go' image and expose port 9092.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --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: ...
Forward local port 9090 to port 8000 in the pod
Command: ```bash kubectl port-forward pod/api-service-pod 9090 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 au...
Listen on port 8000 on your local machine and forward the traffic to the pod 'frontend-pod' on port 8000
Command: ```bash kubectl port-forward pod/frontend-pod 8000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Start a jenkins pod named 'hazelcast' using the 'jenkins' image, and expose port 3000 from the container.
Command: ```bash kubectl run hazelcast --image=jenkins --port=3000 ``` 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": "--...
Open a raw terminal to access the 'bash' shell in the 'cosmic-container' running in the 'proxy-server-pod' pod
Command: ```bash kubectl attach proxy-server-pod -c cosmic-container -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. ...
Forward port 5432 on localhost and IP 10.19.21.23 to port 9090 in the cdn-service-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-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 cri...
update the annotation of a pod specified in options.json with the SLA value of '99.9% uptime'
Command: ```bash kubectl annotate -f options.json 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 arbitrar...
Update the deployment 'search-engine-deployment' by adding a new environment variable called CACHE_SIZE with a value of 64MB.
Command: ```bash kubectl set env deployment/search-engine-deployment CACHE_SIZE=64MB ``` 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...
Create a config map named app-name-config using specified key-value pairs from files.
Command: ```bash kubectl create configmap app-name-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. ...
Remove all taints with key 'datacenter' from node 'kube-master-9'
Command: ```bash kubectl taint nodes kube-master-9 datacenter- ``` 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 specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/log-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
create a cron job named weekly-summary with the image "wordpress", schedule it to run every minute, and execute the command "apache2ctl -D FOREGROUND"
Command: ```bash kubectl create cronjob weekly-summary --image=wordpress --schedule="*/1 * * * *" -- apache2ctl -D FOREGROUND ``` 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": "--outp...
Set the custom TLS server name to "kube-cluster-1" for the "edge-cluster" cluster entry
Command: ```bash kubectl config set-cluster edge-cluster --tls-server-name=kube-cluster-1 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Forward traffic from local ports 8888 and 6000 to ports 9090 and 6000 in the selected pod, from the deployment named 'database-deployment'.
Command: ```bash kubectl port-forward deployment/database-deployment 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 will be ...
Create an ingress called 'external-ingress' that directs requests to website.com/bar to the service 'svc1' on port 9092 with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress external-ingress --rule="website.com/bar=svc1:9092,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...
Update the 'frontend' pod with the 'last-deployment' annotation set to '2023-03-15', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods frontend 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 ...
List the specified resources (replication controller, service, and pod) by their type and names.
Command: ```bash kubectl get rc/web service/api-service-rc pods/backend-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...
Import the keys 'MAX_CONNECTIONS' from the 'env-vars' config map and set them as environment variables in the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --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 definit...
Apply a partial update to the prod-node-5 node by merging the specified patch in YAML format
Command: ```bash kubectl patch node prod-node-5 -p $'spec:\n type: LoadBalancer' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful f...
Retrieve the previous terminated container logs named "astro-container" from the pod named "frontend-pod"
Command: ```bash kubectl logs -p -c astro-container frontend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", ...
Create a new ClusterIP service named api-service-clusterip that maps port 5000 to port 8088
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=5000:8088 ``` 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...
Set the client-key-data field in the operator user with raw bytes option
Command: ```bash kubectl config set users.operator.client-key-data cert_data_here --set-raw-bytes=true ``` 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 ...
update the deployment 'payment-processor-deployment' in the default namespace with a new environment variable SMTP_PASSWORD=your-password
Command: ```bash kubectl set env deployment/payment-processor-deployment SMTP_PASSWORD=your-password ``` 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 mo...
Retrieve the previous terminated logs from the 'time-machine' container in the 'email-service-pod' pod
Command: ```bash kubectl logs -p -c time-machine email-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Autoscale the replication controller "log-aggregator" with a maximum of 7 pods and a target CPU utilization of 20%.
Command: ```bash kubectl autoscale rc log-aggregator --max=7 --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 th...
Import the 'smtp_server' key from the 'app-secrets' config map into the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-secrets deployment/load-balancer-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...
Forward local port 8000 to port 8081 on the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Update the 'backend-microservice-deployment' deployment by setting the environment variable DEBUG=true.
Command: ```bash kubectl set env deployment/backend-microservice-deployment DEBUG=true ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templat...
List deployments in YAML format from the "prod-apps" API group with the version "alpha-2.0".
Command: ```bash kubectl get deployments.alpha-2.0.prod-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wi...
Print the supported API resources and sort them by name.
Command: ```bash kubectl api-resources --sort-by=name ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Set the service account of the deployment named payment-processor-deployment to fluentd
Command: ```bash kubectl set serviceaccount deployment payment-processor-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: `...
Update the 'monitoring-stack-deployment' deployment by setting a new environment variable called ENV to 'prod'
Command: ```bash kubectl set env deployment/monitoring-stack-deployment ENV=prod ``` 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 (wi...
Embed the certificate authority data for the "star-cluster" cluster entry
Command: ```bash kubectl config set-cluster star-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 ...
import the API_KEY key from the kube-system-config ConfigMap and set it as an environment variable for the gateway-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/kube-system-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...
Set the cluster field in the app-1-context context to staging-cluster
Command: ```bash kubectl config set contexts.app-1-context.cluster staging-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
List the resources of type ReplicaController named 'web', service named 'gateway-rc', and pods named 'gateway-pod'
Command: ```bash kubectl get rc/web service/gateway-rc pods/gateway-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 copy of the "email-service-pod" with a debug container and change container images
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Expose the replication controller specified in "wordpress-controller.yaml" as a service on port 8088, connecting to the containers on port 808900.
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8088 --target-port=808900 ``` 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 ...
Partially update a node using a strategic merge patch, specifying the patch as JSON
Command: ```bash kubectl patch node worker-node-3 -p '{"data":{"key":"new-value"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful...
Set the cluster field in the 'my-context' context to 'cluster-alpha'
Command: ```bash kubectl config set contexts.cloud-context.cluster cluster-alpha ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you w...
Create a cluster role named "view" with the ability to connect and access specific configmaps (app-worker-1 and mail-server).
Command: ```bash kubectl create clusterrole view --verb=connect --resource=configmaps --resource-name=app-worker-1 --resource-name=mail-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Copy the directory /var/run/secrets/kubernetes.io/serviceaccount/ from the metrics-exporter-pod-10 pod in the istio-system namespace to the /tmp/bar directory locally.
Command: ```bash kubectl cp istio-system/metrics-exporter-pod-10:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "", "usag...
Listen on port 8081 on your local machine and forward it to port 9090 in the web-app-pod pod.
Command: ```bash kubectl port-forward pod/web-app-pod 8081:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Start a postgres pod with the nginx image, but override the pod specification using a JSON object, which includes the apiVersion and spec fields.
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "v2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMM...
Import the `CONFIG_FILE_PATH` key from the `namespace-config` config map and set it as an environment variable for the `notification-handler-deployment` deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/namespace-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment ...
Set the service account of the deployment 'authentication-service-deployment' to 'vault'
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment vault ``` 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 service for a replication controller specified in a YAML file, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=80 --target-port=500000 ``` 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 th...
Set the cluster field in the dev-context context to galaxy-cluster
Command: ```bash kubectl config set contexts.dev-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-config-prod deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Remove all taints with key 'workload' from node 'monitoring-node-15'.
Command: ```bash kubectl taint nodes monitoring-node-15 workload- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Display the most recent 20 lines of output in the vpn-service-pod pod
Command: ```bash kubectl logs --tail=20 vpn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": ...
Import the SMTP_SERVER key from the app-config config map and set it as an environment variable for the web-app-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Output the modified deployment in YAML format without altering the object on the server
Command: ```bash kubectl set env deployment/payment-processor-deployment S3_BUCKET=my-s3-bucket -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...
Execute the command 'kafka-server-start /etc/kafka/server.properties' on the first pod of the 'mydeployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/mydeployment -- kafka-server-start /etc/kafka/server.properties ``` 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": "C...
Forward local ports 8080 and 6000 to ports 8081 and 6000 in the specified deployment's pod
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8080 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 ...
Expose a replication controller from a yaml file, with specified ports for serving and connecting to containers.
Command: ```bash kubectl expose -f centos-controller.yaml --port=5000 --target-port=888800 ``` 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...
Start a pod named 'nginx' with the 'ruby' image, but modify the spec of the pod using a partial set of values parsed from a JSON file or string
Command: ```bash kubectl run nginx --image=ruby --overrides='{ "apiVersion": "hotfix-1.1.2", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [CO...
Create a new config map named "app-settings" with the specified keys instead of using file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/data/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 co...
Add the taint with key 'zone' on nodes having the label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz 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": "Out...
create a new ExternalName service named external-ldap-service with the external name dummy-website.io
Command: ```bash kubectl create service externalname external-ldap-service --external-name dummy-website.io ``` 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 servic...
Execute the 'python --version' command in the time-machine container of the gateway-pod pod and get the output
Command: ```bash kubectl exec gateway-pod -c time-machine -- python --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Forward traffic from port 3000 on localhost and IP address 10.19.21.23 to port 8000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 3000: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 criteri...
Install AWS CLI in the astro-container of the pod proxy-server-pod
Command: ```bash kubectl exec proxy-server-pod -c astro-container -- 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 ...
Create an ingress called 'api-ingress' that directs requests to testing.com/bar to a service named svc1 on port 8088, and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress api-ingress --rule="testing.com/bar=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
List the resource types and names for the following: replication controller (rc/web), service (service/backend-rc), pod (pods/analytics-pod)
Command: ```bash kubectl get rc/web service/backend-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 y...
Execute the command 'dotnet --list-runtimes' in the first container of the 'gateway-service' service.
Command: ```bash kubectl exec svc/gateway-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 omitted...
Get the output from running the 'mongo' command in the 'time-machine' container of the 'e-commerce-pod' pod
Command: ```bash kubectl exec e-commerce-pod -c time-machine -- mongo ``` 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 ...
Copy the directory /tmp/foo_dir from a remote pod named ingress-controller-pod-8 in the namespace prometheus to the local directory /etc/kubernetes.
Command: ```bash kubectl cp prometheus/ingress-controller-pod-8:/tmp/foo_dir /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Create a deployment named worker with the python image and expose port 8000
Command: ```bash kubectl create deployment worker --image=python --port=8000 ``` 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...
Forward local port 3000 to port 6379 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 3000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Update the deployment 'gateway-deployment' by setting the environment variable DB_HOST=localhost.
Command: ```bash kubectl set env deployment/gateway-deployment DB_HOST=localhost ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (wi...
Forward traffic from a local random port to port 8000 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod :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 a...
Begin streaming the logs of a specific container in a pod
Command: ```bash kubectl logs -f -c quantum-quark mypod ``` 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": ...
Add a taint with key 'app' on nodes that have the label 'instance' set to 'app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 app=worker-node-3: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...
Forward local port 8000 to the target port of the "https" service port in a selected pod
Command: ```bash kubectl port-forward service/web-service 8000: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 selected a...
Update pod 'analytics' with the annotation 'expiration-date' and the value '2024-12-31', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods analytics expiration-date='2024-12-31' ``` 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...
Forward the local port 9090 to port 9090 in the mypod pod.
Command: ```bash kubectl port-forward pod/mypod 9090: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 automaticall...
Import the keys MAX_CONNECTIONS from the config map env-vars and set them as environment variables for the database-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/env-vars 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 definitions ...
Forward traffic from port 8000 on all addresses to port 5000 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8000: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...
Listen on port 8888 on all addresses, and forward the traffic to port 5000 in the log-aggregator-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8888: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...
Create a pod disruption budget named monitoring-pdb that selects pods with the label version=v2 and ensures that at least 9 of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=version=v2 --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 [--d...
Set up an autoscaling configuration for the 'monitoring' replication controller
Command: ```bash kubectl autoscale rc monitoring --max=3 --cpu-percent=40 ``` 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 u...
Create an ingress called 'private-service-ingress' that directs requests to website.com/example to svc1:8888 with a TLS secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/example=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default...
Update the pod specified in the "conf.json" file by adding the annotation "contact-email" with the value "support@example.com"
Command: ```bash kubectl annotate -f conf.json contact-email=support@example.com ``` 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...
View the resource usage metrics (CPU and memory) for the specified pod and its containers.
Command: ```bash kubectl top pod proxy-service-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top...
Create a deployment named "wordpress" running the "mysql" image and exposing port 8080.
Command: ```bash kubectl create deployment wordpress --image=mysql --port=8080 ``` 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:...
Configure auto scaling for a replication controller named "cdn" with a target CPU utilization of 20% and a minimum of 1 pod and a maximum of 4 pods.
Command: ```bash kubectl autoscale rc cdn --max=4 --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 an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="testing.com/=svc:https,tls" \ --rule="testing.com/path/subpath*=othersvc:8089" ``` 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"...
Remove the label named 'env' from the pod named 'chat-app'
Command: ```bash kubectl label pods chat-app env- ``` 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 true...
Create a copy of the chat-app-pod by adding a debug container and changing the container images
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Create an ingress called 'web-ingress' with a rule that directs requests for website.com/input to svc1:8000 using the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="website.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"...
Import the 'LOG_LEVEL' key from the 'app-name-config' config map into the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-name-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...