prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Add a taint with key 'dedicated' on nodes having the label customer=acme-corp with the value 'dev-node-4:PreferNoSchedule'
Command: ```bash kubectl taint node -l customer=acme-corp 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": "", "usag...
Edit the 'log-analysis-job' job using the v1 API format and save the changes in JSON format.
Command: ```bash kubectl edit job.v1.batch/log-analysis-job -o json ``` 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,...
Set a custom TLS server name for the cluster entry named "data-cluster"
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=data-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] [--certificate...
create a secret from an environment file
Command: ```bash kubectl create secret generic email-credentials-secret --from-env-file=path/to/data.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the...
Update the deployment 'mydeployment' by adding a new environment variable named SECRET_KEY with the value "your-secret-key".
Command: ```bash kubectl set env deployment/mydeployment SECRET_KEY=your-secret-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 pod templates ...
Create a new role named "custom_role" with the specified SubResource parameters
Command: ```bash kubectl create role custom_role --verb=use,delete,connect --resource=customresources,customresources/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|non...
Import the specific keys MAX_CONNECTIONS from the config map env-vars to the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/env-vars 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 i...
Import the specific keys "config_file_path" from the config map "api-config" into the deployment "notification-handler-deployment"
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/api-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...
Forward local port 8888 to port 3000 in the pod called api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 8888: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 au...
Create an ingress with multiple hosts and the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:8084" \ --rule="bar.com/admin*=svc2:http" ``` 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",...
Add a taint with the key 'zone' and value 'prod-node-5:PreferNoSchedule' on all nodes that have the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz zone=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": "", "usage":...
Listen on port 5000 locally, forwarding data to/from port 5000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 5000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Embed certificate authority data for the testing-cluster cluster entry
Command: ```bash kubectl config set-cluster testing-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 confi...
delete the pods and services named "database" and "api"
Command: ```bash kubectl delete pod,service database api ``` 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...
Create a debug copy of a pod by adding a debug container and changing container images
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-app --image=debian --set-image=scheduler=my-scheduler:1.0,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects ide...
Create a job named "report-generation-job" with the image "postgres" and the command "psql"
Command: ```bash kubectl create job report-generation-job --image=postgres -- psql ``` 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 for...
Create a new config map with specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=conf=/path/to/parameters/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...
Listen on the local ports 9090 and 6000, and forward data to/from ports 9090 and 6000 in a pod selected by the 'authentication-service-deployment' deployment
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 9090 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, ...
Execute the 'jenkins-plugin-cli' command in code-explorer from the security-service-pod and retrieve the output.
Command: ```bash kubectl exec security-service-pod -c code-explorer -- jenkins-plugin-cli ``` 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 na...
Create a pod named "hazelcast" using the image "docker.elastic.co/elasticsearch/elasticsearch" and expose port 7000.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=7000 ``` 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] ...
List the deployments in the "v2.1.0" version of the "third-party-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.v2.1.0.third-party-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 yo...
Forward traffic from port 8088 on your local machine to port 5432 in the pod named cdn-service-pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8088: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 au...
Return a snapshot of the previous terminated logs from the "astro-container" container in the "database-pod" pod
Command: ```bash kubectl logs -p -c astro-container database-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 priority class named internal-priority with a value of 6 and a description of "Priority for internal services and tasks"
Command: ```bash kubectl create priorityclass internal-priority --value=6 --description="Priority for internal services and tasks" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--...
Start forwarding traffic from local port 8081 to pod port 8080 of the cdn-service-pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081 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 au...
Create a job named "testing" using the Alpine image and run the command "ash"
Command: ```bash kubectl create job testing --image=alpine -- ash ``` 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: json...
Get the output from running the 'ash' command in the first container of the 'proxy-service-pod' pod
Command: ```bash kubectl exec proxy-service-pod -- 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, use the kubectl.kub...
Forward local port 9090 to port 8888 in a pod selected by the deployment "web-app-deployment"
Command: ```bash kubectl port-forward deployment/web-app-deployment 9090 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 s...
Add the taint with key 'hardware' on all nodes that have the label 'component=proxy', specifically the node 'edge-node-10', with the effect of 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l component=proxy hardware=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"...
Create a deployment named "db" running the centos image and expose port 8084.
Command: ```bash kubectl create deployment db --image=centos --port=8084 ``` 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|...
List the desired resources by their type and names.
Command: ```bash kubectl get rc/web service/frontend-rc pods/database-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 y...
Create a cron job named 'metrics-collection' with the image 'ethereum/client-go'
Command: ```bash kubectl create cronjob metrics-collection --image=ethereum/client-go --schedule="*/1 * * * *" -- geth ``` 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", "s...
delete both pods and services named "gateway" and "frontend"
Command: ```bash kubectl delete pod,service gateway 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 selector...
Update the image of all containers in the daemonset 'app-v2' to 'postgres:13.4'
Command: ```bash kubectl set image daemonset app-v2 *=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), replicaset (rs) Syntax: `kub...
Forward local port 5432 to port 9090 inside the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod 5432: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 select...
Forward traffic from port 8081 on all addresses to port 5432 in the cdn-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8081: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 w...
Add a taint with the key 'datacenter' on nodes that have the label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 datacenter=kube-master-9: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...
Create a new deployment named "monitoring" with the image "docker.elastic.co/elasticsearch/elasticsearch" and expose port 8080.
Command: ```bash kubectl create deployment monitoring --image=docker.elastic.co/elasticsearch/elasticsearch --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", "defau...
Embed the certificate authority data for the specified cluster entry.
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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...
Set up auto scaling for the replication controller "chat-app" with a target CPU utilization of 90%
Command: ```bash kubectl autoscale rc chat-app --max=7 --cpu-percent=90 ``` 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...
Forward port 5432 on all addresses to port 8088 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 5432: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 wil...
Import the 'debug_mode' key from the 'global-config' config map and set it as an environment variable for the 'cache-cluster-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/global-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Update the pod 'foo' by adding the annotation 'last-deployment' with the value '2023-03-15'.
Command: ```bash kubectl annotate pods foo last-deployment=2023-03-15 ``` 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 arbitra...
Create a role named "admin_role" with SubResource specified
Command: ```bash kubectl create role admin_role --verb=use,delete,connect --resource=persistentvolumes,persistentvolumes/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|...
Forward traffic from local port 5000 to the target port of the "https" service port in a pod selected by the "monitoring-service" service
Command: ```bash kubectl port-forward service/monitoring-service 5000: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 sel...
Add a taint with key 'dedicated' on nodes having label release=beta
Command: ```bash kubectl taint node -l release=beta dedicated=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": "Ou...
Attach to the 'warp-drive' container inside the 'media-stream-pod' pod and switch to raw terminal mode
Command: ```bash kubectl attach media-stream-pod -c warp-drive -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 omi...
Create a copy of the "web-app-pod" with an added "debug" container and update the container images.
Command: ```bash kubectl debug web-app-pod -it --copy-to=dgb-img --image=debian --set-image=cache=redis:alpine,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and nam...
display the logs from the 'nginx' backend kubelet without verifying the serving certificate
Command: ```bash kubectl logs --insecure-skip-tls-verify-backend nginx ``` 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": "--contai...
Update the cluster field in the my-context context to cluster-gamma
Command: ```bash kubectl config set contexts.local-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 w...
Import the specific keys 'max_connections' from the 'app-settings' configmap and set them as environment variables for the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-settings deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a pod with the postgres image and set labels "app=postgres" and "env=prod" in the container
Command: ```bash kubectl run hazelcast --image=postgres --labels="app=postgres,env=prod" ``` 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...]` Help...
List the deployments of the "feature-branch-2.3.0" version in the "testing-apps" API group in JSON format.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.testing-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 nam...
forward port 5000 on all addresses to port 8081 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5000: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 ...
Forward traffic from port 8080 on all addresses to port 8080 on the backend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8080: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 ...
Begin streaming the logs of the "cosmic-container" container in the "cdn-service-pod" pod.
Command: ```bash kubectl logs -f -c cosmic-container 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": "--containe...
Create a hazelcast pod with a customized spec using a JSON file
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "custom-version", "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] [...
Run the 'go' command inside the first pod of the service backend-service and retrieve the output
Command: ```bash kubectl exec svc/backend-service -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Check if the current user has permission to list the job named "load-testing-job" in the "kube-node-lease" namespace
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n kube-node-lease ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Stream the logs in real-time from all containers in pods that have the label feature=feature-xyz.
Command: ```bash kubectl logs -f -l feature=feature-xyz --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "-...
Return the snapshot logs from container mypod-1 of the cache-cluster-deployment deployment.
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c mypod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--...
Create a single ingress called 'app-loadbalancer-ingress' that directs requests to foo.com/input to svc1:6379 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.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": ""...
Forward traffic from port 5000 on all addresses to port 5000 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 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...
Attach to the auth-service-pod container named stardust-shuttle and get its output.
Command: ```bash kubectl attach auth-service-pod -c stardust-shuttle ``` 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 omi...
Switch to raw terminal mode and attach to the 'cosmic-container' inside the 'frontend-pod' pod.
Command: ```bash kubectl attach frontend-pod -c cosmic-container -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...
Add a taint with key 'environment' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 environment=storage-node-13: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 debug image of the analytics-pod, specifically the quantum-quark container, and launch an interactive shell within the debug image
Command: ```bash kubectl debug analytics-pod -it --copy-to=dgb-img --container=quantum-quark -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default i...
Drain node "k8s-node-1" forcefully, even if there are unmanaged pods on it
Command: ```bash kubectl drain k8s-node-1 --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...
Create a deployment named "jenkins" using the "redis" image and expose port 5001
Command: ```bash kubectl create deployment jenkins --image=redis --port=5001 ``` 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: j...
Begin streaming the logs of the "warp-drive" container in the "log-aggregator-pod" pod
Command: ```bash kubectl logs -f -c warp-drive log-aggregator-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 label of a specific pod. Set the label 'component' with the value 'api' for the pod named 'gateway'.
Command: ```bash kubectl label pods gateway component=api ``` 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 cluster role named "admin_role" with the ability to execute, access, and manage resources named "configmaps", "content-delivery", and "nginx-proxy"
Command: ```bash kubectl create clusterrole admin_role --verb=exec --resource=configmaps --resource-name=content-delivery --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...
Get the output from running the 'redis-server' command in the 'mycontainer' container from the 'proxy-service-pod' pod.
Command: ```bash kubectl exec proxy-service-pod -c mycontainer -- redis-server ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Run the 'mongo' command in the 'nano-bot' container of the 'cdn-service-pod' pod and get the output.
Command: ```bash kubectl exec cdn-service-pod -c nano-bot -- mongo ``` 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...
Retrieve the snapshot logs from the container "media-stream-pod-1" of the "load-balancer-deployment" deployment.
Command: ```bash kubectl logs deployment/load-balancer-deployment -c media-stream-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: ...
Update the image of all containers in the daemonset named 'nginx' to 'debian:11.0'
Command: ```bash kubectl set image daemonset nginx *=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: `kubect...
Add a taint to node 'k8s-node-1' with key 'hardware', value 'gpu', and effect 'NoExecute'
Command: ```bash kubectl taint nodes k8s-node-1 hardware=gpu:NoExecute ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of...
Create a new pod named "hazelcast" using the WordPress image and have the container in the pod expose port 8181.
Command: ```bash kubectl run hazelcast --image=wordpress --port=8181 ``` 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": "...
Remove all taints with the key 'hardware' from the 'node-2' node
Command: ```bash kubectl taint nodes node-2 hardware- ``` 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|...
Forward traffic from port 9090 on your localhost and IP address 10.19.21.23 to port 8000 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
Add a taint with key 'special' on nodes having the label team=devops
Command: ```bash kubectl taint node -l team=devops special=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": "", "usage...
Check if you have permission to list the job named "content-import-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/content-import-job -n kube-ingress ``` 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...
Start the 'nginx' pod using the 'docker.elastic.co/elasticsearch/elasticsearch' image, but override the spec with a partial set of values parsed from the provided JSON file.
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "v1.0.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] [--overri...
Import the 'DATABASE_URL' key from the 'app-name-config' config map into the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-name-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 variabl...
Create an ingress named 'public-api-ingress' that routes requests to 'website.com/bar' to 'svc1:27017' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/bar=svc1:27017,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 streaming the logs of the 'warp-drive' container in the 'api-service-pod' pod.
Command: ```bash kubectl logs -f -c warp-drive api-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", "s...
Copy the local file '/tmp/foo_dir' to the '/etc/kubernetes' path inside the 'admin-dashboard-pod-16' pod in the 'monitoring' namespace.
Command: ```bash kubectl cp /tmp/foo_dir monitoring/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...
Start a MySQL pod with port 8010 exposed
Command: ```bash kubectl run hazelcast --image=mysql --port=8010 ``` 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": "--fi...
List the replication controllers named 'web', the service named 'database-rc', and the pods named 'monitoring-pod'
Command: ```bash kubectl get rc/web service/database-rc pods/monitoring-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...
List the details of a specific pod in YAML format.
Command: ```bash kubectl get -o yaml pod payment-gateway-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 will only ...
Set an environment variable for a deployment
Command: ```bash kubectl set env deployment/user-management-deployment SECRET_KEY=your-secret-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 service for the ruby deployment, serving on port 9092 and connecting to the containers on port 818100.
Command: ```bash kubectl expose deployment ruby --port=9092 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified...
Create a deployment with a specific name and image
Command: ```bash kubectl create deployment my-dep --image=jenkins ``` 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|yaml|na...
Configure autoscaling for a replication controller called "security" with a target CPU utilization of 90% and with the number of pods ranging from 1 to 6.
Command: ```bash kubectl autoscale rc security --max=6 --cpu-percent=90 ``` 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...
Run a proxy on port 5001 serving static content from "./local/www/"
Command: ```bash kubectl proxy --port=5001 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Listen on a random port locally and forward traffic to port 8000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod :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 automatica...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/env-vars 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 definit...
Add a taint to nodes with label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace hardware=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": "", "u...
Start a pod named "nginx" with the image "confluentinc/cp-kafka", but override the pod's spec with a partial set of values parsed from the provided JSON object
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "v1.1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--comm...
Create a debug copy of a pod by adding a debug container and changing container images.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified...