prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a single ingress called 'app-proxy-ingress' that directs requests to site.com/input to svc1:3001
Command: ```bash kubectl create ingress app-proxy-ingress --rule="site.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": "", "usa...
Update the label of pod 'database' with the key 'app' and the value 'myapp'
Command: ```bash kubectl label pods database app=myapp ``` 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...
Check if you have permission to list the job named "backup-job" in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/backup-job -n default ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL that st...
Copy the local file /tmp/foo to the remote pod 'worker-pod-4' in the 'default' namespace, at the path /etc/kubernetes.
Command: ```bash kubectl cp /tmp/foo default/worker-pod-4:/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 omitted, use the kubect...
Set environment variables for a deployment using a config map with a prefix
Command: ```bash kubectl set env --from=configmap/app-secrets --prefix=MYSQL_ deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Import the SMTP_SERVER key from the app-name-config ConfigMap into the environment variables of the database-deployment deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-name-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Create a job called "database-seeding-job" using the image "redis" and running the command "redis-cli"
Command: ```bash kubectl create job database-seeding-job --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 fo...
Set resource requests and limits for all containers in the kafka deployment
Command: ```bash kubectl set resources deployment kafka --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested...
Check if your current user has permission to list the "log-analysis-job" job in the "production" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/log-analysis-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 partial UR...
Set the cluster field in a context to a specific cluster
Command: ```bash kubectl config set contexts.local-context.cluster data-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 wa...
Scale a resource to a specific number of replicas using a configuration file
Command: ```bash kubectl scale --replicas=7 -f options.yaml ``` 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 specified, it is validat...
Create a copy of the 'monitoring-pod' and change all container images to 'ruby'. Name the copy 'debug-image-api'.
Command: ```bash kubectl debug monitoring-pod --copy-to=debug-image-api --set-image=*=ruby ``` 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 if no res...
Add a taint with the key 'special' on nodes that have the label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack special=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"...
Copy the local file "/tmp/foo" to the "/etc/kubernetes" directory of the remote pod "logging/cache-pod-5" in the current namespace.
Command: ```bash kubectl cp /tmp/foo logging/cache-pod-5:/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 omitted, use the kubectl...
Set the custom TLS server name to 'web-cluster' for the 'cluster-alpha' cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --tls-server-name=web-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...
Apply a taint with the key 'datacenter' on nodes that have the label 'myLabel' and assign the value 'prod-node-5:PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel datacenter=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
create a deployment named prometheus using the golang image and expose port 8181
Command: ```bash kubectl create deployment prometheus --image=golang --port=8181 ``` 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...
Import the log_level key from the monitoring-config config map into the web-app-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Forward local port 8888 to port 9090 in the pod selected by the authentication-service-deployment deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8888 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, ...
Create a service for the alpine deployment, exposing port 5432 and forwarding traffic to the containers on target port 900000.
Command: ```bash kubectl expose deployment alpine --port=5432 --target-port=900000 ``` 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...
Retrieve the previous logs of the "cyber-sleuth" container from the "database-pod" pod
Command: ```bash kubectl logs -p -c cyber-sleuth 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", "sh...
Create an ingress named 'www-ingress' that directs requests for testing.com/bar to svc1:8084 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="testing.com/bar=svc1:8084,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": ...
Check if the current user has permission to list the job named "queue-processing-job" in the "kube-public" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n kube-public ``` 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...
Forward local port 9090 to port 6379 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 9090:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a single ingress called 'external-ingress' that directs requests to 'testing.com/bar' to service 'svc1:8010' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress external-ingress --rule="testing.com/bar=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a new config map named db-config with the specified keys by referencing files on the disk: properties=/path/to/options/file1.txt and key1=/path/to/profiles/file2.txt.
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Rename the context 'staging-context' to 'team-beta-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context staging-context team-beta-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will...
Resume the paused deployment named 'namespace-3'
Command: ```bash kubectl rollout resume deployment/namespace-3 ``` What it does: Resume a paused resource. Paused resources will not be reconciled by a controller. By resuming a resource, we allow it to be reconciled again. Currently only deployments support being resumed. Syntax: `kubectl rollout resume RESOURCE` H...
Scale the replica set named 'payment-service-rs' to 3 replicas
Command: ```bash kubectl scale --replicas=3 rs/payment-service-rs ``` 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 specified, it is v...
Rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context old-name team-beta-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also b...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to the /etc/kubernetes directory in the admin-dashboard-pod-16 pod using the auth-service container.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ admin-dashboard-pod-16:/etc/kubernetes -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": ...
List all deployments in the "beta-1.0" version of the "sandbox-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.beta-1.0.sandbox-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you ...
Execute the 'bash' command inside the code-explorer container of the database-pod pod
Command: ```bash kubectl exec database-pod -c code-explorer -- 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, use th...
Create a ClusterIP service with the name "cache-service-clusterip"
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=5000:9091 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
Get the output from running the 'ruby --version' command in the code-explorer container of the monitoring-pod.
Command: ```bash kubectl exec monitoring-pod -c code-explorer -- 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 omi...
Set the user field on the 'service-account-context' context entry to 'cluster-admin' without modifying any other values.
Command: ```bash kubectl config set-context service-account-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluste...
Add or update the "contact-email" annotation for the pod specified in "preferences.json" to "support@example.com"
Command: ```bash kubectl annotate -f preferences.json 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 labels a...
Create an ingress called 'api-gateway-ingress' that directs requests from website.com/input to svc1:8010 with TLS certificate "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="website.com/input=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Display the details of the 'web' replication controller, 'e-commerce-rc' service, and 'backend-pod' pod
Command: ```bash kubectl get rc/web service/e-commerce-rc pods/backend-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 ...
Forward traffic from local port 3000 to port 5000 in the cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Edit the `payment-service` service using the "code" editor.
Command: ```bash KUBE_EDITOR="code" kubectl edit svc/payment-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...
Copy the file /tmp/foo from the pod backend-pod-13 of the openfaas deployment to the /etc/kubernetes directory on your local machine
Command: ```bash kubectl cp openfaas/backend-pod-13:/tmp/foo /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 omitted, use the kub...
Enable the OpenID Connect auth provider for the "deploy-bot" entry by setting the auth-provider to oidc and providing the client-id and client-secret arguments
Command: ```bash kubectl config set-credentials deploy-bot --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: --...
Open a raw terminal session for the nebula-navigator container in the auth-service-pod pod and interact with the bash shell.
Command: ```bash kubectl exec auth-service-pod -c nebula-navigator -i -t -- bash -il ``` 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. I...
Create a new config map named ui-config using specified files as key-value pairs
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Get output from running 'ash' command in the first pod of the 'gateway-service' service.
Command: ```bash kubectl exec svc/gateway-service -- 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.k...
Forward traffic from local port 8000 to port 6379 in a pod selected by the monitoring-stack-deployment deployment
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 8000 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 ...
Update the 'password' field of the 'app-node-6' node by partially merging the provided JSON patch
Command: ```bash kubectl patch node app-node-6 -p '{"stringData":{"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...
Enable port forwarding from port 8088 on both localhost and the IP address 10.19.21.23 to port 8888 in the pod named 'proxy-server-pod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8088: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 cr...
Attach to a specific container inside a pod in interactive mode
Command: ```bash kubectl attach security-service-pod -c rocket-ranger -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....
Update the annotation for a pod specified in a config file
Command: ```bash kubectl annotate -f config.json git-repo='https://github.com/example/my-app' ``` 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 la...
Retrieve the output of running the 'elasticsearch-plugin --list' command in the stardust-shuttle container of the api-service-pod pod.
Command: ```bash kubectl exec api-service-pod -c stardust-shuttle -- 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": "Conta...
Set the service account of the database-deployment deployment to tekton
Command: ```bash kubectl set serviceaccount deployment database-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: `kubectl se...
Update the compliance level annotation for the pod defined in the settings.json file to "PCI-DSS"
Command: ```bash kubectl annotate -f settings.json compliance-level=PCI-DSS ``` 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 a...
Remove the label named 'bar' from the 'api' pod
Command: ```bash kubectl label pods api release- ``` 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 true,...
View the revision history of a daemonset and display details for revision 1
Command: ```bash kubectl rollout history daemonset/namespace-1 --revision=1 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Attach to a specific pod, and switch to raw terminal mode to interact with the "nano-bot" container
Command: ```bash kubectl attach database-pod -c nano-bot -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 omitted, ...
Update the 'analytics' pod's annotation 'security-scan-status' to 'pass', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods analytics security-scan-status='pass' ``` 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 ...
Embed the certificate authority data for the cloud-cluster cluster entry using the command "kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cloud-cluster --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...
Delete the pods and services with the names "frontend" and "chat-app"
Command: ```bash kubectl delete pod,service frontend 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 selecto...
Return the snapshot logs from all containers in pods that have the label "cluster=my-cluster"
Command: ```bash kubectl logs -l cluster=my-cluster --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": "--con...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/namespace-config 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 vari...
Create a deployment named "ingress" using the "alpine" image and expose port 3000.
Command: ```bash kubectl create deployment ingress --image=alpine --port=3000 ``` 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: ...
Taint node 'k8s-node-1' with a key 'workload', value 'high-priority', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes k8s-node-1 workload=high-priority:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Update the pod identified by type and name in "docker-registry.yaml" and set the description to 'Web server for marketing site'
Command: ```bash kubectl annotate -f docker-registry.yaml description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger...
Import the MAX_CONNECTIONS key from the app-name-config config map into the database-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-name-config deployment/database-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...
Set the service account of a deployment to default
Command: ```bash kubectl set serviceaccount deployment mydeployment default ``` 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: `kubectl set serv...
Auto scale the deployment named "database" with a minimum of 2 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment database --min=2 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a cluster role named "default_role" with ResourceName specified
Command: ```bash kubectl create clusterrole default_role --verb=list --resource=services --resource-name=report-generator --resource-name=file-processing ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=se...
Expose the centos deployment as a service, with the service listening on port 5432 and forwarding traffic to the containers on port 808800.
Command: ```bash kubectl expose deployment centos --port=5432 --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 specifi...
Apply a taint to nodes that have a specific label
Command: ```bash kubectl taint node -l component=proxy app=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": "Outp...
Set the custom TLS server name to "prod-cluster" for the cluster entry "prod-cluster" in the kubectl configuration.
Command: ```bash kubectl config set-cluster prod-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] [--certificate...
Auto scale the 'auth' replication controller with the number of pods ranging from 1 to 5, targeting a CPU utilization of 50%.
Command: ```bash kubectl autoscale rc auth --max=5 --cpu-percent=50 ``` 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 th...
Create a copy of the backend pod with all container images changed to busybox for debugging purposes.
Command: ```bash kubectl debug backend-pod --copy-to=debug-image-api --set-image=*=busybox ``` 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 if no res...
Create a cron job named "cron-task" that runs the command "mongo --version" every minute, using the image "mongo"
Command: ```bash kubectl create cronjob cron-task --image=mongo --schedule="*/1 * * * *" -- mongo --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o"...
Forward local traffic on port 3000 to port 5000 in the log-aggregator-deployment pod of the deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 3000 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 wi...
Create a new ClusterIP service named order-service-clusterip with the port mapping of TCP 8443 to 8010.
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8443:8010 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
Switch to the raw terminal mode and attach to the 'mycontainer' container inside the 'security-service-pod' pod.
Command: ```bash kubectl attach security-service-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. I...
Import specific keys from a config map and set them as environment variables for a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-settings deployment/authentication-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...
Add a taint with key 'disktype' and value 'storage-node-13:PreferNoSchedule' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha disktype=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 service for the 'php' replication controller, which will serve on port 80 and connect to the containers on port 8000.
Command: ```bash kubectl expose rc php --port=8082 --target-port=300000 ``` 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 ...
Scale the 'web' replica set to 1 replica
Command: ```bash kubectl scale --replicas=1 rs/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 specified, it is validated before...
Copy the ~/.config/kube directory from the remote pod kube-proxy/metrics-exporter-pod-10 to the /tmp/bar_dir directory locally
Command: ```bash kubectl cp kube-proxy/metrics-exporter-pod-10:~/.config/kube /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": "Container name. If omitte...
Create a new ClusterIP service named frontend-service-clusterip, listening on port 9091 and forwarding traffic to port 3001.
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=9091:3001 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-settings 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...
Patch a node by specifying a YAML patch.
Command: ```bash kubectl patch node app-node-6 -p $'spec:\n type: LoadBalancer' ``` 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 fl...
Forward local port 8080 to port 8080 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 be selected aut...
Create a new LoadBalancer service named frontend-lb that forwards traffic from port 8083 to port 8443.
Command: ```bash kubectl create service loadbalancer frontend-lb --tcp=8083:8443 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defaul...
Output the modified YAML representation of the 'notification-handler-deployment' deployment with the 'S3_BUCKET' environment variable set to 'my-s3-bucket' without making any changes to the actual object on the server.
Command: ```bash kubectl set env deployment/notification-handler-deployment S3_BUCKET=my-s3-bucket -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...
Add a taint with key 'datacenter' on nodes having label version=v1.0.0 with the value 'backup-node-14' and the taint effect as 'PreferNoSchedule'
Command: ```bash kubectl taint node -l version=v1.0.0 datacenter=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...
Scale the replica set named 'mysql' to have a single replica
Command: ```bash kubectl scale --replicas=1 rs/mysql ``` 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 specified, it is validated befo...
Update the 'backend' pod with the annotation 'deployment-script' and set the value to 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate pods backend deployment-script='https://example.com/deploy.sh' ``` 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...
Attach to a running pod and get the output
Command: ```bash kubectl attach proxy-service-pod ``` 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, use the kubec...
Attach to the running pod named gateway-pod and get its output
Command: ```bash kubectl attach gateway-pod ``` 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, use the kubectl.kub...
Update the label of the pod 'monitoring' by setting the 'env' label to 'production'
Command: ```bash kubectl label pods monitoring env=production ``` 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", "usag...
Set the CPU limit for the nginx container in the deployment to 500 milliCPU and the memory limit to 4 gigabytes.
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=500m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to i...
Forward traffic from port 3000 on localhost and IP 10.19.21.23 to port 9090 on the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 3000: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 cr...
Create a single ingress called 'app2-ingress' that directs requests to website.com/bar to svc1:8089 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/bar=svc1:8089,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":...
Create an ingress resource named 'public-service-ingress' with a rule that directs requests for 'testing.com/module' to 'svc1:3306' and uses the TLS secret named 'my-cert'
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/module=svc1:3306,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":...
Create a pod named "hazelcast" using the "mcr.microsoft.com/dotnet/core/runtime" image
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --labels="app=runtime,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] -...