prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Edit the loadbalancer-service using the vim editor
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/loadbalancer-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment varia...
Set the resource requests and limits for all containers in the 'mysql' deployment to cpu=2, memory=512Mi limits and cpu=200m, memory=512Mi requests.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=512Mi ``` 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...
Create a secret named azure-storage-secret with keys for each file in the specified folder
Command: ```bash kubectl create secret generic azure-storage-secret --from-file=path/to/options ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename...
Update the image of all containers in the daemonset namespace-1 to 'php:7.4.22'
Command: ```bash kubectl set image daemonset namespace-1 *=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...
Create a copy of the database-pod and launch a debugging session for the rocket-ranger container with an interactive terminal.
Command: ```bash kubectl debug database-pod -it --copy-to=my-custom-dbg --container=rocket-ranger -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by defa...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl cp metallb-system/metrics-exporter-pod-10:/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,...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=redis_host --from=configmap/api-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Retrieve snapshot logs from the container "email-service-pod-1" of the deployment "backend-microservice-deployment"
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c email-service-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...
Copy the file located at ~/.config/kube to the /tmp/bar directory within the container named image-resizer in the pod named database-pod-2
Command: ```bash kubectl cp ~/.config/kube database-pod-2::/tmp/bar -c image-resizer ``` 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...
Add a taint with key 'datacenter' on nodes having label team=devops, and the taint value as 'dev-node-4:PreferNoSchedule'
Command: ```bash kubectl taint node -l team=devops datacenter=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": "O...
Import the REDIS_HOST key from the app-settings config map and set it as an environment variable in the authentication-service-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-settings 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...
Create a new LoadBalancer service named proxy-server-lb
Command: ```bash kubectl create service loadbalancer proxy-server-lb --tcp=8089:9091 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Create a debug version of the proxy-service-pod by adding a debug container and changing container images.
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=cache=redis:alpine,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 resour...
Create a new config map named app-secrets with specific keys and their corresponding values from files
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/parameters/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...
Copy the `kube` file from the `~/.config/kube` directory of the `message-broker-pod-15` pod to the `/tmp/bar` directory on the local machine
Command: ```bash kubectl cp kube-public/message-broker-pod-15:~/.config/kube /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Create a job named 'security-scan-job' using the 'golang' image, and run the command 'go version' in the job
Command: ```bash kubectl create job security-scan-job --image=golang -- go 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 for...
Import specific keys from a config map into an application deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/global-config deployment/analytics-platform-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...
Copy the local file `/tmp/foo` to the remote pod `security-scanner-pod-18` at `/tmp/bar`, specifically in the `worker-container` container.
Command: ```bash kubectl cp /tmp/foo security-scanner-pod-18::/tmp/bar -c worker-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", "default": "", "usage": "Container name. If omitte...
Forward traffic from port 3000 on all addresses to port 5000 in the mypod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 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 sel...
Forward port 8888 in the pod `api-service-pod` to port 8000 on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8000: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...
Add a taint with the key 'hardware' on nodes that have the label 'release=beta', specifically on the node 'worker-node-3', with the effect of 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l release=beta hardware=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": ...
List the deployments in JSON output format for the "feature-branch-2.3.0" version of the "prod-apps" API group
Command: ```bash kubectl get deployments.feature-branch-2.3.0.prod-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 namesp...
Open the 'analytics-service' service for editing
Command: ```bash kubectl edit svc/analytics-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to...
Add a taint with the key 'dedicated' and value 'k8s-node-1:PreferNoSchedule' on nodes that have the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 dedicated=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Import specific keys from a config map to environment variables in a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-secrets deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Remove a label named 'bar' from the pod named 'vpn'
Command: ```bash kubectl label pods vpn tier- ``` 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 true, ch...
Auto scale the replication controller "auth" with a target CPU utilization of 40% and a maximum of 6 pods.
Command: ```bash kubectl autoscale rc auth --max=6 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses th...
Create a new cluster role named "custom_role" that allows listing config maps with specific resource names such as "mail-server" and "notification-service"
Command: ```bash kubectl create clusterrole custom_role --verb=list --resource=configmaps --resource-name=mail-server --resource-name=notification-service ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=s...
Create a secret named 'docker-registry-secret' with specified keys, instead of names on disk.
Command: ```bash kubectl create secret generic docker-registry-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...
Set the custom TLS server name to "e2e" for the app-cluster cluster entry.
Command: ```bash kubectl config set-cluster app-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-authority...
Create a pod disruption budget named notification-service-pdb that will select all pods with the owner=team-1 label and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=owner=team-1 --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-avai...
Add a taint with key 'datacenter' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 datacenter=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": "Ou...
Partially update a node by applying a strategic merge patch specified in YAML format
Command: ```bash kubectl patch node testing-node-11 -p $'spec:\n type: LoadBalancer' ``` 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]` Helpf...
Execute the 'python' command in the 'cyber-sleuth' container from the 'api-service-pod' pod and get the output.
Command: ```bash kubectl exec api-service-pod -c cyber-sleuth -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Delete the pods and services with the names "chat-app" and "api"
Command: ```bash kubectl delete pod,service chat-app api ``` 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. So...
Forward local port 8000 to port 8888 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-pod 8000 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Set the service account of the deployment "gateway-deployment" to the default service account.
Command: ```bash kubectl set serviceaccount deployment gateway-deployment default ``` 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 se...
Forward traffic from port 6379 on both localhost and IP address 10.19.21.23 to port 9090 in the frontend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 6379: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 criter...
Create a copy of the 'security-service-pod' and add a 'debug' container with updated images
Command: ```bash kubectl debug security-service-pod -it --copy-to=debug-image-api --image=debian --set-image=cache=redis:alpine,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifie...
Update the environment variable 'ENV' of the deployment 'backend-microservice-deployment' to 'prod'
Command: ```bash kubectl set env deployment/backend-microservice-deployment ENV=prod ``` 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...
Start a pod named nginx using the ruby image and pass custom arguments to the default command.
Command: ```bash kubectl run nginx --image=ruby -- <arg1> <arg2> ... <argN> ``` 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: "f...
Create an ingress called 'public-service-ingress' that maps requests for website.com/input to the service svc1:9091
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/input=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": ...
Update the pod identified by the type and name specified in the "options.json" file, adding the annotation "security-scan-status" with the value "pass"
Command: ```bash kubectl annotate -f options.json security-scan-status=pass ``` 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...
Create a pod disruption budget named cron-jobs-pdb that selects all pods with the owner=team-1 label and ensures that a minimum of four of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=owner=team-1 --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=N [--...
Set the cluster for a specific context
Command: ```bash kubectl config set contexts.client-2-context.cluster cluster-alpha ``` 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...
Create an ingress named 'private-service-ingress' that routes requests for the path '/bar' on the domain 'website.com' to the service named 'svc1' on port 5001
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/bar=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Forward traffic from local port 3000 to port 8080 in the pod called cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 3000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Check if you have permission to list the job named "security-scan-job" in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/security-scan-job -n default ``` 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 URL ...
Auto scale the replication controller 'gateway', allowing a minimum of 1 and a maximum of 3 pods, with a target CPU utilization of 50%.
Command: ```bash kubectl autoscale rc gateway --max=3 --cpu-percent=50 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Import the 'CONFIG_FILE_PATH' key from the 'namespace-config' config map to the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/namespace-config deployment/analytics-platform-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 va...
Create a job named 'backup' with the 'alpine' image and the command 'apk add curl'
Command: ```bash kubectl create job backup --image=alpine -- apk add curl ``` 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 ...
Copy the local directory "/tmp/foo_dir_dir" to the remote pod "ingress-controller-pod-8" in the "/tmp/bar_dir" directory.
Command: ```bash kubectl cp /tmp/foo_dir_dir ingress-controller-pod-8:/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 t...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/namespace-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 variab...
Get the output from running the 'python --version' command in the stardust-shuttle container of the api-service-pod pod.
Command: ```bash kubectl exec api-service-pod -c stardust-shuttle -- python --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. ...
Create a cluster role named "foo" with SubResource specified.
Command: ```bash kubectl create clusterrole foo --verb=use,get,patch --resource=nodes,nodes/proxy ``` 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: "flag": "--output", "...
Copy the '/var/run/secrets/kubernetes.io/serviceaccount/' file from your local machine to the '/tmp/bar' directory in the 'metrics-exporter-pod-10' pod
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ metrics-exporter-pod-10:/tmp/bar -c front-end-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", "default":...
View the list of environment variables defined on the 'api-server-deployment' deployment.
Command: ```bash kubectl set env deployment/api-server-deployment --list ``` 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 (within rep...
Create a new ClusterIP service named cache-service-clusterip that listens on port 8081 and forwards the traffic to port 9090.
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=8081:9090 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
Create an ingress called 'app-gateway-ingress' with a rule that directs requests from testing.com/module to svc1:8081
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/module=svc1:8081,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": ""...
Taint nodes with label 'release=beta' with the key 'dedicated' and set the effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l release=beta dedicated=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": "", "usage...
Copy the local file "/tmp/foo_dir" to the remote pod "admin-dashboard-pod-16" in the container "metrics-exporter" in the directory "/etc/kubernetes".
Command: ```bash kubectl cp /tmp/foo_dir admin-dashboard-pod-16:/etc/kubernetes -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. ...
Execute the command 'apache2ctl -D FOREGROUND' in the lunar-launcher container of the proxy-server-pod and get the output
Command: ```bash kubectl exec proxy-server-pod -c lunar-launcher -- apache2ctl -D FOREGROUND ``` 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...
Set the service account of the deployment "backend-microservice-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment fluentd ``` 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...
Update the service account of the "email-server-deployment" deployment to "kube-proxy"
Command: ```bash kubectl set serviceaccount deployment email-server-deployment kube-proxy ``` 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...
Create an ingress resource named 'private-ingress' that routes requests for 'site.com/example' to the service 'svc1' on port '8084'
Command: ```bash kubectl create ingress private-ingress --rule="site.com/example=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": "", "usa...
Create a new ExternalName service named external-email-service mapping to the external name "travel-sample.travel".
Command: ```bash kubectl create service externalname external-email-service --external-name travel-sample.travel ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference s...
create a copy of the proxy-server-pod and add a debug container with the image debian
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-1 --image=debian --set-image=worker=my-custom-worker:1.2.3,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifi...
Forward traffic from port 5432 on all addresses to port 8080 in the pod "web-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 5432:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Delete the pods and services named "monitoring" and "frontend"
Command: ```bash kubectl delete pod,service monitoring frontend ``` 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 selec...
Delete the pods and services named "gateway" and "media-stream"
Command: ```bash kubectl delete pod,service gateway media-stream ``` 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 sele...
Create an ingress called 'private-service-ingress' that directs requests to website.com/input to svc1 on port 8080 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/input=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":...
Set the cluster field in the "service-account-context" context to "cluster-gamma"
Command: ```bash kubectl config set contexts.service-account-context.cluster cluster-gamma ``` 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 v...
Forward local port 8888 to port 5432 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 8888: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 aut...
Copy the local file "/tmp/foo_dir" to the remote pod "file-server-pod-14" and place it in the "/tmp/bar_dir" directory within the container named "cache-container".
Command: ```bash kubectl cp /tmp/foo_dir file-server-pod-14:/tmp/bar_dir -c cache-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", "default": "", "usage": "Container name. If omitt...
Listen on port 8088 locally and forward the data to/from port 8888 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-pod 8088 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Copy the file "/tmp/foo" from the remote pod "file-server-pod-14" to the local directory "/etc/kubernetes".
Command: ```bash kubectl cp monitoring/file-server-pod-14::/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Set the resource limits and requests for all containers in the postgres deployment
Command: ```bash kubectl set resources deployment postgres --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=2Gi ``` 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 reques...
Create a deployment named logging with the centos image and expose port 8089
Command: ```bash kubectl create deployment logging --image=centos --port=8089 ``` 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: ...
Forward local ports 8081 and 6000 to ports 8081 and 6000 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 8081 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...
Output the modified deployment in YAML format and do not make any changes to the deployment on the server
Command: ```bash kubectl set env deployment/mydeployment DB_HOST=localhost -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 templates (...
Create a pod disruption budget named messaging-pdb that selects all pods with the role=worker label and requires at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=role=worker --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=N [--d...
Create a pod disruption budget named web-app-pdb that will select all pods with the region=us-east label and require a minimum of one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=region=us-east --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 [--...
Apply the configuration in the manifest file and delete any resources that are not in the file and match the specified label.
Command: ```bash kubectl apply --prune -f manifest.yaml -l tier=frontend ``` 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 '...
Get output from the time-machine container in the backend-pod.
Command: ```bash kubectl attach backend-pod -c time-machine ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Create a pod named "nginx" using the "jenkins" image, but overwrite the specification with a partial set of values parsed from JSON in the overrides field.
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "v3.0.0", "spec": { ... } }' ``` 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] -- [COMMA...
Check if you have permission to list the job named "notification-sender-job" in the "kube-node-lease" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-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 ...
Get output from running the 'ash' command in warp-drive from pod e-commerce-pod
Command: ```bash kubectl exec e-commerce-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 the ...
Create a config map named app-settings from specified files
Command: ```bash kubectl create configmap app-settings --from-file=settings=/path/to/profiles/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 ...
Forward local port 8088 to port 5432 in the pod
Command: ```bash kubectl port-forward pod/mypod 8088 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Add a taint with the key 'disktype' on nodes having the label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 disktype=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Execute the 'mongo' command inside the 'astro-container' container in the 'media-stream-pod' pod and get the output
Command: ```bash kubectl exec media-stream-pod -c astro-container -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Update the annotation 'SLA' of pod 'proxy' with the value '99.9% uptime'
Command: ```bash kubectl annotate --overwrite pods proxy SLA='99.9% uptime' ``` 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...
Remove a specific label from a pod
Command: ```bash kubectl label pods frontend env- ``` 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 true...
Create a debug copy of the web-app-pod container, with the command for the cosmic-container being changed.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-web --container=cosmic-container -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by ...
Remove the taints with key 'special' from node 'backup-node-14'
Command: ```bash kubectl taint nodes backup-node-14 special- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yam...
Create a pod disruption budget named "cache-cluster-pdb" that selects all pods with the "release=1.0.0" label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=release=1.0.0 --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 job named data-migration-job using the image "mongo". In the job, run the command "mongo --version".
Command: ```bash kubectl create job data-migration-job --image=mongo -- mongo --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": "Outpu...
Delete the pods and services with the names "gateway" and "payment"
Command: ```bash kubectl delete pod,service gateway payment ``` 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....
Update the deployment 'order-processing-deployment' by adding a new environment variable 'JWT_SECRET=your-jwt-secret'
Command: ```bash kubectl set env deployment/order-processing-deployment JWT_SECRET=your-jwt-secret ``` 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...
Copy the contents of the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the "worker-pod-4" pod in the "default" namespace to the "/tmp/bar_dir" directory on your local machine.
Command: ```bash kubectl cp default/worker-pod-4:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "Contain...