prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod 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 variabl...
Add a taint with key 'special' on nodes having label myLabel
Command: ```bash kubectl taint node -l myLabel 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": "Output f...
Set up an autoscaling for the "api" replication controller with a maximum of 2 pods and a target CPU utilization of 40%.
Command: ```bash kubectl autoscale rc api --max=2 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Check if you have permission to list the job named "report-generation-job" in the "production" namespace
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-job -n production ``` 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...
Attach to the 'stardust-shuttle' container in the 'vpn-service-pod' pod and switch to raw terminal mode
Command: ```bash kubectl attach vpn-service-pod -c stardust-shuttle -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. I...
Remove a taint from a specific node if it exists
Command: ```bash kubectl taint nodes kube-master-9 environment: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. On...
Apply a taint with the key 'cpu-type' and value 'dev-node-4:PreferNoSchedule' to the nodes that have the label app=web-app.
Command: ```bash kubectl taint node -l app=web-app cpu-type=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": "Out...
Copy the local file /tmp/foo_dir to /tmp/bar inside the kube-proxy/payment-gateway-pod-19 pod.
Command: ```bash kubectl cp /tmp/foo_dir kube-proxy/payment-gateway-pod-19:/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 ...
Get the output of 'ruby --version' command from the first pod of the payment-processor-deployment
Command: ```bash kubectl exec deploy/payment-processor-deployment -- ruby --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...
Return the previous terminated logs of the cosmic-container container in the security-service-pod
Command: ```bash kubectl logs -p -c cosmic-container security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--con...
Import the 'smtp_server' key from the 'app-config-prod' config map into the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-config-prod 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...
Copy the contents of the /var/run/secrets/kubernetes.io/serviceaccount/ directory from the remote pod named kube-proxy/security-scanner-pod-18 to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp kube-proxy/security-scanner-pod-18:/var/run/secrets/kubernetes.io/serviceaccount/ /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage"...
Create a new ClusterIP service named my-cs and configure it to forward traffic from port 27017 to port 9092.
Command: ```bash kubectl create service clusterip my-cs --tcp=27017:9092 ``` 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", "default": "", "u...
Import the REDIS_HOST key from the ui-config ConfigMap and set it as an environment variable in the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/ui-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Output the modified deployment in YAML format without making any changes on the server.
Command: ```bash kubectl set env deployment/proxy-service-deployment DB_HOST=localhost -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...
Listen on port 5000 locally, forwarding data to/from port 3000 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 5000 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Update the order-processing-deployment deployment by adding a new environment variable 'PORT' with the value of '8080'
Command: ```bash kubectl set env deployment/order-processing-deployment PORT=8080 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (w...
Embed certificate authority data for the on-prem-cluster cluster entry.
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/edge-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 service for the replication controller specified in the hazelcast-controller.yaml file, which serves on port 8088 and connects to the containers on port 700000.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8088 --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 ...
Add a new environment variable 'DB_PASSWORD' with the value 'secretpassword' to the 'frontend-deployment' deployment
Command: ```bash kubectl set env deployment/frontend-deployment DB_PASSWORD=secretpassword ``` 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 tem...
Run the 'mysql' command inside the 'email-service-pod' pod and print the output.
Command: ```bash kubectl exec email-service-pod -- 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 the kubectl.k...
Check to see if you have permission to read pod logs by running the command "kubectl auth can-i get pods --subresource=log".
Command: ```bash kubectl auth can-i get pods --subresource=log ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that starts with "...
Forward port 8081 on localhost and IP address 10.19.21.23, to port 5000 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8081: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 criter...
Execute the command 'go run hello.go' inside the first container of the pod 'analytics-pod' and retrieve the output.
Command: ```bash kubectl exec analytics-pod -- go run hello.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...
Execute the 'nginx' command inside the 'email-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec email-service-pod -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Create a new config map named 'app-secrets' with the specified keys and file paths
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/parameters/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 ...
create a service for a replicated nginx, serving on port 5001 and connecting to the containers on port 300100
Command: ```bash kubectl expose rc nginx --port=5001 --target-port=300100 ``` 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 new config map named ui-config using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/data/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 config m...
Scale the deployment named bar to have 5 replicas if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/bar ``` 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...
Set resource limits for the specified container in a deployment
Command: ```bash kubectl set resources deployment go -c=nginx --limits=cpu=100m,memory=2Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its ...
Get the snapshot logs from all containers in pods labeled with "zone=us-east-1"
Command: ```bash kubectl logs -l zone=us-east-1 --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": "--contain...
Begin streaming the logs of the specified container in the specified pod
Command: ```bash kubectl logs -f -c code-explorer auth-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Set up autoscaling for the 'vpn' deployment with a minimum of 5 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment vpn --min=5 --max=13 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Forward traffic between local port 8080 and pod port 6379 in the backend-pod.
Command: ```bash kubectl port-forward pod/backend-pod 8080 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 automa...
Execute the command "dotnet --list-sdks" in the pod named "proxy-server-pod" using the container named "lunar-launcher"
Command: ```bash kubectl exec proxy-server-pod -c lunar-launcher -- dotnet --list-sdks ``` 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....
Create a new ClusterIP service named 'monitoring-service-clusterip' with the TCP port mapping from port 7000 to port 8010.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=7000:8010 ``` 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": "...
Set the service account of the deployment "proxy-service-deployment" to "dashboard"
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment dashboard ``` 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: `ku...
Set the resource request and limits for all containers in the 'centos' deployment to CPU limit of 200m and memory limit of 512Mi, and CPU request of 500m and memory request of 4Gi.
Command: ```bash kubectl set resources deployment centos --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource request...
Create a cluster role named "view" with the verb "connect" and the resource "configmaps", including the resource names "cdn-proxy" and "notification-service"
Command: ```bash kubectl create clusterrole view --verb=connect --resource=configmaps --resource-name=cdn-proxy --resource-name=notification-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|...
Delete pods and services with names "proxy" and "log-aggregator"
Command: ```bash kubectl delete pod,service proxy log-aggregator ``` 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 sele...
Run the "go run hello.go" command in the time-machine container of the frontend-pod pod and get the output.
Command: ```bash kubectl exec frontend-pod -c time-machine -- go run hello.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 omitt...
Create a new secret named "cert-manager-secret" and populate it with keys for each file in the "path/to/preferences" folder.
Command: ```bash kubectl create secret generic cert-manager-secret --from-file=path/to/preferences ``` 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...
List resources of type ReplicaSet called "web", Service called "payment-gateway-rc", and Pod called "api-service-pod"
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/api-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is na...
Create a deployment named "gitlab" with the image "golang" and run the command "go"
Command: ```bash kubectl create deployment gitlab --image=golang -- go ``` 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|ya...
Forward port 8000 on localhost and IP address 10.19.21.23 to port 8080 in the e-commerce-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-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 crit...
Create a job named "report-generation-job" using the nginx image and run the command "nginx -t".
Command: ```bash kubectl create job report-generation-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 fo...
Update the web-app-deployment deployment by adding a new environment variable REDIS_HOST with the value redis-server.
Command: ```bash kubectl set env deployment/web-app-deployment REDIS_HOST=redis-server ``` 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...
Create a service for the 'centos' deployment, which serves on port 3001 and connects to the containers on port 330600.
Command: ```bash kubectl expose deployment centos --port=3001 --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...
Create a new secret named cert-manager-secret with key1=supersecret and key2=topsecret
Command: ```bash kubectl create secret generic cert-manager-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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...
import the API_KEY key from the global-config config map and set it as an environment variable for the email-server-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/global-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Begin streaming the logs of the specified container in a specific pod.
Command: ```bash kubectl logs -f -c cosmic-container frontend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Update the 'backend-microservice-deployment' deployment with the new environment variable DB_HOST=localhost
Command: ```bash kubectl set env deployment/backend-microservice-deployment DB_HOST=localhost ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod ...
Update the annotation 'description' of pod 'proxy-server' to 'Web server for marketing site'
Command: ```bash kubectl annotate pods proxy-server description='Web server for marketing site' ``` 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 ...
Create a service for a replication controller with the given specifications.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=9092 --target-port=808400 ``` 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...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/namespace-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 varia...
Create a new ExternalName service named external-email-service
Command: ```bash kubectl create service externalname external-email-service --external-name tutorial-ai.ai ``` 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 service...
Create a service for the 'php' deployment, serving on port 80 and connecting to the containers on port 8000
Command: ```bash kubectl expose deployment php --port=8088 --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 ...
Create an ingress named 'api-ingress' with a rule that directs requests to 'website.com/module' to service 'svc1' on port 8010
Command: ```bash kubectl create ingress api-ingress --rule="website.com/module=svc1:8010,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...
Output the modified deployment in YAML format without making changes to the deployment on the server.
Command: ```bash kubectl set env deployment/analytics-platform-deployment SMTP_HOST=smtp.example.com -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 o...
Create a deployment named jenkins using the hazelcast image
Command: ```bash kubectl create deployment jenkins --image=hazelcast/hazelcast ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Set the resource request and limits for all containers in a deployment named "golang" for cpu and memory
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 request...
View the last-applied-configuration annotations for the 'redis' deployment in YAML format.
Command: ```bash kubectl apply view-last-applied deployment/redis ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-applied ...
Create a job named "backup" using the "jenkins" image, and run the command "jenkins-plugin-cli" in the job.
Command: ```bash kubectl create job backup --image=jenkins -- jenkins-plugin-cli ``` 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...
List the deployments in the specified API group and version, and display the output in YAML format.
Command: ```bash kubectl get deployments.v3.0.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 will...
Create a new secret named gcp-service-account-secret with keys for each file in folder bar.
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-file=path/to/profiles ``` 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 b...
Create a new config map named 'env-vars' using the files '/path/to/properties/file1.txt' and '/path/to/parameters/file2.txt' for the keys 'settings' and 'key2' respectively.
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Forward local ports 3000 and 6000 to ports 3000 and 6000 in a pod selected by the database deployment
Command: ```bash kubectl port-forward deployment/database-deployment 3000 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Create a service for the hazelcast replica set, exposing port 8888 and connecting to the containers on port 637900
Command: ```bash kubectl expose rs hazelcast --port=8888 --target-port=637900 ``` 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 an ingress resource named 'app1-ingress' with a rule that directs requests for 'website.com/input' to the service 'svc1' on port 7000, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/input=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": "", "usage...
Add or update a taint on a specific node with a key, value, and effect
Command: ```bash kubectl taint nodes web-node-8 workload=high-priority: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 for...
Set the CPU limit of the hazelcast container in the deployment to "100m" and the memory limit to "256Mi"
Command: ```bash kubectl set resources deployment hazelcast -c=nginx --limits=cpu=100m,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 u...
Import the log_level key from the app-settings ConfigMap into the email-server-deployment Deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-settings deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Forward local port 8080 to port 5000 in the pod named 'api-service-pod'
Command: ```bash kubectl port-forward pod/api-service-pod 8080: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 be selected au...
Set the custom TLS server name to "testing-cluster" for the "kube-cluster-1" cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --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] [--certif...
Rename the context 'cluster-2-context' to 'service-account-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context cluster-2-context service-account-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this fi...
Create an ExternalName service named external-logging-service
Command: ```bash kubectl create service externalname external-logging-service --external-name sample-domain.net ``` 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 se...
Create a new ClusterIP service named billing-service-clusterip with the TCP port 8083 mapped to port 9092.
Command: ```bash kubectl create service clusterip billing-service-clusterip --tcp=8083:9092 ``` 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"...
Create a new config map named app-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Add a 'special' taint to the node with label instance=app-instance-1, specifically the db-node-7 node, and prefer no scheduling on it.
Command: ```bash kubectl taint node -l instance=app-instance-1 special=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": "", "us...
Run the 'geth attach' command in the nano-bot container of the security-service-pod and retrieve the output
Command: ```bash kubectl exec security-service-pod -c nano-bot -- 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 omitt...
Update the label of the pod 'log-aggregator' to have the label 'tier' with the value 'database'
Command: ```bash kubectl label pods log-aggregator tier=database ``` 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", "u...
Forward local port 5000 to port 5000 of a pod selected by the 'web-app-deployment' deployment
Command: ```bash kubectl port-forward deployment/web-app-deployment 5000 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 be s...
Copy the '/var/run/secrets/kubernetes.io/serviceaccount/' file from the local machine to the '/tmp/bar_dir' directory in the 'logging-agent-pod-7' pod in the 'metallb-system' namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ metallb-system/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": "", "us...
Set the service account of the 'monitoring-stack-deployment' deployment to 'tiller'
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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: `ku...
Create a new service account named elasticsearch
Command: ```bash kubectl create serviceaccount elasticsearch ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name...
Create a debug copy of the analytics-pod, adding a container with "debian" image and changing the image of the existing "web" container to "nginx:latest"
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-web --image=debian --set-image=web=nginx: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 and...
Start a ruby pod with custom overrides from JSON
Command: ```bash kubectl run nginx --image=ruby --overrides='{ "apiVersion": "v1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND]...
Set the service account of the deployment "log-aggregator-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment log-aggregator-deployment fluentd ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kub...
Create a new config map named 'db-config' using the key=value pairs specified in the file located at 'path/to/configs'.
Command: ```bash kubectl create configmap db-config --from-file=path/to/configs ``` 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 ...
update the LOG_LEVEL environment variable in the api-server-deployment deployment to the value stored in the app-secrets config map for the specified keys.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-secrets 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 i...
Set the service account of the order-processing-deployment deployment to "jenkins".
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment jenkins ``` 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: `k...
Return the snapshot logs from the container 'mypod-1' of the 'frontend-deployment-1' deployment
Command: ```bash kubectl logs deployment/frontend-deployment -c mypod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--conta...
Update the 'frontend' pod with the annotation 'alert-email' and set the value to 'alerts@example.com'.
Command: ```bash kubectl annotate pods frontend alert-email=alerts@example.com ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and includ...
Copy the local file /tmp/foo_dir to the remote pod message-broker-pod-15 in the container named worker-container, and place it at the location /etc/kubernetes.
Command: ```bash kubectl cp /tmp/foo_dir message-broker-pod-15:/etc/kubernetes -c worker-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. I...
Delete pods and services with the names "proxy" and "database"
Command: ```bash kubectl delete pod,service proxy 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. ...
Execute the command "redis-server" in the "astro-container" of the "auth-service-pod" pod and get the output.
Command: ```bash kubectl exec auth-service-pod -c astro-container -- redis-server ``` 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...
Create a deployment named proxy using the redis image and expose port 5000
Command: ```bash kubectl create deployment proxy --image=redis --port=5000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Create a new ExternalName service named external-monitoring-service and map it to the external hostname "sandbox-site.co"
Command: ```bash kubectl create service externalname external-monitoring-service --external-name sandbox-site.co ``` 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 s...
Execute the command "ls -t /usr" in the first container of the backend-pod and display the contents of the /usr directory sorted by modification time.
Command: ```bash kubectl exec backend-pod -i -t -- ls -t /usr ``` 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 kube...
Forward local ports 6379 and 6000 to the corresponding ports in a selected pod from the specified deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 6379 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 ...