prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import specific keys from a config map
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-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 variable de...
create a cluster role named "view" with SubResource specified for nodes and nodes/stats
Command: ```bash kubectl create clusterrole view --verb=proxy,get,update --resource=nodes,nodes/stats ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output...
Create a new config map named app-config-dev by specifying keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a con...
Create an ingress resource called 'app-gateway-ingress' that routes requests from testing.com/example to svc1:8443 using a TLS secret named "my-cert".
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.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": "...
Start a pod named "hazelcast" using the mongo image and expose port 27017
Command: ```bash kubectl run hazelcast --image=mongo --port=27017 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Add a taint with key 'environment' and value 'dev-node-4' on nodes having label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe environment=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"...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp cert-manager/admin-dashboard-pod-16:/tmp/foo /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Set the cluster field in the prod-context context to app-cluster.
Command: ```bash kubectl config set contexts.prod-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 value you want...
Forward local ports to a pod from a deployment
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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 wil...
List the pod specified in the "pod.yaml" file in JSON format.
Command: ```bash kubectl get -f pod.yaml -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results ...
Create a pod disruption budget named worker-pdb that will select pods with the project=my-project label and require at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget worker-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-available=N ...
Create a service named "frontend" for the analytics-pod pod, which will serve on port 8888.
Command: ```bash kubectl expose pod analytics-pod --port=8888 --name=frontend ``` 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...
List deployments in YAML output format from the "rc-1.1.0" version of the "beta-apps" API group.
Command: ```bash kubectl get deployments.rc-1.1.0.beta-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 wil...
Add a taint with the key 'zone' and value 'web-node-8:PreferNoSchedule' to all nodes labeled with 'app-type=microservice'.
Command: ```bash kubectl taint node -l app-type=microservice zone=web-node-8: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"...
Edit the last-applied-configuration annotations in the YAML for the deployment named 'node'
Command: ```bash kubectl apply edit-last-applied deployment/node ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor...
Delete the pods and services named "backend" and "database"
Command: ```bash kubectl delete pod,service backend 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...
Copy the "/var/run/secrets/kubernetes.io/serviceaccount/" file to the "/tmp/bar" directory in the "logging-agent-pod-7" pod within the specified namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cert-manager/logging-agent-pod-7::/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 cluster role named "foo" with the ability to delete pods and specific resource names.
Command: ```bash kubectl create clusterrole foo --verb=delete --resource=pods --resource-name=file-uploader --resource-name=nginx-proxy ``` 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]`...
Import specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/env-vars 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 definit...
Set the service account of the deployment named "cache-cluster-deployment" to "tekton".
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment tekton ``` 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: `kubec...
Forward port 5432 locally to port 8000 in the pod
Command: ```bash kubectl port-forward pod/analytics-pod 5432: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 auto...
Create a new config map named app-config-dev using the properties files located in the specified folder
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/properties ``` 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 base...
Embed the certificate authority data for the 'cloud-cluster' cluster entry by running the command: kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-1/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster cloud-cluster --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 ...
Copy the .config/kube file from the task-processor-pod-17 pod located on the kube-server to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp kube-server/task-processor-pod-17:~/.config/kube /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, us...
Copy the local file /tmp/foo_dir to the remote pod message-broker-pod-15 at the location /tmp/bar_dir in the specific container monitoring-agent.
Command: ```bash kubectl cp /tmp/foo_dir message-broker-pod-15:/tmp/bar_dir -c monitoring-agent ``` 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 o...
Create a pod disruption budget named cron-jobs-pdb that will select all pods with the tier=frontend label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=tier=frontend --min-available=1 ``` 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 [-...
Return the snapshot logs from the container "chat-app-pod-1" of the "email-server-deployment" deployment
Command: ```bash kubectl logs deployment/email-server-deployment -c chat-app-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: "flag...
List the replication controller named 'web', the service named 'proxy-service-rc', and the pod named 'log-aggregator-pod'
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/log-aggregator-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 n...
Create a deployment named "monitoring" using the "ubuntu" image and expose port 8443.
Command: ```bash kubectl create deployment monitoring --image=ubuntu --port=8443 ``` 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...
Listen on all addresses for incoming requests on port 9090 and forward them to port 8088 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 9090:8088 ``` 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...
Add a taint with key 'datacenter' and value 'prod-node-5:PreferNoSchedule' on nodes having label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha datacenter=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": "", ...
Create a new generic secret named payment-gateway-secret using the options.env file located at path/to/.
Command: ```bash kubectl create secret generic payment-gateway-secret --from-env-file=path/to/options.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 th...
Retrieve the output of running the command 'nginx -g "daemon off;"' in the 'cyber-sleuth' container of the 'proxy-server-pod' pod.
Command: ```bash kubectl exec proxy-server-pod -c cyber-sleuth -- nginx -g "daemon off;" ``` 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 nam...
Create a new pod running Python
Command: ```bash kubectl run nginx --image=python ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--filename", "short...
Update the cluster role binding "admin" by adding the service account "gitlab-runner" from the "namespace" namespace as a subject.
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:gitlab-runner ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=...
Get output from running 'elasticsearch' command from the first pod of the deployment 'payment-processor-deployment'.
Command: ```bash kubectl exec deploy/payment-processor-deployment -- elasticsearch ``` 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 ...
Create a new pod named "nginx" using the "node" image, but customize the specifications by providing a partial set of values in JSON format.
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "v2.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]...
Import the log_level key from the log-config config map and set it in the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/log-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 definitions...
Forward local port 8888 to port 8888 in the chat-app-pod, allowing data to be sent and received on both ports
Command: ```bash kubectl port-forward pod/chat-app-pod 8888 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Set the cluster field in the specific context to a specific cluster name
Command: ```bash kubectl config set contexts.user-b-context.cluster cluster-gamma ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Forward data between port 8888 on the local machine and port 9090 in the "mypod" pod
Command: ```bash kubectl port-forward pod/mypod 8888 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Add a taint to a node with a specific key and no value
Command: ```bash kubectl taint nodes worker-node-3 cpu-type: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...
Scale the deployment named app-v2-replicaset to 3 replicas if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=3 deployment/app-v2-replicaset ``` 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-v...
Update the pod 'backend' with the label 'tier' and the value 'database'
Command: ```bash kubectl label pods backend 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", "usage": ...
Create a service for the replicated nginx, which serves on port 3001 and connects to the containers on port 844300.
Command: ```bash kubectl expose rs nginx --port=3001 --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 specified port. ...
Copy the local file "/tmp/foo" to the "/etc/kubernetes" directory of the remote pod "metrics-exporter-pod-10" in the "metallb-system" namespace.
Command: ```bash kubectl cp :/tmp/foo metallb-system/metrics-exporter-pod-10:/etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Update the 'gateway-deployment' by adding a new environment variable called GOOGLE_API_KEY with your own Google API key.
Command: ```bash kubectl set env deployment/gateway-deployment GOOGLE_API_KEY=your-google-api-key ``` 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 ...
Create a new config map named 'kube-system-config' with the given keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/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 creatin...
create a deployment with an nginx image and run the nginx command
Command: ```bash kubectl create deployment app --image=nginx -- nginx -g "daemon off;" ``` 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....
List the deployments in the "stable-2.0.0" version of the "web-apps" API group in JSON output format
Command: ```bash kubectl get deployments.stable-2.0.0.web-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you ...
Create a cron job named cron-task using the mysql image that runs the command "mysql --version" every minute
Command: ```bash kubectl create cronjob cron-task --image=mysql --schedule="*/1 * * * *" -- mysql --version ``` 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"...
Execute the 'docker run -it ubuntu' command inside the 'monitoring-pod' pod and retrieve the output.
Command: ```bash kubectl exec monitoring-pod -- docker run -it ubuntu ``` 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 ...
Add a taint with the key 'app' on the nodes that have the label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz app=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Update the label of the pod 'backend' to have the key 'component' and the value 'worker'
Command: ```bash kubectl label pods backend component=worker ``` 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...
List the name and image of the first container in the gateway-pod and display the information in custom columns
Command: ```bash kubectl get pod gateway-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image ``` 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 --sel...
Create a new ExternalName service named external-ldap-service
Command: ```bash kubectl create service externalname external-ldap-service --external-name education-edu.edu ``` 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 servi...
Create a job named 'testing', using the 'mongo' image, and running the 'mongod' command.
Command: ```bash kubectl create job testing --image=mongo -- mongod ``` 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 of: js...
Copy the file "foo" from the remote pod "database-pod-2" to the local directory "/tmp/bar" in the specific container "database-container".
Command: ```bash kubectl cp :/tmp/foo database-pod-2::/tmp/bar -c database-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 omitted, use...
Copy the file kube from the local machine to the /tmp/bar directory in the remote pod named monitoring-agent-pod-6, which is in the ingress-nginx namespace.
Command: ```bash kubectl cp ~/.config/kube ingress-nginx/monitoring-agent-pod-6:/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,...
Create a new ClusterIP service named 'cache-service-clusterip' that forwards traffic from port 9092 to port 7000
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=9092:7000 ``` 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 db-config using parameters from a folder.
Command: ```bash kubectl create configmap db-config --from-file=path/to/parameters ``` 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 ...
Undo the previous deployment of the namespace-1 deployment.
Command: ```bash kubectl rollout undo deployment/namespace-1 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource t...
Create a pod disruption budget named 'monitoring-pdb' that will select all pods with the 'owner=team-1' label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-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-available=N [-...
Create a job named 'scaling-job' using the 'ubuntu' image and run the command 'docker run ubuntu echo "Hello"'
Command: ```bash kubectl create job scaling-job --image=ubuntu -- docker run ubuntu echo "Hello ``` 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"...
Update the image of all containers in the 'namespace-1' daemonset to 'centos:8.4.2105'
Command: ```bash kubectl set image daemonset namespace-1 *=centos:8.4.2105 ``` 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) Synta...
Set the custom TLS server name to use for validation for the "my-k8s-cluster" cluster entry
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=moon-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] [--certifica...
Create a pod disruption budget named 'critical-services-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 critical-services-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-availabl...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/monitoring-config 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 de...
Switch to raw terminal mode and attach to the 'lunar-launcher' container in the 'e-commerce-pod' pod.
Command: ```bash kubectl attach e-commerce-pod -c lunar-launcher -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Set up an autoscaling policy for the 'web' deployment with a minimum of 6 pods and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment web --min=6 --max=12 ``` 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...
Execute the 'geth attach' command in stardust-shuttle container of gateway-pod and get the output.
Command: ```bash kubectl exec gateway-pod -c stardust-shuttle -- 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 omitte...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-secrets 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 defi...
List the web replication controllers, the email-service service, and the vpn-service pod.
Command: ```bash kubectl get rc/web service/email-service-rc pods/vpn-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 name...
Auto scale the "vpn" deployment, allowing the number of pods to scale between 4 and 12
Command: ```bash kubectl autoscale deployment vpn --min=4 --max=12 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Create an ingress called "public-ingress" that directs requests from "foo.com/bar" to service "svc1:8088", and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress public-ingress --rule="foo.com/bar=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Scale the backend-service-replicaset deployment's replicas to 1, considering that its current replicas are already 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/backend-service-replicaset ``` 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 --r...
Create a pod disruption budget named web-app-pdb that selects all pods with the env=production label and ensures that at least 9 of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=env=production --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--...
import the 'secret_key' from the 'app-secrets' config map into the deployment named 'monitoring-stack-deployment'
Command: ```bash kubectl set env --keys=secret_key --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 defini...
Wait for the pod named "vpn-service-pod" to be in the "Ready" state
Command: ```bash kubectl wait --for=condition=Ready pod/vpn-service-pod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command ca...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-dev deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create a new config map named db-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Set the custom TLS server name to "cloud-cluster" for the "on-prem-cluster" cluster entry.
Command: ```bash kubectl config set-cluster on-prem-cluster --tls-server-name=cloud-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] [--certifi...
Set the cluster field in the specific context to the desired cluster
Command: ```bash kubectl config set contexts.team-beta-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Forward port 3000 on all addresses to port 6379 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 3000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Create a deployment named mattermost using the mongo image and expose port 8080.
Command: ```bash kubectl create deployment mattermost --image=mongo --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...
Create a new config map named 'db-config' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/preferences/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 the replication controller specified in the "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8000 --target-port=808200 ``` 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...
Create a new config map named 'db-config' using the specified keys and file paths
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/profiles/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 ...
Start a pod named 'hazelcast' using the 'confluentinc/cp-kafka' container image, and expose port 8888 on the container
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=8888 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flag...
Expose the deployment named "alpine" on port 9090, connecting to the container port 8000.
Command: ```bash kubectl expose deployment alpine --port=9090 --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 specifi...
Forward local port 9090 to port 8000 in the pod
Command: ```bash kubectl port-forward pod/security-service-pod 9090:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Import the "log_level" key from the "global-config" ConfigMap into the environment variables of the "email-server-deployment" deployment.
Command: ```bash kubectl set env --keys=log_level --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 definitio...
Create a service for the replication controller specified in the "hazelcast-controller.yaml" file, which serves on port 5432 and connects to the containers on port 808000.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=5432 --target-port=808000 ``` 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 ...
Auto scale the replication controller "database" with a target CPU utilization of 81%, ensuring that the number of pods is between 1 and 6.
Command: ```bash kubectl autoscale rc database --max=6 --cpu-percent=81 ``` 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 use...
Create a pod disruption budget named critical-services-pdb that selects all pods with the role=worker label, and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=role=worker --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-availabl...
Create a copy of the email-service-pod with a debug container by adding a debug image container and changing the image of the existing containers.
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-api --image=debian --set-image=web=nginx:latest,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Check if you have permission to list the job named "notification-sender-job" in the "logging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n logging ``` 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 partia...
Forward port 6379 on all addresses to port 6379 in the pod named web-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 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 pod will ...
Create a service for the hazelcast deployment, which serves on port 9091 and connects to the containers on port 909000.
Command: ```bash kubectl expose deployment hazelcast --port=9091 --target-port=909000 ``` 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 spec...
Auto scale the "gateway" replication controller with a minimum of 1 pod, a maximum of 7 pods, and target CPU utilization of 20%
Command: ```bash kubectl autoscale rc gateway --max=7 --cpu-percent=20 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...