prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Autoscale the replication controller "auth" to have a minimum of 1 pod and a maximum of 2 pods, with a target CPU utilization of 40%.
Command: ```bash kubectl autoscale rc auth --max=2 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses th...
Provide detailed information of all services
Command: ```bash kubectl describe services ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a name pre...
Create a new ExternalName service with the name "external-messaging-service" and the external name "governmental-demo.gov".
Command: ```bash kubectl create service externalname external-messaging-service --external-name governmental-demo.gov ``` 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 refere...
Create a cluster role named "foo" with the verb "update" and the NonResourceURL specified as "/debug/core"
Command: ```bash kubectl create clusterrole "foo" --verb=update --non-resource-url=/debug/core ``` 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", "sho...
Execute the 'go' command in the time-machine container of the monitoring-pod and display the output.
Command: ```bash kubectl exec monitoring-pod -c time-machine -- 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...
Create a pod running the Ruby image and expose port 8181 for communication.
Command: ```bash kubectl run hazelcast --image=ruby --port=8181 ``` 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": "--fil...
Update the 'api-server-deployment' deployment by setting a new environment variable 'CACHE_SIZE' to '64MB'.
Command: ```bash kubectl set env deployment/api-server-deployment CACHE_SIZE=64MB ``` 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 (w...
Create an ingress resource called 'app-loadbalancer-ingress' that directs requests from website.com/example to svc1:8080 using the tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="website.com/example=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", "defaul...
Create a wordpress pod with custom specifications using JSON overrides
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "v1.1.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...
Start a pod named 'hazelcast' using the 'docker.elastic.co/elasticsearch/elasticsearch' image and expose port 8010
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8010 ``` 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] ...
create a job with a specific command
Command: ```bash kubectl create job cleanup --image=wordpress -- wp ``` 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: js...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/kube-system-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environmen...
Create a new ingress object called 'default-ingress' that routes requests from testing.com/input to the service 'svc1' on port 8080
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/input=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Create a ruby pod with custom specifications using a JSON override
Command: ```bash kubectl run nginx --image=ruby --overrides='{ "apiVersion": "v1.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] -- [COMMAND]...
Create an ingress called 'app-loadbalancer-ingress' that directs requests for 'site.com/example' to 'svc1:8081'
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/example=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Create an ingress called 'service-ingress' with a rule that directs requests from site.com/input to the service 'svc1:8084'
Command: ```bash kubectl create ingress service-ingress --rule="site.com/input=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Retrieve the output from running the `mongo --version` command in the container `lunar-launcher` within the `log-aggregator-pod` pod
Command: ```bash kubectl exec log-aggregator-pod -c lunar-launcher -- mongo --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. ...
Forward traffic from port 5000 on both localhost and IP 10.19.21.23 to port 8088 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 5000: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...
Rename a context in the kubeconfig file.
Command: ```bash kubectl config rename-context on-prem-context team-beta-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...
Create a copy of the "proxy-service-pod" pod, with a different name "my-custom-dbg", and enter into the pod's "code-explorer" container for debugging.
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=my-custom-dbg --container=code-explorer -- 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...
Create a new config map named log-config with specified keys from files on disk
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/configurations/file1.txt --from-file=key2=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Create an ingress called 'app-ingress' that directs requests to site.com/bar to service svc1 on port 3001, and use the TLS secret 'my-cert'
Command: ```bash kubectl create ingress app-ingress --rule="site.com/bar=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": "Ou...
Create a new service account named kube-scheduler
Command: ```bash kubectl create serviceaccount kube-scheduler ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|nam...
Update the image of the first container in the frontend-pod pod with the new image using a JSON patch with positional arrays.
Command: ```bash kubectl patch pod frontend-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 (-f...
Remove the "client-secret" configuration value for the OpenID Connect authentication provider for the "api-user" entry.
Command: ```bash kubectl config set-credentials api-user --auth-provider=oidc --auth-provider-arg=client-secret- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-ke...
Auto scale the replication controller "web" with a minimum of 1 and a maximum of 7 pods, targeting a CPU utilization of 40%.
Command: ```bash kubectl autoscale rc web --max=7 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Switch to the context for the data-cluster cluster
Command: ```bash kubectl config use-context data-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Retrieve the previous terminated logs of the "time-machine" container from the pod "mypod"
Command: ```bash kubectl logs -p -c time-machine mypod ``` 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 copy of the e-commerce pod named "debug-image-api" and change all container images to "jenkins".
Command: ```bash kubectl debug e-commerce-pod --copy-to=debug-image-api --set-image=*=jenkins ``` 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 ...
Forward local port 5000 to port 8888 in the pod named e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Update the pod 'database' with the annotation 'expiration-date' and set its value to '2024-12-31'.
Command: ```bash kubectl annotate pods database expiration-date='2024-12-31' ``` 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 ...
Add a taint on nodes with the label 'component=proxy' and the key 'hardware' set to 'k8s-node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l component=proxy hardware=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Set the service account of the 'load-balancer-deployment' deployment to 'tekton'
Command: ```bash kubectl set serviceaccount deployment load-balancer-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: `kubec...
List the replication controller named "web", the service named "cdn-service-rc", and the pod named "email-service-pod"
Command: ```bash kubectl get rc/web service/cdn-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 name...
Expose a service for a replication controller based on the configuration file "python-controller.yaml" that serves on port 5001 and connects to the containers on port 900000
Command: ```bash kubectl expose -f python-controller.yaml --port=5001 --target-port=900000 ``` 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...
Create a cluster role named "bar" with the verb "connect" and the non-resource URL "/debug/ns/*" specified.
Command: ```bash kubectl create clusterrole "bar" --verb=connect --non-resource-url=/debug/ns/* ``` 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", "sh...
Attach to the "time-machine" container in the "e-commerce-pod" pod to get its output.
Command: ```bash kubectl attach e-commerce-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, ...
Create an ingress called 'external-ingress' with a rule that directs requests to foo.com/example to the service svc1:8081
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/example=svc1:8081,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Update the pod named 'monitoring' with the annotation 'contact-email' and the value 'support@example.com', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods monitoring contact-email='support@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger tha...
List the 'payment-gateway-pod' pod in JSON output format
Command: ```bash kubectl get -o json pod payment-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 you will only ...
Check if you have permission to list the "image-processing-job" job in the "cert-manager" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-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 part...
Set the service account for the deployment "monitoring-stack-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment my-service-account ``` 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 ...
forward traffic from port 8088 on all addresses to port 3000 in the backend-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-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 ...
Create a new ClusterIP service named 'analytics-service-clusterip' with a forwarding rule from port 5432 to port 6379
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=5432:6379 ``` 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": "-...
Edit the last-applied-configuration annotations of a deployment named "mysql" in YAML format
Command: ```bash kubectl apply edit-last-applied deployment/mysql ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the edito...
Retrieve the version of the 'gem' command running in the 'cosmic-container' within the 'api-service-pod' pod
Command: ```bash kubectl exec api-service-pod -c cosmic-container -- gem --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Forward traffic from port 5432 on all addresses to port 6379 inside the security-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5432: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 ...
Create a cluster role named "default_role" with the ResourceName specified
Command: ```bash kubectl create clusterrole default_role --verb=create --resource=services --resource-name=content-delivery --resource-name=machine-learning ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run...
Execute the command "node --version" inside the "cosmic-container" container running in the pod named "mypod" and display the output.
Command: ```bash kubectl exec mypod -c cosmic-container -- node --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, ...
Set the CPU limits of the hazelcast container in the 'deployment' resource to "1" and the memory limits to "256Mi"
Command: ```bash kubectl set resources deployment hazelcast -c=nginx --limits=cpu=1,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...
Listen on port 3000 on all addresses and forward the traffic to port 9090 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-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 wil...
Delete the pods and services with the names "proxy-server" and "analytics"
Command: ```bash kubectl delete pod,service proxy-server analytics ``` 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 se...
Create a cron job named "monthly-audit" with the image "ethereum/client-go", scheduled to run every minute, and execute the command "geth version".
Command: ```bash kubectl create cronjob monthly-audit --image=ethereum/client-go --schedule="*/1 * * * *" -- geth 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",...
Update the pod 'proxy-server' by adding the annotation 'security-scan-status' with the value 'pass'.
Command: ```bash kubectl annotate pods proxy-server security-scan-status=pass ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include...
Import the REDIS_HOST key from the app-name-config config map and set it as an environment variable in the frontend-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-name-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...
Copy the file '/tmp/foo' from the remote pod 'database-pod-2' in the 'ingress-nginx' namespace to '/tmp/bar' on your local machine.
Command: ```bash kubectl cp ingress-nginx/database-pod-2::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Create a service for the replication controller specified in "hazelcast-controller.yaml" file, which serves on port 5001 and connects to the containers on port 300100.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=5001 --target-port=300100 ``` 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 ...
Start a pod named "hazelcast" using the "postgres" image and expose port 8000
Command: ```bash kubectl run hazelcast --image=postgres --port=8000 ``` 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": "-...
Check if the current user can list the job named "content-import-job" in the "production" namespace
Command: ```bash kubectl auth can-i list jobs.batch/content-import-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 ...
Set the CPU limits of the Kafka container in the deployment to "5" and the memory limits to "2Gi".
Command: ```bash kubectl set resources deployment kafka -c=nginx --limits=cpu=5,memory=2Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its ...
Create an ingress named ingress1 in the default class, with multiple hosts and the pathType set as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8888" \ --rule="input.com/admin*=svc2:http" ``` 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...
Scale the 'api-service-rs' deployment to 7 replicas, only if the current size is 5 for the deployment named 'api-service-rs'.
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/api-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-vers...
Run the command 'docker run ubuntu echo "Hello, World"' in lunar-launcher container from the pod proxy-service-pod.
Command: ```bash kubectl exec proxy-service-pod -c lunar-launcher -- docker run ubuntu echo "Hello, World" ``` 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": "", "usag...
Check if the current user has permission to GET the /logs/ URL
Command: ```bash kubectl auth can-i get /logs/ ``` 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 that starts with "/". NAME is the ...
Get logs from container "payment-processor-deployment-1" of the deployment "monitoring-pod"
Command: ```bash kubectl logs deployment/payment-processor-deployment -c monitoring-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags...
Create a new ExternalName service named external-file-storage-service pointing to document-company.com
Command: ```bash kubectl create service externalname external-file-storage-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 refe...
Execute the 'dotnet' command within the astro-container of the analytics-pod.
Command: ```bash kubectl exec analytics-pod -c astro-container -- dotnet ``` 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 role named "custom_role" with ResourceName specified as "queue-consumer" and "report-generator".
Command: ```bash kubectl create role custom_role --verb=get --resource=pods --resource-name=queue-consumer --resource-name=report-generator ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=se...
Create a new secret named 'docker-registry-secret' from the environment variables specified in the 'properties.env' file
Command: ```bash kubectl create secret generic docker-registry-secret --from-env-file=path/to/properties.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...
List deployments in JSON output format using the API group "experimental-apps" and version "v1.1.1".
Command: ```bash kubectl get deployments.v1.1.1.experimental-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...
Execute the command 'mongo --version' in the first container of the 'load-balancer-deployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- mongo --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...
Forward local port 8088 to port 8888 in the pod selected by the deployment "notification-handler-deployment".
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8088 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Forward traffic from a random local port to port 8000 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward pod/log-aggregator-pod :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 selected aut...
Create an ingress resource named 'annotated' with the class 'default' and the rule 'website.com/input=svc:port'
Command: ```bash kubectl create ingress annotated --class=default --rule="website.com/input=svc:port" \ --annotation ingress.annotation1=website \ --annotation ingress.annotation2=bla ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=...
Create an ingress named 'web-ingress' that directs requests from 'website.com/example' to the service 'svc1' on port '8010', using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress web-ingress --rule="website.com/example=svc1:8010,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...
Use the Emacs editor to edit the service "docker-registry"
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/docker-registry ``` 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...
Add a taint with key 'zone' on nodes having label 'region=eu-west-2' and the value 'zone=testing-node-11' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l region=eu-west-2 zone=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Add a taint with the key 'special' on nodes having the label release=beta
Command: ```bash kubectl taint node -l release=beta special=web-node-8: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": "Out...
Forward local port 8000 to port 3000 in the proxy-server-pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 8000 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 a...
Import environment variables from a config map named 'app-settings' with a prefix 'MYSQL_' into the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --from=configmap/app-settings --prefix=MYSQL_ deployment/cache-cluster-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...
Add a taint with key 'app' on nodes having label owner=john-doe, with the taint value 'node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe app=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": "Output fo...
Retrieve a snapshot of the previous terminated logs from the "mycontainer" container in the "gateway-pod" pod
Command: ```bash kubectl logs -p -c mycontainer gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "shor...
Forward local port 5000 to port 9090 in the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5000: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...
Embed the certificate authority data for the 'kube-cluster-1' cluster entry using the command 'kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/prod-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/prod-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Listen on port 5432 on localhost and the IP address 10.19.21.23, and forward the traffic to port 5000 in the pod named 'security-service-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 5432: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 th...
Update the pod named 'security' by setting the annotation 'expiration-date' to '2024-12-31', overwriting the existing value if any.
Command: ```bash kubectl annotate --overwrite pods security expiration-date='2024-12-31' ``` 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 ...
Create a new pod named "hazelcast" using the "amazonlinux" image and expose port 5432
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=5432 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag":...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/global-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 i...
Create a pod disruption budget named 'logging-pdb' that selects all pods with the 'component=web' label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=component=web --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--d...
Create a new config map named app-name-config with the specified keys/values from the provided files
Command: ```bash kubectl create configmap app-name-config --from-file=settings=/path/to/data/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 creating ...
Add a taint with key 'dedicated' on nodes having label myLabel
Command: ```bash kubectl taint node -l myLabel dedicated=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Get the output from running the 'redis-server' command in the 'astro-container' from the 'e-commerce-pod' pod.
Command: ```bash kubectl exec e-commerce-pod -c astro-container -- redis-server ``` 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...
Import the SMTP_SERVER key from the monitoring-config config map to the search-engine-deployment deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/monitoring-config deployment/search-engine-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...
Import specific keys from a config map into environment variables of a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-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...
Remove all taints with the key 'datacenter' from node 'node-2'
Command: ```bash kubectl taint nodes node-2 datacenter- ``` 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|nam...
Import the CONFIG_FILE_PATH key from the app-name-config ConfigMap into the environment variables of the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-name-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment v...
Create a new NodePort service named log-aggregator-nodeport with the TCP port mapping of 8443:8089.
Command: ```bash kubectl create service nodeport log-aggregator-nodeport --tcp=8443:8089 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defaul...
Scale the deployment named app-v2-replicaset to 7 replicas
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/app-v2-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-v...
Update the pod 'security' by removing the annotation named 'description', if it exists.
Command: ```bash kubectl annotate pods security description- ``` 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 string...
Execute the 'irb' command in the first container of the 'order-service' service and get the output.
Command: ```bash kubectl exec svc/order-service -- 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, use the kubectl.kub...