prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the 'api-server-deployment' deployment by setting the environment variable QUEUE_NAME to 'task-queue'.
Command: ```bash kubectl set env deployment/api-server-deployment QUEUE_NAME=task-queue ``` 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 templa...
Update the 'payment-processor-deployment' deployment by setting the environment variable CACHE_SIZE to 64MB
Command: ```bash kubectl set env deployment/payment-processor-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 templ...
Retrieve the logs of the previously terminated 'code-explorer' container from the 'media-stream-pod' pod.
Command: ```bash kubectl logs -p -c code-explorer media-stream-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 service for the replicated wordpress deployment, serving on port 8084 and connecting to the containers on port 30000.
Command: ```bash kubectl expose rc wordpress --port=8084 --target-port=300000 ``` 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 po...
Create a new ClusterIP service named shipping-service-clusterip that forwards traffic from port 5000 on the pod to port 8084 on the cluster IP.
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=5000:8084 ``` 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...
Import the 'debug_mode' key from the 'api-config' config map to the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/api-config 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 definition...
Create a deployment named drupal using the php image and expose port 8089.
Command: ```bash kubectl create deployment drupal --image=php --port=8089 ``` 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: json...
Embed the certificate authority data for the e2e cluster entry using the provided certificate authority file and set the cluster name as "e2e".
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/cluster-gamma/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-cluster...
Copy local file /tmp/foo_dir to remote pod message-broker-pod-15 in the container ingress-controller to the path /etc/kubernetes
Command: ```bash kubectl cp /tmp/foo_dir message-broker-pod-15:/etc/kubernetes -c ingress-controller ``` 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....
Return snapshot logs from the 'web-app-pod' pod with multiple containers
Command: ```bash kubectl logs web-app-pod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Create a copy of the proxy-server-pod called dgb-img with a debug container and change the container images to debian
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=dgb-img --image=debian --set-image=scheduler=my-scheduler:1.0,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Set the cluster field of a context to a specified value
Command: ```bash kubectl config set contexts.prod-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 you wan...
Create a deployment named 'cache' using the 'mcr.microsoft.com/dotnet/core/runtime' image
Command: ```bash kubectl create deployment cache --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": "Output...
Import the EXTERNAL_API_URL key from the global-config ConfigMap into the environment variables of the proxy-service-deployment Deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/global-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 d...
Return the previous terminated logs of the 'rocket-ranger' container from the 'e-commerce-pod' pod.
Command: ```bash kubectl logs -p -c rocket-ranger e-commerce-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", ...
Set a custom TLS server name for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --tls-server-name=testing-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-autho...
Import the specific key `database_url` from the `api-config` config map into the `gateway-deployment` deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/api-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...
Create a copy of the cdn-service-pod and name it debug-image-web, changing all container images to amazonlinux.
Command: ```bash kubectl debug cdn-service-pod --copy-to=debug-image-web --set-image=*=amazonlinux ``` 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 i...
Create a service for the 'alpine' deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment alpine --port=9000 --target-port=818100 ``` 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...
Set the server field of the on-prem-cluster cluster to the provided IP address
Command: ```bash kubectl config set clusters.on-prem-cluster.server https://1.2.3.4 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Copy the kube config file from your local machine to a specific directory in a remote pod.
Command: ```bash kubectl cp ~/.config/kube kube-proxy/logging-agent-pod-7:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Create a deployment named 'loadbalancer' that runs the 'php' image and exposes port '8089'
Command: ```bash kubectl create deployment loadbalancer --image=php --port=8089 ``` 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...
Forward port 8088 to port 8888 in the pod proxy-server-pod and listen on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-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 ...
Return the snapshot of previously terminated logs from the 'ruby' container of the 'database-pod' pod.
Command: ```bash kubectl logs -p -c ruby database-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": "-...
Create a service for the replication controller specified in "node-controller.yaml" file
Command: ```bash kubectl expose -f node-controller.yaml --port=8081 --target-port=300000 ``` 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 s...
Create a new ExternalName service named external-database-service with the external name set to "mockup-cloud.cloud".
Command: ```bash kubectl create service externalname external-database-service --external-name mockup-cloud.cloud ``` 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 ...
Create a pod disruption budget named 'load-balancer-pdb' that will select all pods with the 'version=v2' label, and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=version=v2 --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=N [...
Create a cron job named "report-generation" with the image "confluentinc/cp-kafka" and the schedule "*/1 * * * *", and run the command "kafka-topics --list"
Command: ```bash kubectl create cronjob report-generation --image=confluentinc/cp-kafka --schedule="*/1 * * * *" -- kafka-topics --list ``` 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...
Import the log_level key from the monitoring-config config map into the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-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 definition...
Add a taint with the key 'disktype' on nodes having the label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster 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": "", "usa...
Create a single ingress named 'www-ingress' that directs requests to 'testing.com/module' to the service 'svc1' on port '8083', using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress www-ingress --rule="testing.com/module=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Get the output of running the 'bash' command in the 'code-explorer' container from the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c code-explorer -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Create a debug version of the email-service pod by adding a debug container and changing the container images
Command: ```bash kubectl debug email-service-pod -it --copy-to=dgb-img --image=debian --set-image=database=mysql:5.7,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
Partially update a node by applying a strategic merge patch provided as YAML.
Command: ```bash kubectl patch node web-node-8 -p $'data:\n 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 flags:...
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/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 va...
Create a new ClusterIP service named 'log-service-clusterip' mapping the TCP port 27017 internally and externally.
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=27017:27017 ``` 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", ...
Forward local port 3000 to port 8888 in the pod selected by the 'search-engine-deployment' deployment
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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 wil...
Add a taint with the key 'environment' to nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice environment=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", "defaul...
Create a new ClusterIP service named 'analytics-service-clusterip' that forwards traffic from port 8181 to port 3000
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=8181:3000 ``` 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": "-...
import the `debug_mode` key from the `app-name-config` ConfigMap into the `search-engine-deployment` Deployment's environment variables.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-name-config 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 defin...
Stream the logs of the 'mycontainer' container in the 'database-pod' pod
Command: ```bash kubectl logs -f -c mycontainer database-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", "sho...
Add a taint with the key 'datacenter' to the nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha datacenter=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 job named "certificate-renewal" using the "ruby" image and run the command "irb"
Command: ```bash kubectl create job certificate-renewal --image=ruby -- irb ``` 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. On...
Copy the kube config file from your local machine to the /tmp/bar directory in the backend-pod-13 pod in the ingress-nginx namespace.
Command: ```bash kubectl cp ~/.config/kube ingress-nginx/backend-pod-13::/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 th...
Add a taint with the key 'environment' and the value 'prod-node-5:PreferNoSchedule' on all nodes with the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace environment=prod-node-5: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": "",...
Get the output from running 'gem --version' command from the first pod of the 'email-service' service, using the first container by default
Command: ```bash kubectl exec svc/email-service -- gem --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Start a new pod named 'hazelcast' with the 'wordpress' image, and configure the container to expose port 3001
Command: ```bash kubectl run hazelcast --image=wordpress --port=3001 ``` 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": "...
Import environment variables from the 'docker-registry-secret' secret into the 'api-server-deployment' deployment
Command: ```bash kubectl set env --from=secret/docker-registry-secret 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 definitions in one or ...
Import environment variables from a secret into a deployment.
Command: ```bash kubectl set env --from=secret/aws-credentials-secret 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 definitions in one ...
Provide a detailed description of the 'security-scanner-pod-18' pod
Command: ```bash kubectl describe pods/security-scanner-pod-18 ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type...
Display only the most recent 3 lines of output in the payment-gateway-pod.
Command: ```bash kubectl logs --tail=3 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": "--container", "short...
Update the image of all containers in the daemonset named 'prod' to 'golang:1.17'.
Command: ```bash kubectl set image daemonset prod *=golang:1.17 ``` 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 (rs) Syntax: `kubectl...
Add a taint with the key 'dedicated' on nodes that have the label owner=john-doe.
Command: ```bash kubectl taint node -l owner=john-doe dedicated=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create an ingress rule named "app-loadbalancer-ingress" that directs requests from foo.com/module to a service named "svc1" on port 7000, using the TLS secret "my-cert".
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/module=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
View the details of a specific revision for a daemonset.
Command: ```bash kubectl rollout history daemonset/namespace-2 --revision=5 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Forward port 5432 on your local machine to port 6379 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 5432: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 autom...
Auto scale the replication controller "monitoring" to have a minimum of 1 and a maximum of 5 pods, with a target CPU utilization of 90%.
Command: ```bash kubectl autoscale rc monitoring --max=5 --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 u...
Check if you have permission to list the job named "deploy-artifacts-job" in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/deploy-artifacts-job -n kube-dns ``` 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 ...
Import the 'debug_mode' key from the 'app-config-dev' ConfigMap into the 'backend-microservice-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-dev 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 variable...
rollback the deployment named "prod" to the previous version
Command: ```bash kubectl rollout undo deployment/prod ``` What it does: Manage the rollout of a resource. Valid resource types include: Syntax: `kubectl rollout SUBCOMMAND`
create a job with a specific command to monitor the version of Ethereum client
Command: ```bash kubectl create job monitoring-job --image=ethereum/client-go -- geth version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Get output from running the 'geth attach' command in nebula-navigator from pod media-stream-pod
Command: ```bash kubectl exec media-stream-pod -c nebula-navigator -- geth attach ``` 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 o...
Update the description of pod 'frontend' only if the current resource version is 1
Command: ```bash kubectl annotate pods frontend description='my frontend running nginx' --resource-version=1 ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be...
create a job named "log-collection" with the image "amazonlinux" and execute the "bash" command
Command: ```bash kubectl create job log-collection --image=amazonlinux -- bash ``` 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....
Listen on port 8000 locally, forwarding data to/from port 8080 in the pod selected by the notification-handler-deployment deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8000 8080 ``` 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 ...
Retrieve the output from running the 'dotnet' command in the astro-container of the email-service-pod.
Command: ```bash kubectl exec email-service-pod -c astro-container -- dotnet ``` 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...
Roll back to the previous deployment
Command: ```bash kubectl rollout undo deployment/services ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource to g...
stream logs of the nano-bot container in the e-commerce-pod pod
Command: ```bash kubectl logs -f -c nano-bot e-commerce-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", "shor...
Update the pod 'database' by removing the label 'bar'
Command: ```bash kubectl label pods database role- ``` 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 tru...
Set the golang deployment's nginx container cpu limit to "50m" and memory limit to "512Mi"
Command: ```bash kubectl set resources deployment golang -c=nginx --limits=cpu=50m,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 requested, but may burst up to...
Set the service account of the deployment named 'api-server-deployment' to 'tiller'
Command: ```bash kubectl set serviceaccount deployment api-server-deployment tiller ``` 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 ...
Import environment variables from the config map "env-vars" into the backend microservice deployment, with a prefix of "MYSQL_"
Command: ```bash kubectl set env --from=configmap/env-vars --prefix=MYSQL_ 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 variable definit...
Copy the file named 'foo' from the '/tmp' directory inside the 'backend-pod-13' pod in the default namespace, to the local '/tmp' directory and rename it as 'bar'.
Command: ```bash kubectl cp default/backend-pod-13:/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 kubectl.ku...
Create a cluster role named "admin_role" with the ability to delete configmaps and specifically name them as "cache-redis" and "error-logger"
Command: ```bash kubectl create clusterrole admin_role --verb=delete --resource=configmaps --resource-name=cache-redis --resource-name=error-logger ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|c...
Forward locally listened on port 8000 to port 8080 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod 8000:8080 ``` 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 local port 8888 to port 8888 inside the pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8888: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 a...
Copy the "~/.config/kube" directory from the remote pod "kube-dns/payment-gateway-pod-19" to the local directory "/tmp/bar_dir"
Command: ```bash kubectl cp kube-dns/payment-gateway-pod-19:~/.config/kube /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, ...
Create a new config map named "namespace-config" using the "properties" file from "/path/to/configs/file1.txt" and the "key1" file from "/path/to/profiles/file2.txt"
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/profiles/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...
Expose a service for the replication controller specified in "php-controller.yaml" with the following settings: serve on port 9090, connect to the containers on port 808300
Command: ```bash kubectl expose -f php-controller.yaml --port=9090 --target-port=808300 ``` 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...
Attach to a specific container within a pod and interact with its terminal.
Command: ```bash kubectl attach web-app-pod -c nano-bot -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 omitted, u...
Set the service account for the deployment named "gateway-deployment" to "elasticsearch"
Command: ```bash kubectl set serviceaccount deployment gateway-deployment elasticsearch ``` 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...
Add or update the label 'component' with the value 'web' for the pod 'gateway'
Command: ```bash kubectl label pods gateway component=web ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": ...
Create a job named 'log-collection' using the 'ethereum/client-go' container image and run the 'geth' command within it
Command: ```bash kubectl create job log-collection --image=ethereum/client-go -- geth ``` 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 ...
Import the keys EXTERNAL_API_URL from the config map called app-name-config into the deployment named frontend-deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-name-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Retrieve the YAML representation of all deployments in the "alpha-apps" API group with version "dev-2.2.0"
Command: ```bash kubectl get deployments.dev-2.2.0.alpha-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 w...
Get the output from running the 'ash' command inside the first container of the first pod in the email-server-deployment deployment.
Command: ```bash kubectl exec deploy/email-server-deployment -- ash ``` 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...
Update the annotation 'release-notes' of pod 'proxy' with the value 'https://example.com/release-notes/v2.5.1', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods proxy release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that c...
Forward local port 6379 to the target port of the "https" service in a selected pod of the "user-service" service.
Command: ```bash kubectl port-forward service/user-service 6379: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 ...
Set the certificate-authority-data field for a cluster on the Kubernetes configuration file.
Command: ```bash kubectl config set clusters.cloud-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) ``` 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...
Create a new LoadBalancer service named media-stream-lb that forwards traffic from port 8084 to port 8089
Command: ```bash kubectl create service loadbalancer media-stream-lb --tcp=8084:8089 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Execute the 'go' command inside the 'mycontainer' container in the 'log-aggregator-pod' pod and retrieve the output
Command: ```bash kubectl exec log-aggregator-pod -c mycontainer -- go ``` 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 local file `~/.config/kube` to the remote pod `openfaas/cache-pod-5` in the namespace, and place it at `/tmp/bar`.
Command: ```bash kubectl cp ~/.config/kube openfaas/cache-pod-5::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Create a cluster role named "bar" with API Group specified
Command: ```bash kubectl create clusterrole bar --verb=patch,proxy,delete --resource=persistentvolumes.storage.k8s.io ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "...
Import the keys REDIS_HOST from the config map db-config into the environment variables of the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/db-config deployment/analytics-platform-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...
Forward data between local port 5000 and pod port 8000 on the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 5000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Import specific keys from a config map into a deployment called "monitoring-stack-deployment"
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/api-config deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create a cluster role named "bar" with the verb "delete" allowed for non-resource URLs starting with "/oapi/"
Command: ```bash kubectl create clusterrole "bar" --verb=delete --non-resource-url=/oapi/* ``` 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": "--output", "short":...
Copy the file named "foo" from the directory "/tmp" in the pod "monitoring/logging-agent-pod-7" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp monitoring/logging-agent-pod-7:/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/database-secret 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 definitions in one or m...
Delete the 'cloud-user' user from the Kubernetes configuration.
Command: ```bash kubectl config delete-user cloud-user ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`