prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the image of the 'nginx' container in all deployments and replication controllers to 'python:3.9.7'
Command: ```bash kubectl set image deployments,rc python=python:3.9.7 --all ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Synt...
Update the annotation of a pod specified in the setup.json file with a new git-repo URL
Command: ```bash kubectl annotate -f setup.json git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than lab...
Create a new config map named namespace-config using the preferences from the specified folder
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/preferences ``` 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 b...
Create a new NodePort service named 'backend-nodeport' that maps port 3000 of the service to port 5432 of the pods
Command: ```bash kubectl create service nodeport backend-nodeport --tcp=3000:5432 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Listen on port 8080 on all addresses and forward the traffic to port 8000 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-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...
Add a taint with key 'hardware' and value 'storage-node-13:PreferNoSchedule' on all nodes with the label 'cluster=my-cluster'.
Command: ```bash kubectl taint node -l cluster=my-cluster hardware=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Create a new service named "external-ldap-service" with the type "ExternalName" and the external name "demo-service.dev"
Command: ```bash kubectl create service externalname external-ldap-service --external-name demo-service.dev ``` 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 servic...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/gateway-rc pods/media-stream-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 namespace...
Delete pods and services with names "api" and "cdn"
Command: ```bash kubectl delete pod,service api cdn ``` 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...
Retrieve the list of deployments in the "v1.1.0" version of the "prod-apps" API group and display them in YAML format
Command: ```bash kubectl get deployments.v1.1.0.prod-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 will ...
Add a taint to nodes in a specific region with the label "app"
Command: ```bash kubectl taint node -l region=eu-west-2 app=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": "", "usage": "Out...
Update the annotation of a pod named 'media-stream' with the key 'compliance-level' and the value 'PCI-DSS', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods media-stream compliance-level='PCI-DSS' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than label...
Monitor the status of the rollout for the deployment named "app-v2"
Command: ```bash kubectl rollout status deployment/app-v2 ``` What it does: Show the status of the rollout. By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts in-b...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-config-dev deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Execute the command 'elasticsearch --version' in the pod named 'frontend-pod' and container 'nebula-navigator' and retrieve the output.
Command: ```bash kubectl exec frontend-pod -c nebula-navigator -- elasticsearch --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 na...
Add a taint with the key 'zone' on nodes having the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta zone=gpu-node-12: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": "Outpu...
Forward traffic from local port 8888 to port 6379 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-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 a...
Remove the taint with key 'environment' and effect 'NoSchedule' from node 'node-1' if it exists
Command: ```bash kubectl taint nodes node-1 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. One of: j...
Create a secret named "monitoring-credentials-secret" by using the values from an environment file.
Command: ```bash kubectl create secret generic monitoring-credentials-secret --from-env-file=path/to/options.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 defaul...
Create a new config map named app-config using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cre...
Forward local port 5432 and the selected IP to port 9090 in the e-commerce pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 5432:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Forward local port 8088 to port 9090 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-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 selected autom...
Update the image of all containers in the daemonset "namespace-2" to 'openjdk:16.0.2'
Command: ```bash kubectl set image daemonset namespace-2 *=openjdk:16.0.2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax...
Add a taint with key 'disktype' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack disktype=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": "", "usage":...
Create an ingress named 'api-v1-ingress' that routes requests from foo.com/module to svc1:5000 with a TLS secret called "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="foo.com/module=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": "", "usage"...
Set the custom TLS server name for the app-cluster cluster entry
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=moon-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-...
Create a new config map named 'db-config' using the preferences.env file located at 'path/to/preferences.env'
Command: ```bash kubectl create configmap db-config --from-env-file=path/to/preferences.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 default to the ...
Create a new service of type ExternalName named external-authentication-service and set the external name to sandbox-site.co
Command: ```bash kubectl create service externalname external-authentication-service --external-name sandbox-site.co ``` 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...
Import specific keys from a config map in a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-name-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 defini...
Output the modified cache-cluster-deployment deployment in YAML format, without altering the object on the server, and set the SMTP_USERNAME environment variable to "your-username".
Command: ```bash kubectl set env deployment/cache-cluster-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 o...
Import specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/namespace-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Import specific keys from a config map to set as environment variables for a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/ui-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Add a taint to 'backup-node-14' with the key 'hardware' and no value
Command: ```bash kubectl taint nodes backup-node-14 hardware: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...
Create a service for replicated wordpress on port 80, connecting to containers on port 8000
Command: ```bash kubectl expose rs wordpress --port=5000 --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 the specified po...
Expose the replicated Wordpress deployment as a service on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose rc wordpress --port=5000 --target-port=800000 ``` 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 po...
Get deployments in JSON output format in the "v1.1.0" version of the "web-apps" API group
Command: ```bash kubectl get deployments.v1.1.0.web-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 you will o...
Create a job named "audit-job" using the busybox image.
Command: ```bash kubectl create job audit-job --image=busybox ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yam...
Forward local port 5432 to the target port of the "https" service port in a pod selected by the service "search-service"
Command: ```bash kubectl port-forward service/search-service 5432: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 selecte...
import the "api_key" key from the "global-config" config map and set it as an environment variable for the "order-processing-deployment" deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/global-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 definit...
Add a taint with the key 'zone' and the value 'worker-node-3:PreferNoSchedule' to the nodes labeled with 'component=proxy'.
Command: ```bash kubectl taint node -l component=proxy zone=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": "", "usage": "...
Update the image of all containers in the 'development' daemonset to 'debian:11.0'
Command: ```bash kubectl set image daemonset development *=debian:11.0 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `...
Set the custom TLS server name to 'my-k8s-cluster' for the 'prod-cluster' cluster entry
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=my-k8s-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...
Forward local ports 5000 and 6000 to ports 5432 and 6000 in the selected pod of the deployment named "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5000 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 po...
Create a copy of the 'auth-service-pod' with a debug container, using the image 'debian'
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-api --image=debian --set-image=api=api:v2,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 and ...
Expose a replication controller as a service with specified ports
Command: ```bash kubectl expose rc hazelcast --port=7000 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Update the image of all containers in the daemonset "test" to "httpd:2.4.48"
Command: ```bash kubectl set image daemonset test *=httpd:2.4.48 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubect...
Remove the "client-secret" value for the OpenID Connect auth provider for the "cloud-user" entry
Command: ```bash kubectl config set-credentials cloud-user --auth-provider=oidc --auth-provider-arg=client-secret- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-...
Create a new config map named app-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/options/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 creating ...
Begin streaming the logs of the code-explorer container in the monitoring-pod
Command: ```bash kubectl logs -f -c code-explorer monitoring-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", ...
Import the 'external_api_url' key from the 'kube-system-config' config map to the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --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 varia...
Execute the 'jenkins --version' command in the time-machine container within the e-commerce-pod and retrieve the output.
Command: ```bash kubectl exec e-commerce-pod -c time-machine -- jenkins --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 o...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-settings deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Import the "redis_host" key from the "app-config" config map and set it as an environment variable for the "cache-cluster-deployment" deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-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 definition...
delete the context for the specified cluster
Command: ```bash kubectl config delete-context cloud-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Create a job named "security-scan-job" that runs the command "geth version" using the Ethereum client-go image
Command: ```bash kubectl create job security-scan-job --image=ethereum/client-go -- geth 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...
Copy the directory /tmp/foo_dir from the remote pod logging-agent-pod-7 in the kube-system namespace to the local directory /etc/kubernetes.
Command: ```bash kubectl cp kube-system/logging-agent-pod-7:/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,...
Update the image of all containers in the daemonset named "development" to "php:7.4.22".
Command: ```bash kubectl set image daemonset development *=php:7.4.22 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `k...
Update the annotation 'git-repo' of the pod 'cdn' with the value 'https://github.com/example/my-app', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods cdn git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger t...
Copy the ~/.config/kube file from a remote pod named "front-end-pod-12" in the "cert-manager" namespace to the local directory "/tmp/bar_dir".
Command: ```bash kubectl cp cert-manager/front-end-pod-12:~/.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, us...
Apply a taint with the key 'special' on nodes that have the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend special=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": "", "usage": ...
Check if you have permission to list the job named "log-analysis-job" in the "kube-node-lease" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-analysis-job -n kube-node-lease ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Create a new config map named 'app-name-config' from the key=value pairs in the file located at 'path/to/properties'
Command: ```bash kubectl create configmap app-name-config --from-file=path/to/properties ``` 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 bas...
Set the service account of the deployment 'order-processing-deployment' to 'tiller'
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment tiller ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `ku...
Update the node specified in "node.json" with the changes defined in the strategic merge patch provided in "cni.conf"
Command: ```bash kubectl patch -f cni.conf -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: `kubectl patch ...
Add a taint with key 'cpu-type' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 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": "", "usage"...
Forward local port 8080 to port 8888 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8080: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...
Create a pod disruption budget named frontend-pdb that will select all pods with the project=my-project label and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=project=my-project --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=...
Create a secret named tls-certificate-secret from environment file.
Command: ```bash kubectl create secret generic tls-certificate-secret --from-env-file=path/to/configurations.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 defaul...
Create a cluster role named "foo" with ResourceName specified
Command: ```bash kubectl create clusterrole foo --verb=connect --resource=configmaps --resource-name=app-worker-1 --resource-name=database-master ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Forward traffic between local ports 8080 and 6379 to a pod selected by the deployment "notification-handler-deployment".
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8080 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 ...
Create a job to run a command within a container named "database-seeding-job"
Command: ```bash kubectl create job database-seeding-job --image=amazonlinux -- /bin/bash -c "echo 'Hello ``` 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": "...
Import the SECRET_KEY from the kube-system-config config map and set it as an environment variable for the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/kube-system-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 de...
Set the cluster for a specific context in the Kubernetes configuration file.
Command: ```bash kubectl config set contexts.on-prem-context.cluster my-k8s-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/ui-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Partially update a node using a strategic merge patch and specify the patch as a JSON
Command: ```bash kubectl patch node backup-node-14 -p '{"spec":{"someField":"newValue"}' ``` 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]` H...
Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc nginx --port=80 --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 specified port. A ...
List deployments in YAML format using the v2.1.0 version of the apps API group.
Command: ```bash kubectl get deployments.v2.1.0.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 will only ...
Start a Jenkins pod named "hazelcast" using the "jenkins" image and expose port 8080.
Command: ```bash kubectl run hazelcast --image=jenkins --port=8080 ``` 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": "--...
Start streaming the logs of the nano-bot container in the cdn-service-pod pod.
Command: ```bash kubectl logs -f -c nano-bot cdn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Create an ingress named 'service-ingress' that routes requests from site.com/bar to svc1:8083 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="site.com/bar=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Create a new config map named "namespace-config" with the key1 as "config1" and the key2 as "config2"
Command: ```bash kubectl create configmap namespace-config --from-literal=conf=config1 --from-literal=data=config2 ``` 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 k...
Create a copy of the 'frontend-pod' and change all container images to 'docker.elastic.co/elasticsearch/elasticsearch'
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-api --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` 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....
Create an ingress called 'www-ingress' that routes requests from foo.com/module to svc1:8089 with TLS encryption using the secret "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/module=svc1:8089,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Import the API_KEY key from the db-config config map and set it as an environment variable in the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
Create an ingress called 'public-ingress' that directs requests to a specific path and service with a TLS secret
Command: ```bash kubectl create ingress public-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": "", "u...
Import the 'redis_host' key from the 'log-config' ConfigMap and set it as an environment variable in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/log-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Display the resource usage metrics for pods with the label 'customer=acme-corp'
Command: ```bash kubectl top pod -l customer=acme-corp ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAM...
Add a 'Preferred NoSchedule' taint with key 'cpu-type' on nodes having the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 cpu-type=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Update the image of all containers in the daemonset called namespace-1 to 'mysql:5.7.35'
Command: ```bash kubectl set image daemonset namespace-1 *=mysql:5.7.35 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: ...
Retrieve the output from running the 'ash' command in the 'warp-drive' container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c warp-drive -- ash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Create a new config map named env-vars with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --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 m...
List the replication controller 'web', service 'web-app-rc' and pod 'proxy-server-pod'
Command: ```bash kubectl get rc/web service/web-app-rc pods/proxy-server-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 namespace...
Create a cluster role named "reader" with permissions to list, create, and connect to namespaces and namespaces/status subresources.
Command: ```bash kubectl create clusterrole reader --verb=list,create,connect --resource=namespaces,namespaces/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]` Helpful flags: "...
Retrieve a list of deployments in the "legacy-apps" API group with version "v3.0.0" in JSON format.
Command: ```bash kubectl get deployments.v3.0.0.legacy-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 you wil...
Scale the resource specified in the "parameters.yaml" file to have 5 replicas.
Command: ```bash kubectl scale --replicas=5 -f parameters.yaml ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is vali...
Create a cluster role named "admin_role" with AggregationRule specified
Command: ```bash kubectl create clusterrole admin_role --aggregation-rule="rbac.example.com/aggregate-to-security=true" ``` 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]` Helpful flags:...
Return snapshot logs from the container "media-stream-pod-1" of the deployment named "user-management-deployment"
Command: ```bash kubectl logs deployment/user-management-deployment -c media-stream-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags...
Update the annotation 'last-deployment' of the pod 'media-stream' to '2023-03-15', overwriting the existing value
Command: ```bash kubectl annotate --overwrite 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 lab...
Update the pod named 'auth' by adding or updating the annotation 'owner' with the value 'alice-smith'
Command: ```bash kubectl annotate --overwrite pods auth owner='alice-smith' ``` 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...
Copy the local file /tmp/foo to the remote pod kube-dns/message-broker-pod-15 in the /tmp/bar directory.
Command: ```bash kubectl cp /tmp/foo kube-dns/message-broker-pod-15:/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 kub...