prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Retrieve the password for the "testing-cluster" user in the Kubernetes configuration file
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "testing-cluster")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Help...
Retrieve the documentation for the "labels" field within the "metadata" section of the "services" resource.
Command: ```bash kubectl explain resource=services.metadata.labels ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag ...
Set the resource request and limits for all containers in the wordpress deployment to request 500m CPU and 64Mi memory, and limit to 200m CPU and 512Mi memory.
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=64Mi ``` 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 req...
Import the 'api_key' key from the 'kube-system-config' config map into the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/kube-system-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Update the 'monitoring' pod by setting the 'expiration-date' annotation to '2024-12-31', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods monitoring expiration-date='2024-12-31' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than label...
Run the 'node' command in the 'lunar-launcher' container of the 'api-service-pod' pod and get the output
Command: ```bash kubectl exec api-service-pod -c lunar-launcher -- node ``` 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, us...
start a MongoDB pod with the name "nginx"
Command: ```bash kubectl run nginx --image=mongo ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--filename", "short"...
Update the image of the first container in a pod using a JSON patch with positional arrays.
Command: ```bash kubectl patch pod payment-gateway-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl pa...
Get the output of running the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' in the first container of the pod from the deployment named 'api-server-deployment'
Command: ```bash kubectl exec deploy/api-server-deployment -- /bin/bash -c "echo 'Hello, Amazon Linux'" ``` 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":...
Create a service for the replication controller defined in "php-controller.yaml" file, which serves on port 9092 and connects to the containers on port 808900.
Command: ```bash kubectl expose -f php-controller.yaml --port=9092 --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 sp...
Apply the resources defined in the kustomization.yaml file located in the options/ directory.
Command: ```bash kubectl apply -k options/ ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'. JSON an...
Create an ingress named 'internal-ingress' that routes requests for 'website.com/example' to 'svc1:5432' with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/example=svc1:5432,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": "", ...
Copy the local file "/tmp/foo" to the remote pod "api-server-pod-3" in the "metallb-system" namespace, and save it as "/tmp/bar".
Command: ```bash kubectl cp :/tmp/foo metallb-system/api-server-pod-3::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Create a priority class named maintenance-priority without preemption
Command: ```bash kubectl create priorityclass maintenance-priority --value=30 --description="Priority for maintenance tasks" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --g...
Create a new ExternalName service named 'external-geolocation-service' with the external name 'travel-sample.travel'
Command: ```bash kubectl create service externalname external-geolocation-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 refer...
Update the environment variable 'QUEUE_NAME' in the deployment 'search-engine-deployment' to 'task-queue'
Command: ```bash kubectl set env deployment/search-engine-deployment QUEUE_NAME=task-queue ``` 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 tem...
Get the output from the nano-bot container in the cdn-service-pod.
Command: ```bash kubectl attach cdn-service-pod -c nano-bot ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
List the specified resources by their types and names
Command: ```bash kubectl get rc/web service/database-rc pods/e-commerce-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...
Create an ingress called 'private-ingress' with a rule that directs requests from foo.com/example to svc1:9091
Command: ```bash kubectl create ingress private-ingress --rule="foo.com/example=svc1:9091,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...
Copy the kube config file from the remote pod "admin-dashboard-pod-16" in the "istio-system" namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp istio-system/admin-dashboard-pod-16:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Update the 'log-aggregator' pod with the label 'release' and the value 'v2.0'
Command: ```bash kubectl label pods log-aggregator release=v2.0 ``` 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", "us...
Create an ingress resource named 'default-ingress' with a rule that directs requests for testing.com/example to the service 'svc1' running on port 9090
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/example=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": "", "...
Forward local port 8081 to port 8888 in the 'log-aggregator-pod' pod.
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Set the custom TLS server name to 'staging-cluster' for the 'app-cluster' cluster entry.
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=staging-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Set resource requests and limits for all containers in the "ubuntu" deployment
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=1,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 requeste...
Create a service for the replicated alpine using replica set
Command: ```bash kubectl expose rs alpine --port=8083 --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 specified port....
Forward port 8888 on localhost and IP 10.19.21.23 to port 9090 in the pod "web-app-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 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 criteri...
Forward data between ports 5000 and 8000 on your local machine to the corresponding ports on the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5000 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...
Modify the environment variables of a deployment and output the modified configuration in YAML format, without making any changes to the deployment on the server
Command: ```bash kubectl set env deployment/load-balancer-deployment REDIS_HOST=redis-server -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 mo...
Display the details of the replica controller 'web', the service 'proxy-server-rc', and the pod 'monitoring-pod'.
Command: ```bash kubectl get rc/web service/proxy-server-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 namesp...
Create a new config map named 'namespace-config' by importing the environment variables from the 'configurations.env' file
Command: ```bash kubectl create configmap namespace-config --from-env-file=path/to/configurations.env ``` 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 defau...
Create a job named "batch-processing" using the image "confluentinc/cp-kafka" and run the command "kafka-topics --list" inside the job.
Command: ```bash kubectl create job batch-processing --image=confluentinc/cp-kafka -- kafka-topics --list ``` 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": "...
Forward local port 8081 to port 9090 in the pod "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081: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 a...
Copy the local file '/tmp/foo_dir' to the '/tmp/bar' directory inside the 'web-app-pod-1' pod in the 'rook-ceph' namespace.
Command: ```bash kubectl cp /tmp/foo_dir rook-ceph/web-app-pod-1::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Copy the local file "~/.config/kube" to the remote pod "cache-pod-5" in the container "monitoring-agent", and place it in the directory "/tmp/bar_dir".
Command: ```bash kubectl cp ~/.config/kube cache-pod-5:/tmp/bar_dir -c monitoring-agent ``` 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, ...
Set up an autoscaling policy for deployment "frontend" with a minimum of 5 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment frontend --min=5 --max=8 ``` 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...
Retrieve the output from running the 'yum install -y aws-cli' command in the first container of the api-service service's first pod.
Command: ```bash kubectl exec svc/api-service -- yum install -y aws-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 name. If omitted, us...
Create a port-forwarding from port 8080 on all addresses to port 8080 in the proxy-server-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-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 ...
Forward local port 5000 to port 8081 in the pod named "chat-app-pod".
Command: ```bash kubectl port-forward pod/chat-app-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 pod will be selected autom...
Create a new ClusterIP service named 'auth-service-clusterip' that maps port 8088 on the ClusterIP to port 8080 on the service.
Command: ```bash kubectl create service clusterip auth-service-clusterip --tcp=8088:8080 ``` 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 new LoadBalancer service named vpn-service-lb that maps port 8181 on the external IP to port 5001 on the pod.
Command: ```bash kubectl create service loadbalancer vpn-service-lb --tcp=8181:5001 ``` 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", "def...
Forward port 3000 on all addresses to port 6379 in the pod named "proxy-server-pod" in order to listen on the forwarding port 3000.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 3000: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 ...
Create a pod using the data provided in the './parameters.json' file
Command: ```bash kubectl create -f ./parameters.json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use to cr...
Copy the file /tmp/foo from the remote pod database-pod-2 in the kube-flannel namespace to the local machine's /tmp/bar directory.
Command: ```bash kubectl cp kube-flannel/database-pod-2:/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Add a taint with key 'cpu-type' to nodes that have the label 'instance=app-instance-1', and set the taint effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l instance=app-instance-1 cpu-type=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...
Import the SMTP_SERVER key from the 'global-config' ConfigMap into the 'scheduler-app-deployment' deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-config 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 defini...
Get the output of running 'go version' command from the first container of the first pod of the analytics-service service
Command: ```bash kubectl exec svc/analytics-service -- 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, use the ...
Scale the deployment named `mysql` from the current size of 3 replicas to 7 replicas.
Command: ```bash kubectl scale --current-replicas=3 --replicas=7 deployment/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 sp...
Start streaming the logs of the 'cyber-sleuth' container in the 'database-pod' pod
Command: ```bash kubectl logs -f -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...
Import the DEBUG_MODE key from the app-config config map and set it as an environment variable for the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config 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 definition...
Create a new ExternalName service named external-caching-service
Command: ```bash kubectl create service externalname external-caching-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 referen...
Create a cron job named metrics-collection that runs the command "dotnet --list-runtimes" every minute
Command: ```bash kubectl create cronjob metrics-collection --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-runtimes ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` ...
Create a service for the 'ubuntu' replication controller, which serves on port 8181 and connects to the containers on port 330600
Command: ```bash kubectl expose rc ubuntu --port=8181 --target-port=330600 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a copy of the 'backend-pod' pod, and add a debug container
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-api --image=debian --set-image=mailer=mailer:latest,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Remove all taints with the key 'special' from the 'web-node-8' node.
Command: ```bash kubectl taint nodes web-node-8 special- ``` 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|na...
create a job named 'indexing' with the Redis image and run the command 'redis-server --version'
Command: ```bash kubectl create job indexing --image=redis -- redis-server --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", "short": "-o", "default": "", "usage": "Output f...
Create a cron job called "database-maintenance" that runs the command "geth version" every minute using the Ethereum Client Go image.
Command: ```bash kubectl create cronjob database-maintenance --image=ethereum/client-go --schedule="*/1 * * * *" -- geth 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": "--o...
Retrieve the logs of the previous terminated container "quantum-quark" from the pod "chat-app-pod".
Command: ```bash kubectl logs -p -c quantum-quark 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", "s...
Copy the local file /tmp/foo to the remote pod load-balancer-pod-9, specifically to the directory /etc/kubernetes, in the container ingress-controller.
Command: ```bash kubectl cp :/tmp/foo load-balancer-pod-9:/etc/kubernetes -c ingress-controller ``` 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 o...
Forward the traffic coming to port 3000 on your local machine to port 8081 inside the pod named 'log-aggregator-pod'.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Copy the local file /tmp/foo to the remote pod front-end-pod-12 in the kubeapps namespace, at the location /tmp/bar_dir
Command: ```bash kubectl cp /tmp/foo kubeapps/front-end-pod-12:/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, use the kube...
Forward traffic from local port 8081 to the targetPort of the "https" service in a pod selected by the service.
Command: ```bash kubectl port-forward service/web-service 8081: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 selected a...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/global-config deployment/load-balancer-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 defini...
Create a new secret named ldap-credentials-secret using the profiles.env file.
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-env-file=path/to/profiles.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 ...
Configure autoscaling for the deployment named "vpn" with a minimum of 6 pods and a maximum of 9 pods
Command: ```bash kubectl autoscale deployment vpn --min=6 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the ...
Rename the context 'cluster-2-context' to 'user-b-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context cluster-2-context user-b-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 ...
Add a taint with key 'hardware' on nodes having label 'stack=tech-stack' and set the value to 'PreferNoSchedule' with the node name 'backup-node-14'
Command: ```bash kubectl taint node -l stack=tech-stack hardware=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...
Create a new config map named 'namespace-config' and populate it with the contents of the specified files
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/properties/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...
Scale the deployment "backend" to have a minimum of 4 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment backend --min=4 --max=8 ``` 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 ...
Copy the file "foo" from the local machine to the "bar" file in the "/tmp" directory of the "monitoring-agent-pod-6" pod in the "monitoring" namespace.
Command: ```bash kubectl cp :/tmp/foo monitoring/monitoring-agent-pod-6::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Update the 'gateway-deployment' deployment by setting the environment variable 'MAX_CONNECTIONS' to '100'.
Command: ```bash kubectl set env deployment/gateway-deployment MAX_CONNECTIONS=100 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (...
Forward traffic from port 8088 on all addresses to port 8000 in the cdn-service-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-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 w...
Print the result, in YAML format, of updating the MySQL container image to mysql:5.7.35 from a local file specified at path/to/file.yaml without hitting the server.
Command: ```bash kubectl set image -f path/to/file.yaml mysql=mysql:5.7.35 --local -o yaml ``` 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), replic...
Remove all the taints with the key 'hardware' from the node 'node-1'
Command: ```bash kubectl taint nodes node-1 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|...
Set the custom TLS server name to "prod-cluster" for the cluster entry "cluster-gamma"
Command: ```bash kubectl config set-cluster cluster-gamma --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] [--certificat...
Create an ingress called 'web-ingress' that directs requests to a specific service and port, and enable TLS with a specific certificate secret.
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/bar=svc1:5432,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": "Out...
Update the 'env' annotation of the 'web' pod with the value 'staging'
Command: ```bash kubectl annotate pods web env=staging ``` 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 arbitrary string value...
Create a new secret named private-key-secret with specified keys instead of names on disk.
Command: ```bash kubectl create secret generic private-key-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` 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 sec...
Add a taint with the key 'hardware' and value 'k8s-node-1:PreferNoSchedule' on nodes having the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 hardware=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": "", "...
Expose a service for a replication controller specified in a yaml file, listening on port 8010 and forwarding traffic to containers on port 300100
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8010 --target-port=300100 ``` 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 ...
Expose the python deployment as a service, serving on port 8083 and connecting to the containers on port 808400.
Command: ```bash kubectl expose deployment python --port=8083 --target-port=808400 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Create a pod named "hazelcast" using the "hazelcast/hazelcast" image and expose port 8088.
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=8088 ``` 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:...
Create an ingress called 'app-loadbalancer-ingress' that directs requests to site.com/bar to svc1:5000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/bar=svc1:5000,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": "",...
Delete the pods and services with the names "web" and "foo".
Command: ```bash kubectl delete pod,service web foo ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some re...
Create a service for the replication controller specified in the "python-controller.yaml" file
Command: ```bash kubectl expose -f python-controller.yaml --port=5001 --target-port=808300 ``` 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...
Create a pod disruption budget with a minimum availability requirement for pods with the role=worker label
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=role=worker --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dr...
Create a new config map named 'app-name-config' with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/options/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 cre...
Add a taint with key 'datacenter' and no value to the node 'node-2'
Command: ```bash kubectl taint nodes node-2 datacenter: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 of: jso...
Create a copy of the 'proxy-service-pod' with a debug container and change the container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=my-debugger --image=debian --set-image=proxy=nginx:1.21,web=nginx: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...
Add a taint with key 'datacenter' to nodes with the label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 datacenter=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"...
Forward traffic from a local random port to port 8888 in a specific pod
Command: ```bash kubectl port-forward pod/cdn-service-pod :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 automa...
Retrieve the snapshot logs from container payment-processor-deployment-1 of the deployment named payment-gateway-pod.
Command: ```bash kubectl logs deployment/payment-processor-deployment -c payment-gateway-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 ...
Add an annotation to the pod 'monitoring' with the key 'description' and the value 'Web server for marketing site'
Command: ```bash kubectl annotate pods monitoring 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 than la...
Update the deployment 'cache-cluster-deployment' by setting the environment variable 'DB_HOST' to 'localhost'
Command: ```bash kubectl set env deployment/cache-cluster-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 templat...
Create a cluster role named "bar" with the specified API Group, and define the permissions to delete, update, and proxy certificatesigningrequests.certificates.k8s.io resources
Command: ```bash kubectl create clusterrole bar --verb=delete,update,proxy --resource=certificatesigningrequests.certificates.k8s.io ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` H...
Execute the 'redis-server' command in the first container of the 'cache-cluster-deployment' deployment and get the output.
Command: ```bash kubectl exec deploy/cache-cluster-deployment -- 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 omitt...
Create a pod disruption budget that selects pods with a specific label and requires a minimum number of them to be available at any time
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=component=web --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...
Retrieve the logs from container `frontend-pod-1` of a deployment named `proxy-service-deployment`.
Command: ```bash kubectl logs deployment/proxy-service-deployment -c frontend-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...
Retrieve information for the specified resources: 'web' replication controller, 'web-app-rc' service, and 'vpn-service-pod' pod
Command: ```bash kubectl get rc/web service/web-app-rc pods/vpn-service-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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config-prod deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...