prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a service for a replicated ruby, which serves on port 8080 and connects to the containers on port 330600
Command: ```bash kubectl expose rc ruby --port=8080 --target-port=330600 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Start a node pod named 'nginx' with the 'node' image.
Command: ```bash kubectl run nginx --image=node ``` 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":...
Set the cluster field of a context to a specific cluster name
Command: ```bash kubectl config set contexts.local-context.cluster web-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 wan...
Get output from running the 'mysqld' command in the 'nano-bot' container of the 'cdn-service-pod' pod.
Command: ```bash kubectl exec cdn-service-pod -c nano-bot -- mysqld ``` 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 th...
Begin streaming the logs of the 'ruby' container in the 'cdn-service-pod' pod
Command: ```bash kubectl logs -f -c ruby cdn-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":...
Port forward from local port 8000 to port 5432 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Get the output from running the 'kafka-console-producer --broker-list localhost:9092 --topic test' command in the rocket-ranger container of the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c rocket-ranger -- kafka-console-producer --broker-list localhost:9092 --topic test ``` 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...
Forward local port 8081 to port 5000 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-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 criteria, a pod will be selected autom...
Execute the command 'geth attach' in the 'rocket-ranger' container of the 'e-commerce-pod' pod and retrieve the output.
Command: ```bash kubectl exec e-commerce-pod -c rocket-ranger -- 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...
Create a service for the replicated ubuntu pods using the replica set, with the service serving on port 8181 and connecting to the containers on port 543200
Command: ```bash kubectl expose rs ubuntu --port=8181 --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 specified port....
Create a job with a specific command to be executed
Command: ```bash kubectl create job scaling-job --image=ethereum/client-go -- geth attach ``` 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...
Attach to a pod and enter interactive mode to access the container's terminal
Command: ```bash kubectl attach proxy-server-pod -c mycontainer -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 om...
Output the modified configuration of a deployment in YAML format without making any changes to the actual deployment on the server.
Command: ```bash kubectl set env deployment/user-management-deployment JWT_SECRET=your-jwt-secret -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 ...
Create a new ExternalName service named external-logging-service with the external name example-domain.com.
Command: ```bash kubectl create service externalname external-logging-service --external-name example-domain.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference s...
Add a taint with key 'app' on nodes having label app-type=microservice, and the taint value as backup-node-14:PreferNoSchedule
Command: ```bash kubectl taint node -l app-type=microservice app=backup-node-14:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Retrieve the logs for the container api-service-pod-1 in the deployment monitoring-stack-deployment
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c api-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...
Provide a detailed description of the node "monitoring-node-16.monitoring-center.net"
Command: ```bash kubectl describe nodes monitoring-node-16.monitoring-center.net ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all ob...
Update the 'proxy' pod by adding a label with the key 'tier' and the value 'frontend'
Command: ```bash kubectl label pods proxy tier=frontend ``` 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": "I...
Forward port 5432 of the pod "security-service-pod" to port 5432 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5432:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 8000 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Import the keys 'redis_host' from the config map 'ui-config' and set them as environment variables for the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --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 one or m...
Add a taint with key 'environment' and value 'monitoring-node-15:PreferNoSchedule' on nodes having the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp environment=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default":...
Delete pods and services named "api" and "chat-app"
Command: ```bash kubectl delete pod,service api chat-app ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. So...
Expose the replicated alpine pods on port 8081 and connect to the containers in the pods on port 909200.
Command: ```bash kubectl expose rc alpine --port=8081 --target-port=909200 ``` 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....
Set the service account of deployment "log-aggregator-deployment" to "tekton".
Command: ```bash kubectl set serviceaccount deployment log-aggregator-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: `kube...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/api-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 definitions ...
Create a new ClusterIP service named notification-service-clusterip, mapping port 8081 of the service to port 9000 of the pods
Command: ```bash kubectl create service clusterip notification-service-clusterip --tcp=8081:9000 ``` 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 a cluster role named "default_role" with the verb "create" and a non-resource URL path of "/api-docs/*".
Command: ```bash kubectl create clusterrole "default_role" --verb=create --non-resource-url=/api-docs/* ``` 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": "--outp...
Add a taint with key 'dedicated' and value 'dev-node-4:PreferNoSchedule' on nodes having the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend dedicated=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": "...
Run the 'irb' command in the first container of the analytics-platform-deployment deployment.
Command: ```bash kubectl exec deploy/analytics-platform-deployment -- irb ``` 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, ...
Add a taint to the nodes that have the label "team=devops" with the key "special" and the value "PreferNoSchedule".
Command: ```bash kubectl taint node -l team=devops 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": "", "usage": "Outpu...
Display the most recent 53 lines of logs for the pod named proxy-service-pod
Command: ```bash kubectl logs --tail=53 proxy-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"...
Set the cluster field in the context to dev-cluster
Command: ```bash kubectl config set contexts.dev-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 want ...
Forward traffic between local ports 6379 and a pod selected by the deployment "api-server-deployment" on ports 6379
Command: ```bash kubectl port-forward deployment/api-server-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 pod will b...
Set the CPU limits of the nginx container in the mysql deployment to "50m" and the memory limits to "4Gi"
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=50m,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 requested, but may burst up to it...
Update a specific node by providing a JSON file containing the node's information and a patch flag with the required changes.
Command: ```bash kubectl patch -f node-specific.yaml -p '{"spec":{"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]` ...
Change the cluster field in the 'team-beta-context' context to 'cluster-gamma'
Command: ```bash kubectl config set contexts.team-beta-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 y...
Forward traffic from port 5432 on localhost and IP 10.19.21.23 to port 8888 in the pod named "api-service-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 5432: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 cri...
Import the 'log_level' key from the 'app-settings' config map into the 'payment-processor-deployment' deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-settings deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
View the difference between the current configuration and the one provided in the settings.json file.
Command: ```bash cat settings.json | kubectl diff -f - ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own di...
Add the certificate authority data for the 'cluster-alpha' cluster entry by running the command 'kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/star-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 se...
Update the pod named 'proxy' with the annotation 'custom-label' and set it to 'my-custom-value'.
Command: ```bash kubectl annotate pods proxy custom-label=my-custom-value ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arb...
Run the 'ash' command in the first container of the 'payment-processor-deployment' deployment.
Command: ```bash kubectl exec deploy/payment-processor-deployment -- ash ``` 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, u...
Return the previous terminated logs of the 'astro-container' container from the 'backend-pod' pod
Command: ```bash kubectl logs -p -c astro-container backend-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", "...
Create a cron job named "log-rotation" using the Ubuntu image, with a schedule of running every minute
Command: ```bash kubectl create cronjob log-rotation --image=ubuntu --schedule="*/1 * * * *" -- docker run -it ubuntu ``` 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", "sh...
Set the cluster field in the 'my-context' context to 'app-cluster'.
Command: ```bash kubectl config set contexts.edge-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...
Mark the node "testing-node-11" as unschedulable
Command: ```bash kubectl cordon testing-node-11 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Scale the deployment named "foo" to have 7 replicas, assuming the current size is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=7 deployment/foo ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Update the deployment named 'analytics-platform-deployment' by setting the environment variable JWT_SECRET to 'your-jwt-secret'.
Command: ```bash kubectl set env deployment/analytics-platform-deployment JWT_SECRET=your-jwt-secret ``` 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 mo...
Forward local port 8080 to port 6379 in the pod named 'cdn-service-pod'
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Create a new config map named app-settings from specified files
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/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...
Create a new config map named env-vars with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/profiles/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 map ...
Create an ingress named 'www-ingress' that routes requests to site.com/input to service 'svc1' on port 6379, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress www-ingress --rule="site.com/input=svc1:6379,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": "...
Update the image version of a pod to v4
Command: ```bash kubectl get pod e-commerce-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by ...
Create a pod disruption budget named "api-service-pdb" that will select all pods with the "app=rails" label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=app=rails --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 [--d...
Embed the certificate authority data for the "kube-cluster-1" cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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...
import the EXTERNAL_API_URL key from the config map named env-vars to the deployment named mydeployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/env-vars 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 one...
Get the output from running the 'redis-server --version' command in the stardust-shuttle container within the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c stardust-shuttle -- redis-server --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container n...
Get the output from the time-machine container in the proxy-service-pod pod
Command: ```bash kubectl attach proxy-service-pod -c time-machine ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Set the custom TLS server name to "e2e" for the kube-cluster-1 cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=e2e ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-author...
Enable a new exec auth plugin for the "api-user" entry by running the command: kubectl config set-credentials api-user --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1
Command: ```bash kubectl config set-credentials api-user --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --...
expose the hazelcast deployment as a service on port 80 and connect to the containers on port 8000
Command: ```bash kubectl expose deployment hazelcast --port=8000 --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 spec...
Set the custom TLS server name "staging-cluster" to use for validation for the "star-cluster" cluster entry
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=staging-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...
Set the custom TLS server name for the my-k8s-cluster cluster entry.
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=cluster-alpha ``` 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...
Create a role named "admin_role" with SubResource specified
Command: ```bash kubectl create role admin_role --verb=list,create,update --resource=secrets,secrets/status ``` 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]` Helpful flag...
Apply a taint to nodes with label region=eu-west-2 with key 'zone' and value 'app-node-6'
Command: ```bash kubectl taint node -l region=eu-west-2 zone=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": "Ou...
Update the image version of the proxy-service-pod container to v4
Command: ```bash kubectl get pod proxy-service-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained ...
create a cron job named 'cleanup-task' that runs the 'wp' command every minute using the 'wordpress' image
Command: ```bash kubectl create cronjob cleanup-task --image=wordpress --schedule="*/1 * * * *" -- wp ``` 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", "def...
Copy the local file "/tmp/foo" to the remote pod "metrics-exporter-pod-10" in the container "auth-service", with the destination path "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo metrics-exporter-pod-10::/tmp/bar -c auth-service ``` 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, u...
Attach to the nano-bot container in the media-stream-pod to get its output
Command: ```bash kubectl attach media-stream-pod -c nano-bot ``` 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, us...
Create a new config map named 'log-config' using the files '/path/to/configurations/file1.txt' and '/path/to/parameters/file2.txt'
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/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...
Auto scale the "monitoring" deployment, allowing the number of pods to scale between 5 and 12 based on demand.
Command: ```bash kubectl autoscale deployment monitoring --min=5 --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 u...
Create a new secret named aws-credentials-secret from the properties.env file located at path/to/properties.env
Command: ```bash kubectl create secret generic aws-credentials-secret --from-env-file=path/to/properties.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...
Create an ingress called 'rontend-ingress' that directs requests to a specific path with a specific service and TLS secret.
Command: ```bash kubectl create ingress rontend-ingress --rule="site.com/example=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a pod named 'hazelcast' with the image 'docker.elastic.co/elasticsearch/elasticsearch'
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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] [--ove...
Create a job named 'monitoring-job' using the 'ubuntu' image and run the command 'docker run -it ubuntu' inside the job.
Command: ```bash kubectl create job monitoring-job --image=ubuntu -- docker run -it ubuntu ``` 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": "Ou...
Forward local ports 5000 and 6000 to a pod selected by the deployment 'email-server-deployment', so data can be sent and received between the local ports and the pod ports.
Command: ```bash kubectl port-forward deployment/email-server-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...
Partially update a node by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node monitoring-node-15 -p '{"spec":{"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]`...
Partially update a node's configuration with a strategic merge patch in YAML format.
Command: ```bash kubectl patch node node-2 -p $'stringData:\n password: new-password' ``` 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]` Help...
create a job named batch-processing with the Ubuntu image and run the command "docker run -it ubuntu"
Command: ```bash kubectl create job batch-processing --image=ubuntu -- docker run -it ubuntu ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create an ingress resource named 'api-gateway-ingress' that will direct requests from 'website.com/input' to 'svc1:3001' using the TLS certificate named 'my-cert'
Command: ```bash kubectl create ingress api-gateway-ingress --rule="website.com/input=svc1:3001,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": "",...
Set the service account of the deployment "monitoring-stack-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-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: `k...
Apply a taint on nodes with the label 'service=auth' with the key 'cpu-type' and value 'worker-node-3' to prefer no scheduling on them.
Command: ```bash kubectl taint node -l service=auth cpu-type=worker-node-3: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": ...
Partially update the 'app-node-6' node by specifying the patch in JSON format. Set the number of replicas to 3.
Command: ```bash kubectl patch node app-node-6 -p '{"spec":{"replicas":3}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags: ...
Read the most recent 43 lines of logs for the pod named web-app-pod.
Command: ```bash kubectl logs --tail=43 web-app-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": "-c"...
Update the 'postgres' deployment by setting its 'postgres:13.4' container image to 'postgres' and its 'busybox' container image to 'busybox'.
Command: ```bash kubectl set image deployment/postgres busybox=busybox postgres=postgres:13.4 ``` 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), rep...
Set the last-applied-configuration of a resource to match the contents of options.yaml file
Command: ```bash kubectl apply set-last-applied -f options.yaml ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without updating any other parts of ...
Add a taint with key 'environment' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice environment=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
list the replication controller named "web", the service named "web-app-rc", and the pods named "web-app-pod"
Command: ```bash kubectl get rc/web service/web-app-rc pods/web-app-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 namespaced you...
Import the 'my-example-key' key from the 'monitoring-config' config map and set it as an environment variable in the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/monitoring-config deployment/analytics-platform-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 var...
Add the annotation 'backup-strategy' with the value 'daily backups' to the 'web' pod.
Command: ```bash kubectl annotate pods web backup-strategy='daily backups' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ar...
Create a new ExternalName service named external-email-service pointing to the external address blog-test.blog.
Command: ```bash kubectl create service externalname external-email-service --external-name blog-test.blog ``` 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...
Forward port 3000 on your local machine to port 8081 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 3000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a service for the replicated nginx using replica set, which will serve on port 8081 and connect to the containers on port 9092.
Command: ```bash kubectl expose rs nginx --port=8081 --target-port=909200 ``` 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. ...
Forward traffic from local port 8088 to pod port 8080 on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-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...
Create a pod disruption budget named statefulset-pdb that selects pods with the label version=v2 and requires at least 9 of these pods to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=version=v2 --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 [--...
Update the pod 'foo' with the annotation 'contact-email' and the value 'support@example.com', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods foo contact-email='support@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 label...
Forcefully drain the node "web-node-8" even if there are non-managed pods on it
Command: ```bash kubectl drain web-node-8 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise, i...
Import the DATABASE_URL key from the config map "app-settings" and set it as an environment variable in the "payment-processor-deployment" deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-settings deployment/payment-processor-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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/api-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...