prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the image of all containers in the daemonset named "test" to "debian:11.0"
Command: ```bash kubectl set image daemonset test *=debian:11.0 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubectl...
Forward port 8080 on your local machine to port 3000 in the analytics-pod
Command: ```bash kubectl port-forward pod/analytics-pod 8080: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 auto...
Set CPU and memory limits for a container in a deployment
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=500m,memory=128Mi ``` 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 t...
Add a taint with key 'app' on nodes having label app=web-app
Command: ```bash kubectl taint node -l app=web-app app=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": "Output fo...
Execute the 'nginx' command inside the 'monitoring-pod' pod and display the output.
Command: ```bash kubectl exec monitoring-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.kube...
Create a service for the 'alpine' deployment, which serves on port 9091 and connects to the containers on port 543200
Command: ```bash kubectl expose deployment alpine --port=9091 --target-port=543200 ``` 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 deployment named "proxy" with the image "python" and the command "python"
Command: ```bash kubectl create deployment proxy --image=python -- python ``` 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...
Partially update a node by making it unschedulable. Use a strategic merge patch specified as YAML.
Command: ```bash kubectl patch node k8s-node-1 -p $'spec:\n unschedulable: true' ``` 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 f...
Delete the pods and services with the names "api" and "foo"
Command: ```bash kubectl delete pod,service api foo ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some re...
List deployments using the JSON output format, specifically requesting the "v3.0.0" version of the "api-v1" API group.
Command: ```bash kubectl get deployments.v3.0.0.api-v1 -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 onl...
Open the service named 'order-service' in an editor for editing
Command: ```bash kubectl edit svc/order-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 variables, or fall back to 'vi...
Copy the contents of the local file '/var/run/secrets/kubernetes.io/serviceaccount/' to the remote pod 'logging/payment-gateway-pod-19' in the '/tmp/bar_dir' directory
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ logging/payment-gateway-pod-19:/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"...
Create an ingress named 'app2-ingress' that routes requests from testing.com/example to svc1:8000 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/example=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": "", "usa...
Create a job named 'data-migration-job' using the 'mongo' container image, and run the 'mongo' command inside the job.
Command: ```bash kubectl create job data-migration-job --image=mongo -- mongo ``` 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 new pod named 'hazelcast' with the php image and expose port 8888.
Command: ```bash kubectl run hazelcast --image=php --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 flags: "flag": "--file...
Autoscale the deployment "payment" with a minimum of 3 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment payment --min=3 --max=9 ``` 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 ...
Set a custom TLS server name for the cloud-cluster cluster entry.
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=cluster-gamma ``` 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...
Retrieve the output of the 'dotnet' command running in the 'nano-bot' container of the 'proxy-server-pod' pod.
Command: ```bash kubectl exec proxy-server-pod -c nano-bot -- dotnet ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Check if you have permission to list the job named "notification-sender-job" in the "production" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-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 par...
Update the pod named 'auth' with the annotation 'release-notes' and the value 'https://example.com/release-notes/v2.5.1', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods auth release-notes='https://example.com/release-notes/v2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that ca...
Return the snapshot logs from container 'cdn-service-pod-1' of the 'frontend-deployment' deployment.
Command: ```bash kubectl logs deployment/frontend-deployment -c cdn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag"...
Embed the certificate authority data for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/app-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster N...
Create a pod disruption budget named "replica-set-pdb" that selects all pods with the "region=us-east" label and ensures that at least 9 of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=region=us-east --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...
Get output from running the 'bash' command in lunar-launcher from the pod payment-gateway-pod.
Command: ```bash kubectl exec payment-gateway-pod -c lunar-launcher -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Create a cluster role named "default_role" that allows the user to perform "list", "create", and "connect" operations on configmaps.
Command: ```bash kubectl create clusterrole default_role --verb=list,create,connect --resource=configmaps ``` 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": "--ou...
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="website.com/path/subpath*=othersvc:8084" ``` 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": "-...
Update the image of the 'java' container to 'java:11.0.12' in all deployments and replication controllers.
Command: ```bash kubectl set image deployments,rc java=java:11.0.12 --all ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax...
Update the image for all containers in the 'staging' daemonset to 'openjdk:16.0.2'
Command: ```bash kubectl set image daemonset staging *=openjdk:16.0.2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `k...
Create a new ClusterIP service named monitoring-service-clusterip that will route traffic from port 5000 to port 8000.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=5000:8000 ``` 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": "...
Forward requests from port 8080 on localhost and IP address 10.19.21.23 to port 8000 in the proxy-server-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8080: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 cr...
Create a deployment named 'wordpress' using the 'ethereum/client-go' image and expose port 8888.
Command: ```bash kubectl create deployment wordpress --image=ethereum/client-go --port=8888 ``` 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 fo...
Create a service for the replication controller specified in the "php-controller.yaml" file
Command: ```bash kubectl expose -f php-controller.yaml --port=9000 --target-port=808100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the sp...
Display the resource usage metrics for all pods with the label 'owner=john-doe'
Command: ```bash kubectl top pod -l owner=john-doe ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAME | ...
Display the deployments in the "external-apps" API group, version "v2.1.0", in JSON format.
Command: ```bash kubectl get deployments.v2.1.0.external-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 w...
Partially update a node using a strategic merge patch with JSON.
Command: ```bash kubectl patch node testing-node-11 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 ...
Forward traffic from local port 9090 to the targetPort of the "https" port of a pod selected by the "scheduler-service" service
Command: ```bash kubectl port-forward service/scheduler-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 sele...
Attach to the lunar-launcher container in the e-commerce-pod and get its output.
Command: ```bash kubectl attach e-commerce-pod -c lunar-launcher ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Get the output of the 'ruby --version' command from the 'time-machine' container running in the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c time-machine -- 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 omitted...
Create a pod disruption budget named worker-pdb that will select all pods with the role=worker label and require a minimum of four of them to be 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-...
Use an alternative editor (notepad) to edit the web-service service.
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/web-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 variables,...
Add a taint with key 'environment' on nodes with the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 environment=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": "", "usag...
If the current number of replicas for the deployment named 'web' is 5, scale the 'mysql' deployment down to 1 replica.
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 deployment/web ``` 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 job named "testing" with the image "redis" and the command "redis-cli"
Command: ```bash kubectl create job testing --image=redis -- redis-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 format. One of:...
Remove all taints with the key 'app' from node 'web-node-8'
Command: ```bash kubectl taint nodes web-node-8 app- ``` 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: json|yaml|name|g...
Expose a service for a replication controller using a YAML file, specify the port mappings.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8181 --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 s...
Create a deployment named sonarqube using the confluentinc/cp-kafka image with 7 replicas.
Command: ```bash kubectl create deployment sonarqube --image=confluentinc/cp-kafka --replicas=7 ``` 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": "Outpu...
Continuously stream the logs of the `astro-container` container in the `gateway-pod` pod.
Command: ```bash kubectl logs -f -c astro-container gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Update the image of the 'kubernetes-serve-hostname' container in the 'backend-pod' pod to the specified 'new image'
Command: ```bash kubectl patch pod backend-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' ``` 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...
Auto scale the replication controller "security" with a minimum of 1 pod, a maximum of 2 pods, and a target CPU utilization of 81%.
Command: ```bash kubectl autoscale rc security --max=2 --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...
List deployments from the "backup-apps" API group, in the "v1.0.0" version, and output the result in JSON format.
Command: ```bash kubectl get deployments.v1.0.0.backup-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 wil...
Create a deployment named proxy using the golang image and exposing port 8000.
Command: ```bash kubectl create deployment proxy --image=golang --port=8000 ``` 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: js...
Execute the command 'elasticsearch-plugin --list' in the 'lunar-launcher' container of the 'auth-service-pod' pod and print the output.
Command: ```bash kubectl exec auth-service-pod -c lunar-launcher -- elasticsearch-plugin --list ``` 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": "Contai...
Create a deployment named my-dep using the wordpress image with 4 replicas.
Command: ```bash kubectl create deployment my-dep --image=wordpress --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 o...
Display only the most recent 12 lines of output in the vpn-service-pod pod
Command: ```bash kubectl logs --tail=12 vpn-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", "short": ...
Auto scale the "log-aggregator" deployment with a minimum of 7 and maximum of 13 pods, using the default autoscaling policy.
Command: ```bash kubectl autoscale deployment log-aggregator --min=7 --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 th...
Execute the 'nginx' command in the 'time-machine' container of the 'api-service-pod' pod and display the output.
Command: ```bash kubectl exec api-service-pod -c time-machine -- 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...
Forward local ports 8088 to 8080 in the pod "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...
Check if the current user has permission to list the "batch-processing-job" job in the "testing" namespace
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n testing ``` 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 U...
Delete pods and services named "database" and "frontend"
Command: ```bash kubectl delete pod,service database frontend ``` 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 selecto...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/ui-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Copy the local file `/tmp/foo` to the remote pod named `metrics-exporter-pod-10` in the `logging` namespace, and place it at the path `/tmp/bar`.
Command: ```bash kubectl cp /tmp/foo logging/metrics-exporter-pod-10::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Forward traffic from port 8000 on all addresses to port 3000 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-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 criteria, a pod will...
Start a php pod named 'hazelcast' with the image 'php' and expose port 27017.
Command: ```bash kubectl run hazelcast --image=php --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": "--fil...
Create a new role called "custom_role" with specific API Group permissions.
Command: ```bash kubectl create role custom_role --verb=proxy,get,update --resource=clusterroles.rbac.authorization.k8s.io ``` 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=server|client|none]...
Set the custom TLS server name to "prod-cluster" for the "on-prem-cluster" cluster entry.
Command: ```bash kubectl config set-cluster on-prem-cluster --tls-server-name=prod-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] [--certific...
Copy the local file '/tmp/foo_dir' to the remote pod 'monitoring-agent-pod-6' in the '/tmp/bar_dir' location within the 'load-balancer' container.
Command: ```bash kubectl cp /tmp/foo_dir monitoring-agent-pod-6:/tmp/bar_dir -c load-balancer ``` 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 omi...
Add a taint to nodes with the label 'team=devops' to indicate a preference for no scheduling of pods with the key 'cpu-type'.
Command: ```bash kubectl taint node -l team=devops cpu-type=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": "Outp...
Import environment from a secret for a deployment
Command: ```bash kubectl set env --from=secret/api-secret-key deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod...
Create a ClusterIP service named messaging-service-clusterip that maps port 8081 on the service to port 8181 on the target
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=8081:8181 ``` 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": "-...
Create an ingress named 'api-v2-ingress' that routes requests to the path 'website.com/example' to the service 'svc1:8082' with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.com/example=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": "", "u...
Create a single ingress called 'app2-ingress' that directs requests to testing.com/module to the service 'svc1' on port 8088, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="testing.com/module=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": "", "usag...
Delete the pods and services named "auth" and "database"
Command: ```bash kubectl delete pod,service auth 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. S...
Forward traffic from port 8088 on all addresses to port 3000 in the 'mypod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8088: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 sel...
set the environment variable MAX_CONNECTIONS to 100 for all containers in all replication controllers in the project
Command: ```bash kubectl set env rc --all MAX_CONNECTIONS=100 ``` 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 (within replication co...
Create a new config map named log-config in the default namespace
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/options/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 creating a ...
Set specific environment variables for a deployment
Command: ```bash env | grep RAILS_ | kubectl set env -e - 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 definitions in one or more p...
Retrieve the deployments in the YAML output format from the "hotfix-1.1.2" version of the "alpha-apps" API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.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 yo...
Assign the label 'env=staging' to the pod named 'cdn'.
Command: ```bash kubectl label pods cdn env=staging ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If tr...
Expose a replica set named "hazelcast" as a service, serving on port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose rs hazelcast --port=80 --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 specified port...
create a cron job called "metrics-collection" that uses the "golang" image, runs every minute, and executes the command "go"
Command: ```bash kubectl create cronjob metrics-collection --image=golang --schedule="*/1 * * * *" -- go ``` 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", "...
Add taint 'datacenter' with value 'testing-node-11:PreferNoSchedule' on nodes labeled with 'app=web-app'
Command: ```bash kubectl taint node -l app=web-app datacenter=testing-node-11: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...
Forward local port 9090 to port 8088 in the pod
Command: ```bash kubectl port-forward pod/proxy-server-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 be selected a...
Copy the ~/.config/kube_dir directory from the local machine to the /tmp/bar_dir_dir directory in the file-server-pod-14 pod in the default namespace.
Command: ```bash kubectl cp ~/.config/kube_dir file-server-pod-14:/tmp/bar_dir_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Create a NodePort service named "backend-nodeport" that maps port 8083 on the cluster nodes to port 3000 on the backend service.
Command: ```bash kubectl create service nodeport backend-nodeport --tcp=8083:3000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Get the output from running the 'elasticsearch --version' command in the container 'lunar-launcher' of the pod 'gateway-pod'
Command: ```bash kubectl exec gateway-pod -c lunar-launcher -- elasticsearch --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....
Set up an autoscaling policy for the "chat-app" deployment with a minimum of 2 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment chat-app --min=2 --max=11 ``` 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...
Import environment variables from a secret for a deployment
Command: ```bash kubectl set env --from=secret/encryption-key-secret deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more...
Create a new secret named "private-key-secret" using the files in the "path/to/properties" folder.
Command: ```bash kubectl create secret generic private-key-secret --from-file=path/to/properties ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basenam...
Add a taint with key 'hardware' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 hardware=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
List deployments in YAML output format, specifically in the "v3.0.0" version of the "api-v2" API group.
Command: ```bash kubectl get deployments.v3.0.0.api-v2 -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 onl...
Create a job using the specified image and command
Command: ```bash kubectl create job image-build-job --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": "Out...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config deployment/notification-handler-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...
Create a new ClusterIP service named analytics-service-clusterip
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=9090:5432 ``` 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": "-...
Copy the local file '~/.config/kube' to '/etc/kubernetes' inside the 'admin-dashboard-pod-16' pod in the 'kube-dns' namespace.
Command: ```bash kubectl cp ~/.config/kube kube-dns/admin-dashboard-pod-16:/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 omitte...
Auto scale the "proxy" replication controller with the maximum number of pods set to 3 and target CPU utilization set to 81%.
Command: ```bash kubectl autoscale rc proxy --max=3 --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 uses t...
Create a job named 'database-seeding-job' using the 'alpine' image, and execute the 'sleep 3600' command in the job.
Command: ```bash kubectl create job database-seeding-job --image=alpine -- sleep 3600 ``` 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 ...
Retrieve the output from running the 'geth attach' command in the 'nano-bot' container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-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 omitted, use t...
Start the ruby pod with custom command and arguments.
Command: ```bash kubectl run nginx --image=ruby --command -- <cmd> <arg1> ... <argN> ``` 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 ...
Set the context to use the cloud-cluster cluster
Command: ```bash kubectl config use-context cloud-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Create a pod disruption budget named notification-service-pdb that will select all pods with the role=worker label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=role=worker --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-avail...