prompt
stringlengths
13
282
response
stringlengths
128
3.11k
View the modified deployment in YAML format without making any changes to the actual object on the server.
Command: ```bash kubectl set env deployment/email-server-deployment SMTP_USERNAME=your-username -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 or...
Autoscale the deployment named "chat-app" with a minimum of 6 pods and a maximum of 12 pods
Command: ```bash kubectl autoscale deployment chat-app --min=6 --max=12 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create a new service account named kube-dns
Command: ```bash kubectl create serviceaccount kube-dns ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-t...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/env-vars deployment/scheduler-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 definitions ...
Add the label 'component=web' to the pod named 'web'.
Command: ```bash kubectl label pods web component=web ``` 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 ...
Add a taint with the key 'app' and the value 'worker-node-3:PreferNoSchedule' on the nodes that have the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace app=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": "", "usag...
Retrieve the previous terminated logs of the "cyber-sleuth" container from the "proxy-server-pod" pod
Command: ```bash kubectl logs -p -c cyber-sleuth proxy-server-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 annotation 'scaling-policy' of the 'api' pod to 'auto-horizontal-scaling'
Command: ```bash kubectl annotate pods api scaling-policy=auto-horizontal-scaling ``` 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 inc...
Forward traffic from local port 8081 to port 8888 in the pod named 'frontend-pod'
Command: ```bash kubectl port-forward pod/frontend-pod 8081 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
delete the pods and services with the names "gateway" and "database"
Command: ```bash kubectl delete pod,service gateway database ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector...
Get the output from running the 'go version' command in the astro-container from the backend-pod.
Command: ```bash kubectl exec backend-pod -c astro-container -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Forward traffic from port 8000 on localhost and IP address 10.19.21.23 to port 8080 in the pod named web-app-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8000: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 criteri...
Forward local port 8088 to port 9090 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 8088:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Forward local port 8088 to port 8000 in the pod "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 8088: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 automa...
Set the CPU limit of the python container in the deployment "python" to 3 and the memory limit to 1Gi.
Command: ```bash kubectl set resources deployment python -c=nginx --limits=cpu=3,memory=1Gi ``` 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 its...
List specific resources by their type and names
Command: ```bash kubectl get rc/web service/proxy-service-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 namespa...
Create a new resource quota named persistent-volume-quota with a limit of 10 persistent volume claims.
Command: ```bash kubectl create quota persistent-volume-quota --hard=persistentvolumeclaims=10 ``` What it does: Create a resource quota with the specified name, hard limits, and optional scopes. Syntax: `kubectl create quota NAME [--hard=key1=value1,key2=value2] [--scopes=Scope1,Scope2] [--dry-run=server|client|none...
Create an ingress called 'service-ingress' that directs requests for 'site.com/input' to 'svc1:9092' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="site.com/input=svc1:9092,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 pod 'vpn' by adding the annotation 'custom-label' with the value 'my-custom-value'
Command: ```bash kubectl annotate pods vpn 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 arbit...
Create a debug container of log-aggregator-pod with a modified command for nebula-navigator
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-1 --container=nebula-navigator -- 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 use...
Create a new ExternalName service named external-file-storage-service with the --external-name set to travel-sample.travel
Command: ```bash kubectl create service externalname external-file-storage-service --external-name travel-sample.travel ``` 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 refe...
Remove the taint with key 'environment' and effect 'NoSchedule' from the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 environment:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. ...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/monitoring-config deployment/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 ...
Create an ingress resource with the name 'ingsecret' in the default class and a rule that maps all requests with the domain 'testing.com' and any path to a service named 'svc' listening on port 7000
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="testing.com/*=svc:7000,tls=secret1" ``` 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 new secret named 'database-secret' in the default namespace by using the files located in the 'path/to/configurations' folder.
Command: ```bash kubectl create secret generic database-secret --from-file=path/to/configurations ``` 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 basena...
Set the resource request and limits for all containers in the 'mysql' deployment.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=1Gi ``` 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 requeste...
Forward traffic from local port 8888 to port 8000 in the pod 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 8888: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 autom...
Output the modified frontend-deployment deployment in YAML format with the GOOGLE_API_KEY environment variable set to 'your-google-api-key', and make sure to not alter the object on the server.
Command: ```bash kubectl set env deployment/frontend-deployment GOOGLE_API_KEY=your-google-api-key -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 service for the Ubuntu deployment that serves on port 9091 and connects to the containers on port 808900.
Command: ```bash kubectl expose deployment ubuntu --port=9091 --target-port=808900 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Create a cluster role named "view" with the verbs "create" and the resources "configmaps", "report-generator", and "content-delivery"
Command: ```bash kubectl create clusterrole view --verb=create --resource=configmaps --resource-name=report-generator --resource-name=content-delivery ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serve...
Create an ingress called 'app-gateway-ingress' that directs requests to "site.com/input" to the service "svc1" with port "9090", and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.com/input=svc1:9090,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Copy the local file /tmp/foo_dir to the remote pod admin-dashboard-pod-16 in the namespace monitoring, and place it in the /tmp/bar_dir location inside the pod.
Command: ```bash kubectl cp /tmp/foo_dir monitoring/admin-dashboard-pod-16:/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 omitted, ...
Retrieve snapshot logs from the container "backend-pod-1" of the deployment "log-aggregator-deployment".
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c backend-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: "fla...
Partially update the 'app-node-6' node by setting the 'unschedulable' field to true using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node app-node-6 -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]` Helpfu...
Listen on port 3000 on all addresses, and forward the traffic to port 8000 in the mypod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 3000: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 sel...
Scale the deployment named webapp-replicaset from a current size of 3 replicas to a new size of 1 replica.
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/webapp-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-v...
Create a role named "default_role" with specific permissions for a specific resource(s)
Command: ```bash kubectl create role default_role --verb=list,create,connect --resource=endpoints,endpoints/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]` Helpf...
Create an ingress resource called 'default-ingress' that directs requests from testing.com/bar to svc1:8010 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress default-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": "", "usag...
Forward port 8888 locally to port 6379 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 8888: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 auto...
Display the most recent 53 lines of logs for the chat-app-pod
Command: ```bash kubectl logs --tail=53 chat-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...
Create a cluster role binding named "foo" that binds the "foo" cluster role to the users "developer3" and "k8s-admin", as well as the group "qa-engineers"
Command: ```bash kubectl create clusterrolebinding foo --clusterrole=foo --user=developer3 --user=k8s-admin --group=qa-engineers ``` What it does: Create a cluster role binding for a particular cluster role. Syntax: `kubectl create clusterrolebinding NAME --clusterrole=NAME [--user=username] [--group=groupname] [--se...
Forward local traffic on port 3000 to port 5000 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-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 autom...
Update the label of pod 'payment' to have the value 'worker' for the key 'component'
Command: ```bash kubectl label pods payment component=worker ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage...
Add a taint with key 'dedicated' on nodes having label app-type=microservice, and set the NoSchedule effect on the node with the label "k8s-node-1".
Command: ```bash kubectl taint node -l app-type=microservice dedicated=k8s-node-1: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...
List deployments in YAML output format for the "dev-2.2.0" version of the "legacy-apps" API group
Command: ```bash kubectl get deployments.dev-2.2.0.legacy-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 ...
Add a taint with the key 'disktype' on nodes that have the label 'app=web-app' and set the value as 'monitoring-node-15:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app disktype=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": "", "usag...
Forward port 8000 on all addresses to port 6379 in the pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 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 po...
Forward port 3000 in the pod named "e-commerce-pod" to your local machine's port 8081.
Command: ```bash kubectl port-forward pod/e-commerce-pod 8081: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 aut...
Create a service for the replicated php using a replica set
Command: ```bash kubectl expose rs php --port=5432 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Create an ingress called 'app-ingress' that directs requests to a specific path and service, and includes a TLS secret for secure communication.
Command: ```bash kubectl create ingress app-ingress --rule="site.com/example=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Add a taint with key 'cpu-type' on nodes having label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace cpu-type=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": "", "us...
Port forward traffic from local ports 8081 to ports 3000 in a pod selected by the 'email-server-deployment' deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8081 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...
create a cron job named "monthly-audit" with the image "jenkins" that runs every minute and executes the command "jenkins --version"
Command: ```bash kubectl create cronjob monthly-audit --image=jenkins --schedule="*/1 * * * *" -- jenkins --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", "shor...
Create a cluster role named "default_role" with the specified resource names
Command: ```bash kubectl create clusterrole default_role --verb=watch --resource=pods --resource-name=dashboard-ui --resource-name=load-balancer ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Forward traffic from port 8080 on all addresses to port 8000 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8080:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Forward port 6379 on all addresses to port 5000 in the security-service-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 6379: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 ...
Add a taint with key 'cpu-type' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster cpu-type=node-1: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": "...
Begin streaming the logs of the "rocket-ranger" container in the "proxy-service-pod" pod
Command: ```bash kubectl logs -f -c rocket-ranger 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...
Add specific keys from a configmap to the environment variables of a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/kube-system-config 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 defin...
Retrieve the previous terminated logs of the code-explorer container from the api-service-pod
Command: ```bash kubectl logs -p -c code-explorer 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",...
Add a taint with the key 'cpu-type' and value 'worker-node-3:PreferNoSchedule' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production 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": "",...
Execute the 'java -jar /usr/share/jenkins/jenkins.war' command in the first container of the first pod of the 'payment-service' service and get the output
Command: ```bash kubectl exec svc/payment-service -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "Containe...
Create a new secret named cert-manager-secret from an environment file
Command: ```bash kubectl create secret generic cert-manager-secret --from-env-file=path/to/configs.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 b...
Forward local port 8888 to port 8088 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 8888:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
create a job with a specific command and image
Command: ```bash kubectl create job security-scan-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch ``` 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":...
Get the output from running the 'elasticsearch-plugin --list' command from the analytics-pod pod, using the first container by default.
Command: ```bash kubectl exec analytics-pod -- 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": "Container name. If omitted,...
Create a pod disruption budget named replica-set-pdb that selects all pods with the version=v2 label and requires at least one of them to be available at all times.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=version=v2 --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--...
Create an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="testing.com/path/subpath*=othersvc:8000" ``` 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": "...
Create a job named "log-collection" using the Centos image, with a command to sleep for 3600 seconds.
Command: ```bash kubectl create job log-collection --image=centos -- sleep 3600 ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format...
Create a pod running the php image and expose port 8083
Command: ```bash kubectl run hazelcast --image=php --port=8083 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--file...
update the 'monitoring-stack-deployment' deployment by setting the environment variable 'DB_HOST' to 'localhost'
Command: ```bash kubectl set env deployment/monitoring-stack-deployment DB_HOST=localhost ``` 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 temp...
Forward port 5432 from your local machine to port 5432 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 pod will be selected automaticall...
import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/global-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment var...
Auto scale the deployment "cdn" with a range of 5 to 14 pods
Command: ```bash kubectl autoscale deployment cdn --min=5 --max=14 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Copy the /tmp/foo_dir directory from the auth-service-pod-11 pod to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp kube-server/auth-service-pod-11:/tmp/foo_dir /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,...
Add annotation 'last-deployment' with value '2023-03-15' to the pod 'media-stream'
Command: ```bash kubectl annotate pods media-stream 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 includ...
Execute the 'mongo' command on the first pod of the 'payment-service' service and display the output.
Command: ```bash kubectl exec svc/payment-service -- 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 kubectl...
Update the annotation 'team' of the pod 'security' with the value 'frontend team'
Command: ```bash kubectl annotate pods security team='frontend team' ``` 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 arbitrar...
Apply a strategic merge patch to update the 'replicas' field of the 'spec' section for the 'edge-node-10' node
Command: ```bash kubectl patch node edge-node-10 -p $'spec:\n 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: ...
Create a new ExternalName service named external-ldap-service with the external name illustration-shop.shop.
Command: ```bash kubectl create service externalname external-ldap-service --external-name illustration-shop.shop ``` 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 ...
Output the modified deployment in YAML, without making any changes to the object on the server
Command: ```bash kubectl set env deployment/gateway-deployment GOOGLE_API_KEY=your-google-api-key -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 ...
Auto scale the 'log-aggregator' deployment with a minimum of 1 pod and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment log-aggregator --min=1 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler th...
Create a new ClusterIP service named backend-service-clusterip that maps port 6379 on the service to port 7000 on the pods.
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=6379:7000 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Create a job named 'log-processing-job' using the 'docker.elastic.co/elasticsearch/elasticsearch' image
Command: ```bash kubectl create job log-processing-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch --version ``` 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...
Add a taint with the key 'special' on nodes having the label feature=feature-xyz, specifically on the db-node-7 node with a taint effect of PreferNoSchedule
Command: ```bash kubectl taint node -l feature=feature-xyz 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"...
Remove the taint with key 'cpu-type' and effect 'NoSchedule' from the node 'testing-node-11' if one exists.
Command: ```bash kubectl taint nodes testing-node-11 cpu-type:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Forward port 8080 on your local machine to port 8000 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8080:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Get output from cyber-sleuth of pod proxy-server-pod.
Command: ```bash kubectl attach proxy-server-pod -c cyber-sleuth ``` 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...
Create a new config map named env-vars using the parameters found in the folder path/to/parameters
Command: ```bash kubectl create configmap env-vars --from-file=path/to/parameters ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename o...
Remove all taints with the key 'environment' from the node 'monitoring-node-15'
Command: ```bash kubectl taint nodes monitoring-node-15 environment- ``` 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: ...
Copy the ~/.config/kube file from the 'web-app-pod-1' pod in the 'rook-ceph' namespace to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp rook-ceph/web-app-pod-1:~/.config/kube /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 t...
Update the 'payment' pod's annotation 'deployment-script' with the value 'https://example.com/deploy.sh', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods payment 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...
Forward local port 8080 to port 9090 in a selected pod of the deployment named "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8080 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 po...
Set the resource request and limits for all containers in the hazelcast deployment to request 10m CPU and 256Mi memory, and limit to 200m CPU and 512Mi memory.
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=10,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 requ...
Create a new LoadBalancer service named 'proxy-service-lb' that forwards traffic from port 8888 to port 8443.
Command: ```bash kubectl create service loadbalancer proxy-service-lb --tcp=8888: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", "d...
Create a copy of the payment-gateway-pod, with the command of the rocket-ranger container modified
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-custom-dbg --container=rocket-ranger -- 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 ...
Create a new config map named ui-config with the keys "conf" and "data" that correspond to the files /path/to/settings/file1.txt and /path/to/configs/file2.txt, respectively
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ...
Import specific keys from a config map into a deployment environment variable
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/ui-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 definiti...
Check if the current authenticated user has permission to list the "batch-processing-job" job in the "staging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial U...
Create a pod disruption budget with a specific label and availability requirement
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=owner=team-1 --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--d...