prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new config map named global-config with the specified keys, settings and key2, using the files file1.txt and file2.txt respectively.
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/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 creatin...
Import environment from a secret for a specific deployment
Command: ```bash kubectl set env --from=secret/api-key-secret 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 definitions in one or mo...
Create a cron job with a specified command
Command: ```bash kubectl create cronjob backup-job --image=ethereum/client-go --schedule="*/1 * * * *" -- geth ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "...
Create an ingress called 'myapp-ingress' that directs requests to 'website.com/input' to service 'svc1' on port '3306' with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/input=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a secret named ssh-key-secret with two key-value pairs: key1=supersecret and key2=topsecret
Command: ```bash kubectl create secret generic ssh-key-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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 ...
Retrieve information about the replication controller named "web", the service named "log-aggregator-rc", and the pod named "vpn-service-pod".
Command: ```bash kubectl get rc/web service/log-aggregator-rc pods/vpn-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is nam...
Execute the command '/bin/bash -c "echo 'Hello, Amazon Linux'"' inside the pod security-service-pod and display the output, using the first container by default.
Command: ```bash kubectl exec security-service-pod -- /bin/bash -c "echo 'Hello, Amazon Linux'" ``` 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...
List the deployments in YAML output format for the "custom-apps" API group with the version "dev-2.2.0"
Command: ```bash kubectl get deployments.dev-2.2.0.custom-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you ...
Create an ingress called 'public-service-ingress' that directs requests to website.com/bar to svc1:8089 with the tls secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/bar=svc1:8089,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": ""...
Begin streaming the logs of the ruby container in the vpn-service-pod pod.
Command: ```bash kubectl logs -f -c ruby 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":...
Import the 'my-example-key' key from the 'log-config' config map and set it as an environment variable in the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/log-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 variable...
Copy the local file /tmp/foo to the /tmp/bar path in the remote pod named image-resizer-pod-20 in the metallb-system namespace.
Command: ```bash kubectl cp /tmp/foo metallb-system/image-resizer-pod-20::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Execute the command "geth version" inside the first pod of the "proxy-service" service, and display the output.
Command: ```bash kubectl exec svc/proxy-service -- 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 ku...
Create a cluster role named "admin_role" with ResourceName specified
Command: ```bash kubectl create clusterrole admin_role --verb=use --resource=services --resource-name=machine-learning --resource-name=error-logger ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|c...
Forward traffic from port 8080 on the local machine to port 8080 in the pod "e-commerce-pod", listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8080: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 wi...
Execute the command "kafka-server-start /etc/kafka/server.properties" inside the pod named "gateway-pod" and retrieve the output.
Command: ```bash kubectl exec gateway-pod -- kafka-server-start /etc/kafka/server.properties ``` 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...
Import the specific key 'secret_key' from the 'db-config' config map into the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/db-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Update the 'backend' pod by removing the label named 'bar'
Command: ```bash kubectl label pods backend env- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If true,...
Create a role named "bar" with the ability to list pods and specifics resources named "cache-redis" and "order-fulfillment"
Command: ```bash kubectl create role bar --verb=list --resource=pods --resource-name=cache-redis --resource-name=order-fulfillment ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|clie...
Create an ingress named 'www-ingress' that routes requests for website.com/module to svc1:27017 using the TLS secret named "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="website.com/module=svc1:27017,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...
Import specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-settings deployment/load-balancer-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 an ingress called 'private-ingress' with a rule that directs requests from testing.com/input to svc1:8083, using the tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="testing.com/input=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": "", "us...
Add a taint on nodes with a specific label
Command: ```bash kubectl taint node -l cluster=my-cluster datacenter=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Mark the node "monitoring-node-15" as unschedulable
Command: ```bash kubectl cordon monitoring-node-15 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Set the resource request and limits for all containers in nginx deployment
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Add a taint with key 'zone' and value 'worker-node-3:PreferNoSchedule' on nodes that have the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 zone=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": ...
Create a service for a replicated hazelcast using replica set, which serves on port 9090 and connects to the containers on port 8000
Command: ```bash kubectl expose rs hazelcast --port=9090 --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 po...
Set the server field of the star-cluster cluster entry to "https://1.2.3.4" without modifying any other values.
Command: ```bash kubectl config set-cluster star-cluster --server=https://1.2.3.4 ``` 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-autho...
Forward port 5432 locally to the targetPort of the "https" service port in a pod selected by the backend-service service.
Command: ```bash kubectl port-forward service/backend-service 5432: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 select...
Display resource usage metrics for the 'database-pod' pod, including its containers.
Command: ```bash kubectl top pod database-pod --containers ``` 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 ...
Import the MAX_CONNECTIONS key from the global-config config map and set it as an environment variable in the proxy-service-deployment deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/global-config deployment/proxy-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 variable de...
Create an ingress called 'app2-ingress' with a rule that directs requests for site.com/bar to svc1:8010
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/bar=svc1:8010,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Execute the 'sleep 3600' command in the cyber-sleuth container of the auth-service-pod and retrieve the output.
Command: ```bash kubectl exec auth-service-pod -c cyber-sleuth -- sleep 3600 ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Create a new config map named 'ui-config' with the specified keys 'conf' and 'data' using the files '/path/to/data/file1.txt' and '/path/to/configurations/file2.txt' respectively.
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a conf...
Create a config map named namespace-config using specific keys and files from the specified paths.
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Execute the command 'java -jar /usr/share/jenkins/jenkins.war' in the 'quantum-quark' container of the 'email-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec email-service-pod -c quantum-quark -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "", "us...
Create a job named "security-scan-job" using the Python image. The job should execute the command "python".
Command: ```bash kubectl create job security-scan-job --image=python -- python ``` 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....
Restart a specific daemon set
Command: ```bash kubectl rollout restart daemonset/app-v2 ``` 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 t...
Provide a detailed description of all the pods with the label "namespace=mynamespace"
Command: ```bash kubectl describe po -l namespace=mynamespace ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type,...
Set the cluster field in the "team-alpha-context" context to "kube-cluster-1"
Command: ```bash kubectl config set contexts.team-alpha-context.cluster kube-cluster-1 ``` 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...
Create an ingress called 'web-ingress' with a rule that directs requests to site.com/module to svc1:8084, and uses the TLS secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="site.com/module=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Create a cron job named "data-sync" that runs a command every minute
Command: ```bash kubectl create cronjob data-sync --image=php --schedule="*/1 * * * *" -- composer --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 cluster role named "default_role" with the specified API Group, with the ability to patch, watch, and exec on persistent volumes in the storage.k8s.io resource.
Command: ```bash kubectl create clusterrole default_role --verb=patch,watch,exec --resource=persistentvolumes.storage.k8s.io ``` 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 f...
Create a copy of the 'chat-app-pod' pod, adding a debug container and changing the container images
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-web --image=debian --set-image=app=app:debug,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Update the pod named 'database' with the annotation 'criticality' and the value 'high', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods database criticality='high' ``` 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...
Set the custom TLS server name to "web-cluster" for the moon-cluster cluster entry
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=web-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-...
Import the 'smtp_server' key from the 'ui-config' config map into the 'cache-cluster-deployment' deployment configuration
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/ui-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 definition...
Create an ingress called 'frontend-ingress' that directs requests to site.com/example to the service named 'svc1' on port 9090, and use the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress rontend-ingress --rule="site.com/example=svc1:9090,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Forward local port 8088 to port 9090 in a pod selected by the 'analytics-platform-deployment' deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8088 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 po...
Start a CentOS Pod and set the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container
Command: ```bash kubectl run hazelcast --image=centos --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...
retrieve the details of the resource controllers "rc/web" and "service/payment-gateway-rc", as well as the pod "proxy-server-pod"
Command: ```bash kubectl get rc/web service/payment-gateway-rc pods/proxy-server-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 n...
Set up autoscaling for the replication controller "frontend" with a target CPU utilization of 40% and a minimum of 1 pod and a maximum of 8 pods.
Command: ```bash kubectl autoscale rc frontend --max=8 --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 use...
Create a copy of the gateway-pod and change all container images to amazonlinux. The new pod will be named debug-image-api.
Command: ```bash kubectl debug gateway-pod --copy-to=debug-image-api --set-image=*=amazonlinux ``` 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...
Import environment variables from a config map with a specific prefix for a deployment
Command: ```bash kubectl set env --from=configmap/app-name-config --prefix=MYSQL_ 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 defi...
Create a deployment named "db" with the "ruby" image and expose port 3306.
Command: ```bash kubectl create deployment db --image=ruby --port=3306 ``` 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: json|ya...
Add a taint to the 'storage-node-13' node with key 'app' and no value
Command: ```bash kubectl taint nodes storage-node-13 app: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: j...
Add a taint with key 'datacenter' on nodes having label 'customer=acme-corp' with the value 'monitoring-node-15' and effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l customer=acme-corp datacenter=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": ...
Copy the local file '/var/run/secrets/kubernetes.io/serviceaccount/' to the remote pod 'security-scanner-pod-18' in the 'monitoring' namespace, and place it in the '/tmp/bar' directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ monitoring/security-scanner-pod-18::/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...
Start a new php pod named 'hazelcast' with the 'php' image, and have the container expose port 5001.
Command: ```bash kubectl run hazelcast --image=php --port=5001 ``` 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...
Create a job named "certificate-renewal" using the image "golang" and running the command "go".
Command: ```bash kubectl create job certificate-renewal --image=golang -- go ``` 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. O...
Get the output from running the 'npm --version' command from the container named 'warp-drive' in the pod named 'database-pod'.
Command: ```bash kubectl exec database-pod -c warp-drive -- npm --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, ...
Import the 'EXTERNAL_API_URL' key from the 'monitoring-config' ConfigMap and set it as an environment variable for the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/monitoring-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 variab...
Create an ingress named 'www-ingress' with a rule that directs requests for site.com/input to svc1:8888, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="site.com/input=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create a new config map named 'app-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/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...
Execute the 'go' command inside the container named 'mycontainer' of the 'database-pod' pod and retrieve the output.
Command: ```bash kubectl exec database-pod -c mycontainer -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Copy the local directory '~/.config/kube_dir' to the '/tmp/bar_dir' directory in the 'api-server-pod-3' pod in the 'default' namespace.
Command: ```bash kubectl cp ~/.config/kube_dir api-server-pod-3:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Expose a service for the replication controller specified in the "wordpress-controller.yaml" file, serving on port 8010 and connecting to the containers on port 909200.
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8010 --target-port=909200 ``` 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 ...
Update the 'log-aggregator' pod by adding or modifying the annotation 'alert-email' with the value 'alerts@example.com'
Command: ```bash kubectl annotate --overwrite pods log-aggregator alert-email='alerts@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger th...
Compare the resources defined in the preferences.yaml file with the current state in the cluster
Command: ```bash kubectl diff -f preferences.yaml ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff co...
Create an ingress resource named 'app2-ingress' that routes requests for site.com/module to the service named svc1 on port 5001
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/module=svc1:5001,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":...
Copy the file /tmp/foo from the remote pod named backend-pod-13 in the rook-ceph namespace to the local directory /tmp/bar.
Command: ```bash kubectl cp rook-ceph/backend-pod-13::/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....
Import specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=redis_host --from=configmap/kube-system-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 variab...
Copy the local file '~/.config/kube' to the remote pod named 'front-end-pod-12' in the 'argocd' namespace, and place it in the '/etc/kubernetes' directory.
Command: ```bash kubectl cp ~/.config/kube argocd/front-end-pod-12:/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 t...
Create a service named 'php' that exposes the php deployment on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment php --port=8088 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified ...
Create a config map named db-config using specified keys and files
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/path/to/settings/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 single ingress called 'app-loadbalancer-ingress' with the following rule: foo.com/example should be directed to svc1:8443, using the tls secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/example=svc1:8443,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": ...
Begin streaming the logs of the "astro-container" container in the "proxy-service-pod" pod
Command: ```bash kubectl logs -f -c astro-container 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": "--contain...
Apply a taint on nodes that have a specific label
Command: ```bash kubectl taint node -l tier=frontend workload=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...
Partially update a node by specifying a YAML patch
Command: ```bash kubectl patch node app-node-6 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n 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. Syn...
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=8088 --target-port=500100 ``` 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...
Set the custom TLS server name "cluster-gamma" for the "moon-cluster" cluster entry.
Command: ```bash kubectl config set-cluster moon-cluster --tls-server-name=cluster-gamma ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificat...
Forward local port 8888 to port 5432 in a pod selected by the 'mydeployment' deployment
Command: ```bash kubectl port-forward deployment/mydeployment 8888 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 selecte...
Set the custom TLS server name "dev-cluster" for the "cluster-alpha" cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --tls-server-name=dev-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate...
Create an ingress called 'internal-ingress' that routes requests from 'site.com/input' to the service 'svc1' on port 27017, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress internal-ingress --rule="site.com/input=svc1:27017,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 debug container for email-service-pod, copy it to debug-image-api and start an interactive shell in the nano-bot container.
Command: ```bash kubectl debug email-service-pod -it --copy-to=debug-image-api --container=nano-bot -- 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 de...
Create a job named "indexing" using the Elasticsearch image from Docker, with the command "elasticsearch --version".
Command: ```bash kubectl create job indexing --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch --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"...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-dev 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 variab...
Start a php pod named nginx, but customize its specifications by providing a partial set of values parsed from a JSON file
Command: ```bash kubectl run nginx --image=php --overrides='{ "apiVersion": "hotfix-1.1.2", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COM...
Remove a taint from a specific node
Command: ```bash kubectl taint nodes prod-node-5 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:...
Create a job named "certificate-renewal" using the Ubuntu image, with the command to echo "Hello".
Command: ```bash kubectl create job certificate-renewal --image=ubuntu -- docker run ubuntu echo "Hello ``` 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": "",...
Scale the deployment named backend-service-replicaset to have 5 replicas, assuming the current size is already 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=5 deployment/backend-service-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 --r...
List all deployments in YAML output format, specifically in the "legacy-1.0.0" version of the "custom-deployments" API group
Command: ```bash kubectl get deployments.legacy-1.0.0.custom-deployments -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 names...
Import the specific key 'config_file_path' from the 'ui-config' config map and set it as an environment variable in the 'frontend-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/ui-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8080 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Add an annotation with the description 'my frontend running nginx' to the 'monitoring' pod, but only if the pod has not been changed since version 1.
Command: ```bash kubectl annotate pods monitoring description='my frontend running nginx' --resource-version=1 ``` 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 ...
Remove the label 'release-' from the pod 'media-stream'
Command: ```bash kubectl label pods media-stream release- ``` 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": ...
Create a role named "bar" with specific resource names
Command: ```bash kubectl create role bar --verb=connect --resource=pods --resource-name=app-worker-2 --resource-name=nginx-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=server|client...
List the desired resources by their respective types and names
Command: ```bash kubectl get rc/web service/security-service-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 n...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config deployment/proxy-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 variable defi...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/ui-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...