prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new secret named jwt-secret from an env file
Command: ```bash kubectl create secret generic jwt-secret --from-env-file=path/to/profiles.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename ...
Import the environment variables from the ssh-key-secret secret and set them in the deployment/notification-handler-deployment
Command: ```bash kubectl set env --from=secret/ssh-key-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 o...
Forward traffic from port 8080 on both localhost and IP address 10.19.21.23 to port 9090 in the backend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 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 criteri...
Set the basic auth credentials for the "service-account" entry with the username "admin" and password "uXFGweU9l35qcif"
Command: ```bash kubectl config set-credentials service-account --username=admin --password=uXFGweU9l35qcif ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=key...
Remove the "client-secret" config value for the OpenID Connect auth provider for the "robot-user" entry
Command: ```bash kubectl config set-credentials robot-user --auth-provider=oidc --auth-provider-arg=client-secret- ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-...
Roll back the deployment "namespace-3" to the previous version
Command: ```bash kubectl rollout undo deployment/namespace-3 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource t...
Update the environment variable 'PORT' in deployment 'mydeployment' to the value 8080
Command: ```bash kubectl set env deployment/mydeployment PORT=8080 ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates (within replicati...
Taint the nodes with the label "namespace=mynamespace" with a taint key "disktype" and value "prod-node-5:PreferNoSchedule"
Command: ```bash kubectl taint node -l namespace=mynamespace 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": "", "u...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/namespace-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Create a deployment named 'monitoring' that runs the 'ruby' image and exposes port 8888.
Command: ```bash kubectl create deployment monitoring --image=ruby --port=8888 ``` 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:...
Auto scale the deployment "monitoring" with minimum 1 pod and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment monitoring --min=1 --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 us...
Listen on port 8081 on localhost and IP address 10.19.21.23, forwarding the traffic to port 8080 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8081: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 cri...
Create a new config map named db-config using the settings and key2 files as its data sources
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/configs/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 conf...
Run the composer --version command in the cyber-sleuth container of the analytics-pod pod
Command: ```bash kubectl exec analytics-pod -c cyber-sleuth -- composer --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 o...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/monitoring-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...
Start a php pod and configure the container to expose port 7000
Command: ```bash kubectl run hazelcast --image=php --port=7000 ``` 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...
Add a taint with key 'special' on nodes having the label 'instance=app-instance-1' and the value 'k8s-node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l instance=app-instance-1 special=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": "", "u...
Display resource usage metrics for all pods in the "my-ns" namespace
Command: ```bash kubectl top pod --namespace=my-ns ``` 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 | ...
Rename the context 'prod-context' to 'client-1-context' in your kubeconfig file
Command: ```bash kubectl config rename-context prod-context client-1-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will als...
Listen on the local ports 8088 and 6000 and forward data to/from the ports 3000 and 6000 in a pod selected by the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 8088 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Set the minimum and maximum number of pods for the "frontend" deployment to 1 and 8 respectively, enabling autoscaling.
Command: ```bash kubectl autoscale deployment frontend --min=1 --max=8 ``` 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...
Create an ingress called 'public-service-ingress' that directs requests to foo.com/bar to svc1:3000
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/bar=svc1:3000,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...
Install the aws-cli package in the cosmic-container running in the payment-gateway-pod, and display the output.
Command: ```bash kubectl exec payment-gateway-pod -c cosmic-container -- yum install -y aws-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": "Contai...
Create a pod disruption budget named api-service-pdb that will select all pods with the role=worker label and require a minimum of 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=role=worker --min-available=9 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [-...
Create a single ingress called 'default-ingress' that directs requests from foo.com/example to the service 'svc1' on port 8088 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/example=svc1:8088,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Set the user field for a specific context entry
Command: ```bash kubectl config set-context cloud-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nickname...
View the output from the nebula-navigator container in the payment-gateway-pod pod.
Command: ```bash kubectl attach payment-gateway-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 ...
Delete the pods and services with the names "api" and "frontend"
Command: ```bash kubectl delete pod,service api frontend ``` 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. So...
Create a service for a replication controller, as specified in the "alpine-controller.yaml" file, that serves traffic on port 80 and connects to containers on port 8000.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=6379 --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...
Get the output from running the 'kafka-topics --list' command from the first pod of the web-app-deployment deployment.
Command: ```bash kubectl exec deploy/web-app-deployment -- kafka-topics --list ``` 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 omit...
Embed the certificate authority data for the web-cluster cluster entry by running the command "kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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...
Add a taint on nodes labeled with 'myLabel' with the key 'workload' and value 'worker-node-3:PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel workload=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Create a new config map named 'ui-config' using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/settings/file1.txt --from-file=key1=/path/to/profiles/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 ...
Add a taint on nodes with a specific label
Command: ```bash kubectl taint node -l feature=feature-xyz datacenter=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 new service named external-logging-service of type ExternalName, with the externalName set to dummy-website.io
Command: ```bash kubectl create service externalname external-logging-service --external-name dummy-website.io ``` 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 ser...
Autoscale the deployment "payment" with a minimum of 6 pods and a maximum of 9 pods, using the default autoscaling policy
Command: ```bash kubectl autoscale deployment payment --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 uses ...
Create a new config map named env-vars with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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...
Restart the DaemonSet named 'nginx'
Command: ```bash kubectl rollout restart daemonset/nginx ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource to...
Copy the contents of the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the "logging/database-pod-2" pod to the "/tmp/bar_dir" directory locally.
Command: ```bash kubectl cp logging/database-pod-2:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "Conta...
Forward local port 9090 to port 8088 in the pod named `log-aggregator-pod`.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 9090: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...
Import the environment variables from the `my-secret` secret and set them in the `frontend-deployment` deployment.
Command: ```bash kubectl set env --from=secret/my-secret deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templa...
Add a taint with the key 'dedicated' on nodes having the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe dedicated=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": "", "usage"...
Create an ingress called ingress1 with multiple hosts and the pathType set as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:9092" \ --rule="module.com/admin*=svc2:http" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", ...
Listen on a random local port and forward traffic to port 9090 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod :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...
Update the annotation 'backup-strategy' of pod 'payment' with the value 'daily-backups', and overwrite any existing value
Command: ```bash kubectl annotate --overwrite pods payment backup-strategy='daily-backups' ``` 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 label...
Remove the 'dedicated' taint from node 'node-1'
Command: ```bash kubectl taint nodes node-1 dedicated- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name...
Forward port 8888 on localhost and IP 10.19.21.23 to port 8000 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 8888: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 th...
Forward local port 3000 to port 8088 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-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 be selected aut...
Forward port 8080 on localhost and IP 10.19.21.23 to port 5432 in the backend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-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 criteri...
Add a taint with the key 'special' to nodes that have the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe special=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...
Add a description to a pod identified by type and name in "setup.json"
Command: ```bash kubectl annotate -f setup.json description='Web server for marketing site' ``` 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 labe...
Delete a pod forcefully, even if it's on a dead node
Command: ```bash kubectl delete pod foo --force ``` 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. Some resour...
create a cron job that runs a command every 1 minute using the "node" image
Command: ```bash kubectl create cronjob backup-job --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", "default"...
Create a cron job named 'system-health-check' using the 'golang' image
Command: ```bash kubectl create cronjob system-health-check --image=golang --schedule="*/1 * * * *" -- go run hello.go ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "s...
Begin streaming the logs of the 'nebula-navigator' container in the 'database-pod' pod
Command: ```bash kubectl logs -f -c nebula-navigator 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",...
Create an ingress called 'app1-ingress' that directs requests to site.com/module to a service named svc1 on port 5432, using the TLS secret named "my-cert".
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/module=svc1:5432,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 an ingress called 'default-ingress' with a rule that directs requests for testing.com/bar to svc1:7000 using the tls secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="testing.com/bar=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
create a new ClusterIP service named frontend-service-clusterip
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=5000:6379 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Update the pod 'proxy-server' by adding the annotation 'scaling-policy' with the value 'auto-horizontal-scaling'.
Command: ```bash kubectl annotate pods proxy-server scaling-policy=auto-horizontal-scaling ``` 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 label...
Scale the deployment named "mysql" to 1 replica if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 deployment/bar ``` 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 spec...
Create a cron job with a specific schedule and image
Command: ```bash kubectl create cronjob backup-job --image=php --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": "", ...
Import the 'DEBUG_MODE' key from the 'db-config' config map into the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/db-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create a service named "frontend" for the pod "media-stream-pod" that serves on port 444 and exposes port 8082.
Command: ```bash kubectl expose pod media-stream-pod --port=8082 --name=frontend ``` 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...
Remove the taint with the key 'dedicated' from the node 'app-node-6'
Command: ```bash kubectl taint nodes app-node-6 dedicated- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|...
Get deployments in JSON format from the "external-apps" API group in version v2.0.0.
Command: ```bash kubectl get deployments.v2.0.0.external-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 w...
return the snapshot logs from the container notification-handler-deployment-1 of the deployment named proxy-server-pod
Command: ```bash kubectl logs deployment/notification-handler-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 ...
Create a new deployment named "ingress" using the "ubuntu" image. The container will execute the command "echo 'Hello'".
Command: ```bash kubectl create deployment ingress --image=ubuntu -- docker run ubuntu echo "Hello ``` 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": "Ou...
Update the environment variable 'PORT' of the deployment 'search-engine-deployment' to 8080.
Command: ```bash kubectl set env deployment/search-engine-deployment PORT=8080 ``` 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 (with...
Create a single ingress called 'www-ingress' that directs requests to website.com/example to svc # svc1:9000 with a TLS secret "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="website.com/example=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": "", "usag...
Create a cluster role named "admin_role" with the `create` verb allowed for the `/healthz` non-resource URL
Command: ```bash kubectl create clusterrole "admin_role" --verb=create --non-resource-url=/healthz ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", ...
Forward local port 8088 to port 8088 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Execute the 'mysql' command in the 'cyber-sleuth' container of the 'web-app-pod' pod and display the output.
Command: ```bash kubectl exec web-app-pod -c cyber-sleuth -- 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 omitted, use the...
Setup auto scaling for a replication controller named "proxy" with a target CPU utilization of 60% and a minimum of 1 pod and a maximum of 2 pods.
Command: ```bash kubectl autoscale rc proxy --max=2 --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 uses t...
Update the pod identified by type and name in the "settings.json" file by adding the annotation "custom-label" with the value "my-custom-value"
Command: ```bash kubectl annotate -f settings.json custom-label=my-custom-value ``` 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 inclu...
Add a taint with the key 'environment' and the value 'k8s-node-1:PreferNoSchedule' on all nodes that have the label 'customer=acme-corp'.
Command: ```bash kubectl taint node -l customer=acme-corp environment=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...
Run the command 'node --version' inside the cosmic-container in the auth-service-pod and print the output.
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- node --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Forward port 5432 from the pod "analytics-pod" to all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 5432: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 wil...
Begin streaming the logs of the 'cosmic-container' container in the pod 'monitoring-pod'.
Command: ```bash kubectl logs -f -c cosmic-container 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...
Create an ingress called 'app-gateway-ingress' that directs requests to website.com/module to the service with the name svc1 and port 8083
Command: ```bash kubectl create ingress app-gateway-ingress --rule="website.com/module=svc1:8083,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": ""...
Add a taint with the key 'special' and the value 'worker-node-3:PreferNoSchedule' on nodes that have the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta special=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Get the logs from the container "web-app-pod-1" of the deployment "proxy-service-deployment".
Command: ```bash kubectl logs deployment/proxy-service-deployment -c web-app-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...
Import the 'SECRET_KEY' key from the 'ui-config' ConfigMap and set it as an environment variable in the 'search-engine-deployment' Deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --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...
Create a new ExternalName service named external-notification-service
Command: ```bash kubectl create service externalname external-notification-service --external-name bar.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 service...
Set the service account of the deployment "cache-cluster-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment fluentd ``` 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: `kube...
Run the 'node' command inside the 'nebula-navigator' container of the 'security-service-pod' pod and get the output.
Command: ```bash kubectl exec security-service-pod -c nebula-navigator -- 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 omit...
Set the service account of the deployment 'log-aggregator-deployment' to 'kube-dns'
Command: ```bash kubectl set serviceaccount deployment log-aggregator-deployment kube-dns ``` 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: `ku...
Create a service for the replication controller specified in the "alpine-controller.yaml" file, which serves on port 3000 and connects to the containers on port 808200
Command: ```bash kubectl expose -f alpine-controller.yaml --port=3000 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
create a job called log-processing-job using the mysql image and running the command "mysqld"
Command: ```bash kubectl create job log-processing-job --image=mysql -- mysqld ``` 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....
Get the output from running the 'mysqld' command from the backend-pod pod
Command: ```bash kubectl exec backend-pod -- mysqld ``` 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.kubern...
List deployments in the YAML output format for the "custom-version" version of the "api-v1" API group
Command: ```bash kubectl get deployments.custom-version.api-v1 -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 ...
Import specific keys from a config map into deployment's environment variables
Command: ```bash kubectl set env --keys=api_key --from=configmap/log-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Forward the local port 6379 to port 8888 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-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 will be selected automa...
Create a copy of the email-service-pod with a debug container and attach to it
Command: ```bash kubectl debug email-service-pod -it --image=busybox --copy-to=debug-image-app ``` 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...
Start an alpine pod and configure the container to expose port 5432
Command: ```bash kubectl run hazelcast --image=alpine --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": "--f...
Create a role named "reader" with the ability to update pods and specifically target the resources "monitoring-prometheus" and "content-delivery".
Command: ```bash kubectl create role reader --verb=update --resource=pods --resource-name=monitoring-prometheus --resource-name=content-delivery ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-r...
Copy the local file "/tmp/foo_dir" to the remote pod "monitoring-agent-pod-6" in the "kube-proxy" namespace, and save it as "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo_dir kube-proxy/monitoring-agent-pod-6:/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 ...
Create a cluster role named "reader" with the ability to create and access configmaps with the name "order-fulfillment"
Command: ```bash kubectl create clusterrole reader --verb=create --resource=configmaps --resource-name=order-fulfillment --resource-name=order-fulfillment ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=s...
Start a pod with the image mcr.microsoft.com/dotnet/core/runtime and keep it running in the foreground
Command: ```bash kubectl run -i -t busybox --image=mcr.microsoft.com/dotnet/core/runtime --restart=Never ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] ...
Start a pod named hazelcast using the alpine image and expose port 5000
Command: ```bash kubectl run hazelcast --image=alpine --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": "--f...
Listen on port 3000 locally, forwarding to port 8080 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 3000: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 aut...