prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Remove exec auth plugin environment variables for a specific user entry
Command: ```bash kubectl config set-credentials prod-user --exec-env=var-to-remove- ``` 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 Bearer token flags:...
Create a copy of the "proxy-server-pod" with a debug container and change the images of the containers
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=my-debugger --image=debian --set-image=mailer=mailer:latest,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 resource ...
Get the output from running the 'jenkins-plugin-cli' command from the first pod of the 'search-engine-deployment' deployment, using the first container by default
Command: ```bash kubectl exec deploy/search-engine-deployment -- jenkins-plugin-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Import the DATABASE_URL key from the app-secrets ConfigMap into the monitoring-stack-deployment Deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-secrets 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 defi...
Output the modified search-engine-deployment deployment in YAML format, with the environment variable PORT set to 8080, without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/search-engine-deployment PORT=8080 -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templat...
Forward traffic from localhost and IP 10.19.21.23 on port 9090 to port 5000 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 9090:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Copy the local directory "/tmp/foo_dir" to the remote pod "payment-gateway-pod-19" in the default namespace, and place it in the "/tmp/bar_dir_dir" directory.
Command: ```bash kubectl cp :/tmp/foo_dir payment-gateway-pod-19:/tmp/bar_dir_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Forward port 5432 locally to the targetPort of the "https" port in the "gateway-service" service
Command: ```bash kubectl port-forward service/gateway-service 5432: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 select...
Set the service account of the deployment "order-processing-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment my-service-account ``` 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 ...
Set the 'mongo' deployment's 'nginx' container CPU limits to "500m" and memory to "256Mi"
Command: ```bash kubectl set resources deployment mongo -c=nginx --limits=cpu=500m,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to...
Create a deployment named "registry" with 6 replicas using the Jenkins image.
Command: ```bash kubectl create deployment registry --image=jenkins --replicas=6 ``` 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 o...
Attach to the pod log-aggregator-pod and get the output from the cyber-sleuth container.
Command: ```bash kubectl attach log-aggregator-pod -c cyber-sleuth ``` 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 omitt...
Forward local port 8088 to port 8080 in the "backend-pod" pod
Command: ```bash kubectl port-forward pod/backend-pod 8088: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...
List multiple resources by their type and names
Command: ```bash kubectl get rc/web service/frontend-rc pods/payment-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 names...
Create an ingress named 'api-ingress' with a rule that directs requests for 'site.com/bar' to the service 'svc1' on port '8888' and uses the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-ingress --rule="site.com/bar=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": "", "usage": "Ou...
Create an ingress named 'app-ingress' that routes requests from 'website.com/example' to the service 'svc1' on port '8443'
Command: ```bash kubectl create ingress app-ingress --rule="website.com/example=svc1:8443,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a deployment called "auth" using the "centos" image.
Command: ```bash kubectl create deployment auth --image=centos ``` 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|yaml|name|...
Add a taint with key 'environment' on nodes having label 'myLabel'
Command: ```bash kubectl taint node -l myLabel environment=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Create a service for the replication controller specified in "hazelcast-controller.yaml"
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=9090 --target-port=808800 ``` 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 ...
Forward traffic from port 8000 on all addresses to port 6379 in the backend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8000: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 ...
Create a new LoadBalancer service named payment-gateway-lb that maps port 8080 on the service to port 6379 on the pods.
Command: ```bash kubectl create service loadbalancer payment-gateway-lb --tcp=8080:6379 ``` 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", ...
Create a secret named encryption-key-secret and populate it with keys from files in the specified folder
Command: ```bash kubectl create secret generic encryption-key-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 basenam...
expose a replica set called hazelcast as a service
Command: ```bash kubectl expose rs hazelcast --port=6379 --target-port=330600 ``` 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...
Delete a pod using the configuration specified in the pod.json file.
Command: ```bash kubectl delete -f ./pod.json ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some resource...
Set specific environment variables from a config map for a deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Attach to the astro-container inside the monitoring-pod pod and get the output from it.
Command: ```bash kubectl attach monitoring-pod -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 omitte...
Create a cluster role binding named "reader" with the "reader" cluster role
Command: ```bash kubectl create clusterrolebinding reader --clusterrole=reader --user=user1 --user=user2 --group=group1 ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--serviceacco...
Add a taint with key 'disktype' on nodes having label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz disktype=app-node-6: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": "", "usag...
Remove exec auth plugin environment variables for the "security-user" entry
Command: ```bash kubectl config set-credentials security-user --exec-env=var-to-remove- ``` 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 Bearer token fl...
Create a cluster role named "foo" with the specified resources and resource names
Command: ```bash kubectl create clusterrole foo --verb=connect --resource=configmaps --resource-name=file-processing --resource-name=app-worker-1 ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Create a deployment named 'jenkins' with the image 'redis' and the command 'redis-server'
Command: ```bash kubectl create deployment jenkins --image=redis -- redis-server ``` 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 o...
Forward local traffic from port 8000 to port 8000 in the mydeployment deployment
Command: ```bash kubectl port-forward deployment/mydeployment 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 selecte...
Only update the "client-key" field for the "developer" entry in the kubeconfig file. Do not modify any other values.
Command: ```bash kubectl config set-credentials developer --client-key=~/.kube/admin.key ``` 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 Bearer token f...
Add a taint with key 'environment' and value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'team=devops'.
Command: ```bash kubectl taint node -l team=devops 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": "", "usage": ...
Get the output from running "docker run ubuntu echo 'Hello, World'" command inside the auth-service-pod using the nano-bot container
Command: ```bash kubectl exec auth-service-pod -c nano-bot -- docker run ubuntu echo "Hello, World" ``` 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": "Co...
Set up port forwarding to listen on port 8088 locally and forward data to/from port 5000 in the pod selected by the 'email-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8088 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Retrieve the output from running the 'python' command in the email-service-pod.
Command: ```bash kubectl exec email-service-pod -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Copy the local file /tmp/foo to the remote pod backend-pod-13 in the namespace prometheus, and place it at the location /tmp/bar.
Command: ```bash kubectl cp /tmp/foo prometheus/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 the kubectl...
Set the custom TLS server name to "cluster-beta" for validation in the cluster-beta cluster entry configuration.
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=cluster-beta ``` 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...
Set up the autoscaling for the deployment "proxy-server" with a minimum of 7 pods and a maximum of 15 pods
Command: ```bash kubectl autoscale deployment proxy-server --min=7 --max=15 ``` 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...
Forward local port 3000 to port 8000 in the pod
Command: ```bash kubectl port-forward pod/frontend-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 criteria, a pod will be selected autom...
Delete the pods and services with the names "media-stream" and "foo"
Command: ```bash kubectl delete pod,service media-stream foo ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...
Create a debug copy of the web-app-pod.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-web --image=debian --set-image=cache=redis:alpine,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by reso...
List the desired resources by their type and names
Command: ```bash kubectl get rc/web service/security-service-rc pods/database-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 name...
Forward traffic from port 5000 on all addresses to port 8000 in the backend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-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 ...
Create a cron job to sync data regularly.
Command: ```bash kubectl create cronjob data-sync --image=ruby --schedule="*/1 * * * *" -- irb ``` 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", "default": ...
Forward local port 5432 to port 9090 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-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 automa...
Retrieve the previous logs of the nano-bot container from the frontend-pod, even if it has terminated.
Command: ```bash kubectl logs -p -c nano-bot 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", "short"...
Enable a new exec auth plugin for the "web-app" entry
Command: ```bash kubectl config set-credentials web-app --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` 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: --c...
Import the `smtp_server` key from the `ui-config` ConfigMap into the `load-balancer-deployment` deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/ui-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 an ingress called 'api-v2-ingress' that directs requests from testing.com/example to svc1:9092 using a TLS secret called "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/example=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": "", "u...
Update the label of the pod 'foo' by setting the 'env' label to 'staging'
Command: ```bash kubectl label pods foo env=staging ``` 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 tr...
Create a new secret named my-secret from ~/.docker/config.json file.
Command: ```bash kubectl create secret docker-registry my-secret --from-file=.dockerconfigjson=path/to/.docker/config.json ``` What it does: Create a new secret for use with Docker registries. Dockercfg secrets are used to authenticate against Docker registries. When using the Docker command line to push images, you c...
Create a service for a replication controller identified by type and name specified in "ubuntu-controller.yaml", which serves on port 8000 and connects to the containers on port 8000
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8000 --target-port=800000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Output the modified deployment in YAML format without applying the changes to the object on the server
Command: ```bash kubectl set env deployment/proxy-service-deployment SECRET_KEY=your-secret-key -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...
Create an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="foo.com/=svc:https,tls" \ --rule="foo.com/path/subpath*=othersvc:9091" ``` 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": "--out...
Update the image of all containers in the 'nginx' daemonset to 'golang:1.17'
Command: ```bash kubectl set image daemonset nginx *=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: `kubect...
Display the most recent 31 lines of logs for the pod named "log-aggregator-pod"
Command: ```bash kubectl logs --tail=31 log-aggregator-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 new config map named "api-config" using the parameters from an environment file.
Command: ```bash kubectl create configmap api-config --from-env-file=path/to/parameters.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the ...
Create a new deployment named 'ingress' that uses the 'jenkins' image and has 4 replicas
Command: ```bash kubectl create deployment ingress --image=jenkins --replicas=4 ``` 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...
Create a cluster role named "view" with the ability to watch configmaps and specific resource names like "cdn-proxy" and "queue-consumer"
Command: ```bash kubectl create clusterrole view --verb=watch --resource=configmaps --resource-name=cdn-proxy --resource-name=queue-consumer ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|n...
Create a copy of mypod named my-debugger, changing all container images to python
Command: ```bash kubectl debug mypod --copy-to=my-debugger --set-image=*=python ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource is sp...
Create a new secret named 'ssh-key-secret' from the environment file located at 'path/to/settings.env'
Command: ```bash kubectl create secret generic ssh-key-secret --from-env-file=path/to/settings.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basen...
Create a new config map named env-vars using specified files as the source for the config values.
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/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 creating a con...
Create a new secret named docker-registry-secret from an env file
Command: ```bash kubectl create secret generic docker-registry-secret --from-env-file=path/to/preferences.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default t...
Forward port 5432 on localhost and IP 10.19.21.23 to port 8080 in the frontend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 5432: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 criter...
Execute the 'go' command in the astro-container from the pod named mypod and return the output.
Command: ```bash kubectl exec mypod -c astro-container -- 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 the kubec...
Create a service for the replicated wordpress, serving on port 5001 and connecting to the containers on port 801000.
Command: ```bash kubectl expose rc wordpress --port=5001 --target-port=801000 ``` 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...
Embed the certificate authority data for the sun-cluster cluster entry by running the command: kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/on-prem-cluster/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/on-prem-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 s...
Get the output from running the 'php --version' command in the 'nebula-navigator' container of the 'payment-gateway-pod' pod.
Command: ```bash kubectl exec payment-gateway-pod -c nebula-navigator -- 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....
Forward port 5432 from localhost and IP 10.19.21.23 to port 5432 in the pod "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-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 cri...
Create a deployment named "ingress" using the "php" image and exposing port 9092
Command: ```bash kubectl create deployment ingress --image=php --port=9092 ``` 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: jso...
Forward port 8888 on all addresses to port 5432 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Create a new config map named env-vars with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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 ...
Forward traffic from local ports 8888 to pod port 8888 using kubectl port-forward
Command: ```bash kubectl port-forward pod/security-service-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 select...
create a service for the replicated 'centos' resource
Command: ```bash kubectl expose rc centos --port=8082 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a job named "monitoring-job" using the dotnet/core/runtime image. The job should run the command "dotnet --list-sdks".
Command: ```bash kubectl create job monitoring-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet --list-sdks ``` 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",...
Import the 'API_KEY' key from the 'log-config' config map into the 'authentication-service-deployment' deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/log-config deployment/authentication-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 defi...
set the resource request and limits for all containers in the Jenkins deployment to specify the CPU and memory usage.
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource reques...
Force replace a resource using the configuration file provided
Command: ```bash kubectl replace --force -f ./options.yaml ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f...
Execute the 'go' command in the container named 'mycontainer' from the pod named 'web-app-pod' and display the output.
Command: ```bash kubectl exec web-app-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 the kub...
Create a service for a replicated alpine using replica set
Command: ```bash kubectl expose rs alpine --port=8082 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/api-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Embed the certificate authority data for the dev-cluster cluster entry
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/sun-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 set-c...
Retrieve snapshot logs from container "proxy-service-pod-1" of the deployment "search-engine-deployment"
Command: ```bash kubectl logs deployment/search-engine-deployment -c proxy-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:...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=secret_key --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 variable de...
Update the annotation of the 'auth' pod with a description if the resource version is still 1.
Command: ```bash kubectl annotate pods auth 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 lar...
Create a resource using the edited data from a JSON file
Command: ```bash kubectl create -f options.json --edit -o json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to...
Copy the directory /tmp/foo_dir from the remote pod cert-manager/auth-service-pod-11 to the local directory /tmp/bar
Command: ```bash kubectl cp cert-manager/auth-service-pod-11:/tmp/foo_dir /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 t...
Create a cluster role named "foo" with the following permissions:
Command: ```bash kubectl create clusterrole foo --verb=exec --resource=pods --resource-name=app-worker-1 --resource-name=file-uploader ``` 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]` ...
Set the service account for the deployment named 'cache-cluster-deployment' to 'kube-dns'
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment kube-dns ``` 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: `kub...
Delete the pods and services with the names "cdn" and "database"
Command: ```bash kubectl delete pod,service cdn database ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. So...
Add a taint with the key 'cpu-type' and the value 'monitoring-node-15:PreferNoSchedule' on nodes having the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha cpu-type=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":...
Forward all traffic on port 8000 to the 'log-aggregator-pod' pod on port 8000, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-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 po...
Scale the deployment named frontend-rs to 1 replica
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/frontend-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...
Roll back the deployment "namespace-3" to the previous version, but only perform a dry run and do not actually make any changes.
Command: ```bash kubectl rollout undo --dry-run=server deployment/namespace-3 ``` 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 identifyi...
Open and edit the 'deploy-artifacts-job' job in JSON format using the v1 API
Command: ```bash kubectl edit job.v1.batch/deploy-artifacts-job -o json ``` 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...
Begin streaming the logs of the astro-container container in the analytics-pod pod
Command: ```bash kubectl logs -f -c astro-container 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",...
Copy the `/var/run/secrets/kubernetes.io/serviceaccount/` file from the local machine to the `/tmp/bar` directory in the `ingress-nginx/image-resizer-pod-20` pod in the specified namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ ingress-nginx/image-resizer-pod-20:/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"...
Create a new ExternalName service named external-security-service with the external name set as bar.com
Command: ```bash kubectl create service externalname external-security-service --external-name bar.com ``` 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 th...