prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward port 8080 on all addresses to port 8888 in the pod named `cdn-service-pod`
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8080:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Import specific keys from a config map into an environment variable.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-name-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Set custom TLS server name for a cluster configuration
Command: ```bash kubectl config set-cluster kube-cluster-1 --tls-server-name=app-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] [--certificat...
Embed the certificate authority data for the "cluster-alpha" cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/web-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 set...
Start a ubuntu pod named nginx with the specified image and spec overrides from the provided JSON data
Command: ```bash kubectl run nginx --image=ubuntu --overrides='{ "apiVersion": "legacy-1.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] -- [...
Delete pods and services named "payment" and "web"
Command: ```bash kubectl delete pod,service payment web ``` 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 selector. Som...
Get a shell session in the 'code-explorer' container of the 'gateway-pod' pod.
Command: ```bash kubectl exec gateway-pod -c code-explorer -- 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...
Forward the local port 6379 to port 8000 in the pod selected by the 'search-engine-deployment' deployment.
Command: ```bash kubectl port-forward deployment/search-engine-deployment 6379 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 wil...
Start an interactive debugging session on the node named "mynode" using the busybox image
Command: ```bash kubectl debug node/mynode -it --image=busybox ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource is specified. The acti...
List the resource information for the specified resource types and names
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/vpn-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 na...
Create an ingress called 'myapp-ingress' to route requests from foo.com/input to svc1:9000 with TLS using the secret "my-cert"
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/input=svc1:9000,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": ...
Change the number of replicas for a resource specified in the "conf.json" file to 5.
Command: ```bash kubectl scale --replicas=5 -f conf.json ``` 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-version is specified, it is validated ...
Create a pod disruption budget named statefulset-pdb that selects pods with the version=v2 label and requires at least four of them to be available at any given time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=version=v2 --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 [--...
Partially update a node using a strategic merge patch
Command: ```bash kubectl patch -f kubelet-config.yaml -p '{"spec":{"type":"LoadBalancer"}' ``` 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 FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` ...
Forward traffic from local port 8088 to port 8081 in the 'frontend-pod' pod, and also forward traffic from local port 6000 to port 6000 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8088 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Edit the configuration of the backend-service using the "micro" editor
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/backend-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...
Begin streaming the logs of the "quantum-quark" container in the "database-pod" pod
Command: ```bash kubectl logs -f -c quantum-quark database-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", "s...
Create a copy of the "monitoring-pod" by adding a debug container and changing the container images
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-1 --image=debian --set-image=mailer=mailer:latest,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by...
List deployments in YAML output format, with specific version and API group
Command: ```bash kubectl get deployments.feature-branch-2.3.0.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 ...
Forward local port 8088 to the targetPort of the "https" port in a pod selected by the "monitoring-service" service.
Command: ```bash kubectl port-forward service/monitoring-service 8088:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sel...
Display the modified backend-microservice-deployment deployment in YAML format, with the updated DB_USER environment variable set to "username"
Command: ```bash kubectl set env deployment/backend-microservice-deployment DB_USER=username -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or mo...
Set custom TLS server name to use for validation for the star-cluster cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=app-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-...
List deployments in the "v2.1.0" version of the "alpha-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.v2.1.0.alpha-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...
List all deployments in the "beta-1.0" version of the "testing-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.beta-1.0.testing-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you ...
Add a taint with key 'disktype' on nodes having label app=web-app with the value 'testing-node-11:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app disktype=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":...
Update the pod named 'web' with the annotation 'team' and the value 'frontend team'.
Command: ```bash kubectl annotate pods web team='frontend team' ``` 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 str...
Create a service for a replication controller specified in the "php-controller.yaml" file, serving on port 8181 and connecting to the containers on port 700000.
Command: ```bash kubectl expose -f php-controller.yaml --port=8181 --target-port=700000 ``` 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...
Create a new LoadBalancer service named analytics-lb that maps the external port 8888 to the internal port 8000.
Command: ```bash kubectl create service loadbalancer analytics-lb --tcp=8888:8000 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defau...
Get the output from running the 'dotnet --list-sdks' command in the code-explorer container of the frontend-pod
Command: ```bash kubectl exec frontend-pod -c code-explorer -- 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 o...
Forward traffic from local port 6379 to port 5000 in the pod
Command: ```bash kubectl port-forward pod/api-service-pod 6379 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Listen on port 5000 on your local machine and forward traffic to port 8080 in the pod named 'backend-pod'.
Command: ```bash kubectl port-forward pod/backend-pod 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, a pod will be selected automa...
Copy the local file /tmp/foo_dir to the remote pod auth-service-pod-11, specifically to the path /tmp/bar_dir in the container security-scanner.
Command: ```bash kubectl cp /tmp/foo_dir auth-service-pod-11:/tmp/bar_dir -c security-scanner ``` 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 omi...
Retrieve the snapshot logs from the first container of the deploy-artifacts-job job
Command: ```bash kubectl logs job/deploy-artifacts-job ``` 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": "...
Get the output from running the 'redis-cli' command in the 'rocket-ranger' container within the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c rocket-ranger -- redis-cli ``` 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 a copy of the analytics-pod with a custom debug container named "my-custom-dbg" and open a shell inside it
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-custom-dbg --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...
Execute the 'mysql --version' command inside the 'database-pod' pod, specifically in the 'lunar-launcher' container.
Command: ```bash kubectl exec database-pod -c lunar-launcher -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Add a taint with the key 'environment' and value 'node-1:PreferNoSchedule' on nodes having the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend environment=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": "Ou...
Create a new LoadBalancer service named auth-service-lb that forwards traffic from port 8888 to port 8081.
Command: ```bash kubectl create service loadbalancer auth-service-lb --tcp=8888:8081 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Forward traffic from local port 8080 to port 3000 in the selected pod of the analytics-platform-deployment deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8080 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 po...
Create a deployment named drupal using the alpine image and expose port 8084.
Command: ```bash kubectl create deployment drupal --image=alpine --port=8084 ``` 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: j...
Execute the command 'redis-server --version' in the container named 'mycontainer' within the 'auth-service-pod' pod and display the output.
Command: ```bash kubectl exec auth-service-pod -c mycontainer -- redis-server --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 localhost and IP 10.19.21.23 to port 8088 on your local machine to port 8888 in the pod named "security-service-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 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 th...
Create a new config map named 'env-vars' using the files 'file1.txt' and 'file2.txt'
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/configurations/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 confi...
Execute the command 'docker run ubuntu echo "Hello, World"' inside the 'cyber-sleuth' container of the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c cyber-sleuth -- 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": "", "usage"...
Import environment variables from the api-config config map with a prefix of MYSQL_ into the notification-handler-deployment deployment.
Command: ```bash kubectl set env --from=configmap/api-config --prefix=MYSQL_ 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 defin...
Create a new config map named "kube-system-config" using the specified keys instead of the file basenames on disk.
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/settings/file1.txt --from-file=data=/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 creating ...
Create a role named "reader" with the ability to patch, watch, and execute commands on the "namespaces" and "namespaces/status" SubResources.
Command: ```bash kubectl create role reader --verb=patch,watch,exec --resource=namespaces,namespaces/status ``` 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=server|client|none]` Helpful flag...
Edit the 'user-management-deployment' deployment by opening it in YAML format, make the necessary modifications, and save the modified configuration in the deployment's annotation.
Command: ```bash kubectl edit deployment/user-management-deployment -o yaml --save-config ``` 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 ...
Forward port 3000 on your local machine to port 8000 in the pod
Command: ```bash kubectl port-forward pod/backend-pod 3000: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 automa...
Forward traffic from local port 5432 to port 8081 in the pod named api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 5432:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Set the cluster field in the admin-context context to kube-cluster-2
Command: ```bash kubectl config set contexts.admin-context.cluster kube-cluster-2 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Create a copy of the 'proxy-service-pod', changing all container images to 'wordpress'. Name the copy 'debug-image-1'.
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-1 --set-image=*=wordpress ``` 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 ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
List the media-stream-pod in YAML output format.
Command: ```bash kubectl get -o yaml pod 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 namespaced you will only see...
Update the environment variable 'JWT_SECRET' for the deployment 'api-server-deployment'
Command: ```bash kubectl set env deployment/api-server-deployment JWT_SECRET=your-jwt-secret ``` 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 t...
Add a taint with the key 'disktype' on nodes that have the label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice disktype=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": "", "us...
Copy the file `/tmp/foo` from the remote pod `ingress-controller-pod-8` in the `default` namespace to the local directory `/tmp/bar_dir`.
Command: ```bash kubectl cp default/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, use ...
Create a new service account named 'flux'
Command: ```bash kubectl create serviceaccount flux ``` 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|name|go-templ...
View the details of the daemonset revision 1 for 'namespace-3'
Command: ```bash kubectl rollout history daemonset/namespace-3 --revision=1 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Get output from running a Docker command in a specific container within a pod
Command: ```bash kubectl exec cdn-service-pod -c nano-bot -- docker run -d ubuntu sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container...
Display detailed information about the context named "cluster-2-context" from your kubeconfig file.
Command: ```bash kubectl config get-contexts cluster-2-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 "
Port forward deployment/monitoring-stack-deployment from local ports 5432 to pod ports 8000
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 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 ...
Create an ingress with a rule that directs requests from website.com/input to svc1:9090 using the tls secret "my-cert"
Command: ```bash kubectl create ingress public-service-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": ...
Open the 'gateway-service' service manifest in the 'sublime' editor to make any necessary changes.
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/gateway-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 variab...
Create a cron job named "log-rotation" that runs the "node" command every minute.
Command: ```bash kubectl create cronjob log-rotation --image=node --schedule="*/1 * * * *" -- node ``` 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", "short": "-o", "defaul...
Embed the certificate authority data for the "cloud-cluster" cluster entry.
Command: ```bash kubectl config set-cluster cloud-cluster --embed-certs --certificate-authority=~/.kube/dev-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 set...
Delete the pods and services with the names "auth" and "analytics".
Command: ```bash kubectl delete pod,service auth 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 selector. ...
Partially update a node by setting the "unschedulable" field to true
Command: ```bash kubectl patch node node-2 -p $'spec:\n unschedulable: true' ``` 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 FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags...
Auto scale the deployment "gateway" with a minimum of 4 pods and a maximum of 9 pods, using the default autoscaling policy.
Command: ```bash kubectl autoscale deployment gateway --min=4 --max=9 ``` 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 ...
Execute the 'nginx' command in the 'astro-container' from the 'gateway-pod' and retrieve the output.
Command: ```bash kubectl exec gateway-pod -c astro-container -- nginx ``` 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 ...
Return the logs from the container named proxy-service-pod-1 in the cache-cluster-deployment-1 deployment.
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c proxy-service-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:...
Copy the local file "/tmp/foo_dir" to the remote pod "rook-ceph/image-resizer-pod-20" in the namespace, and place it in the "/tmp/bar" directory.
Command: ```bash kubectl cp /tmp/foo_dir rook-ceph/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 th...
Create an ingress rule named 'www-ingress' with the specified configuration
Command: ```bash kubectl create ingress www-ingress --rule="testing.com/module=svc1:8082,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 specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-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 definit...
Add an annotation to the pod 'chat-app' with the key 'monitoring-tool' and the value 'Prometheus'
Command: ```bash kubectl annotate pods chat-app monitoring-tool=Prometheus ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ar...
Set the client-key-data field in the 'web-app' user configuration using the provided certificate data by using the --set-raw-bytes=true option.
Command: ```bash kubectl config set users.web-app.client-key-data cert_data_here --set-raw-bytes=true ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE i...
Set the custom TLS server name to "sun-cluster" for the "cluster-gamma" cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=sun-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...
View the details of revision 3 of the namespace-3 daemonset's rollout history.
Command: ```bash kubectl rollout history daemonset/namespace-3 --revision=3 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Remove the label named 'env' with the value 'bar' from the 'auth' pod
Command: ```bash kubectl label pods auth env- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true, ch...
Embed the certificate authority data for the cluster-gamma cluster entry by running the command "kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/moon-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/moon-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...
Create a new resource quota named "service-quota" with a maximum limit of 5 services.
Command: ```bash kubectl create quota service-quota --hard=services=5 ``` What it does: Create a resource quota with the specified name, hard limits, and optional scopes. Syntax: `kubectl create quota NAME [--hard=key1=value1,key2=value2] [--scopes=Scope1,Scope2] [--dry-run=server|client|none]` Helpful flags: "flag"...
Create a job named "log-processing-job" with the "golang" image and run the command "go version"
Command: ```bash kubectl create job log-processing-job --image=golang -- go 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": "Output fo...
Retrieve the logs from container "backend-pod-1" of the "email-server-deployment" deployment.
Command: ```bash kubectl logs deployment/email-server-deployment -c backend-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: "flag"...
create a cron job named "report-generation" using the "redis" image
Command: ```bash kubectl create cronjob report-generation --image=redis --schedule="*/1 * * * *" -- redis-server ``` 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", "short":...
Create a new config map named app-secrets with specified keys and their corresponding file paths
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/configurations/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 creat...
Patch a node with a new password by using a strategic merge patch in YAML format.
Command: ```bash kubectl patch node kube-master-9 -p $'stringData:\n password: new-password' ``` 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 FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]...
Forward port 8000 from localhost and IP 10.19.21.23 to port 9090 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crite...
Copy the local file /tmp/foo_dir to the /tmp/bar directory of the metrics-exporter-pod-10 pod in the argocd namespace.
Command: ```bash kubectl cp /tmp/foo_dir argocd/metrics-exporter-pod-10::/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 th...
Add a taint with key 'environment' on nodes having label owner=john-doe, set to PreferNoSchedule.
Command: ```bash kubectl taint node -l owner=john-doe environment=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": "", "usag...
Disable certificate checking for the staging-cluster entry in the kubeconfig file.
Command: ```bash kubectl config set-cluster staging-cluster --insecure-skip-tls-verify=true ``` 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...
Set the CPU limits of the nginx container in the "node" deployment to "5" and the memory limits to "2Gi".
Command: ```bash kubectl set resources deployment node -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 s...
Return the snapshot logs from the container 'api-service-pod-1' of the deployment named 'database-deployment'.
Command: ```bash kubectl logs deployment/database-deployment -c api-service-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: "flag"...
Auto scale the deployment "media-stream" with the number of pods between 6 and 9.
Command: ```bash kubectl autoscale deployment media-stream --min=6 --max=9 ``` 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 ...
Update the image of all containers in the daemonset named 'namespace-' to 'mongo:5.0.2'
Command: ```bash kubectl set image daemonset namespace-3 *=mongo:5.0.2 ``` 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: `...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/ui-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Retrieve the deployments in YAML output format for the "testing-apps" API group with version "dev-2.2.0"
Command: ```bash kubectl get deployments.dev-2.2.0.testing-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...
Create a new ingress resource called 'public-ingress' with a rule that directs requests from foo.com/example to the service 'svc1' on port 3306
Command: ```bash kubectl create ingress public-ingress --rule="foo.com/example=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a copy of the 'media-stream-pod' pod, changing the command of the 'stardust-shuttle' container
Command: ```bash kubectl debug media-stream-pod -it --copy-to=dgb-img --container=stardust-shuttle -- 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 def...
Check if you have permission to list the job named "content-import-job" in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/content-import-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 partial...
Check if you have access to list the "database-indexing-job" job in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/database-indexing-job -n default ``` 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 ...