prompt
stringlengths
13
282
response
stringlengths
128
3.11k
create a service for the hazelcast deployment, exposing port 8181 and connecting to the containers on port 808800
Command: ```bash kubectl expose deployment hazelcast --port=8181 --target-port=808800 ``` 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...
Autoscale the deployment named "foo" with a minimum of 1 pod and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment foo --min=1 --max=13 ``` 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...
Partially update a node using a strategic merge patch
Command: ```bash kubectl patch -f node.json -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 flags...
Copy the directory `/tmp/foo_dir` from a remote pod named `backend-pod-13` to the local directory `/tmp/bar`.
Command: ```bash kubectl cp kube-proxy/backend-pod-13:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Create a job with a specific command
Command: ```bash kubectl create job deployment-rollout-job --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 for...
Forward traffic from port 8088 on all addresses to port 8088 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8088: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 wil...
Create a cron job with a specified command.
Command: ```bash kubectl create cronjob database-maintenance --image=nginx --schedule="*/1 * * * *" -- nginx -g "daemon off;" ``` 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": "--outp...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/ui-config deployment/gateway-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 on...
Add a taint with key 'disktype' and value 'prod-node-5:PreferNoSchedule' on nodes having label 'role=database'
Command: ```bash kubectl taint node -l role=database disktype=prod-node-5: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 label of the pod 'log-aggregator' with the label 'release' and the value 'v1.0'
Command: ```bash kubectl label pods log-aggregator release=v1.0 ``` 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", "us...
Set up auto scaling for the replication controller "vpn" with a target CPU utilization of 40% and a minimum of 1 pod and a maximum of 7 pods.
Command: ```bash kubectl autoscale rc vpn --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...
Start an alpine pod with specific environment variables
Command: ```bash kubectl run hazelcast --image=alpine --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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 "node" image and expose port 5000.
Command: ```bash kubectl run hazelcast --image=node --port=5000 ``` 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...
Forward port 6379 of a pod to port 8888 on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 6379:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Create an ingress to route requests from testing.com/example to svc1:8080 with a TLS secret called "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="testing.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", "default": "", "...
Create a new ExternalName service named my-ns with the external name "sample-domain.net"
Command: ```bash kubectl create service externalname my-ns --external-name sample-domain.net ``` 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 services that exist o...
List deployments in JSON output format from the "third-party-apps" API group in version "v3.0.0"
Command: ```bash kubectl get deployments.v3.0.0.third-party-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 yo...
Create an ExternalName service named external-geolocation-service pointing to the external domain tutorial-ai.ai
Command: ```bash kubectl create service externalname external-geolocation-service --external-name tutorial-ai.ai ``` 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 s...
Taint nodes with label owner=john-doe with the key 'special' and value 'app-node-6:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe special=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Add a taint with a specific key and value on nodes that have a specific label
Command: ```bash kubectl taint node -l cluster=my-cluster cpu-type=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": "", "u...
Output the modified payment-processor-deployment deployment in YAML format without altering the object on the server
Command: ```bash kubectl set env deployment/payment-processor-deployment DB_PASSWORD=secretpassword -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 on...
Expose the replicated Centos instances using a replica set, making them available on port 8888 externally and connecting to the containers on port 801000
Command: ```bash kubectl expose rs centos --port=8888 --target-port=801000 ``` 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....
Import the 'external_api_url' key from the 'app-config' config map and set it as an environment variable for the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a deployment named mattermost using the ruby image and expose port 8082
Command: ```bash kubectl create deployment mattermost --image=ruby --port=8082 ``` 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:...
Create a deployment named 'grafana' using the 'amazonlinux' image and expose port 27017.
Command: ```bash kubectl create deployment grafana --image=amazonlinux --port=27017 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. On...
create a cron job with the given schedule and image
Command: ```bash kubectl create cronjob alerts-cleanup --image=busybox --schedule="*/1 * * * *" ``` 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", "default":...
Run the 'irb' command in the 'stardust-shuttle' container of the 'mypod' pod
Command: ```bash kubectl exec mypod -c stardust-shuttle -- 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 kub...
Create a single ingress named 'app1-ingress' with the rule that directs requests to website.com/example to svc1:9091
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/example=svc1:9091,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...
Create a new NodePort service named payment-gateway-nodeport with port forwarding from local port 3000 to pod port 8088
Command: ```bash kubectl create service nodeport payment-gateway-nodeport --tcp=3000:8088 ``` 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", "defau...
Start a new pod named "hazelcast" using the WordPress image and expose port 5432
Command: ```bash kubectl run hazelcast --image=wordpress --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": "...
Partially update the node configuration specified in "kubeadm-config.yaml" by merging the changes specified in the strategic merge patch provided in the command
Command: ```bash kubectl patch -f kubeadm-config.yaml -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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: `kub...
Forward port 8080 on your localhost and IP address 10.19.21.23, and forward it to port 5432 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8080: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...
Update the 'payment' pod by adding or updating the annotation 'security-scan-status' with the value 'pass', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods payment 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 an...
Partially update a node by applying a strategic merge patch provided as a YAML file
Command: ```bash kubectl patch node dev-node-4 -p $'spec:\n 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]` Helpful fl...
Update the 'backend-microservice-deployment' deployment with a new environment variable named SECRET_KEY and set it to 'your-secret-key'
Command: ```bash kubectl set env deployment/backend-microservice-deployment SECRET_KEY=your-secret-key ``` 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 ...
Update the 'database' pod by setting the annotation 'SLA' to '99.9% uptime', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods database SLA='99.9% uptime' ``` 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 includ...
Add a taint on nodes with label 'role=database'
Command: ```bash kubectl taint node -l role=database cpu-type=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": "", "us...
Forward traffic from port 6379 on localhost and IP 10.19.21.23 to port 8888 in the pod named e-commerce-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 6379:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Approve a Certificate Signing Request (CSR) with the name 'csr-sqgzp'
Command: ```bash kubectl certificate approve csr-sqgzp ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attribut...
Describe the team-beta-context in your kubeconfig file
Command: ```bash kubectl config get-contexts team-beta-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 "
Create a copy of the cdn-service-pod and start an interactive debugging session with the 'cyber-sleuth' container
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=dgb-img --container=cyber-sleuth -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default ...
Set the service account of the deployment "email-server-deployment" to "default"
Command: ```bash kubectl set serviceaccount deployment email-server-deployment default ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubec...
Display metrics for all pods in the default namespace.
Command: ```bash kubectl top pod ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAME | -l label]` Helpfu...
Expose a replicated node using a replica set as a service, serving on port 8083 and connecting to the containers on port 800000
Command: ```bash kubectl expose rs node --port=8083 --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. A...
Inject specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config 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 defi...
Update the labels of the pod 'log-aggregator' with the label 'role' and the value 'backend'
Command: ```bash kubectl label pods log-aggregator role=backend ``` 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", "us...
Set the custom TLS server name "cluster-beta" for the "prod-cluster" cluster entry using the command "kubectl config set-cluster prod-cluster --tls-server-name=cluster-beta"
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=cluster-beta ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate...
Execute the 'mysql' command inside the 'stardust-shuttle' container of the 'proxy-service-pod' pod to get the output.
Command: ```bash kubectl exec proxy-service-pod -c stardust-shuttle -- mysql ``` 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 omitte...
Update the pod 'auth' with the annotation 'team' and the value 'frontend-team' by overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods auth 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 ...
Update the pod using the information specified in the 'config.json' file.
Command: ```bash kubectl replace -f ./config.json ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by $ kubectl get TYPE NAME -o yaml Syntax: `kubectl replace -f FILENAME...
Enable a raw terminal connection to the code-explorer container in the gateway-pod.
Command: ```bash kubectl attach gateway-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...
Create a copy of the auth-service-pod and change all container images to nginx
Command: ```bash kubectl debug auth-service-pod --copy-to=my-debugger --set-image=*=nginx ``` 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 reso...
Update the deployment 'email-server-deployment' by adding a new environment variable named LOG_LEVEL with the value of 'info'.
Command: ```bash kubectl set env deployment/email-server-deployment LOG_LEVEL=info ``` 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 (...
Retrieve the logs of the previous terminated stardust-shuttle container from the pod named proxy-service-pod.
Command: ```bash kubectl logs -p -c stardust-shuttle 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": "--contai...
Create a single ingress called 'rontend-ingress' that directs requests to testing.com/input to svc # svc1:8000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="testing.com/input=svc1:8000,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...
Begin streaming the logs of the 'time-machine' container in the 'media-stream-pod' pod
Command: ```bash kubectl logs -f -c time-machine media-stream-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Set the annotation 'expiration-date' with the value '2024-12-31' on the pod named 'web'.
Command: ```bash kubectl annotate pods web 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 arbit...
Forward port 8088 on your local machine to port 8088 in the web-app-pod pod
Command: ```bash kubectl port-forward pod/web-app-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a deployment with the specified image and command.
Command: ```bash kubectl create deployment wordpress --image=jenkins -- jenkins-plugin-cli ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output for...
Create a deployment named "drupal" with the "centos" image and 6 replicas.
Command: ```bash kubectl create deployment drupal --image=centos --replicas=6 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Set the service account for the deployment 'monitoring-stack-deployment' to 'default'
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment default ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `k...
Check if the current user has permission to list jobs in the "kube-public" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/deploy-artifacts-job -n kube-public ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Import the SECRET_KEY key from the app-config ConfigMap into the environment variables for the order-processing-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-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 variable definit...
Start a proxy server that allows accessing the Kubernetes API and static files
Command: ```bash kubectl proxy --www=/my/files --www-prefix=/static/ --api-prefix=/api/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and ge...
Add a taint with the key 'app' and the value 'db-node-7:PreferNoSchedule' on nodes having the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 app=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output...
Start a pod named hazelcast using the mongo image and expose port 9092
Command: ```bash kubectl run hazelcast --image=mongo --port=9092 ``` 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": "--fi...
Forward local port to a pod port
Command: ```bash kubectl port-forward pod/mypod :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 automatically. T...
Execute the 'redis-server' command in the first pod of the 'database-service' service.
Command: ```bash kubectl exec svc/database-service -- 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 omitted, use the...
Run 'apache2ctl -D FOREGROUND' command in time-machine in the pod proxy-server-pod and get the output
Command: ```bash kubectl exec proxy-server-pod -c time-machine -- apache2ctl -D FOREGROUND ``` 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 n...
Retrieve the previous terminated logs from the 'cosmic-container' container within the 'web-app-pod' pod
Command: ```bash kubectl logs -p -c cosmic-container web-app-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", ...
Create a cron job to run a command on a schedule
Command: ```bash kubectl create cronjob cron-task --image=jenkins --schedule="*/1 * * * *" -- jenkins --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": ...
Add a taint to the node 'storage-node-13' with the key 'app', value 'backend' and effect 'PreferNoSchedule'.
Command: ```bash kubectl taint nodes storage-node-13 app=backend: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 for...
Embed certificate authority data for the 'sun-cluster' cluster entry by executing the command 'kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/data-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-...
Display the most recent 43 lines of logs from the pod named vpn-service-pod
Command: ```bash kubectl logs --tail=43 vpn-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": ...
Scale down the deployment named app-v2-replicaset's replicas of mysql to 1.
Command: ```bash kubectl scale --current-replicas=5 --replicas=1 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...
Start a hazelcast pod with the image 'hazelcast/hazelcast' and make the container expose port 5000.
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=5000 ``` 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:...
Create a new ClusterIP service named log-service-clusterip
Command: ```bash kubectl create service clusterip log-service-clusterip --tcp=9090: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": "-o", "d...
Auto scale the replication controller "security" with the number of pods between 1 and 5, targeting a CPU utilization of 60%
Command: ```bash kubectl autoscale rc security --max=5 --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 use...
Forward local port 9090 to pod port 9090
Command: ```bash kubectl port-forward pod/web-app-pod 9090 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Import the my-example-key key from the config map app-name-config into the environment variables of the backend-microservice-deployment deployment.
Command: ```bash kubectl set env --keys=my-example-key --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 var...
Partially update the node named 'edge-node-10' by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node edge-node-10 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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...
Add the label 'role=frontend' to the pod named 'analytics'
Command: ```bash kubectl label pods analytics role=frontend ``` 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"...
Get the output from running the 'geth attach' command in the 'warp-drive' container of the 'cdn-service-pod' pod.
Command: ```bash kubectl exec cdn-service-pod -c warp-drive -- geth attach ``` 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 "email-service-pod" pod, changing the command of the "time-machine" container, and start an interactive shell session.
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-api --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 b...
Copy the local file `/tmp/foo` to the remote pod `payment-gateway-pod-19` in the `rook-ceph` namespace as `/tmp/bar`.
Command: ```bash kubectl cp :/tmp/foo rook-ceph/payment-gateway-pod-19::/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...
Copy the file /tmp/foo from the remote pod monitoring/cache-pod-5 to the local directory /tmp/bar.
Command: ```bash kubectl cp monitoring/cache-pod-5::/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 kubectl.k...
Create a new LoadBalancer service named email-service-lb
Command: ```bash kubectl create service loadbalancer email-service-lb --tcp=9091:8083 ``` 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", "d...
Create a pod disruption budget named notification-service-pdb that selects all pods with the region=us-east label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=region=us-east --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-av...
Create a service for a replicated ruby application that serves on port 9090 and connects to the containers on port 909000.
Command: ```bash kubectl expose rc ruby --port=9090 --target-port=909000 ``` 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...
Import environment variables from a secret for a deployment
Command: ```bash kubectl set env --from=secret/encryption-key-secret deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or m...
Forward the local ports 8080 and 6000 to ports 9090 and 6000 of a pod selected by the 'notification-handler-deployment' deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8080 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 ...
create a job with a command using a specific image
Command: ```bash kubectl create job indexing --image=php -- ``` 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: json|yaml|...
Wait for the status condition of the pod "frontend-pod" to be "Ready"
Command: ```bash kubectl wait --for=condition=Ready pod/frontend-pod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command can w...
Return the snapshot of previous terminated 'warp-drive' container logs from the 'auth-service-pod' pod.
Command: ```bash kubectl logs -p -c warp-drive auth-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", "...
Create a deployment named 'drupal' with 2 replicas using the 'alpine' image.
Command: ```bash kubectl create deployment drupal --image=alpine --replicas=2 ``` 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: ...
Copy the local file /tmp/foo_dir to the directory /etc/kubernetes in the pod named image-resizer-pod-20, in the namespace cert-manager.
Command: ```bash kubectl cp /tmp/foo_dir cert-manager/image-resizer-pod-20:/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 omitte...
Display a list of supported API resources sorted by scope.
Command: ```bash kubectl api-resources --sort-by=scope ``` 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 an ingress named "ingress1" with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:8181" \ --rule="example.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": "--outp...
Retrieve the output from running the 'node' command inside the 'mycontainer' container of the 'vpn-service-pod' pod.
Command: ```bash kubectl exec vpn-service-pod -c mycontainer -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Get the previous terminated logs of the "rocket-ranger" container from the "proxy-service-pod" pod.
Command: ```bash kubectl logs -p -c rocket-ranger 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...