prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import the 'EXTERNAL_API_URL' key from the 'env-vars' config map into the 'cache-cluster-deployment' deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/env-vars deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Partially update a node using strategic merge patch
Command: ```bash kubectl patch -f node-config.toml -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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: `kubect...
Import the specific key CONFIG_FILE_PATH from the app-config-prod ConfigMap and set it as an environment variable in the mydeployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config-prod 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...
Copy the ~/.config/kube file from a remote pod named ingress-controller-pod-8 to the /etc/kubernetes directory on your local machine.
Command: ```bash kubectl cp kube-server/ingress-controller-pod-8:~/.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 o...
Remove the 'description' annotation from the 'database' pod
Command: ```bash kubectl annotate pods database description- ``` 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...
View the last-applied-configuration annotations of the deployment named "mcr.microsoft.com/dotnet/core/runtime" in YAML format
Command: ```bash kubectl apply view-last-applied deployment/mcr.microsoft.com/dotnet/core/runtime ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `...
Forward local port 5432 to port 8000 in the specified pod
Command: ```bash kubectl port-forward pod/api-service-pod 5432: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 au...
Create an ingress called 'internal-ingress' with a rule that directs requests for foo.com/module to svc1:8080 and uses the TLS secret "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="foo.com/module=svc1:8080,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 all traffic from port 3000 on all addresses to port 5432 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 3000: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 ...
Return snapshot logs from container database-pod-1 of the order-processing-deployment deployment
Command: ```bash kubectl logs deployment/order-processing-deployment -c database-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: "...
Delete pods and services with names "frontend" and "backend"
Command: ```bash kubectl delete pod,service frontend backend ``` 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...
Forward local ports 3000 and 6000 to ports 5000 and 6000 on a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 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 selecte...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config-prod deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/namespace-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 ...
Add a taint with the key 'workload' on nodes having the label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp workload=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...
Update the image of the first container in the api-service-pod using a JSON patch. Set the image to "new image".
Command: ```bash kubectl patch pod api-service-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 patch ...
Copy the file "foo" located at "/tmp/foo" on your local machine to the directory "/tmp/bar_dir" in the container named "metrics-exporter" of the pod named "cache-pod-5".
Command: ```bash kubectl cp :/tmp/foo cache-pod-5:/tmp/bar_dir -c metrics-exporter ``` 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...
Get the output from running the 'jenkins-plugin-cli' command from the first pod of the 'order-processing-deployment' deployment.
Command: ```bash kubectl exec deploy/order-processing-deployment -- jenkins-plugin-cli ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
Create a copy of the chat-app-pod and add a debug container with a debian image, also update the image of the web container to nginx:latest and the worker container to my-custom-worker:1.2.3
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-custom-dbg --image=debian --set-image=web=nginx:latest,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by re...
Create a new secret named tls-certificate-secret from an env file
Command: ```bash kubectl create secret generic tls-certificate-secret --from-env-file=path/to/settings.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 t...
Import the 'my-example-key' key from the 'app-config-dev' config map and set it as an environment variable in the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config-dev deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Set up autoscaling for the 'security' deployment with a minimum of 4 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment security --min=4 --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 job named log-collection using the ubuntu image, and run the command "docker run -it ubuntu" inside the job.
Command: ```bash kubectl create job log-collection --image=ubuntu -- docker run -it ubuntu ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Expose a service for a replication controller specified in a yaml file, serving on port 8081 and connecting to the containers on port 8000
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8081 --target-port=8000 ``` 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...
Create a cluster role named "reader" with the SubResource specified by allowing the "list", "create", and "connect" verbs on both the "persistentvolumes" and "persistentvolumes/status" resources.
Command: ```bash kubectl create clusterrole reader --verb=list,create,connect --resource=persistentvolumes,persistentvolumes/status ``` 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]` He...
Mark a specific node as unschedulable
Command: ```bash kubectl cordon edge-node-10 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Create a deployment using the specified image and execute the "geth version" command
Command: ```bash kubectl create deployment db --image=ethereum/client-go -- geth version ``` 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 forma...
Create a debug container in vpn-service-pod, copy the pod to my-custom-dbg, and change the container image to debian
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=database=mysql:5.7,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Copy the directory "/tmp/foo_dir" from the remote pod "istio-system/image-resizer-pod-20" to the local directory "/tmp/bar".
Command: ```bash kubectl cp istio-system/image-resizer-pod-20:/tmp/foo_dir /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 ...
Forward traffic from local port 3000 to port 3000 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Set the server field for the dev-cluster cluster without modifying other fields
Command: ```bash kubectl config set-cluster dev-cluster --server=https://1.2.3.4 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-author...
Forward local port 8088 to port 9090 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 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 select...
Create a new ExternalName service with the name "external-git-service" and point it to the external name "practice-online.site"
Command: ```bash kubectl create service externalname external-git-service --external-name practice-online.site ``` 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 ser...
Create a role binding named "admin" with the "admin" cluster role, and assign it to the users "jane.doe" and "bob.smith", as well as the group "developers".
Command: ```bash kubectl create rolebinding admin --clusterrole=admin --user=jane.doe --user=bob.smith --group=developers ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serv...
List all services in ps output format with more information, including the node name
Command: ```bash kubectl get services -o wide ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in ...
Forward local port to pod port
Command: ```bash kubectl port-forward pod/backend-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 automa...
Begin streaming the logs of the 'rocket-ranger' container in the 'frontend-pod' pod
Command: ```bash kubectl logs -f -c rocket-ranger frontend-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...
Execute the 'nginx' command in the first container of the first pod of the 'scheduler-app-deployment' deployment and display the output.
Command: ```bash kubectl exec deploy/scheduler-app-deployment -- nginx ``` 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...
Set the custom TLS server name to "app-cluster" for the cluster entry named "app-cluster" in your kubectl configuration.
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=app-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-a...
Import environment variables from the 'app-config' config map into the 'log-aggregator-deployment' deployment as prefix 'MYSQL_'
Command: ```bash kubectl set env --from=configmap/app-config --prefix=MYSQL_ deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Partially update a node by providing a strategic merge patch in JSON format.
Command: ```bash kubectl patch node dev-node-4 -p '{"data":{"key":"new-value"}' ``` 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...
Copy the ~/.config/kube directory from a remote pod named "image-resizer-pod-20" to the local directory /tmp/bar_dir.
Command: ```bash kubectl cp velero/image-resizer-pod-20:~/.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 omitted, use ...
Create a pod disruption budget named api-service-pdb that selects all pods with the env=production label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=env=production --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...
Forward traffic between local ports 6379 and 6000 to/from ports 5432 and 6000 in the pod named cdn-service
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a copy of the 'payment-gateway-pod' pod with a debug container and changes to the container images
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-app --image=debian --set-image=app=app:debug,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified...
Update the pod named 'proxy' with the annotation 'monitoring-tool' and the value 'Prometheus', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods proxy monitoring-tool='Prometheus' ``` 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...
Create a job called "data-migration-job" using the "centos" image and executing the command "bash"
Command: ```bash kubectl create job data-migration-job --image=centos -- bash ``` 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 new ClusterIP service named frontend-service-clusterip that maps port 27017 from the service to port 8888 on the backend
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=27017:8888 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-...
Create a job named deployment-rollout-job using the redis image. Run the command "redis-server --version" in the job.
Command: ```bash kubectl create job deployment-rollout-job --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": "", "usa...
Create a debug copy of the backend-pod by adding a debug container and changing container images
Command: ```bash kubectl debug backend-pod -it --copy-to=my-custom-dbg --image=debian --set-image=proxy=nginx:1.21,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and nam...
View the most recent 20 lines of output from the logs of the pod named frontend-pod
Command: ```bash kubectl logs --tail=20 frontend-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 deployment named "scheduler" using the Redis image and run the Redis CLI command within the deployment.
Command: ```bash kubectl create deployment scheduler --image=redis -- redis-cli ``` 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...
Import the log_level key from the app-config-prod config map into the load-balancer-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-prod 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...
Add a taint with the key 'zone' on nodes having the label project=project-alpha and taint the node edge-node-10 with the taint value PreferNoSchedule.
Command: ```bash kubectl taint node -l project=project-alpha zone=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": "", "usag...
Create an ingress resource named 'web-ingress' that directs requests to the host 'testing.com' and path '/example' to the service 'svc1:5000'
Command: ```bash kubectl create ingress web-ingress --rule="testing.com/example=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": "", "usag...
Create an ingress with a specific rule and TLS secret.
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/example=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": "", "u...
Add a taint with key 'workload' and value 'storage-node-13' on nodes having label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe workload=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": "", "usag...
Start streaming the logs of the 'rocket-ranger' container in the 'gateway-pod' pod.
Command: ```bash kubectl logs -f -c rocket-ranger gateway-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...
Add a new taint to node 'app-node-6' with the key 'cpu-type', value 'x86', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes app-node-6 cpu-type=x86: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 o...
Update the pod named 'cdn' with the annotation 'description' and set the value as 'Web server for marketing site', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods cdn 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 th...
List all services in ps output format
Command: ```bash kubectl get services ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see results in your cur...
Reconcile the RBAC resources defined in the 'my-rbac-rules.yaml' file
Command: ```bash kubectl auth reconcile -f my-rbac-rules.yaml ``` What it does: Reconciles rules for RBAC role, role binding, cluster role, and cluster role binding objects. Missing objects are created, and the containing namespace is created for namespaced objects, if required. Existing roles are updated to include t...
Copy a file named "foo" from the remote pod "admin-dashboard-pod-16" in the "prometheus" namespace to the local machine at the destination path "/tmp/bar".
Command: ```bash kubectl cp prometheus/admin-dashboard-pod-16:/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...
configure environment variables of a deployment with specific keys from a config map
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/namespace-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Update the expiration date annotation of the pod specified in the "conf.json" file to '2024-12-31'.
Command: ```bash kubectl annotate -f conf.json 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 labels and include a...
Start a pod named 'hazelcast' with the Redis image and expose port 3001
Command: ```bash kubectl run hazelcast --image=redis --port=3001 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Create a deployment named "web" using the "alpine" image and expose port 5000.
Command: ```bash kubectl create deployment web --image=alpine --port=5000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json...
Create a pod disruption budget named 'replica-set-pdb' that will select all pods with the 'app=rails' label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget replica-set-pdb --selector=app=rails --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...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/namespace-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Create a pod disruption budget for pods with a specific label, ensuring a minimum number of them are available at all times.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=release=1.0.0 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=...
Partially update a node by applying a strategic merge patch in YAML format
Command: ```bash kubectl patch node node-1 -p $'data:\n key: new-value' ``` 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: "fl...
Mark node "web-node-8" as unschedulable
Command: ```bash kubectl cordon web-node-8 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Set a custom TLS server name for the "moon-cluster" cluster in the kubeconfig file.
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=e2e ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-authorit...
Set the resource request and limits for all containers in the amazonlinux deployment
Command: ```bash kubectl set resources deployment amazonlinux --limits=cpu=200m,memory=512Mi --requests=cpu=5,memory=128Mi ``` 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 specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/ui-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...
Update the 'scheduler-app-deployment' deployment by adding a new environment variable 'SMTP_PASSWORD' with the value 'your-password'
Command: ```bash kubectl set env deployment/scheduler-app-deployment SMTP_PASSWORD=your-password ``` 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 p...
Describe a resource specified in a preferences file
Command: ```bash kubectl describe -f preferences.json ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide...
Retrieve the logs from the previous terminated 'stardust-shuttle' container in the 'payment-gateway-pod' pod.
Command: ```bash kubectl logs -p -c stardust-shuttle payment-gateway-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": "--cont...
Create a ClusterIP service named log-service-clusterip with port mapping from local port 8084 to target port 3306.
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=8084:3306 ``` 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", "d...
set the annotation "criticality=high" for the pod specified in the "config.json" file
Command: ```bash kubectl annotate -f config.json criticality=high ``` 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 s...
Create a service for the replication controller specified in "nginx-controller.yaml" that serves on port 9091 and connects to the containers on port 888800.
Command: ```bash kubectl expose -f nginx-controller.yaml --port=9091 --target-port=888800 ``` 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 ...
Retrieve the output from running the 'mysqld' command in the warp-drive container of the pod named 'web-app-pod'
Command: ```bash kubectl exec web-app-pod -c warp-drive -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Set the resource limits and requests for all containers in a deployment named "go" for CPU and memory.
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=128Mi ``` 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,...
Add a taint with key 'special' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 special=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": "", "usa...
Switch to the raw terminal mode and attach to the 'mycontainer' in the 'payment-gateway-pod' pod.
Command: ```bash kubectl attach payment-gateway-pod -c mycontainer -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Copy the file /tmp/foo from the backend-pod-13 pod in the ingress-nginx namespace to /tmp/bar on your local machine.
Command: ```bash kubectl cp ingress-nginx/backend-pod-13:/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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/db-config deployment/search-engine-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 job using a cron job named "metrics-collection"
Command: ```bash kubectl create job test-job --from=cronjob/metrics-collection ``` 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....
Execute the 'dotnet --list-sdks' command on the 'warp-drive' container inside the 'proxy-server-pod' pod and get the output.
Command: ```bash kubectl exec proxy-server-pod -c warp-drive -- dotnet --list-sdks ``` 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 ...
Add a taint with key 'hardware' on nodes having the label 'myLabel' and value 'node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel hardware=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": "Output form...
Retrieve the snapshot logs from the container named monitoring-pod-1 of the cache-cluster-deployment deployment.
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c monitoring-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: "f...
Create a pod named "hazelcast" using the "amazonlinux" image and make the container inside the pod expose port 3306.
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=3306 ``` 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":...
List all deployments in JSON format for the "stable-2.0.0" version of the "sandbox-apps" API group
Command: ```bash kubectl get deployments.stable-2.0.0.sandbox-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced ...
Start a pod named "hazelcast" using the image "ethereum/client-go" and expose port 7000 for networking.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=7000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: ...
Create a deployment named "registry" using the "docker.elastic.co/elasticsearch/elasticsearch" image and expose port 8888.
Command: ```bash kubectl create deployment registry --image=docker.elastic.co/elasticsearch/elasticsearch --port=8888 ``` 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...
Set the service account for the deployment "authentication-service-deployment" to "jenkins"
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment jenkins ``` 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 Synt...
Create a priority class named 'default-priority' with a value of 1000 that is considered as the global default priority and has a description of "default priority".
Command: ```bash kubectl create priorityclass default-priority --value=1000 --global-default=true --description="default priority" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/api-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 definition...
Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment nginx --port=5001 --target-port=909200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifie...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to the /etc/kubernetes directory in the backend-container of the payment-gateway-pod-19 pod.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ payment-gateway-pod-19:/etc/kubernetes -c backend-container ``` 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", "defau...