prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a deployment named 'auth' using the 'alpine' image and expose port 8181.
Command: ```bash kubectl create deployment auth --image=alpine --port=8181 ``` 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...
Check if you have permission to list the job named "certificates-renewal-job" in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-job -n staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Create a role named "custom_role" with specific resource names
Command: ```bash kubectl create role custom_role --verb=watch --resource=pods --resource-name=log-aggregator --resource-name=mail-server ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=serve...
Scale the deployment "prod-app-rs" to 1 replica if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 deployment/prod-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version...
List a pod specified in a YAML file, and display the output in YAML format
Command: ```bash kubectl get -f options.yaml -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 will only see resu...
Create a single ingress called 'api-v2-ingress' that directs requests to site.com/example to svc1:5000 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.com/example=svc1:5000,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 service for a replicated Wordpress which serves on port 5432 and connects to the containers on port 700000.
Command: ```bash kubectl expose rc wordpress --port=5432 --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 specified po...
Create a job with a specific command to be executed
Command: ```bash kubectl create job log-processing-job --image=nginx -- nginx -t ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output forma...
Expose the deployment named "alpine" as a service, where the service listens on port 9090 and connects to the containers on port 808900.
Command: ```bash kubectl expose deployment alpine --port=9090 --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 the specifi...
Create a copy of the payment-gateway-pod with the name my-debugger, adding a debug container with the debian image
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-debugger --image=debian --set-image=web=nginx:latest,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and nam...
Create a deployment named grafana with the postgres image running and expose port 8080
Command: ```bash kubectl create deployment grafana --image=postgres --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...
Add a taint with the key 'environment' and the value 'db-node-7:PreferNoSchedule' on nodes having the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops environment=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Execute the 'psql' command inside the first pod of the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl exec deploy/scheduler-app-deployment -- psql ``` 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 ...
Set the service account of the deployment "backend-microservice-deployment" to "kube-proxy"
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment kube-proxy ``` 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 Syn...
Add a taint with key 'special' on nodes having label team=devops, and the taint value as 'dev-node-4:PreferNoSchedule'
Command: ```bash kubectl taint node -l team=devops special=dev-node-4: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": "Outp...
List deployments in YAML format for the "external-apps" API group with the beta-1.0 version
Command: ```bash kubectl get deployments.beta-1.0.external-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...
Execute the 'mysql' command in the 'quantum-quark' container of the 'database-pod' pod and retrieve the output.
Command: ```bash kubectl exec database-pod -c quantum-quark -- mysql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Deny a Certificate Signing Request (CSR) named 'csr-postgres-12'
Command: ```bash kubectl certificate deny csr-postgres-12 ``` What it does: Deny a certificate signing request. kubectl certificate deny allows a cluster admin to deny a certificate signing request (CSR). This action tells a certificate signing controller to not to issue a certificate to the requestor. Syntax: `kubec...
Import the DEBUG_MODE key from the config map "app-config-prod" and set it as an environment variable in the deployment "proxy-service-deployment".
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config-prod 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 defin...
Create a new config map named log-config from the key=value pairs in the file.
Command: ```bash kubectl create configmap log-config --from-file=path/to/data ``` 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 basename of th...
Import specific keys from a config map into a deployment's environment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod 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 de...
Use the 'vim' editor to modify the 'notification-service' service
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/notification-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 varia...
Forward ports for a deployment to your local machine
Command: ```bash kubectl port-forward deployment/database-deployment 8081 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Forward port 9090 locally to the targetPort of the "https" service port in a pod selected by the user-service service
Command: ```bash kubectl port-forward service/user-service 9090: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 ...
Forward traffic from your local machine's port 8888 to port 5432 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Retrieve output from the 'redis-server --version' command running in the time-machine container of the e-commerce-pod pod
Command: ```bash kubectl exec e-commerce-pod -c time-machine -- redis-server --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....
Enable auto scaling for the deployment "payment" with a minimum of 4 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment payment --min=4 --max=8 ``` 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 ...
Create an ingress named 'app1-ingress' with a rule that directs requests to site.com/module and forwards them to the service 'svc1' on port 8082
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/module=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":...
Retrieve the previous terminated logs of the "nebula-navigator" container from the "mypod" pod.
Command: ```bash kubectl logs -p -c nebula-navigator 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...
Create a service for the centos deployment, which serves on port 7000 and connects to the containers on port 330600
Command: ```bash kubectl expose deployment centos --port=7000 --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 specifi...
Forward traffic from port 8000 on localhost and IP address 10.19.21.23 to port 3000 in the pod named "api-service-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Import the LOG_LEVEL key from the app-config-prod config map and set it as an environment variable for the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-prod deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Create a job with the name "backup" using the "ruby" image and execute the command "gem --version"
Command: ```bash kubectl create job backup --image=ruby -- gem --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": "Output format. One o...
Add or update the 'owner' annotation for pod 'proxy-server' with the value 'alice-smith'
Command: ```bash kubectl annotate --overwrite pods proxy-server owner='alice-smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
Create a service for a CentOS deployment on port 8181, connecting to the containers on port 844300
Command: ```bash kubectl expose deployment centos --port=8181 --target-port=844300 ``` 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...
Inject specific keys from a config map into a deployment's environment variable
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/namespace-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 va...
Create a service for the replicated php pods, which serves on port 8443 and connects to the containers on port 808300
Command: ```bash kubectl expose rc php --port=8443 --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 specified port. A ...
Create a deployment named drupal using the amazonlinux image and set the number of replicas to 4.
Command: ```bash kubectl create deployment drupal --image=amazonlinux --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...
Create a copy of the "e-commerce-pod" by adding a debug container and changing container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-custom-dbg --image=debian --set-image=worker=my-custom-worker:1.2.3,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identi...
Copy the local file /tmp/foo to the /etc/kubernetes directory in the remote pod with the name image-resizer-pod-20 in the metallb-system namespace.
Command: ```bash kubectl cp :/tmp/foo metallb-system/image-resizer-pod-20:/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...
Create a pod disruption budget named notification-service-pdb for pods with the owner=team-1 label
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=owner=team-1 --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-avai...
Embed the certificate authority data for the cluster-beta cluster entry using the command "kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/kube-cluster-1/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/kube-cluster-1/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...
Add a taint with key 'disktype' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe disktype=gpu-node-12:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Copy the kube config file located at ~/.config/kube to the /etc/kubernetes directory in the front-end-pod-12 pod, specifically in the web-app-container container.
Command: ```bash kubectl cp ~/.config/kube front-end-pod-12:/etc/kubernetes -c web-app-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Import the key "max_connections" from the config map named "monitoring-config" into the deployment named "cache-cluster-deployment"
Command: ```bash kubectl set env --keys=max_connections --from=configmap/monitoring-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 variabl...
delete the pods and services named "analytics" and "cdn"
Command: ```bash kubectl delete pod,service analytics cdn ``` 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. S...
Remove label 'bar' from pod 'proxy-server' if it exists
Command: ```bash kubectl label pods proxy-server unhealthy- ``` 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 pod disruption budget named worker-pdb that will select all pods with the role=worker label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=role=worker --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 [--dry-...
Create a new ClusterIP service named order-service-clusterip with a TCP port mapping of 8888:5000.
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8888:5000 ``` 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", ...
Listen on port 8888 locally, and forward the traffic to port 8080 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 8888: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 autom...
Create an ingress called 'private-ingress' that directs requests to testing.com/example to svc1:8181 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="testing.com/example=svc1:8181,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": "", "...
Create a pod disruption budget named api-service-pdb that will select all pods with the project=my-project label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=project=my-project --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-availab...
Retrieve the previous terminated lunar-launcher container logs from the proxy-server-pod
Command: ```bash kubectl logs -p -c lunar-launcher proxy-server-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...
Retrieve the output of running the 'wp' command in the first container of the first pod of the 'frontend-service' service.
Command: ```bash kubectl exec svc/frontend-service -- wp ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Scale the deployment named "foo" to have only 1 replica, assuming its current size is 5
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/foo ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Create a service for a replicated Ruby application that listens on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc ruby --port=8084 --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 specified port. A...
Forward traffic from port 3000 on localhost and IP 10.19.21.23 to port 5000 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 3000: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 crite...
Use an alternative editor to edit a service
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/loadbalancer-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 vari...
Set the CPU and memory resource limits and requests for all containers in the 'go' deployment
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=2,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 requested, but...
Embed certificate authority data for the moon-cluster cluster entry
Command: ```bash kubectl config set-cluster moon-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 ...
Create a job named "report-generation-job" with the image "postgres" and the command "pg_dump --version"
Command: ```bash kubectl create job report-generation-job --image=postgres -- pg_dump --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"...
Create a copy of the log-aggregator-pod and change all container images to ruby using the kubectl debug command
Command: ```bash kubectl debug log-aggregator-pod --copy-to=debug-image-web --set-image=*=ruby ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no...
Get the output from running the 'node' command in the stardust-shuttle container from the proxy-service-pod
Command: ```bash kubectl exec proxy-service-pod -c stardust-shuttle -- node ``` 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...
Create a new config map named app-secrets with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a co...
Get the output from running the 'go version' command in a pod named vpn-service-pod, using the container named nano-bot.
Command: ```bash kubectl exec vpn-service-pod -c nano-bot -- go 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, us...
Forward local port 8088 to port 8080 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-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 autom...
Create a new config map named app-settings using specific file names and paths for the keys instead of using the basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/configurations/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 crea...
Create a job named "indexing" using the Python image, and run the command "python --version" within the job.
Command: ```bash kubectl create job indexing --image=python -- python --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": "Output format...
Create a service that exposes the replicated alpine deployment on port 3001 and connects to the containers on port 8080.
Command: ```bash kubectl expose rc alpine --port=3001 --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 the specified port....
Create a secret named monitoring-credentials-secret from an env file
Command: ```bash kubectl create secret generic monitoring-credentials-secret --from-env-file=path/to/data.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...
Change the cluster field in the my-context context to cloud-cluster
Command: ```bash kubectl config set contexts.cluster-2-context.cluster cloud-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value y...
Create a cluster role named "default_role" with the verb "list" and the following resource names: "log-aggregator" and "blog-backend"
Command: ```bash kubectl create clusterrole default_role --verb=list --resource=pods --resource-name=log-aggregator --resource-name=blog-backend ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Add a taint with key 'special' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack special=backup-node-14: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...
Update the pod named 'analytics' by adding an annotation 'git-repo' with the value 'https://github.com/example/my-app'.
Command: ```bash kubectl annotate pods analytics git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than la...
Create a config map named namespace-config from specified files with custom keys instead of using the file basenames on disk.
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...
Create a secret named "database-secret" from an environment file.
Command: ```bash kubectl create secret generic database-secret --from-env-file=path/to/data.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 basename...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/frontend-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 autom...
Partially update a resource using a strategic merge patch
Command: ```bash kubectl patch -f 10-mynet.conf -p '{"spec":{"replicas":3}' ``` 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:...
Copy the local file /tmp/foo_dir to the remote pod named monitoring-agent-pod-6 in the kube-public namespace, and place it in the /tmp/bar_dir directory.
Command: ```bash kubectl cp /tmp/foo_dir kube-public/monitoring-agent-pod-6:/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,...
Add a taint to nodes labeled with 'service=auth'
Command: ```bash kubectl taint node -l service=auth workload=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Port forward the local port 8888 to port 5432 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Stream the logs of a specific container within a pod in real-time.
Command: ```bash kubectl logs -f -c mycontainer 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": "-...
Create a new config map named 'ui-config' from the environment file located at 'path/to/settings.env'
Command: ```bash kubectl create configmap ui-config --from-env-file=path/to/settings.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 bas...
Compare the changes in the Kubernetes resources described in the 'params.json' file with the current state of the cluster.
Command: ```bash cat params.json | kubectl diff -f - ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff...
Add a taint with key 'disktype' and no value to the 'edge-node-10' node.
Command: ```bash kubectl taint nodes edge-node-10 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Create a new config map named global-config with the specified keys, properties and key1, using the files file1.txt and file2.txt from the provided paths
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/settings/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 crea...
Set the service account of the deployment "database-deployment" to "cert-manager"
Command: ```bash kubectl set serviceaccount deployment database-deployment cert-manager ``` 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...
Forward port 8000 in the specified pod to port 9090 on localhost and the selected IP
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-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 criteri...
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:5000" ``` 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 'email' pod with the annotation 'owner' and set its value to 'alice smith'.
Command: ```bash kubectl annotate pods email owner='alice smith' ``` 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 arbitrary st...
Create a service for a replicated python application that serves on port 9092 and connects to the containers on port 8000
Command: ```bash kubectl expose rc python --port=9092 --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 specified port....
Import the "database_url" key from the "log-config" config map to the "database-deployment" deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/log-config 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 i...
create a service for a replicated node, providing access on port 5001 and connecting to the containers on port 8181
Command: ```bash kubectl expose rc node --port=5001 --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 specified port. A...
Create a new ClusterIP service named 'auth-service-clusterip' that maps port 5001 on the service to port 5001 on the pods
Command: ```bash kubectl create service clusterip auth-service-clusterip --tcp=5001:5001 ``` 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 data between local port 9090 and pod port 3000 in the 'notification-handler-deployment' deployment.
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 9090 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Get the output from running the 'kafka-server-start /etc/kafka/server.properties' command inside the 'media-stream-pod' pod
Command: ```bash kubectl exec media-stream-pod -- 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": "Cont...
Create an ingress resource called 'service-ingress' with a rule that directs requests for 'testing.com/bar' to 'svc1:8000' and uses the TLS secret named "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/bar=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": "", "usag...
Create a cluster role named "default_role" with SubResource specified.
Command: ```bash kubectl create clusterrole default_role --verb=list,create,update --resource=secrets,secrets/status ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "f...
Create a cron job named cron-task that runs an Ubuntu image every minute and prints "Hello"
Command: ```bash kubectl create cronjob cron-task --image=ubuntu --schedule="*/1 * * * *" -- docker run ubuntu echo "Hello ``` 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"...
Change the cluster field for a specific context to the provided value
Command: ```bash kubectl config set contexts.service-account-context.cluster app-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 val...