prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Display the most recent 20 lines of log output from the pod named proxy-service-pod.
Command: ```bash kubectl logs --tail=20 proxy-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"...
Create a new config map named app-config-dev in the default namespace, using the files located in the 'path/to/configurations' folder.
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/configurations ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the ...
Create a cluster role named "custom_role" with ResourceName specified
Command: ```bash kubectl create clusterrole custom_role --verb=list --resource=pods --resource-name=file-uploader --resource-name=dev-database ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Import the 'secret_key' key from the 'configmap/ui-config' ConfigMap into the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/ui-config deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Retrieve the output from running the 'elasticsearch-plugin --list' command from the first container of the 'load-balancer-deployment' deployment
Command: ```bash kubectl exec deploy/load-balancer-deployment -- elasticsearch-plugin --list ``` 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...
Forward port 3000 on all addresses to port 8081 in the web-app-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-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 ...
Create a copy of the chat-app-pod and name it my-debugger, while changing all container images to python.
Command: ```bash kubectl debug chat-app-pod --copy-to=my-debugger --set-image=*=python ``` 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 resourc...
Retrieve the previous terminated logs from the 'time-machine' container in the 'web-app-pod' pod.
Command: ```bash kubectl logs -p -c time-machine web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Taint node 'node-2' with a specific value
Command: ```bash kubectl taint nodes node-2 datacenter=dc-1:NoExecute ``` 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:...
Create a deployment named "registry" running the MySQL image and expose port 8000.
Command: ```bash kubectl create deployment registry --image=mysql --port=8000 ``` 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: ...
Create a copy of the security-service-pod and launch a shell session with the debug-image-web image as the container, changing the command to "sh".
Command: ```bash kubectl debug security-service-pod -it --copy-to=debug-image-web --container=nebula-navigator -- 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...
Create an ingress rule named 'app1-ingress' that directs requests from 'site.com/module' to 'svc1:9092' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app1-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": "", "usage":...
List deployments in JSON output format for the "v2.1.0" version of the "testing-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.testing-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wi...
Add a taint with the key 'hardware' to nodes that have the label 'cluster=my-cluster' and set the effect to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l cluster=my-cluster hardware=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
View the detailed information of a specific context in your kubeconfig file
Command: ```bash kubectl config get-contexts edge-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Start a pod named "hazelcast" using the "alpine" image, and have the container inside the pod expose port 9091
Command: ```bash kubectl run hazelcast --image=alpine --port=9091 ``` 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": "--f...
Forward local port 8080 to pod port 8000
Command: ```bash kubectl port-forward deployment/api-server-deployment 8080 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will b...
Set the custom TLS server name to use for validation for the cluster-beta cluster entry to "data-cluster".
Command: ```bash kubectl config set-cluster cluster-beta --tls-server-name=data-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate...
Add a taint with key 'zone' on nodes that have the label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack zone=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Set the custom TLS server name to use for validation for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --tls-server-name=cluster-gamma ``` 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-authori...
Forward local port 5432 to port 8888 in the backend-pod pod
Command: ```bash kubectl port-forward pod/backend-pod 5432: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 automa...
Forward all traffic from port 3000 on all addresses to port 5432 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 3000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/ui-config deployment/frontend-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...
Remove the taint with key 'hardware' and effect 'NoExecute' from the 'node-2' node if one exists
Command: ```bash kubectl taint nodes node-2 hardware:NoExecute- ``` 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|...
list specific resources by their type and names
Command: ```bash kubectl get rc/web service/auth-service-rc pods/email-service-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 nam...
Create a new LoadBalancer service named database-lb on port 9092 that forwards traffic to port 3306.
Command: ```bash kubectl create service loadbalancer database-lb --tcp=9092:3306 ``` 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", "defaul...
import the specific key `external_api_url` from the `monitoring-config` config map and set it as an environment variable for the `email-server-deployment` deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/monitoring-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
Create a service for the replicated ubuntu using the replica set 'ubuntu', the service should serve on port 7000 and connect to the containers on port 808800.
Command: ```bash kubectl expose rs ubuntu --port=7000 --target-port=808800 ``` 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....
Copy the local file ~/.config/kube to the /tmp/bar directory within the auth-service-pod-11 pod's backend-container container.
Command: ```bash kubectl cp ~/.config/kube auth-service-pod-11:/tmp/bar -c backend-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Add a taint with the key 'zone' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production zone=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": "...
Start a pod named hazelcast using the mysql image and expose port 8888
Command: ```bash kubectl run hazelcast --image=mysql --port=8888 ``` 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...
Edit the configuration of the 'email-service' service
Command: ```bash kubectl edit svc/email-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 'vi...
Update the 'cdn' pod with the annotation 'security-scan-status' and the value 'pass', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods cdn 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 in...
Embed the certificate authority data for the "moon-cluster" cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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 se...
Get output from the running auth-service-pod by attaching to it
Command: ```bash kubectl attach auth-service-pod ``` 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 the kubect...
Forward local port 8088 to port 9090 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8088:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Import the REDIS_HOST key from the app-secrets config map and set it as an environment variable for the order-processing-deployment deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l project=project-alpha dedicated=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": "", ...
Set the cluster field in the 'app-2-context' context to 'testing-cluster'
Command: ```bash kubectl config set contexts.app-2-context.cluster testing-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 you...
Execute the command 'mysql --version' in the running container of the first pod of the 'analytics-service' service.
Command: ```bash kubectl exec svc/analytics-service -- mysql --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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=api_key --from=configmap/log-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 definitions...
Create a copy of the backend-pod with all container images changed to postgres
Command: ```bash kubectl debug backend-pod --copy-to=debug-image-web --set-image=*=postgres ``` 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 re...
Forward local port 5000 to port 8888 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 5000: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 au...
Create an ingress called 'app-proxy-ingress', and configure it to route requests from 'website.com/input' to the service 'svc1' on port 8000
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.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": "", "...
Create an ingress called 'app-ingress' that directs requests from foo.com/module to svc1:3001 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="foo.com/module=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Forward data between local port 6379 and port 6379 in the security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 6379 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create an ingress called 'web-ingress' that directs requests from foo.com/bar to svc1:8080 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress web-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": "", "usage": "Out...
Set the custom TLS server name to "prod-cluster" for the "staging-cluster" cluster entry.
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=prod-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Execute the 'mysql --version' command in the proxy-service-pod and retrieve the output.
Command: ```bash kubectl exec proxy-service-pod -- mysql --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...
Create a service for a replicated Python application served on port 80, connected to containers on port 8000.
Command: ```bash kubectl expose rs python --port=8082 --target-port=909100 ``` 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....
Forward traffic between ports 9090 and 6000 on your local machine to ports 9090 and 6000 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod 9090 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Label the pod 'auth' with the label 'role' and the value 'backend'
Command: ```bash kubectl label pods auth role=backend ``` 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 ...
Annotate the pod 'backend' with the annotation 'security-scan-status' and the value 'pass', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods backend 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 an...
Listen to the local port 8000 and forward it to port 6379 inside the 'security-service-pod' pod.
Command: ```bash kubectl port-forward pod/security-service-pod 8000:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
create a new ClusterIP service named log-service-clusterip that maps the local port 8081 to the target port 8084
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=8081:8084 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "d...
Expose a replication controller defined in "ruby-controller.yaml" as a service on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=9091 --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 s...
Create a single ingress called 'api-v1-ingress' that directs requests to testing.com/module to svc1:27017 with the tls secret "my-cert" specified.
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/module=svc1:27017,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...
Attach to the `nano-bot` container in the `payment-gateway-pod` pod to get its output
Command: ```bash kubectl attach payment-gateway-pod -c nano-bot ``` 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,...
Set the custom TLS server name for the "sun-cluster" cluster entry
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=kube-cluster-2 ``` 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...
Forward data between local ports 8080 and 6000 to the corresponding ports in the pod named "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 8080 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 automa...
Retrieve the output from running the 'ash' command inside the first container of the first pod of the notification-service service.
Command: ```bash kubectl exec svc/notification-service -- 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 kube...
Forward port 3000 of the local machine to port 9090 of the web-app-pod pod, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-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 criteria, a pod will ...
Create a new ExternalName service named external-messaging-service with the external name document-company.com
Command: ```bash kubectl create service externalname external-messaging-service --external-name document-company.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to referen...
Create a job with a command
Command: ```bash kubectl create job backup --image=mongo -- mongod ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Get the output from running the 'irb' command in the stardust-shuttle container of the api-service-pod pod.
Command: ```bash kubectl exec api-service-pod -c stardust-shuttle -- irb ``` 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...
Specify an alternative editor (in this case, Vim) to edit a Kubernetes service resource.
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/payment-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,...
Update the node 'backup-node-14' with a taint having key 'zone', value 'us-west-1a', and effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes backup-node-14 zone=us-west-1a:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output ...
Copy the /tmp/foo file from the local machine to the /tmp/bar file in the specified container "web-app-container" of the "auth-service-pod-11" pod.
Command: ```bash kubectl cp /tmp/foo auth-service-pod-11:/tmp/bar -c web-app-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, u...
taint nodes with special key if their team label is devops
Command: ```bash kubectl taint node -l team=devops special=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Start streaming the logs of the "warp-drive" container in the pod named "backend-pod"
Command: ```bash kubectl logs -f -c warp-drive backend-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...
Import specific keys from a config map to the deployment's environment variable
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-config-prod 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 definit...
Create a copy of the auth-service-pod and add a debug container to it, while also changing the container images.
Command: ```bash kubectl debug auth-service-pod -it --copy-to=dgb-img --image=debian --set-image=logger=logging-app:debug,api=api:v2 ``` 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...
Forward local port 6379 to port 5000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-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 criteria, a pod will be selected au...
Get the output from running the 'psql' command in the first container of the 'cache-cluster-deployment' deployment
Command: ```bash kubectl exec deploy/cache-cluster-deployment -- psql ``` 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 ...
Rollback to the previous deployment by undoing the changes made in the specified deployment/namespace.
Command: ```bash kubectl rollout undo deployment/namespace-2 ``` What it does: Manage the rollout of a resource. Valid resource types include: Syntax: `kubectl rollout SUBCOMMAND`
Create a new pod named "hazelcast" using the "docker.elastic.co/elasticsearch/elasticsearch" image, and expose port 3306.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=3306 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] ...
List a pod specified in "config.yaml" file in JSON format
Command: ```bash kubectl get -f config.yaml -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will only see resul...
Forward local port 8888 to port 8081 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888 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...
Start a php pod named hazelcast with the image php and set the environment variables DNS_DOMAIN=cluster and POD_NAMESPACE=default
Command: ```bash kubectl run hazelcast --image=php --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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] -- [COMMAN...
create a job named "log-collection" using the ubuntu image and run the command "echo "Hello" in the container
Command: ```bash kubectl create job log-collection --image=ubuntu -- docker run ubuntu echo "Hello ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Rename the context 'cluster-1-context' to 'edge-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cluster-1-context edge-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 field will al...
Create a new ExternalName service named 'external-security-service' with the external name 'blog-test.blog'
Command: ```bash kubectl create service externalname external-security-service --external-name blog-test.blog ``` 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 serv...
Create a copy of the 'vpn-service-pod' pod, adding a debug container and changing the container images
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=mailer=mailer:latest,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 b...
Import the 'SMTP_SERVER' key from the 'app-settings' config map and set it as an environment variable in the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-settings 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 definition...
Forward traffic from local port 8088 to port 3000 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8088:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named log-config and populate it with the contents of the specified files
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/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 c...
Create a deployment named sonarqube using the node image and expose port 8089
Command: ```bash kubectl create deployment sonarqube --image=node --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: ...
Start a wordpress pod named nginx, but override the spec with a partial set of values parsed from the provided JSON file.
Command: ```bash kubectl run nginx --image=wordpress --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] -- [COM...
run the 'sleep 3600' command inside the email-service-pod and display the output
Command: ```bash kubectl exec email-service-pod -- sleep 3600 ``` 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 kube...
Copy the local file /tmp/foo to the /etc/kubernetes directory inside the backend-pod-13 pod in the velero namespace
Command: ```bash kubectl cp /tmp/foo velero/backend-pod-13:/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 the kubec...
Forward port 6379 on localhost and IP 10.19.21.23 to port 3000 in the pod named api-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 6379:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/monitoring-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create a role binding named 'reader' and assign the 'reader' cluster role to 'user1', 'user2' and 'group1'.
Command: ```bash kubectl create rolebinding reader --clusterrole=reader --user=user1 --user=user2 --group=group1 ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serviceaccoun...
Set the annotation 'monitoring-tool' to 'Prometheus' for the pod named 'web'
Command: ```bash kubectl annotate pods web monitoring-tool=Prometheus ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitra...
Forward traffic from port 6379 on all addresses to port 9090 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-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 criteria, a pod w...
Copy the local directory '/tmp/foo_dir' to the remote pod 'backend-pod-13' in the '/tmp/bar_dir' directory.
Command: ```bash kubectl cp /tmp/foo_dir backend-pod-13::/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 kubectl.ku...
Set the service account of the deployment named "email-server-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment email-server-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: `kubec...
Set the resource request and limits for all containers in the hazelcast deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=256Mi ``` 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 reque...
Set the cpu limits of the nginx container in the ubuntu deployment to 10 and the memory limits to 512Mi
Command: ```bash kubectl set resources deployment ubuntu -c=nginx --limits=cpu=10,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, but may burst up to ...
Delete pods and services with the label version=v1.0.0
Command: ```bash kubectl delete pods,services -l version=v1.0.0 ``` 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...