prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the image of all containers in the 'prod' daemonset to 'debian:11.0'
Command: ```bash kubectl set image daemonset prod *=debian:11.0 ``` 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: `kubectl...
Set the 'unschedulable' field to true for the node named 'app-node-6' using a strategic merge patch specified in YAML format.
Command: ```bash kubectl patch node app-node-6 -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 f...
Create a job named "cleanup" with the image "wordpress" and the command "mysql --version"
Command: ```bash kubectl create job cleanup --image=wordpress -- mysql --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 forma...
Expose a deployment called "hazelcast" as a service, with a service port of 6379, and connect to the containers on port 8000.
Command: ```bash kubectl expose deployment hazelcast --port=6379 --target-port=8000 ``` 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 specif...
Copy the file /var/run/secrets/kubernetes.io/serviceaccount/ from your local machine to the /tmp/bar_dir directory in the monitoring-agent-pod-6 pod in the kube-server namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-server/monitoring-agent-pod-6:/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": "", "us...
Update the annotation 'team' of the pod 'backend' to 'frontend team'.
Command: ```bash kubectl annotate pods backend 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...
Create a job named "log-processing-job" using the PHP image and run the command "composer --version" within the job.
Command: ```bash kubectl create job log-processing-job --image=php -- composer --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Import the environment from the 'jwt-secret' secret into the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --from=secret/jwt-secret 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 definitions in one or mo...
Create a cron job named daily-report that runs the command `pip --version` every minute using the Python image.
Command: ```bash kubectl create cronjob daily-report --image=python --schedule="*/1 * * * *" -- pip --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", "short": "-...
Display the last 23 lines of logs for the 'monitoring-pod' pod
Command: ```bash kubectl logs --tail=23 monitoring-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "...
Import specific keys from a config map to an environment variable for a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/log-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 in one ...
Check the output of the 'nginx -t' command in the first container of the api-server-deployment.
Command: ```bash kubectl exec deploy/api-server-deployment -- nginx -t ``` 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...
Forward local port 8081 to port 8888 in the pod "mypod"
Command: ```bash kubectl port-forward pod/mypod 8081: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 automaticall...
Forward traffic from port 3000 on all addresses to port 6379 within the analytics-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 3000: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 wil...
Create a new config map named app-config using specific keys from files
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/parameters/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...
Forward data between local port 8000 and pod port 5432 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward pod/analytics-pod 8000 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 auto...
Run the 'psql' command inside the first container of the first pod of the scheduler-service service
Command: ```bash kubectl exec svc/scheduler-service -- psql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Update the image of all containers in the 'development' daemonset to 'mongo:5.0.2'
Command: ```bash kubectl set image daemonset development *=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: `...
Port forward from localhost and another IP to a pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-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 cri...
Create a new ClusterIP service named messaging-service-clusterip that maps port 5000 to port 8181
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=5000:8181 ``` 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": "-...
Forward traffic from port 8081 on localhost and IP address 10.19.21.23 to port 9090 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8081: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 crit...
Partially update the testing-node-11 node by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node testing-node-11 -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]` H...
Create a job named "audit-job" with the image "ubuntu" and run the command "docker run -it ubuntu"
Command: ```bash kubectl create job audit-job --image=ubuntu -- docker run -it ubuntu ``` 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 ...
Add a taint to a specific node with a key and no value
Command: ```bash kubectl taint nodes worker-node-3 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of...
Attach to the backend pod's code-explorer container in interactive and raw terminal mode
Command: ```bash kubectl attach backend-pod -c code-explorer -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
List the replication controller "web", the service "chat-app-rc", and the pod "cdn-service-pod".
Command: ```bash kubectl get rc/web service/chat-app-rc pods/cdn-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 namespace...
remove the taint with key 'app' and effect 'PreferNoSchedule' from the 'prod-node-5' node
Command: ```bash kubectl taint nodes prod-node-5 app: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 format. One of...
Start a golang pod with the name 'nginx', using the golang image
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "v1.1.1", "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] -- [COMMAN...
Create a service for a replicated node on port 80 that connects to the containers on port 8000.
Command: ```bash kubectl expose rc node --port=8888 --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 specified port. A...
Exec into the first pod of the frontend-service and run the 'docker run -it ubuntu' command.
Command: ```bash kubectl exec svc/frontend-service -- docker run -it ubuntu ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Listen on ports 9090 and 6000 locally, forwarding data to/from ports 9090 and 6000 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 9090 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Create a pod with the WordPress image and set labels "app=wordpress" and "env=prod"
Command: ```bash kubectl run hazelcast --image=wordpress --labels="app=wordpress,env=prod" ``` 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...]` He...
Partially update a node's data using a JSON patch
Command: ```bash kubectl patch node kube-master-9 -p '{"data":{"key":"new-value"}' ``` 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...
Copy the contents of the '/var/run/secrets/kubernetes.io/serviceaccount/' directory from the 'cache-pod-5' pod to the '/etc/kubernetes' directory on the local machine.
Command: ```bash kubectl cp monitoring/cache-pod-5:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "Co...
Forward traffic from local port 3000 to port 3000 in the pod "chat-app-pod" on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 3000: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...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/monitoring-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 ...
Autoscale the 'analytics' deployment with a minimum of 4 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment analytics --min=4 --max=10 ``` 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 us...
Taint nodes with the label "instance=app-instance-1" by adding a taint with the key "zone" and value "backup-node-14" with effect "PreferNoSchedule".
Command: ```bash kubectl taint node -l instance=app-instance-1 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": "", "...
Expose a replication controller as a service on port 80, connecting to containers on port 8000.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=80 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Edit the logging-service service using the emacs editor.
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/logging-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...
Import the 'debug_mode' key from the 'monitoring-config' config map into the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/monitoring-config deployment/authentication-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 var...
Output the modified search-engine-deployment in YAML format, without making any changes to the object on the server
Command: ```bash kubectl set env deployment/search-engine-deployment SMTP_USERNAME=your-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 o...
Create a new config map named app-config based on the parameters in a folder
Command: ```bash kubectl create configmap app-config --from-file=path/to/parameters ``` 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 basename...
Retrieve the output of the 'geth version' command from the web-app-pod pod using the default container.
Command: ```bash kubectl exec web-app-pod -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Retrieve snapshot logs from the container named "gateway-pod-1" in the deployment named "email-server-deployment".
Command: ```bash kubectl logs deployment/email-server-deployment -c gateway-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 service for the php deployment, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment php --port=8084 --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 specified ...
Retrieve the output from running the command 'pg_dump --version' in the 'nebula-navigator' container of the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c nebula-navigator -- pg_dump --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 nam...
Forward all traffic on port 5432 from any address to port 6379 in the 'api-service-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-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 pod w...
Copy the file named "foo" from the remote pod to your local machine and save it as "bar" in the /tmp directory.
Command: ```bash kubectl cp prometheus/payment-gateway-pod-19::/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 th...
Create a new ClusterIP service named database-service-clusterip with TCP port mapping from 5432 to 8888.
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=5432:8888 ``` 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...
Create an ingress called 'www-ingress' that directs requests from 'site.com/bar' to 'svc1:8081' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress www-ingress --rule="site.com/bar=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": "", "usage": "Ou...
Set the custom TLS server name to 'kube-cluster-2' for the 'galaxy-cluster' cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=kube-cluster-2 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifi...
Add a taint with the key 'app' on nodes that have the label 'myLabel', specifically on the node named 'monitoring-node-15'
Command: ```bash kubectl taint node -l myLabel app=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Create a job with a specific command
Command: ```bash kubectl create job image-build-job --image=alpine -- ash ``` 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 ...
Create a new config map named app-config using the files file1.txt and file2.txt as the configuration and preference keys, respectively.
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/preferences/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 con...
Create a service for the replicated nginx deployment, which serves on port 7000 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc nginx --port=7000 --target-port=800000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Forward local port 6379 to the targetPort of the "https" port in the pod selected by the service named "search-service"
Command: ```bash kubectl port-forward service/search-service 6379: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 selecte...
Forward local ports to a pod
Command: ```bash kubectl port-forward pod/api-service-pod 6379 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Get the logs of the container "proxy-server-pod" in the deployment "load-balancer-deployment-1".
Command: ```bash kubectl logs deployment/load-balancer-deployment -c proxy-server-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 php pod with a container that exposes port 5432
Command: ```bash kubectl run hazelcast --image=php --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": "--file...
Forward traffic from port 5432 on all addresses to port 8088 in the frontend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5432: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...
Create a cron job with a specific image, schedule, and command
Command: ```bash kubectl create cronjob cron-task --image=node --schedule="*/1 * * * *" -- npm --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", "short": "-o", "...
Create a new ExternalName service named external-security-service with the external name example-domain.com
Command: ```bash kubectl create service externalname external-security-service --external-name example-domain.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 reference ...
set up autoscaling for the replication controller "monitoring" with a target CPU utilization of 60%, and a minimum of 1 pod and a maximum of 7 pods.
Command: ```bash kubectl autoscale rc monitoring --max=7 --cpu-percent=60 ``` 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 u...
Retrieve the output of the 'node --version' command from the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -- 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, use the kub...
Create a copy of proxy-service-pod with a debug container and modified container images.
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-web --image=debian --set-image=scheduler=my-scheduler:1.0,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifi...
Attach to the pod "e-commerce-pod" and get output from the container named "nebula-navigator"
Command: ```bash kubectl attach e-commerce-pod -c nebula-navigator ``` 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 omitt...
Retrieve the logs of the previous terminated "cyber-sleuth" container from the pod named "security-service-pod"
Command: ```bash kubectl logs -p -c cyber-sleuth security-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": "--contain...
Display the last 5 lines of logs for the 'proxy-service-pod' pod.
Command: ```bash kubectl logs --tail=5 proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short":...
Create a debug session for the backend-pod by copying it to a new debug-image-web pod with the stardust-shuttle container and start an interactive shell
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-web --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 ...
Listen on ports 8888 locally and forward data to/from port 6379 in a pod selected by the 'database-deployment' deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 8888 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Copy a file from a remote pod to a local directory
Command: ```bash kubectl cp kube-public/backend-pod-13:/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Create a service for the php deployment, which serves on port 8181 and connects to the containers on port 8080.
Command: ```bash kubectl expose deployment php --port=8181 --target-port=808400 ``` 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 ...
Create an ingress resource called 'default-ingress' that directs requests to website.com/module to the service 'svc1' on port 8080
Command: ```bash kubectl create ingress default-ingress --rule="website.com/module=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": "", "u...
Create a secret named "ldap-credentials-secret" using the configurations from an environment file.
Command: ```bash kubectl create secret generic ldap-credentials-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 defau...
Set the cluster field in the admin-context context to moon-cluster
Command: ```bash kubectl config set contexts.admin-context.cluster moon-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Forward traffic from port 8081 on localhost and IP 10.19.21.23 to port 8088 in the "security-service-pod" pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8081: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 th...
Annotate a pod specified in "config.json" by updating the environment variable to "staging"
Command: ```bash kubectl annotate -f config.json env=staging ``` 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...
List the supported namespaced resources
Command: ```bash kubectl api-resources --namespacedspaced=true ``` 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. "
Create a new config map named "app-config-dev" in the default namespace
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/preferences/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 co...
List the deployments in the "beta-1.0" version of the "beta-apps" API group and display the output in JSON format.
Command: ```bash kubectl get deployments.beta-1.0.beta-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 wil...
Forward traffic from port 8080 on all addresses to port 8000 in the mypod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8080:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sel...
Create a new pod running a container using the `node` image and expose port 8083.
Command: ```bash kubectl run hazelcast --image=node --port=8083 ``` 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...
Create a role named "admin_role" with ResourceName specified
Command: ```bash kubectl create role admin_role --verb=create --resource=pods --resource-name=search-elasticsearch --resource-name=cdn-proxy ``` 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=s...
Create a deployment named "drupal" using the "alpine" image and run the command "sleep 3600"
Command: ```bash kubectl create deployment drupal --image=alpine -- sleep 3600 ``` 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:...
Forward local port 8088 to port 8080 in the pod cdn-service-pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8088 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 au...
Create a service for the wordpress deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment wordpress --port=3306 --target-port=543200 ``` 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 spec...
Taint nodes with label 'owner=john-doe' as 'special=backup-node-14' and set the taint effect to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe special=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"...
Check if you have permission to list the job named "load-testing-job" in the namespace "kube-ingress".
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n kube-ingress ``` 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 ...
Forward traffic from port 8888 on the local machine to port 3000 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 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 select...
check if you have permission to list the job named "load-testing-job" in the namespace "production"
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-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 UR...
Listen on port 3000 on all addresses and forward the traffic to port 8088 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 3000: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...
Listen on both the localhost and IP address 10.19.21.23, and forward traffic from port 8888 to port 9090 inside the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8888: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 crit...
List a single pod in JSON output format.
Command: ```bash kubectl get -o json pod api-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 namespaced you will only see ...
Add a taint with the key 'environment' and value 'edge-node-10:PreferNoSchedule' on nodes having the label 'namespace=mynamespace'.
Command: ```bash kubectl taint node -l namespace=mynamespace 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": ""...
Create a job named "audit-job" with the command "mysql --version" using the "wordpress" image.
Command: ```bash kubectl create job audit-job --image=wordpress -- mysql --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 for...
delete both the pod and service with the names 'proxy' and 'gateway'
Command: ```bash kubectl delete pod,service proxy gateway ``` 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. S...
Create a single ingress called 'api-gateway-ingress' with a rule that directs requests from 'foo.com/module' to service 'svc1' on port '3001', using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/module=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Listen on port 8888 on all addresses, forwarding to port 8080 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8888: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 ...
Import the 'redis_host' key from the config map 'ui-config' into the environment variables of the 'search-engine-deployment' deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/ui-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 definitions...