prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Start a confluentinc/cp-kafka pod named 'nginx' and override the spec with a partial set of values parsed from the provided JSON string
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "beta-1.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--co...
Create an ingress called 'api-v2-ingress' with a rule that redirects requests from foo.com/example to svc1:9000
Command: ```bash kubectl create ingress api-v2-ingress --rule="foo.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": "", "usage...
Retrieve the logs from the container named chat-app-pod-1 in the deployment named mydeployment
Command: ```bash kubectl logs deployment/mydeployment -c chat-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": "--conta...
Partially update the node identified in the "node.json" file using strategic merge patch
Command: ```bash kubectl patch -f node.json -p '{"spec":{"someField":"newValue"}' ``` 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 ...
Forward traffic from local port 6379 to port 8080 inside the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 6379: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...
Create a new pod named 'nginx' using the 'node' image, but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=node --overrides='{ "apiVersion": "v2.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND]...
Rename the context 'old-name' to 'service-account-context' in your kubeconfig file
Command: ```bash kubectl config rename-context old-name service-account-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 ...
Create a new pod named nginx using the image confluentinc/cp-kafka, and override the specification with specific values provided in a JSON format.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "dev-2.2.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--c...
Forward traffic from port 8080 on localhost and IP 10.19.21.23 to port 8088 in the analytics-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 8080: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 crite...
Start a pod named "hazelcast" using the ethereum/client-go image, and expose port 5001.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --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: ...
Forward local traffic on port 8080 to port 8888 in the pod selected by the deployment/authentication-service-deployment deployment
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8080 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, ...
Display the most recent 12 lines of logs for the pod named security-service-pod
Command: ```bash kubectl logs --tail=12 security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Create a job with a command
Command: ```bash kubectl create job scaling-job --image=nginx -- nginx -g "daemon off;" ``` 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": "Outpu...
Set the cluster field in the app-2-context context to cluster-beta
Command: ```bash kubectl config set contexts.app-2-context.cluster cluster-beta ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Start a pod named hazelcast using the ethereum/client-go image, and expose port 3001 for the container.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=3001 ``` 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: ...
Listen on ports 8088 and 6000 on your local machine and forward data to/from ports 6379 and 6000 in a pod selected by the 'database-deployment' deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 8088 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Create a copy of the payment-gateway-pod pod with the updated command for the time-machine container.
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=dgb-img --container=time-machine -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by defa...
Create a job named 'cleanup' using the image 'mcr.microsoft.com/dotnet/core/runtime' and execute the command 'dotnet --list-runtimes'
Command: ```bash kubectl create job cleanup --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet --list-runtimes ``` 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", "d...
Forward traffic from port 8888 on localhost and IP address 10.19.21.23 to port 9090 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 8888:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Add certificate authority data for the cluster-gamma cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/on-prem-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...
Autoscale deployment "foo" with 7 to 12 pods
Command: ```bash kubectl autoscale deployment foo --min=7 --max=12 ``` 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...
Create a secret named jwt-secret using values from an environment file.
Command: ```bash kubectl create secret generic jwt-secret --from-env-file=path/to/data.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 of t...
Copy the /tmp/foo_dir directory from the metrics-exporter-pod-10 pod in the kube-node-lease namespace to the /tmp/bar directory on your local machine.
Command: ```bash kubectl cp kube-node-lease/metrics-exporter-pod-10:/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...
Execute 'geth attach' command in the first pod of the service 'monitoring-service' to get the output
Command: ```bash kubectl exec svc/monitoring-service -- 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, use th...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-secrets 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 definiti...
Copy the ~/.config/kube local file to the /tmp/bar directory in the remote pod named admin-dashboard-pod-16 in the monitoring namespace.
Command: ```bash kubectl cp ~/.config/kube monitoring/admin-dashboard-pod-16:/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, us...
Create a new config map named 'api-config' in the current namespace with the specified keys and files
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/preferences/file1.txt --from-file=key2=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cre...
Display the list of environment variables defined for the 'mydeployment' deployment.
Command: ```bash kubectl set env deployment/mydeployment --list ``` 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 replication ...
Create a deployment named "logging" that runs the "jenkins" image and exposes port 8443.
Command: ```bash kubectl create deployment logging --image=jenkins --port=8443 ``` 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 role named "reader" with delete permission for pods in the api-server and content-delivery resources
Command: ```bash kubectl create role reader --verb=delete --resource=pods --resource-name=api-server --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-run=server|c...
Create a new config map named app-config-dev from the parameters.env file at the given path
Command: ```bash kubectl create configmap app-config-dev --from-env-file=path/to/parameters.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to ...
Open the search-service resource for editing using the nvim editor
Command: ```bash KUBE_EDITOR="nvim" kubectl edit svc/search-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables,...
Remove the environment variable 'ENV' from the container 'stardust-shuttle' in all deployment configs
Command: ```bash kubectl set env deployments --all --containers="stardust-shuttle" ENV- ``` 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...
Edit the monitoring-service service using the vi editor
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/monitoring-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variable...
Edit the configuration of the 'search-service' service
Command: ```bash kubectl edit svc/search-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or fall back to 'v...
Execute the 'ash' command in the 'time-machine' container within the 'payment-gateway-pod' pod and retrieve the output
Command: ```bash kubectl exec payment-gateway-pod -c time-machine -- ash ``` 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, u...
Update the 'web' pod by setting the annotation 'scaling-policy' to 'auto-horizontal-scaling'.
Command: ```bash kubectl annotate pods web 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 labels and inc...
Import environment variables from a secret into a deployment named "monitoring-stack-deployment"
Command: ```bash kubectl set env --from=secret/cert-manager-secret deployment/monitoring-stack-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 ...
Execute the 'python' command inside the 'analytics-pod' pod and retrieve the output from the first container
Command: ```bash kubectl exec analytics-pod -- python ``` 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.kube...
Delete the pods and services with the names "proxy-server" and "cdn"
Command: ```bash kubectl delete pod,service proxy-server cdn ``` 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...
Get the output from running the 'mysql --version' command from the pod named security-service-pod in the default container.
Command: ```bash kubectl exec security-service-pod -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Expose a replication controller as a service on port 8082
Command: ```bash kubectl expose -f php-controller.yaml --port=8082 --target-port=818100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the sp...
Remove the taint with key 'workload' from the node 'web-node-8'.
Command: ```bash kubectl taint nodes web-node-8 workload- ``` 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|n...
Create a service for the replicated node using replica set "node", which serves on port 5000 and connects to the containers on port 8081.
Command: ```bash kubectl expose rs node --port=5000 --target-port=808100 ``` 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...
Forward traffic from the local port 6379 to the pod selected by the deployment named "database-deployment"'s port 6379
Command: ```bash kubectl port-forward deployment/database-deployment 6379 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Open the 'cache-service' service for editing using the 'notepad' editor instead of the default editor
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/cache-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variable...
Set the "client-key" field for the "john.doe" entry in the kubeconfig file, without modifying other values
Command: ```bash kubectl config set-credentials john.doe --client-key=~/.kube/admin.key ``` 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=keyfile Bearer token fl...
Create an ingress called 'app-loadbalancer-ingress' to route requests from foo.com/example to svc1:8083, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/example=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": ...
Edit the 'database-indexing-job' in JSON format using the v1 API
Command: ```bash kubectl edit job.v1.batch/database-indexing-job -o json ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment varia...
Create an Ingress with TLS enabled, using a specific secret and setting the pathType to Prefix
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="testing.com/*=svc:9092,tls=secret1" ``` 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": ...
Update the 'gpu-node-12' node with a taint
Command: ```bash kubectl taint nodes gpu-node-12 datacenter=dc-1:NoExecute ``` 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. On...
Open the `logging-service` resource for editing using the Atom text editor.
Command: ```bash KUBE_EDITOR="atom" kubectl edit svc/logging-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables...
Delete the pod and service with the name "email" and the pod and service with the name "foo".
Command: ```bash kubectl delete pod,service email foo ``` 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 ...
List the deployments in YAML format using the "custom-deployments" API group and the "stable-2.0.0" version.
Command: ```bash kubectl get deployments.stable-2.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...
Retrieve the YAML definition of the 'cdn-service-pod' pod
Command: ```bash kubectl get -o yaml pod 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 namespaced you will only see ...
Create a new config map named log-config using the preferences files located at path/to/preferences.
Command: ```bash kubectl create configmap log-config --from-file=path/to/preferences ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basenam...
Update the annotation of a pod by overwriting the existing value
Command: ```bash kubectl annotate --overwrite pods api git-repo='https://github.com/example/my-app' ``` 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 t...
Create a role named "default_role" with the ResourceName specified as "document-storage" and "machine-learning".
Command: ```bash kubectl create role default_role --verb=proxy --resource=pods --resource-name=document-storage --resource-name=machine-learning ``` 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...
Create a secret named aws-credentials-secret by reading the values from an environment file
Command: ```bash kubectl create secret generic aws-credentials-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 t...
Create a LoadBalancer service named "analytics-lb" and map port 5000 on the external load balancer to port 9090 on the service.
Command: ```bash kubectl create service loadbalancer analytics-lb --tcp=5000:9090 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defau...
Start a pod named 'hazelcast' using the 'centos' image and have it expose port 8082.
Command: ```bash kubectl run hazelcast --image=centos --port=8082 ``` 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 new ClusterIP service named 'git-service-clusterip' that forwards traffic from port 5001 to port 8081
Command: ```bash kubectl create service clusterip git-service-clusterip --tcp=5001:8081 ``` 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...
Set the service account of the deployment "gateway-deployment" to "prometheus"
Command: ```bash kubectl set serviceaccount deployment gateway-deployment prometheus ``` 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: `kubectl...
Create a new ingress resource called 'app-proxy-ingress'
Command: ```bash kubectl create ingress app-proxy-ingress --rule="foo.com/bar=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"...
Create an ingress called 'public-ingress' that directs requests for testing.com/example to svc1:9000
Command: ```bash kubectl create ingress public-ingress --rule="testing.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": "", "u...
Create a new secret with keys for each file in a specific folder.
Command: ```bash kubectl create secret generic encryption-key-secret --from-file=path/to/data ``` 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 o...
Forward data from local ports 8080 and 6000 to ports 8081 and 6000 respectively in a pod controlled by the 'database-deployment' deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 8080 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Create a cron job named 'weekly-summary' using the 'ethereum/client-go' image
Command: ```bash kubectl create cronjob weekly-summary --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...
Update the annotation 'security-scan-status' of pod 'api' with the value 'pass'
Command: ```bash kubectl annotate --overwrite pods api 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 and in...
create a service for the replicated alpine pod using replica set, with the service serving on port 9090 and connecting to the containers on port 909000
Command: ```bash kubectl expose rs alpine --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....
Add a taint with the key 'disktype' on nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel disktype=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": "Output form...
Import the 'LOG_LEVEL' key from the 'app-config-prod' ConfigMap and set it as an environment variable for the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-prod deployment/mydeployment ``` 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...
Listen on all addresses on port 8080 and forward the traffic to port 5000 inside the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8080:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Create a job with a command
Command: ```bash kubectl create job log-collection --image=amazonlinux -- /bin/bash -c "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": "", "us...
Create a role named "foo" with ResourceName specified
Command: ```bash kubectl create role foo --verb=list --resource=pods --resource-name=cdn-proxy --resource-name=load-balancer ``` 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|non...
Import the max_connections key from the kube-system-config config map and set it as an environment variable for the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/kube-system-config deployment/monitoring-stack-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...
Create a debug copy of a pod, adding a debug container and changing container images
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-memcached --image=debian --set-image=web=nginx:latest,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and n...
Update the labels for pod 'database' with the label 'env' and the value 'development'
Command: ```bash kubectl label pods database env=development ``` 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...
Forward the traffic on port 3000 from localhost and IP address 10.19.21.23 to port 8888 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 3000: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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Configure autoscaling for the deployment "proxy" with a minimum of 1 pod and a maximum of 13 pods
Command: ```bash kubectl autoscale deployment proxy --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 t...
Create a service for the replication controller specified in the "ruby-controller.yaml" file
Command: ```bash kubectl expose -f ruby-controller.yaml --port=9091 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-secrets 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 defin...
Forward local port 6379 to port 6379 in the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward pod/log-aggregator-pod 6379:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Set resource requests and limits for all containers in a deployment named postgres
Command: ```bash kubectl set resources deployment postgres --limits=cpu=200m,memory=512Mi --requests=cpu=200m,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 req...
Get output from running the 'go' command in the astro-container from the pod named gateway-pod.
Command: ```bash kubectl exec gateway-pod -c astro-container -- 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...
Create a cluster role named "admin_role" with access to a specific non-resource URL path.
Command: ```bash kubectl create clusterrole "admin_role" --verb=connect --non-resource-url=/apis/* ``` 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", ...
Copy the `~/.config/kube` local file to the `/tmp/bar_dir` directory in a remote pod named `monitoring-agent-pod-6` in the `kube-dns` namespace.
Command: ```bash kubectl cp ~/.config/kube kube-dns/monitoring-agent-pod-6:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Embed the certificate authority data for the e2e cluster entry by running the command "kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt".
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/star-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-cluster ...
Import specific keys from a config map to the environment variables of a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Partially update the dev-node-4 node by setting the unschedulable property to true using the provided strategic merge patch in JSON format.
Command: ```bash kubectl patch node dev-node-4 -p '{"spec":{"unschedulable":true}}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpfu...
Partially update a node by applying a strategic merge patch defined in YAML format.
Command: ```bash kubectl patch node backup-node-14 -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. ...
Set the cluster field for a given context to a specified cluster
Command: ```bash kubectl config set contexts.testing-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you w...
Retrieve only the phase value of a specific pod.
Command: ```bash kubectl get -o template pod/web-app-pod --template={{.status.phase}} ``` 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 ...
Add a taint with key 'zone' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 zone=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": "Output...
Create a pod disruption budget named ingress-controller-pdb that will select all pods with the version=v2 label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget ingress-controller-pdb --selector=version=v2 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-availabl...
restart the services deployment
Command: ```bash kubectl rollout restart deployment/services ``` 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 resourc...
Create a cron job with a command and schedule
Command: ```bash kubectl create cronjob log-rotation --image=docker.elastic.co/elasticsearch/elasticsearch --schedule="*/1 * * * *" -- elasticsearch --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]...
Forward local port 6379 to port 3000 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 6379:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Update the pod 'analytics' with the label 'env' and the value 'development'.
Command: ```bash kubectl label pods analytics env=development ``` 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", "usag...