prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Begin streaming the logs of the astro-container container in the log-aggregator-pod pod
Command: ```bash kubectl logs -f -c astro-container log-aggregator-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": "--contai...
Forward traffic from port 3000 on all addresses to port 8888 in the proxy-server-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 3000: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 ...
Forward local port 8888 to port 3000 of a pod selected by the deployment "mydeployment"
Command: ```bash kubectl port-forward deployment/mydeployment 8888 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 selecte...
Create a service for the replication controller specified in "nginx-controller.yaml" with the following parameters:
Command: ```bash kubectl expose -f nginx-controller.yaml --port=9091 --target-port=330600 ``` 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 ...
Execute the 'jenkins --version' command in the astro-container of the pod named mypod and retrieve the output.
Command: ```bash kubectl exec mypod -c astro-container -- jenkins --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...
Create an ingress called 'api-v1-ingress' that redirects requests from website.com/bar to svc1:5000 and uses the TLS secret "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/bar=svc1:5000,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...
Import the SMTP_SERVER key from the global-config config map into the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-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 variable...
Create a deployment named "api" using the "golang" image and expose port 8443.
Command: ```bash kubectl create deployment api --image=golang --port=8443 ``` 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...
Get deployments in YAML format from the "alpha-2.0" version of the "beta-apps" API group
Command: ```bash kubectl get deployments.alpha-2.0.beta-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 wi...
Execute the 'ash' command inside the first container of the api-service-pod and retrieve the output.
Command: ```bash kubectl exec api-service-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.kuber...
Create a deployment named "auth" running the "confluentinc/cp-kafka" image with 6 replicas.
Command: ```bash kubectl create deployment auth --image=confluentinc/cp-kafka --replicas=6 ``` 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 for...
Set the certificate-authority-data field on the sun-cluster cluster by running the command "kubectl config set clusters.sun-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -)"
Command: ```bash kubectl config set clusters.sun-cluster.certificate-authority-data $(echo "cert_data_here" | base64 -i -) ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain d...
Return the snapshot of the previous terminated 'mycontainer' container logs from the 'vpn-service-pod' pod.
Command: ```bash kubectl logs -p -c mycontainer 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": "--container", "...
Set the CPU and memory limits for a container in a deployment.
Command: ```bash kubectl set resources deployment centos -c=nginx --limits=cpu=5,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 to i...
Import the environment variable "api-secret-key" from the secret into the deployment "payment-processor-deployment"
Command: ```bash kubectl set env --from=secret/api-secret-key deployment/payment-processor-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 or m...
Copy the local file "~/.config/kube" to the remote pod "kube-system/security-scanner-pod-18" in the "/tmp/bar_dir" directory.
Command: ```bash kubectl cp ~/.config/kube kube-system/security-scanner-pod-18:/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 omitt...
Create a deployment named 'registry' using the 'wordpress' image and expose port 9091
Command: ```bash kubectl create deployment registry --image=wordpress --port=9091 ``` 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 ...
Import the 'CONFIG_FILE_PATH' key from the 'app-config' config map to the 'api-server-deployment' deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Set a custom TLS server name for the dev-cluster cluster entry
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=cluster-beta ``` 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-...
Create a pod disruption budget named 'cron-jobs-pdb' that will select all pods with the 'region=us-east' label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=region=us-east --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-available=N [...
Check if you have permission to list the job named "certificates-renewal-job" in the "cert-manager" namespace
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-job -n cert-manager ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a ...
List resources of different types by specifying their type and names
Command: ```bash kubectl get rc/web service/vpn-service-rc pods/gateway-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 namespaced...
Roll back the daemonset 'namespace-1' to revision 5
Command: ```bash kubectl rollout undo daemonset/namespace-1 --to-revision=5 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying...
Remove taints with key 'workload' from node 'gpu-node-12'
Command: ```bash kubectl taint nodes gpu-node-12 workload- ``` 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|yaml|...
Forward port 8888 on your local machine and IP 10.19.21.23 to port 8081 in the pod named proxy-server-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-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 cr...
Check if you have permission to list the job named "batch-processing-job" in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/batch-processing-job -n kube-system ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Create a deployment named "auth" that uses the "hazelcast" image and exposes port 5432.
Command: ```bash kubectl create deployment auth --image=hazelcast/hazelcast --port=5432 ``` 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...
Create a cron job named "database-maintenance" that runs the command "mongo --version" every minute using the "mongo" image.
Command: ```bash kubectl create cronjob database-maintenance --image=mongo --schedule="*/1 * * * *" -- mongo --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "s...
Set the custom TLS server name for validation of the app-cluster cluster entry.
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=web-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-a...
View the supported API resources for the specified APIGroup
Command: ```bash kubectl api-resources --api-group=network.openshift.io ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Forward traffic from port 8000 on localhost and IP address 10.19.21.23 to port 8088 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Remove the taint with key 'datacenter' and effect 'NoExecute' from the node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 datacenter: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 ...
Execute the 'bash' command inside the astro-container of the pod 'proxy-service-pod' and display the output.
Command: ```bash kubectl exec proxy-service-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,...
Update the pod 'analytics' by setting the annotation 'owner' to 'alice-smith', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods analytics 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 incl...
Forward port 9090 on your local machine to port 6379 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-pod 9090: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 selected au...
Import the "secret_key" key from the "namespace-config" config map and set it as an environment variable in the "mydeployment" deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/namespace-config 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 o...
Import the "log_level" key from the "app-secrets" config map into the "proxy-service-deployment" deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-secrets 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...
Run a pod using the golang image with custom arguments
Command: ```bash kubectl run nginx --image=golang -- <arg1> <arg2> ... <argN> ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: ...
Display the differences between the current resources in the cluster and the resources described in the preferences.yaml file.
Command: ```bash cat preferences.yaml | kubectl diff -f - ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own...
Copy the local file located at ~/.config/kube to the remote pod named image-resizer-pod-20 in the velero namespace, with the destination location set to /tmp/bar.
Command: ```bash kubectl cp ~/.config/kube velero/image-resizer-pod-20::/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...
Create a debug pod named "dgb-img" as a copy of "vpn-service-pod" with all container images changed to "amazonlinux".
Command: ```bash kubectl debug vpn-service-pod --copy-to=dgb-img --set-image=*=amazonlinux ``` 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...
Create an ingress called 'app1-ingress' that directs requests to website.com/input to the service 'svc1' on port 9090, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/input=svc1:9090,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 service account of the deployment "analytics-platform-deployment" to "default"
Command: ```bash kubectl set serviceaccount deployment analytics-platform-deployment default ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: ...
Update the pod named 'security' with the label 'role' and the value 'cache'
Command: ```bash kubectl label pods security role=cache ``` 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...
Listen on port 8888 locally and forward it to port 5432 in the pod 'mypod'
Command: ```bash kubectl port-forward pod/mypod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Create a new config map named "namespace-config" using the options found in the folder "path/to/options"
Command: ```bash kubectl create configmap namespace-config --from-file=path/to/options ``` 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 basen...
Create a new job named "log-collection" with the image "confluentinc/cp-kafka" and run the command "kafka-server-start /etc/kafka/server.properties" inside the container.
Command: ```bash kubectl create job log-collection --image=confluentinc/cp-kafka -- kafka-server-start /etc/kafka/server.properties ``` 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", "...
Check if you have permission to list the job named "cleanup-job" in the "production" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-job -n production ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL tha...
Update the image of all deployments and replication controllers to 'ruby:3.0.2'
Command: ```bash kubectl set image deployments,rc ruby=ruby:3.0.2 --all ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: ...
Create a new secret named 'database-secret' with keys for each file in the 'path/to/properties' folder
Command: ```bash kubectl create secret generic database-secret --from-file=path/to/properties ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename o...
Copy the kube config file from your local machine to the /tmp/bar directory of the cache-pod-5 pod in the logging namespace.
Command: ```bash kubectl cp ~/.config/kube logging/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 kubectl....
Forward local port 8081 to port 6379 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081: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 selected a...
Forward port 6379 on your local machine to port 5432 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Update the image of the 'debian' container for all deployments and rc's to 'debian:11.0'
Command: ```bash kubectl set image deployments,rc debian=debian:11.0 --all ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Synta...
Apply a taint to nodes with a specific label.
Command: ```bash kubectl taint node -l namespace=mynamespace environment=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": "", "...
List deployments in JSON format using the "v3.0.0" version of the "apps" API group.
Command: ```bash kubectl get deployments.v3.0.0.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 only ...
Get output from running the 'bash' command in a specific container of a pod
Command: ```bash kubectl exec media-stream-pod -c mycontainer -- 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 ...
Set the CPU and memory limits to 200m CPU and 512Mi memory, and the CPU and memory requests to 100m CPU and 128Mi memory for all containers in the 'mongo' deployment.
Command: ```bash kubectl set resources deployment mongo --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=128Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource reques...
Import environment variables from a config map with a specified prefix
Command: ```bash kubectl set env --from=configmap/app-config --prefix=MYSQL_ 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 definitions i...
Update the image of all containers in the 'namespace-2' daemonset to 'centos:8.4.2105'
Command: ```bash kubectl set image daemonset namespace-2 *=centos:8.4.2105 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Synta...
Create a priority class named 'production-priority' with a value of 150 and a description of "Priority for production workloads"
Command: ```bash kubectl create priorityclass production-priority --value=150 --description="Priority for production workloads" ``` 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...
Forward traffic from local port 9090 to port 3000 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 9090: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 au...
Import the 'external_api_url' key from the 'api-config' ConfigMap and set it as an environment variable for the 'frontend-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/api-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...
Forward data between local ports and pod ports
Command: ```bash kubectl port-forward pod/mypod 6379 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Create a pod disruption budget with the name "cache-cluster-pdb" that selects all pods with the label "version=v2" and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=version=v2 --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [...
Create a debug copy of the media-stream-pod, adding a debug container and changing the container images
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-web --image=debian --set-image=scheduler=my-scheduler:1.0,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 ...
Copy the local file /tmp/foo_dir to the remote pod named kube-dns/metrics-exporter-pod-10 in the /etc/kubernetes directory
Command: ```bash kubectl cp /tmp/foo_dir kube-dns/metrics-exporter-pod-10:/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...
Set the cluster field in the my-context context to on-prem-cluster
Command: ```bash kubectl config set contexts.on-prem-context.cluster on-prem-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...
Add a taint with the key 'app' on nodes having the label service=auth. Specify the taint as app=app-node-6:PreferNoSchedule.
Command: ```bash kubectl taint node -l service=auth app=app-node-6: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 ...
Create a copy of the 'backend-pod' pod and attach to it interactively
Command: ```bash kubectl debug backend-pod -it --copy-to=my-custom-dbg --container=warp-drive -- 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 default ...
Create a copy of the 'vpn-service-pod' and change all container images to 'redis'. Name the new pod 'my-debugger'.
Command: ```bash kubectl debug vpn-service-pod --copy-to=my-debugger --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 resou...
Create a pod disruption budget named statefulset-pdb that selects all pods with the release=1.0.0 label and requires a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=release=1.0.0 --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-available=N ...
Create a new secret named 'oauth-secret' from the environment variables defined in the file located at 'path/to/configs.env'
Command: ```bash kubectl create secret generic oauth-secret --from-env-file=path/to/configs.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename...
Get output from the 'cosmic-container' running in the 'proxy-service-pod'
Command: ```bash kubectl attach proxy-service-pod -c cosmic-container ``` 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 om...
Create a new config map named app-settings with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --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...
List deployments in YAML format, using version v1.1.1 of the custom-apps API group
Command: ```bash kubectl get deployments.v1.1.1.custom-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...
Add a taint with the key 'zone' on nodes that have the label 'customer=acme-corp'.
Command: ```bash kubectl taint node -l customer=acme-corp zone=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...
Create a new secret named ssl-key-secret from the configurations.env file
Command: ```bash kubectl create secret generic ssl-key-secret --from-env-file=path/to/configurations.env ``` 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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Create a secret named ssh-key-secret using values from an environment file.
Command: ```bash kubectl create secret generic ssh-key-secret --from-env-file=path/to/parameters.env ``` 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...
Expose a service for the php replication controller specified in "php-controller.yaml"
Command: ```bash kubectl expose -f php-controller.yaml --port=8443 --target-port=500100 ``` 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 sp...
Embed the certificate authority data for the galaxy-cluster cluster entry by running the kubectl config set-cluster command
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/app-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 se...
Forward port 6379 on your local machine to port 5432 in the pod named "backend-pod".
Command: ```bash kubectl port-forward pod/backend-pod 6379:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Execute the 'bash' command in the container 'mycontainer' of the pod 'chat-app-pod' and retrieve the output.
Command: ```bash kubectl exec chat-app-pod -c mycontainer -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Attach to the pod named analytics-pod and connect to the time-machine container within the pod
Command: ```bash kubectl attach analytics-pod -c time-machine ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-secrets deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Continuously monitor and stream the logs of the "lunar-launcher" container in the "log-aggregator-pod" pod.
Command: ```bash kubectl logs -f -c lunar-launcher log-aggregator-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": "--contain...
Create a pod using `confluentinc/cp-kafka` image and expose port 3306
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --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] [args...]` Helpful flag...
Expose the replica set named 'hazelcast' as a service, which listens on port 3000 and connects to the containers using port 818100.
Command: ```bash kubectl expose rs hazelcast --port=3000 --target-port=818100 ``` 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 po...
Update all containers in all replication controllers in the project to have ENV=prod with the command `kubectl set env rc --all DB_USER=username`
Command: ```bash kubectl set env rc --all DB_USER=username ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (within replication contr...
Set the cluster field for a specific context
Command: ```bash kubectl config set contexts.testing-context.cluster kube-cluster-1 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Create a new ClusterIP service named payment-service-clusterip, mapping the port 5000 of the service to port 9000 of the destination
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=5000:9000 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Add a taint with key 'dedicated' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe dedicated=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...
Create an ingress called 'app2-ingress' that directs requests to a specific module of a website to a service
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/module=svc1:8888,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...
Add a taint with the key 'datacenter' and the value 'app-node-6:PreferNoSchedule' to the nodes that have the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack datacenter=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Copy a directory from a remote pod to your local machine
Command: ```bash kubectl cp monitoring/file-server-pod-14:/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 the...
Listen on port 6379 on localhost and IP address 10.19.21.23, forwarding to port 5432 in the web-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 6379: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 criteri...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/security-service-pod :8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Embed the certificate authority data for the prod-cluster cluster entry using the Kubernetes config command
Command: ```bash kubectl config set-cluster prod-cluster --embed-certs --certificate-authority=~/.kube/e2e/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 set-cluster ...
Run a mongo pod and keep it running in the foreground without restarting if it exits
Command: ```bash kubectl run -i -t busybox --image=mongo --restart=Never ``` 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...