prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the 'security' pod by setting the annotation 'app-version' to the value 2.5.1
Command: ```bash kubectl annotate pods security app-version=2.5.1 ``` 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 s...
Create an ingress with a rule that directs requests from foo.com/example to svc1:8088, with the TLS secret "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="foo.com/example=svc1:8088,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...
Forward local port 8081 to port 8080 in the search-engine-deployment
Command: ```bash kubectl port-forward deployment/search-engine-deployment 8081 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 wil...
Add a taint to the 'app-node-6' node in the cluster
Command: ```bash kubectl taint nodes app-node-6 workload=high-priority: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 for...
Set the service account of the deployment "log-aggregator-deployment" to "elasticsearch"
Command: ```bash kubectl set serviceaccount deployment log-aggregator-deployment elasticsearch ``` 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 image of the container at position 0 inside the 'analytics-pod' pod using a JSON patch
Command: ```bash kubectl patch pod analytics-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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 (-...
Retrieve the logs from all containers in the 'vpn-service-pod' pod.
Command: ```bash kubectl logs vpn-service-pod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container...
Create a copy of the 'backend-pod' and change all container images to 'ubuntu'.
Command: ```bash kubectl debug backend-pod --copy-to=debug-image-memcached --set-image=*=ubuntu ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if n...
Wait for the pod "media-stream-pod" to be deleted after issuing the delete command
Command: ```bash kubectl delete pod/media-stream-pod kubectl wait --for=delete pod/busybox1 --timeout=60s ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resou...
Create a priority class named background-priority with a value of 1 and a description of "Low priority, minimal impact"
Command: ```bash kubectl create priorityclass background-priority --value=1 --description="Low priority, minimal impact" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--dry-run=se...
Create a job called "audit-job" using the ethereum/client-go image and run the command "geth version" in the job.
Command: ```bash kubectl create job audit-job --image=ethereum/client-go -- geth version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Execute the command 'yum install -y wget' in the pod 'gateway-pod' with the container 'nebula-navigator' and get the output.
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- yum install -y wget ``` 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. I...
Run the command 'dotnet --list-sdks' inside the 'nano-bot' container of the 'log-aggregator-pod' pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c nano-bot -- dotnet --list-sdks ``` 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 ...
Forward port 8888 on all addresses to port 5000 in the security-service-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Forward local port 5432 to port 8080 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-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 be selected autom...
Update the pod specified in the 'options.json' file by annotating it with the git-repo annotation set to 'https://github.com/example/my-app'
Command: ```bash kubectl annotate -f options.json git-repo='https://github.com/example/my-app' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than l...
Add a taint with key 'disktype' on the nodes that have the label 'service=auth' with the value 'monitoring-node-15' and a taint effect of 'PreferNoSchedule'
Command: ```bash kubectl taint node -l service=auth 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": "", "usa...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/namespace-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 definitio...
Set the cluster field in the 'on-prem-context' context to 'testing-cluster'
Command: ```bash kubectl config set contexts.on-prem-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 y...
Create a Pod Disruption Budget named "cache-cluster-pdb" that will select all pods with the "owner=team-1" label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-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...
Import specific keys from a config map for a specific deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/env-vars 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 definitions in one...
Set the CPU and memory resource request and limits for all containers in the "ruby" deployment
Command: ```bash kubectl set resources deployment ruby --limits=cpu=200m,memory=512Mi --requests=cpu=10,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, ...
Add a taint to node 'kube-master-9' with the key 'workload', value 'high-priority' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes kube-master-9 workload=high-priority: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 ...
Create a new ClusterIP service named inventory-service-clusterip that listens on port 8888 and forwards traffic to port 3001.
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=8888:3001 ``` 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": "-...
Begin streaming the logs of the 'stardust-shuttle' container in the 'vpn-service-pod' pod
Command: ```bash kubectl logs -f -c stardust-shuttle vpn-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": "--containe...
Create a service for a CentOS deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment centos --port=8080 --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 specifi...
Forward local port 8888 to port 6379 in the pod selected by the deployment "notification-handler-deployment"
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8888 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Set the custom TLS server name "cluster-gamma" for the cluster entry "staging-cluster"
Command: ```bash kubectl config set-cluster staging-cluster --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] [--certifi...
Create a deployment named "jenkins" with the "mongo" image and specify the version as "mongo"
Command: ```bash kubectl create deployment jenkins --image=mongo -- mongo --version ``` 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. On...
Copy the local file /tmp/foo_dir to the remote pod named worker-pod-4 in the container named task-processor.
Command: ```bash kubectl cp /tmp/foo_dir worker-pod-4:/tmp/bar -c task-processor ``` 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...
Copy the local directory '/tmp/foo_dir_dir' to the remote pod 'payment-gateway-pod-19' in the '/tmp/bar_dir_dir' directory within the default namespace.
Command: ```bash kubectl cp /tmp/foo_dir_dir payment-gateway-pod-19:/tmp/bar_dir_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...
Get the output of the 'geth version' command from the first pod of the 'order-processing-deployment' deployment.
Command: ```bash kubectl exec deploy/order-processing-deployment -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Get the output of running the 'bash' command in the 'astro-container' from the 'gateway-pod'
Command: ```bash kubectl exec gateway-pod -c astro-container -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Display the details of the specified resources, including the replication controller "web", the service "media-stream-rc", and the pod "media-stream-pod".
Command: ```bash kubectl get rc/web service/media-stream-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 name...
Add a taint to node 'prod-node-5' with key 'workload' and value 'high-priority' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes prod-node-5 workload=high-priority: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 fo...
Set the service account of the deployment 'search-engine-deployment' to 'istio'
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment istio ``` 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: `kubect...
Forward local port 3000 to port 5000 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward pod/log-aggregator-pod 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 selected...
Create a debug container named "my-debugger" based on the "time-machine" container of the "cdn-service-pod" pod
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=my-debugger --container=time-machine -- 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...
Edit the 'api-service' service using the 'gedit' editor.
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/api-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, o...
Forward local port 8081 to port 8080 in the pod named security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 8081: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 select...
Add a taint with key 'app' on nodes having the label release=beta and set the taint value to 'edge-node-10:PreferNoSchedule'
Command: ```bash kubectl taint node -l release=beta app=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": "", "usage": "Outpu...
Create a cluster role named "foo" that allows the user to perform "list", "create", and "update" operations on pods.
Command: ```bash kubectl create clusterrole foo --verb=list,create,update --resource=pods ``` 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", "short": ...
Attach to the 'warp-drive' container within the 'database-pod' pod and get the output
Command: ```bash kubectl attach database-pod -c warp-drive ``` 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 ...
Get the output from running the 'docker run -it ubuntu' command in the first pod of the cache-service service.
Command: ```bash kubectl exec svc/cache-service -- 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 name. If omitted, u...
Create a new ExternalName service named external-analytics-service with the external name sandbox-site.co.
Command: ```bash kubectl create service externalname external-analytics-service --external-name sandbox-site.co ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference se...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/db-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Create a job that runs the specified command
Command: ```bash kubectl create job backup --image=confluentinc/cp-kafka -- kafka-topics --list ``` 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"...
Set a custom TLS server name to use for validation for a specific cluster entry.
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=edge-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...
Listen on port 5000 on your local machine, and forward traffic to port 8081 in the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod 5000: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 select...
Create a deployment named "db" with the image "ethereum/client-go" and 3 replicas.
Command: ```bash kubectl create deployment db --image=ethereum/client-go --replicas=3 ``` 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. ...
Listen on port 6379 on localhost and IP address 10.19.21.23, forwarding to port 8888 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 6379: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...
Create a pod disruption budget called 'notification-service-pdb' that selects all pods with the 'version=v2' label and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=version=v2 --min-available=9 ``` 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-availa...
Execute the 'kafka-topics --list' command on the first container of the 'payment-service' service and get the output.
Command: ```bash kubectl exec svc/payment-service -- kafka-topics --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 name. If omitted, u...
Forward local traffic on port 9090 to the pod's port 9090
Command: ```bash kubectl port-forward pod/web-app-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 automa...
Import the SMTP_SERVER key from the config map 'namespace-config' into the deployment 'log-aggregator-deployment'
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/namespace-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Create a config map named kube-system-config with specific keys and files.
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Set the custom TLS server name to "dev-cluster" for the "cloud-cluster" cluster entry
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=dev-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...
Execute the 'geth version' command in the astro-container from the monitoring-pod and get the output.
Command: ```bash kubectl exec monitoring-pod -c astro-container -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Embed the certificate authority data for the cluster-gamma cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/my-k8s-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 ...
Execute the 'geth' command in the email-service-pod and get the output.
Command: ```bash kubectl exec email-service-pod -- geth ``` 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.ku...
List deployments in the "hotfix-1.1.2" version of the "apps" API group and display the output in JSON format
Command: ```bash kubectl get deployments.hotfix-1.1.2.apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will...
Retrieve a list of deployments in the "v1.1.1" version of the "internal-apps" API group, and display the output in YAML format.
Command: ```bash kubectl get deployments.v1.1.1.internal-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Embed the certificate authority data for the 'cluster-alpha' cluster entry using the provided certificate authority file
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/cluster-beta/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...
Set up auto scaling for the replication controller "frontend" with a target CPU utilization of 90%, ensuring that the number of pods stays between 1 and 4.
Command: ```bash kubectl autoscale rc frontend --max=4 --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...
Forward local ports to a specific pod in a deployment
Command: ```bash kubectl port-forward deployment/mydeployment 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 selecte...
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 5000 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 9090: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 cri...
Add a taint with key 'datacenter' on nodes having label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 datacenter=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": "...
Remove a label named 'bar' from pod 'database'
Command: ```bash kubectl label pods database unhealthy- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "I...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config-prod deployment/log-aggregator-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...
Set the CPU limits of the nginx container in the wordpress deployment to 3 and the memory limits to 256Mi.
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=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 requested, but may burst up t...
Create a new config map named env-vars using specified files as the key-value pairs
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...
Forward port 5000 from the local machine 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 5000: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...
Update the 'proxy-server' pod by adding an annotation with the key 'deployment-script' and the value 'https://example.com/deploy.sh'.
Command: ```bash kubectl annotate pods proxy-server deployment-script='https://example.com/deploy.sh' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger...
Copy a file named "foo" from the "/tmp" directory of the pod named "ingress-controller-pod-8" in the "cert-manager" namespace to the "/tmp/bar_dir" directory on the local machine.
Command: ```bash kubectl cp cert-manager/ingress-controller-pod-8:/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, ...
Open the order-service service for editing using the Notepad editor.
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/order-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 variable...
Create a new secret with keys for each file in a folder
Command: ```bash kubectl create secret generic email-credentials-secret --from-file=path/to/profiles ``` 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 bas...
View the last-applied-configuration annotations for a specific deployment named "mongo" in YAML format.
Command: ```bash kubectl apply view-last-applied deployment/mongo ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-applied ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-prod 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...
Set the service account of the deployment "order-processing-deployment" to "tekton"
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment tekton ``` 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...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config-prod deployment/load-balancer-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...
Get detailed information about the 'dev-context' context in your kubeconfig file
Command: ```bash kubectl config get-contexts dev-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 "
Execute the 'postgres' command in the 'time-machine' container of the 'chat-app-pod' pod and retrieve the output.
Command: ```bash kubectl exec chat-app-pod -c time-machine -- postgres ``` 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...
Create a copy of the 'chat-app-pod' pod, changing all container images to 'centos' and name it 'debug-image-app'.
Command: ```bash kubectl debug chat-app-pod --copy-to=debug-image-app --set-image=*=centos ``` 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 res...
List the deployments with the API group "backup-apps" in the version "hotfix-1.1.2" in JSON format.
Command: ```bash kubectl get deployments.hotfix-1.1.2.backup-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 y...
Get output from running a command inside a running pod
Command: ```bash kubectl exec monitoring-pod -c cyber-sleuth -- dotnet --list-sdks ``` 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 ...
Create an ingress resource named 'www-ingress' that routes requests for 'foo.com/bar' to the service named 'svc1' on port 8443
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/bar=svc1:8443,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-settings deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Create a pod disruption budget named elastic-search-pdb that will select all pods with the release=1.0.0 label and require a minimum of one of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget elastic-search-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...
Connect to the container named 'astro-container' in pod 'mypod' and interact with its terminal
Command: ```bash kubectl attach mypod -c astro-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 omitted, ...
Execute the 'go' command in the 'nano-bot' container of the 'vpn-service-pod' pod
Command: ```bash kubectl exec vpn-service-pod -c nano-bot -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Import the environment variables with a prefix of 'MYSQL_' from the 'app-name-config' config map into the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl set env --from=configmap/app-name-config --prefix=MYSQL_ deployment/log-aggregator-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...
Create a new secret named gcp-service-account-secret with the given key-value pairs as literals
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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 fi...
Create an ingress rule named 'default-ingress' that directs requests to website.com/bar to a service called svc1 on port 8181
Command: ```bash kubectl create ingress default-ingress --rule="website.com/bar=svc1:8181,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...
List the deployments in YAML output format, for the "v2.1.0" version of the "backup-apps" API group.
Command: ```bash kubectl get deployments.v2.1.0.backup-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Start a pod named 'hazelcast' with the 'alpine' image, and configure the container inside the pod to expose port 8084.
Command: ```bash kubectl run hazelcast --image=alpine --port=8084 ``` 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...
delete the pods and services with the names "log-aggregator" and "proxy"
Command: ```bash kubectl delete pod,service log-aggregator proxy ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label sele...
Forward local port 5432 to port 8000 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward pod/security-service-pod 5432 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Use the emacs editor to edit the 'api-service' service
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/api-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, o...
import the `database_url` key from the `app-name-config` config map and set it as an environment variable in the `scheduler-app-deployment` deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-name-config deployment/scheduler-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 def...
Forward local port 5000 to port 8080 in the pod selected by the deployment "authentication-service-deployment"
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 5000 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, ...