prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Embed certificate authority data for the cluster-beta cluster entry
Command: ```bash kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/galaxy-cluster/kubernetes.ca.crt ``` 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 s...
Update the annotation 'contact-email' of the pod 'log-aggregator' with the value 'support@example.com', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods log-aggregator contact-email='support@example.com' ``` 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...
Create an ingress called 'app1-ingress' that directs requests to 'testing.com/input' to the service 'svc1:8000' using TLS secret "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="testing.com/input=svc1:8000,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 ClusterIP service with the name "monitoring-service-clusterip" and map incoming traffic on port 8010 to port 9092.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8010:9092 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "...
Create a cluster role named "view" that has the ability to patch pods and specific resource names "blog-backend" and "queue-consumer".
Command: ```bash kubectl create clusterrole view --verb=patch --resource=pods --resource-name=blog-backend --resource-name=queue-consumer ``` 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...
Apply the configuration in a file to a pod
Command: ```bash kubectl apply -f ./config.json ``` 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'. JS...
Open a raw terminal session with the lunar-launcher container in the gateway-pod and allow input from the client and output from 'bash' in lunar-launcher container.
Command: ```bash kubectl attach gateway-pod -c lunar-launcher -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Copy the local file "/tmp/foo_dir" to the remote pod "cache-pod-5" in the container named "message-broker" at the destination path "/etc/kubernetes".
Command: ```bash kubectl cp /tmp/foo_dir cache-pod-5:/etc/kubernetes -c message-broker ``` 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, u...
Create a pod named "hazelcast" using the nginx image, and assign the labels "app=nginx" and "env=prod" to the container.
Command: ```bash kubectl run hazelcast --image=nginx --labels="app=nginx,env=prod" ``` 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 fl...
Import the 'SECRET_KEY' key from the 'env-vars' config map and set it as an environment variable for the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/env-vars 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 def...
Annotate pod 'cdn' with the owner 'alice smith'
Command: ```bash kubectl annotate pods cdn 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 arbitrary stri...
Create a service for a replicated CentOS using replica set, which serves on port 7000 and connects to the containers on port 8000.
Command: ```bash kubectl expose rs centos --port=7000 --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 port....
Add a taint with key 'cpu-type' on nodes having label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack cpu-type=testing-node-11: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": "", "us...
Retrieve the snapshot logs from the container log-aggregator-pod-1 of the deployment monitoring-stack-deployment
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c log-aggregator-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 fl...
Create a copy of the 'payment-gateway-pod' and change all container images to 'redis'. Copy it to 'my-custom-dbg'
Command: ```bash kubectl debug payment-gateway-pod --copy-to=my-custom-dbg --set-image=*=redis ``` 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...
Add a taint with key 'zone' on nodes having label role=database and value dev-node-4, with the effect of PreferNoSchedule.
Command: ```bash kubectl taint node -l role=database zone=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": "Outpu...
Import the 'max_connections' key from the 'env-vars' config map and set it as an environment variable in the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/env-vars 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 definiti...
Copy the file ~/.config/kube from the local machine to /tmp/bar inside the 'admin-dashboard-pod-16' pod in the 'metallb-system' namespace.
Command: ```bash kubectl cp ~/.config/kube metallb-system/admin-dashboard-pod-16:/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...
Create a Pod Disruption Budget that selects all pods with the label "tier=frontend" and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=tier=frontend --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 ...
Modify the LOG_LEVEL environment variable of the 'order-processing-deployment' deployment to 'info' and output the modified deployment in YAML format without altering the object on the server.
Command: ```bash kubectl set env deployment/order-processing-deployment LOG_LEVEL=info -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...
Expose a service for a replication controller identified by type and name specified in "nginx-controller.yaml", which serves on port 3000 and connects to the containers on port 8888
Command: ```bash kubectl expose -f nginx-controller.yaml --port=3000 --target-port=888800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the ...
Approve the Certificate Signing Request with the name 'csr-ghi789' by running the command 'kubectl certificate approve csr-ghi789'
Command: ```bash kubectl certificate approve csr-ghi789 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attribu...
Run the 'docker run -it ubuntu' command inside the 'nebula-navigator' container in the 'e-commerce-pod' pod and get the output
Command: ```bash kubectl exec e-commerce-pod -c nebula-navigator -- docker run -it ubuntu ``` 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...
Create a single ingress called 'api-v1-ingress' that directs requests to site.com/module to svc1:8084 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="site.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": "", "usage...
Copy the file ~/.config/kube to the /tmp/bar directory inside the pod kube-flannel/cache-pod-5 in the namespace kube-flannel/cache-pod-5.
Command: ```bash kubectl cp ~/.config/kube kube-flannel/cache-pod-5:/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...
Restart the app-v2 deployment
Command: ```bash kubectl rollout restart deployment/app-v2 ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource ...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/db-config deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Create a copy of the 'cdn-service-pod' pod and add a debug container to it. Attach to the debug container for troubleshooting.
Command: ```bash kubectl debug cdn-service-pod -it --image=busybox --copy-to=dgb-img ``` 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 resource ...
Remove a taint from a specific node if it exists
Command: ```bash kubectl taint nodes testing-node-11 disktype: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...
Create a pod named "hazelcast" using the "amazonlinux" image and enable the container to expose port 9090.
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=9090 ``` 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":...
Import the environment variables from the secret 'tls-certificate-secret' and apply them to the 'mydeployment' deployment.
Command: ```bash kubectl set env --from=secret/tls-certificate-secret deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod ...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/frontend-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 namespac...
Apply a taint with the key 'dedicated' and the value 'backup-node-14:PreferNoSchedule' to all nodes with the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha dedicated=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": ""...
Set the username and password for the "system" entry in the kubectl configuration as admin and uXFGweU9l35qcif respectively.
Command: ```bash kubectl config set-credentials system --username=admin --password=uXFGweU9l35qcif ``` 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 Bear...
Copy the file at /var/run/secrets/kubernetes.io/serviceaccount/ from the local machine to the /tmp/bar_dir directory in the admin-dashboard-pod-16 pod in the cert-manager namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cert-manager/admin-dashboard-pod-16:/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": "", "u...
Copy the file /tmp/foo from the pod backend-pod-13 in the kube-proxy namespace to the directory /tmp/bar_dir on the local machine.
Command: ```bash kubectl cp kube-proxy/backend-pod-13:/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Set the client-key-data field in the deploy-bot user with the provided cert_data_here using the --set-raw-bytes=true option
Command: ```bash kubectl config set users.deploy-bot.client-key-data cert_data_here --set-raw-bytes=true ``` 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_VALU...
Autoscale a replication controller "frontend" to have a minimum of 1 pod, a maximum of 3 pods, and target CPU utilization at 60%
Command: ```bash kubectl autoscale rc frontend --max=3 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Scale the replication controller "chat-app" automatically based on CPU utilization, with a maximum of 8 pods and a target CPU utilization of 90%.
Command: ```bash kubectl autoscale rc chat-app --max=8 --cpu-percent=90 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Import the keys "config_file_path" from the config map "app-name-config" into the environment of the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-name-config 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 v...
Forward port 8081 on localhost and IP 10.19.21.23 to port 5432 in the pod called "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8081: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 p...
Create a single ingress called 'www-ingress' that directs requests to website.com/example to svc1 on port 8089 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="website.com/example=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": "", "usag...
Create an ingress called 'api-v2-ingress' that directs requests from site.com/module to svc1:8081
Command: ```bash kubectl create ingress api-v2-ingress --rule="site.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": "", "usage...
Set the resource request and limits for all containers in the 'nginx' deployment
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Execute the 'wp' command in the cosmic-container of the web-app-pod and get the output
Command: ```bash kubectl exec web-app-pod -c cosmic-container -- wp ``` 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...
Add a taint with the key 'hardware' on nodes having the label 'instance=app-instance-1' with the effect 'PreferNoSchedule' on the node named 'node-2'
Command: ```bash kubectl taint node -l instance=app-instance-1 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": "", "usag...
Execute the command 'elasticsearch --version' in the 'log-aggregator-pod' pod and display the output.
Command: ```bash kubectl exec log-aggregator-pod -- 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 name. If omitted...
Forward local port 3000 to the targetPort of the 'https' port in the 'web-service' service-selected pod
Command: ```bash kubectl port-forward service/web-service 3000:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Forward local port 8888 to port 5000 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8888: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 selected a...
Create a deployment named logging using the php image and expose port 9092
Command: ```bash kubectl create deployment logging --image=php --port=9092 ``` 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: jso...
Import the environment variables from the 'ssl-key-secret' secret into the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --from=secret/ssl-key-secret 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 variable definitions in one o...
Copy the file ~/.config/kube to the path /tmp/bar in the database-container of the web-app-pod-1 pod.
Command: ```bash kubectl cp ~/.config/kube web-app-pod-1::/tmp/bar -c database-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 omitted,...
Set the CPU limit of the 'python' deployment's 'nginx' container to "200m" and the memory limit to "64Mi"
Command: ```bash kubectl set resources deployment python -c=nginx --limits=cpu=200m,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to...
Update the annotation 'alert-email' of the pod 'gateway' with the value 'alerts@example.com', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods gateway alert-email='alerts@example.com' ``` 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 labe...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 8888 in the pod named chat-app-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-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 criter...
Return the logs of the previous terminated 'nano-bot' container from the 'auth-service-pod' pod.
Command: ```bash kubectl logs -p -c nano-bot auth-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", "sh...
Set the CPU limit to "100m" and the memory limit to "1Gi" for the Elasticsearch container in the deployment named "elasticsearch"
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=100m,memory=1Gi ``` 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, but may burst...
Create a copy of the 'log-aggregator-pod' with a debug container and updated container images
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=my-custom-dbg --image=debian --set-image=proxy=nginx:1.21,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Display the details of the replication controller "web", the service "e-commerce-rc", and the pod "media-stream-pod".
Command: ```bash kubectl get rc/web service/e-commerce-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 namesp...
Update the 'web' pod by adding the annotation 'compliance-level' with the value 'PCI-DSS'
Command: ```bash kubectl annotate pods web 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 labels and include arbitrary...
Start streaming the logs of the 'cyber-sleuth' container in the 'payment-gateway-pod' pod
Command: ```bash kubectl logs -f -c cyber-sleuth payment-gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--containe...
Execute the 'ash' command in the 'frontend-pod' pod and retrieve the output
Command: ```bash kubectl exec frontend-pod -- 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 kubectl.kubernet...
Get the version of the 'gem' command running in the cosmic-container within the pod named mypod.
Command: ```bash kubectl exec mypod -c cosmic-container -- gem --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, u...
Copy the local file ~/.config/kube to the remote pod named metrics-exporter-pod-10 in the container named image-resizer, and place it in the /etc/kubernetes directory.
Command: ```bash kubectl cp ~/.config/kube metrics-exporter-pod-10:/etc/kubernetes -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. ...
Forward local port 8000 to port 9090 on the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 8000 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 au...
Forward local port 9090 to port 8888 in the pod "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-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 a...
Create a debug container in the existing pod "mypod" by copying the container images and providing a new image for the debug container.
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-api --image=debian --set-image=cache=redis:alpine,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name....
Forward port 3000 on localhost and selected IP to port 9090 in the pod "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 3000: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 cri...
Update the pod 'proxy-server' with the annotation 'owner' and the value 'alice smith'
Command: ```bash kubectl annotate pods proxy-server 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 arbit...
Add a taint with the key 'disktype' and value 'db-node-7:PreferNoSchedule' to nodes that have the label 'team=devops'
Command: ```bash kubectl taint node -l team=devops disktype=db-node-7: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": "Outp...
Create a service for a replication controller specified in a file, with specific port configurations
Command: ```bash kubectl expose -f node-controller.yaml --port=5000 --target-port=637900 ``` 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 s...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/kube-system-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 varia...
Switch to raw terminal mode and attach to the database-pod pod
Command: ```bash kubectl attach database-pod -c cosmic-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Import the specific keys MAX_CONNECTIONS from the config map monitoring-config into the environment variables of the proxy-service-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/monitoring-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 variabl...
Create a new config map from a file
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/profiles ``` 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 base...
Rename the context 'on-prem-context' to 'service-account-context' in your kubeconfig file
Command: ```bash kubectl config rename-context on-prem-context service-account-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this fiel...
Forward traffic from port 6379 on localhost and IP address 10.19.21.23 to port 5000 in the pod named 'proxy-server-pod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 6379: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 cr...
Add a taint to nodes in the 'us-east-1' zone with the key 'special' and value 'backup-node-14' indicating that the node prefers to not schedule new pods
Command: ```bash kubectl taint node -l zone=us-east-1 special=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": "", "usage"...
display the resource usage metrics for all pods in the external-ldap-service namespace
Command: ```bash kubectl top pod --namespace=external-ldap-service ``` 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 ...
Set a custom TLS server name for validation in the configuration of the "moon-cluster" cluster.
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=cluster-alpha ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Update the contact email annotation of the pod specified in the options.json file
Command: ```bash kubectl annotate -f options.json contact-email=support@example.com ``` 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 i...
Set the service account of the backend-microservice-deployment deployment to argocd
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment argocd ``` 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:...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-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 defi...
Display only the most recent 31 lines of output in a pod
Command: ```bash kubectl logs --tail=31 api-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", "short": ...
Expose the replication controller specified in "nginx-controller.yaml" as a service, serving on port 8082 and connecting to the containers on port 808100.
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8082 --target-port=808100 ``` 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 ...
Copy the local file "/tmp/foo" to the remote pod named "message-broker-pod-15" in the "monitoring" namespace, and place it at the path "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo monitoring/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 ...
Set environment variables from a config map for a specific deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-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 definiti...
import log_level key from app-config-prod config map into analytics-platform-deployment deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-config-prod 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 d...
Forward port 8888 on localhost and IP 10.19.21.23 to port 5432 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-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 th...
Add a taint with the key 'workload' on nodes having the label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp workload=edge-node-10:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create an ingress named 'website-ingress' that routes requests from testing.com/bar to the service named svc1 on port 6379
Command: ```bash kubectl create ingress website-ingress --rule="testing.com/bar=svc1:6379,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...
Set the server field for the cluster-gamma cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --server=https://1.2.3.4 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-auth...
Create an ingress called 'app-proxy-ingress' that directs requests to site.com/module to svc1:9092, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="site.com/module=svc1:9092,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": "", "us...
Create a deployment named 'app' using the 'ruby' image, and expose port 8080.
Command: ```bash kubectl create deployment app --image=ruby --port=8080 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|y...
Apply the strategic merge patch in the 'kube-proxy-config.yaml' file to partially update the node
Command: ```bash kubectl patch -f kube-proxy-config.yaml -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 p...
update the environment variables of the user-management deployment with the API_KEY from the monitoring-config config map
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/monitoring-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/profiles/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 cr...
Update the pod 'auth' with the annotation 'contact-email' set to 'support@example.com', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods auth contact-email='support@example.com' ``` 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 labe...
Copy a directory named "foo_dir" from a remote pod named "admin-dashboard-pod-16" in the "kube-system" namespace to the local directory "/tmp/bar".
Command: ```bash kubectl cp kube-system/admin-dashboard-pod-16:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Apply a taint to a node named 'db-node-7' with the key 'environment' and no value.
Command: ```bash kubectl taint nodes db-node-7 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:...