prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Build the shared configuration directory located at /etc/kube/config/testing using kustomize.
Command: ```bash kubectl kustomize /etc/kube/config/testing ``` What it does: Build a set of KRM resources using a 'kustomization.yaml' file. The DIR argument must be a path to a directory containing 'kustomization.yaml', or a git repository URL with a path suffix specifying same with respect to the repository root. I...
Add a taint with key 'dedicated' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production dedicated=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": "", "usag...
configure the server field for the kube-cluster-1 cluster, set it to the URL https://1.2.3.4
Command: ```bash kubectl config set clusters.kube-cluster-1.server https://1.2.3.4 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you...
Set the certificate authority data field on the staging-cluster cluster
Command: ```bash kubectl config set clusters.staging-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) ``` 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 conta...
Create a new config map named namespace-config in the current namespace, using the specified files as the values for the settings and key2 keys
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/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 creating a ...
Create a new config map named monitoring-config from an environment file.
Command: ```bash kubectl create configmap monitoring-config --from-env-file=path/to/options.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 ...
Add a taint with the key 'cpu-type' on nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha cpu-type=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": "",...
Copy a file from a remote pod to the local machine
Command: ```bash kubectl cp kube-flannel/worker-pod-4::/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 kubectl...
Create a new ExternalName service named external-third-party-api-service with the external name practice-online.site
Command: ```bash kubectl create service externalname external-third-party-api-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 r...
Create an ingress resource called 'external-ingress' that directs requests made to the URL testing.com/bar to the service svc1 on port 5432
Command: ```bash kubectl create ingress external-ingress --rule="testing.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": "", "usa...
Create an ingress called 'app1-ingress' that directs requests to a specific website module to a service, and use a TLS secret for secure communication.
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/module=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
create a new job named "test-job" based on the configuration of the cron job named "data-processing"
Command: ```bash kubectl create job test-job --from=cronjob/data-processing ``` 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. On...
Set the service account for a deployment to "tiller"
Command: ```bash kubectl set serviceaccount deployment mydeployment 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: `kubectl set servi...
Update the annotation 'deployment-script' of the pod 'frontend' with the value 'https://example.com/deploy.sh', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods frontend deployment-script='https://example.com/deploy.sh' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can b...
Retrieve the password for the dev-cluster user by viewing the Kubernetes configuration in JSON format and extracting the password for the user named "dev-cluster".
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "dev-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` Helpful ...
Print the result, in YAML format, of updating the nginx container image from the local file located at 'path/to/file.yaml' to 'amazonlinux:2', without making any changes on the server.
Command: ```bash kubectl set image -f path/to/file.yaml amazonlinux=amazonlinux:2 --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),...
Add a taint 'workload' with no value to node 'dev-node-4'
Command: ```bash kubectl taint nodes dev-node-4 workload: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 new secret named encryption-key-secret with specified keys instead of names on disk
Command: ```bash kubectl create secret generic encryption-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 ...
Add a taint with key 'zone' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production zone=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": ""...
Create an ingress named 'service-ingress' with the rule that directs requests for 'testing.com/module' to 'svc1:9091' and use the TLS secret named "my-cert".
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/module=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": "", "u...
Create a new config map named "api-config" and include the specified files as keys in the config map.
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/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 a con...
If the deployment named 'baz' currently has a size of 5 replicas, scale the deployment 'mysql' to 7 replicas.
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/baz ``` 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 spec...
Retrieve the output of the command `pg_dump --version` from the pod `chat-app-pod` using the container `code-explorer`.
Command: ```bash kubectl exec chat-app-pod -c code-explorer -- pg_dump --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 om...
Forward port 8888 from all addresses to port 8888 in the pod named 'api-service-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8888: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 w...
Create a role named "default_role" with ResourceName specified as "auth-proxy" and "billing-service".
Command: ```bash kubectl create role default_role --verb=list --resource=pods --resource-name=auth-proxy --resource-name=billing-service ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=serve...
Create a new config map named app-secrets with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/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 a...
Forward local port 3000 to port 8081 in pod/api-service-pod
Command: ```bash kubectl port-forward pod/api-service-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 au...
Forward traffic from local port 3000 to pod port 8088 in the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod 3000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Execute the 'geth version' command inside the 'email-service-pod' pod and display the output.
Command: ```bash kubectl exec email-service-pod -- geth 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 ku...
Execute the 'apk add curl' command within the container of the pod 'mypod' and retrieve the output.
Command: ```bash kubectl exec mypod -- apk add curl ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubern...
Add a taint with key 'cpu-type' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp cpu-type=node-2: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 a new ClusterIP service named billing-service-clusterip
Command: ```bash kubectl create service clusterip billing-service-clusterip --tcp=8080:8083 ``` 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"...
Add a taint with key 'environment' on the nodes having the label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 environment=node-2: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": "O...
Create a cluster role named "reader" with specified ResourceNames
Command: ```bash kubectl create clusterrole reader --verb=exec --resource=services --resource-name=nginx-proxy --resource-name=app-worker-1 ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|no...
Retrieve snapshot logs from all containers in pods labeled with instance=app-instance-1
Command: ```bash kubectl logs -l instance=app-instance-1 --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "...
Copy the kube config file from a remote pod to the local /etc/kubernetes directory.
Command: ```bash kubectl cp metallb-system/database-pod-2:~/.config/kube /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Add a taint with key 'workload' on nodes having label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 workload=node-2: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 named "ingdefault" using the default class with a default backend
Command: ```bash kubectl create ingress ingdefault --class=default \ --default-backend=defaultsvc:http \ --rule="site.com/*=svc:8443,tls=secret1" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--o...
Create a debug copy of the chat-app-pod, changing all container images to nginx
Command: ```bash kubectl debug chat-app-pod --copy-to=debug-image-api --set-image=*=nginx ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Add a taint with the key 'special' and the value 'gpu-node-12:PreferNoSchedule' on nodes that have the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe special=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": "...
Create an ingress called 'private-api-ingress' that directs requests to foo.com/bar to svc1:8080 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/bar=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...
Delete the pods and services named "foo" and "backend"
Command: ```bash kubectl delete pod,service foo 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. Som...
Execute the 'bash' command inside the container of the pod named database-pod and display the output.
Command: ```bash kubectl exec database-pod -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kuberne...
Forward a local port to a specific port in a pod.
Command: ```bash kubectl port-forward pod/mypod :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 automatically. T...
Create an ingress named 'web-ingress' that directs traffic from site.com/input to svc1:8443 using the tls secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="site.com/input=svc1:8443,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": "...
Start a Jenkins pod with the name 'hazelcast' and have the container inside the pod expose port 7000
Command: ```bash kubectl run hazelcast --image=jenkins --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: "flag": "--...
Create a job to collect logs by running a specific command
Command: ```bash kubectl create job log-collection --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": ...
Output the modified 'backend-microservice-deployment' deployment file in YAML format with the environment variable 'API_KEY' set to 'your-api-key', without making any changes to the actual object on the server.
Command: ```bash kubectl set env deployment/backend-microservice-deployment API_KEY=your-api-key -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
Start a redis pod named hazelcast with the redis image and expose port 8181
Command: ```bash kubectl run hazelcast --image=redis --port=8181 ``` 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...
Set the service account for the deployment "authentication-service-deployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment kube-dns ``` 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 Syn...
Import the DATABASE_URL key from the config map "namespace-config" and set it as an environment variable in the "api-server-deployment" deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/namespace-config deployment/api-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 defin...
Apply resources from a directory using kustomization.yaml
Command: ```bash kubectl apply -k parameters/ ``` 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...
View snapshot logs from the gateway-pod with multiple containers
Command: ```bash kubectl logs gateway-pod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Update the deployment 'database-deployment' by adding a new environment variable called MONGO_URI with the value 'mongodb://localhost:27017/mydb'
Command: ```bash kubectl set env deployment/database-deployment MONGO_URI=mongodb://localhost:27017/mydb ``` 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...
Update the image of all containers in the 'test' daemonset to 'golang:1.17'
Command: ```bash kubectl set image daemonset test *=golang:1.17 ``` 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: `kubectl...
Delete the pods and services named "gateway" and "proxy"
Command: ```bash kubectl delete pod,service gateway proxy ``` 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. S...
Create a deployment named sonarqube with the mongo image and port 27017 exposed
Command: ```bash kubectl create deployment sonarqube --image=mongo --port=27017 ``` 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...
Update the label of the pod to specify the tier as database
Command: ```bash kubectl label pods cdn tier=database ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If ...
Add a taint with key 'hardware' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database hardware=node-2: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 local port 9090 to port 8088 in the pod
Command: ```bash kubectl port-forward pod/api-service-pod 9090:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
View the most recent 31 lines of logs for the pod named gateway-pod.
Command: ```bash kubectl logs --tail=31 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", "short": "-c"...
Check if the current user has permission to list the job named "log-rotation-job" in the "kube-public" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n kube-public ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial U...
Create a new config map named app-config, using the files file1.txt and file2.txt located at the specified paths in parameters and data, respectively.
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/data/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 ...
Create a pod disruption budget named 'monitoring-pdb' that will select all pods with the 'project=my-project' label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-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-availabl...
Create a copy of the database-pod with a debug container and changing container images
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-web --image=debian --set-image=api=api:v2,mailer=mailer: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 na...
List deployments in YAML output format for the "hotfix-1.1.2" version of the "my-apps" API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.my-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 w...
Update the deployment 'search-engine-deployment' by adding a new environment variable named LOG_LEVEL with the value 'info'.
Command: ```bash kubectl set env deployment/search-engine-deployment LOG_LEVEL=info ``` 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 ...
Install curl in the time-machine container of the web-app-pod.
Command: ```bash kubectl exec web-app-pod -c time-machine -- apk add curl ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Create an ingress resource called 'api-gateway-ingress' that routes requests for 'testing.com/input' to the service 'svc1' on port 7000, and uses a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/input=svc1:7000,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": "",...
Set the OpenID Connect auth provider for the "dev-user" entry with the client ID and client secret provided.
Command: ```bash kubectl config set-credentials dev-user --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --cl...
Update the label for the 'web' pod only if it has not changed from version 1
Command: ```bash kubectl label pods web status=unhealthy --resource-version=1 ``` 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"...
Update the annotation 'last-deployment' of pod 'log-aggregator' to '2023-03-15', overwriting the current value if it exists.
Command: ```bash kubectl annotate --overwrite pods log-aggregator 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 l...
Forward local port 9090 to port 8888 in the pod "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 9090: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 aut...
Create a service for the replicated python application, which serves on port 80 and connects to the containers on port 300000
Command: ```bash kubectl expose rc python --port=80 --target-port=300000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Create a job named "security-scan-job" using the "mysql" image and run the command "mysqld" within the job.
Command: ```bash kubectl create job security-scan-job --image=mysql -- mysqld ``` 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 debug image named debug-image-1 from the analytics-pod with all container images changed to ubuntu
Command: ```bash kubectl debug analytics-pod --copy-to=debug-image-1 --set-image=*=ubuntu ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Set the service account for a deployment to a specific service account
Command: ```bash kubectl set serviceaccount deployment web-app-deployment my-service-account ``` 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: ...
Set the client key for the service account without modifying other values.
Command: ```bash kubectl config set-credentials service-account --client-key=~/.kube/admin.key ``` 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-key=keyfile Bearer t...
Set the cluster field in the specified context to the specified cluster
Command: ```bash kubectl config set contexts.user-b-context.cluster staging-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...
Add a taint with key 'environment' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 environment=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...
Create a job named "batch-processing" using the "alpine" image and run the command "ash" inside the job.
Command: ```bash kubectl create job batch-processing --image=alpine -- ash ``` 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...
Create a service for the replicated php using replica set, which serves on port 8888 and connects to the containers on port 500000
Command: ```bash kubectl expose rs php --port=8888 --target-port=500000 ``` 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 ...
Forward local port 8081 to port 9090 on a pod selected by the deployment "monitoring-stack-deployment"
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 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 ...
Forward port 6379 from your local machine to port 8000 in the pod named chat-app-pod
Command: ```bash kubectl port-forward pod/chat-app-pod 6379:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Set up a new execution authentication plugin for the "app-operator" entry by specifying the executable path and the API version.
Command: ```bash kubectl config set-credentials app-operator --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` 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: ...
Copy the local file /tmp/foo to /tmp/bar inside the front-end-pod-12 pod in the rook-ceph namespace
Command: ```bash kubectl cp /tmp/foo rook-ceph/front-end-pod-12:/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 kubectl...
Create a config map named global-config using specified files for the values
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/parameters/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 ...
Output the modified proxy-service-deployment deployment in YAML format, with the newly added environment variable DB_USER set to "username", without actually applying the changes on the server.
Command: ```bash kubectl set env deployment/proxy-service-deployment DB_USER=username -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod ...
Attach and get output from the rocket-ranger container in the auth-service-pod
Command: ```bash kubectl attach auth-service-pod -c rocket-ranger ``` 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 omitte...
Import specific keys from a config map to environment variables
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-name-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Create a new config map named env-vars with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/path/to/configurations/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 creat...
Display the details of revision 5 for the 'test' daemonset
Command: ```bash kubectl rollout history daemonset/test --revision=5 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to fi...
Create a copy of the "proxy-server-pod" with a debug container and changes to container images
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-api --image=debian --set-image=web=nginx:latest,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Execute command to add curl to nano-bot container in web-app-pod
Command: ```bash kubectl exec web-app-pod -c nano-bot -- apk add curl ``` 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 ...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=log_level --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 defin...
Scale a resource to 1 replica using the parameters specified in the "parameters.yaml" file.
Command: ```bash kubectl scale --replicas=1 -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...
Copy a file from a remote pod to the local machine location
Command: ```bash kubectl cp cert-manager/worker-pod-4:/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 kubectl....
Import the MAX_CONNECTIONS key from the config map 'ui-config' into the environment variables of the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/ui-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Create a new config map named 'db-config' with the keys 'conf' and 'data' using the specified files '/path/to/properties/file1.txt' and '/path/to/options/file2.txt'
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/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 creating a confi...
Update the label 'status' of the pod 'gateway' to 'unhealthy', replacing any existing value
Command: ```bash kubectl label --overwrite pods gateway status=unhealthy ``` 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": "fa...