prompt
stringlengths
13
282
response
stringlengths
128
3.11k
update the image for all containers in a daemonset to 'nginx:1.21.3'
Command: ```bash kubectl set image daemonset namespace-3 *=nginx:1.21.3 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: ...
Begin streaming the logs of the 'stardust-shuttle' container in the 'proxy-service-pod' pod
Command: ```bash kubectl logs -f -c stardust-shuttle proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--contai...
Update the pod identified by the type and name specified in the "settings.json" file and label it as "unhealthy".
Command: ```bash kubectl label -f settings.json status=unhealthy ``` 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", "u...
Expose a deployment named "python" as a service, listening on port 9000 and forwarding traffic to containers on port 800000.
Command: ```bash kubectl expose deployment python --port=9000 --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 specifi...
Enable the OpenID Connect auth provider for the "john.doe" entry with client ID as "foo" and client secret as "bar"
Command: ```bash kubectl config set-credentials john.doe --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: --cl...
Edit the environment variable of the 'monitoring-stack-deployment' deployment by setting the MAX_CONNECTIONS variable to 100.
Command: ```bash kubectl set env deployment/monitoring-stack-deployment MAX_CONNECTIONS=100 ``` 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 te...
Create a new ExternalName service named 'external-email-service' with the external name 'sandbox-site.co'
Command: ```bash kubectl create service externalname external-email-service --external-name sandbox-site.co ``` 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 servic...
Set the cluster field in the specified context to the desired cluster
Command: ```bash kubectl config set contexts.cloud-context.cluster on-prem-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...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-secrets deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Add a taint with the key 'dedicated' and the value 'k8s-node-1:PreferNoSchedule' on nodes having the label 'namespace=mynamespace'.
Command: ```bash kubectl taint node -l namespace=mynamespace dedicated=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...
Create a debug copy of the email-service-pod with all container images changed to "node"
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-app --set-image=*=node ``` 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 ...
Update the image of all containers in the daemonset "app-v2" to "amazonlinux:2"
Command: ```bash kubectl set image daemonset app-v2 *=amazonlinux:2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kub...
Get the output from running the 'mongo' command in the first container of the first pod of the 'cache-cluster-deployment' deployment.
Command: ```bash kubectl exec deploy/cache-cluster-deployment -- mongo ``` 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...
Create an ingress called 'public-api-ingress' that directs requests to foo.com/bar to svc1:8181 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="foo.com/bar=svc1:8181,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...
Start a wordpress pod with specified overrides from a JSON file
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "feature-branch-2.3.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...
Get the output from running the 'go version' command in the cosmic-container of the email-service-pod.
Command: ```bash kubectl exec email-service-pod -c cosmic-container -- go 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...
Start a nginx pod with a customized configuration by providing partial values in JSON format for the spec.
Command: ```bash kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1.1.1", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND...
Import specific keys from a config map to an deployment's environment variables.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-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...
Create a pod disruption budget named 'payment-gateway-pdb' that will select all pods with the 'app=rails' label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=app=rails --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N ...
Copy ~/.config/kube file to /tmp/bar in the database-pod-2 pod in the kube-dns namespace.
Command: ```bash kubectl cp ~/.config/kube kube-dns/database-pod-2:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Start the nginx pod using the default command of the node image, but provide custom arguments <arg1> <arg2> ..
Command: ```bash kubectl run nginx --image=node -- <arg1> <arg2> ... <argN> ``` 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: "f...
Forward local port 5432 to port 8000 in the pod named api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 5432 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Update the cluster field in the given context configuration to the specified cluster name
Command: ```bash kubectl config set contexts.client-2-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 y...
Create a new ExternalName service named external-caching-service with an external name of placeholder-app.app
Command: ```bash kubectl create service externalname external-caching-service --external-name placeholder-app.app ``` 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 ...
Get output from running 'wp' command from the first pod of the service notification-service
Command: ```bash kubectl exec svc/notification-service -- wp ``` 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 kubec...
Create a deployment named "loadbalancer" with the "centos" image and expose port 9091.
Command: ```bash kubectl create deployment loadbalancer --image=centos --port=9091 ``` 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...
Copy the local file "/tmp/foo" to the directory "/etc/kubernetes" in the remote pod "logging-agent-pod-7" in the namespace "ingress-nginx".
Command: ```bash kubectl cp :/tmp/foo ingress-nginx/logging-agent-pod-7:/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, ...
Update the annotation of a pod with a new value, overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods api SLA='99.9% uptime' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arb...
Add a taint with key 'datacenter' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production datacenter=node-2: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": "", "usa...
Create a deployment named SonarQube using the MySQL image and exposing port 8443
Command: ```bash kubectl create deployment sonarqube --image=mysql --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 copy of the gateway-pod by adding a debug container and changing the container images
Command: ```bash kubectl debug gateway-pod -it --copy-to=dgb-img --image=debian --set-image=api=api:v2,mailer=mailer:latest ``` 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 ...
Apply a taint with the key 'disktype' on nodes that have the label 'instance=app-instance-1' and the value 'worker-node-3', and set the taint effect to 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l instance=app-instance-1 disktype=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": ""...
Import specific keys from a config map into environment variables for a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/env-vars deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Autoscale the replication controller "cdn" with a range of 1 to 6 pods, targeting a CPU utilization of 40%.
Command: ```bash kubectl autoscale rc cdn --max=6 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
List deployments in YAML output format, using the "custom-version" version of the "apps" API group.
Command: ```bash kubectl get deployments.custom-version.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 wi...
Update the cluster field in the 'my-context' context to 'sun-cluster' using the service-account-context configuration
Command: ```bash kubectl config set contexts.service-account-context.cluster sun-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 val...
Create a service for a replicated centos using replica set, which serves on port 5432 and connects to the containers on port 8888
Command: ```bash kubectl expose rs centos --port=5432 --target-port=888800 ``` 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....
Create a secret named azure-storage-secret with keys from files in a specific folder
Command: ```bash kubectl create secret generic azure-storage-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 of...
Retrieve the snapshot logs from container vpn-service-pod-1 of the deployment search-engine-deployment.
Command: ```bash kubectl logs deployment/search-engine-deployment -c vpn-service-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: "...
Display the most recent 23 lines of logs for the database-pod
Command: ```bash kubectl logs --tail=23 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", "short": "-c...
list the replication controller named 'web', the service named 'email-service-rc', and the pod named 'analytics-pod'
Command: ```bash kubectl get rc/web service/email-service-rc pods/analytics-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 namesp...
Execute the command 'java -jar /usr/share/jenkins/jenkins.war' in the 'mycontainer' container inside the 'gateway-pod' pod
Command: ```bash kubectl exec gateway-pod -c mycontainer -- 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": "", "usage": "C...
Create a copy of the payment-gateway-pod named "my-debugger" with a debug container added
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-debugger --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 resou...
Create a deployment named "app" using the "golang" image and exposing port 8080.
Command: ```bash kubectl create deployment app --image=golang --port=8080 ``` 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...
Forward the local port 6379 to the targetPort of the service's port named "https" in a pod selected by the service called "database-service"
Command: ```bash kubectl port-forward service/database-service 6379:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selec...
Update the annotation 'git-repo' of the 'gateway' pod with the value 'https://github.com/example/my-app', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods gateway 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 larg...
List the replication controller named "web", the service named "proxy-service-rc", and the pod named "auth-service-pod"
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/auth-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...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l release=beta disktype=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": "", "usage": "Ou...
Start streaming the logs of the "cosmic-container" container in the "chat-app-pod" pod
Command: ```bash kubectl logs -f -c cosmic-container chat-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container",...
Auto scale the replication controller "security" with the number of pods set between 1 and 6, and target CPU utilization set at 60%
Command: ```bash kubectl autoscale rc security --max=6 --cpu-percent=60 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
forward local port 8088 to pod port 8000
Command: ```bash kubectl port-forward pod/backend-pod 8088 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a new secret named api-secret-key from an environment file
Command: ```bash kubectl create secret generic api-secret-key --from-env-file=path/to/preferences.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 ba...
Create a service for a replication controller specified in a YAML file, which serves on port 8088 and connects to the containers on port 909100
Command: ```bash kubectl expose -f node-controller.yaml --port=8088 --target-port=909100 ``` 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...
Copy the local file ~/.config/kube to the remote pod logging-agent-pod-7 at the path /tmp/bar
Command: ```bash kubectl cp ~/.config/kube logging-agent-pod-7:/tmp/bar -c backend-container ``` 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 omit...
Create a service for the 'centos' deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment centos --port=8088 --target-port=909100 ``` 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 specifi...
display detailed information about the "local-context" context
Command: ```bash kubectl config get-contexts local-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Copy the `/tmp/foo` file from the local system to the `/tmp/bar` path in the `file-server-pod-14` pod of the `istio-system` namespace.
Command: ```bash kubectl cp :/tmp/foo istio-system/file-server-pod-14::/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 ...
Create a new ClusterIP service named frontend-service-clusterip
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=9091:8084 ``` 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...
Autoscale the replication controller "frontend" to have a minimum of 1 pod, a maximum of 5 pods, and target a CPU utilization of 40%
Command: ```bash kubectl autoscale rc frontend --max=5 --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...
Start a pod using the image `mcr.microsoft.com/dotnet/core/runtime` and expose port 8010.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=8010 ``` 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......
Create a deployment named jenkins that runs the node image
Command: ```bash kubectl create deployment jenkins --image=node ``` 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|yaml|name...
Forward traffic from port 8888 on all addresses to port 5000 in the web-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8888: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 will ...
Auto scale the "chat-app" deployment with the number of pods ranging from 6 to 11
Command: ```bash kubectl autoscale deployment chat-app --min=6 --max=11 ``` 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...
Roll back a daemonset to a specific revision
Command: ```bash kubectl rollout undo daemonset/namespace-2 --to-revision=7 ``` 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...
Create a new ExternalName service named 'my-ns' that resolves to 'documentation-tech.tech'
Command: ```bash kubectl create service externalname my-ns --external-name documentation-tech.tech ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference services that e...
Add a taint with key 'datacenter' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace datacenter=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": "", "...
Import the 'secret_key' from the 'monitoring-config' config map and set it as an environment variable in the 'authentication-service-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/monitoring-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment var...
Copy the file /tmp/foo from the remote worker-pod-4 pod in the kube-proxy namespace to the local /etc/kubernetes directory.
Command: ```bash kubectl cp kube-proxy/worker-pod-4:/tmp/foo /etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Create a copy of the e-commerce-pod with a debug container, using the debian image
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-memcached --image=debian --set-image=mailer=mailer:latest,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by...
Create a deployment using the image "centos" and the command "sleep 3600" as the entrypoint
Command: ```bash kubectl create deployment prometheus --image=centos -- sleep 3600 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Create a pod disruption budget named web-app-pdb that selects all pods with the region=us-east label, and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=region=us-east --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-available=N [--...
Import specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config-prod 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 varia...
Create a copy of the payment-gateway-pod and add a debug container, also change the images of the logging-app and mailer containers.
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-debugger --image=debian --set-image=logger=logging-app:debug,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified b...
Import the 'CONFIG_FILE_PATH' key from the 'app-config-dev' config map into the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config-dev 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 def...
Set the cluster field in the service-account-context context to cluster-beta
Command: ```bash kubectl config set contexts.service-account-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 va...
Wait for the pod named "analytics-pod" to become ready
Command: ```bash kubectl wait --for=condition=Ready pod/analytics-pod ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resource. Alternatively, the command can ...
Set resource requests and limits for all containers in the "php" deployment
Command: ```bash kubectl set resources deployment php --limits=cpu=200m,memory=512Mi --requests=cpu=200m,memory=128Mi ``` 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...
Update the pod named 'api' with the annotation 'owner' and the value 'alice-smith', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods api owner='alice-smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ar...
Create a new config map named 'app-secrets' using the files '/path/to/parameters/file1.txt' and '/path/to/properties/file2.txt' as the values for the 'properties' and 'key1' keys respectively.
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/path/to/properties/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 creat...
Set a new environment variable for the 'user-management-deployment' deployment
Command: ```bash kubectl set env deployment/user-management-deployment REDIS_HOST=redis-server ``` 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...
Get the output of the 'mysql --version' command from the auth-service-pod.
Command: ```bash kubectl exec auth-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 the ...
Create a pod named 'hazelcast' using the 'jenkins' image and expose port 8088
Command: ```bash kubectl run hazelcast --image=jenkins --port=8088 ``` 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": "--...
Add a taint with key 'app' on nodes that have the label 'customer=acme-corp'.
Command: ```bash kubectl taint node -l customer=acme-corp app=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": ...
Add a taint with key 'hardware' on nodes having label 'cluster=my-cluster' and value 'dev-node-4' with effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l cluster=my-cluster hardware=dev-node-4: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...
Set the cpu limits for the golang container in the deployment named 'golang' to 10 and the memory limits to 256Mi.
Command: ```bash kubectl set resources deployment golang -c=nginx --limits=cpu=10,memory=256Mi ``` 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 requested, but may burst up to ...
Forward traffic from local port 8080 to port 8888 in the pod named api-service-pod
Command: ```bash kubectl port-forward pod/api-service-pod 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, a pod will be selected au...
Forward incoming traffic on port 5000 from localhost and IP address 10.19.21.23 to port 8080 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 5000: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 criteri...
Execute the 'mongo --version' command on the first pod of deployment 'analytics-platform-deployment' and display the output.
Command: ```bash kubectl exec deploy/analytics-platform-deployment -- mongo --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. ...
Create a new config map named app-config-dev using specific files as input
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/path/to/options/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...
Retrieve the snapshot logs of container "search-engine-deployment-1" from the deployment named "monitoring-pod"
Command: ```bash kubectl logs deployment/search-engine-deployment -c monitoring-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: "f...
Label the pods with the label 'component' and the value 'api'
Command: ```bash kubectl label pods security component=api ``` 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":...
Copy the local file "/var/run/secrets/kubernetes.io/serviceaccount/" to the remote pod "payment-gateway-pod-19" in the "rook-ceph" namespace, and save it as "/etc/kubernetes".
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ rook-ceph/payment-gateway-pod-19:/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": "", "u...
Create a debug copy of "mypod" with all container images changed to "centos"
Command: ```bash kubectl debug mypod --copy-to=debug-image-memcached --set-image=*=centos ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no reso...
Copy the local file /tmp/foo_dir to the remote pod logging/security-scanner-pod-18 in the /tmp/bar_dir directory.
Command: ```bash kubectl cp /tmp/foo_dir logging/security-scanner-pod-18:/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, us...
Create an ingress called 'service-ingress' with a rule that directs requests from 'website.com/input' to the service 'svc1:3000'
Command: ```bash kubectl create ingress service-ingress --rule="website.com/input=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": "", "us...
Update the environment variable 'REDIS_HOST' with the value 'redis-server' for the deployment 'authentication-service-deployment'
Command: ```bash kubectl set env deployment/authentication-service-deployment REDIS_HOST=redis-server ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or m...
Create a service for the replicated nginx using the command `kubectl expose rc nginx --port=9092 --target-port=8080`
Command: ```bash kubectl expose rc nginx --port=9092 --target-port=808000 ``` 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. ...
Set the custom TLS server name to use for validation for the 'cloud-cluster' cluster entry to 'on-prem-cluster'
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=on-prem-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] [--certifi...
Partially update a node by merging a strategic merge patch provided in YAML format
Command: ```bash kubectl patch node gpu-node-12 -p $'data:\n key: new-value' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpful flags...
Forward traffic from port 8000 on all addresses to port 8888 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 8000: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...