prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import the 'log_level' key from the 'kube-system-config' ConfigMap into the 'log-aggregator-deployment' Deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/kube-system-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Forward the local port 3000 to the pod named 'api-service-pod', forwarding traffic to port 8080 inside the pod.
Command: ```bash kubectl port-forward pod/api-service-pod 3000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
import the specific key "config_file_path" from the config map named "monitoring-config" and set it as an environment variable in the deployment named "search-engine-deployment"
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/monitoring-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Please taint the nodes with a label of 'app-type' equal to 'microservice' by adding a 'datacenter' key with value 'k8s-node-1' and taint effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l app-type=microservice datacenter=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": "", "...
Import the environment variables from the jwt-secret secret into the database-deployment deployment
Command: ```bash kubectl set env --from=secret/jwt-secret deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templ...
Create a debug copy of the api-service-pod and add a debug container with the debian image
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=web=nginx:latest,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifi...
Add or update the 'last-deployment' annotation with the value '2023-03-15' for the 'vpn' pod. Overwrite any existing value.
Command: ```bash kubectl annotate --overwrite pods vpn last-deployment='2023-03-15' ``` 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 i...
Create a service for the replicated php using replica set, which serves on port 5000 and connects to the containers on port 500100.
Command: ```bash kubectl expose rs php --port=5000 --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 specified port. A ...
Create a new ClusterIP service named my-cs that forwards traffic from port 5432 to port 8000.
Command: ```bash kubectl create service clusterip my-cs --tcp=5432:8000 ``` 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", "default": "", "us...
Create a new config map named 'app-name-config' with the keys 'conf' and 'data' from the files '/path/to/configurations/file1.txt' and '/path/to/configurations/file2.txt' respectively.
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/configurations/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...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/ssh-key-secret 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 definitions in one or more ...
Resume the deployment named my-deployment that is currently paused
Command: ```bash kubectl rollout resume deployment/my-deployment ``` What it does: Resume a paused resource. Paused resources will not be reconciled by a controller. By resuming a resource, we allow it to be reconciled again. Currently only deployments support being resumed. Syntax: `kubectl rollout resume RESOURCE` ...
View the detailed information about a specific node named "storage-node-6.storage-farm.local"
Command: ```bash kubectl describe nodes storage-node-6.storage-farm.local ``` 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 o...
Show all logs from the security-service-pod that were written in the last hour.
Command: ```bash kubectl logs --since=1h 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", "sh...
Copy the `~/.config/kube` file from the remote pod named `admin-dashboard-pod-16` to the local directory `/tmp/bar`.
Command: ```bash kubectl cp logging/admin-dashboard-pod-16:~/.config/kube /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...
Import the environment variables from the 'git-credentials-secret' secret and set them for the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --from=secret/git-credentials-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 o...
Set the CPU and memory limits to 200 milliCPU and 512Mi respectively, and the CPU and memory requests to 100 milliCPU and 4Gi respectively, for all containers in the 'hazelcast' deployment.
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=4Gi ``` 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 requ...
Set the cluster field in the specified context to the desired cluster name
Command: ```bash kubectl config set contexts.edge-context.cluster data-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 wan...
Create a new config map called app-config-prod using the files file1.txt and file2.txt located at /path/to/data/ and /path/to/configurations/ respectively.
Command: ```bash kubectl create configmap app-config-prod --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 ...
Import the CONFIG_FILE_PATH key from the db-config config map into the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/db-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Update the annotation of a pod with a specific value.
Command: ```bash kubectl annotate pods database team='frontend team' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrar...
Set the cpu limits of the 'ruby' deployment's nginx container to 1 and memory limits to 64Mi.
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=1,memory=64Mi ``` 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 its ...
Create a copy of the proxy-service-pod with a debug container and change container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-web --image=debian --set-image=proxy=nginx:1.21,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 reso...
Create a pod disruption budget that ensures at least four pods with the "env=production" label are available at all times.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=env=production --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=...
Create an ingress named 'public-ingress' that will route requests from foo.com/input to the service 'svc1' on port 9092 using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress public-ingress --rule="foo.com/input=svc1:9092,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":...
Import environment variables from the gcp-service-account-secret secret into the scheduler-app-deployment deployment
Command: ```bash kubectl set env --from=secret/gcp-service-account-secret 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 definitions in ...
Retrieve logs from all containers in the "monitoring-pod" pod
Command: ```bash kubectl logs monitoring-pod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container"...
Set new exec auth plugin args for the "app-service" entry
Command: ```bash kubectl config set-credentials app-service --exec-arg=arg1 --exec-arg=arg2 ``` 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 toke...
Listen on port 8088 on all addresses, forwarding to port 8088 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
create a pod using the data from the params.json file
Command: ```bash kubectl create -f ./params.json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to use to create...
Run the 'node' command in the warp-drive container of the analytics-pod and display the output
Command: ```bash kubectl exec analytics-pod -c warp-drive -- node ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Set the service account of the deployment 'search-engine-deployment' to 'jenkins'
Command: ```bash kubectl set serviceaccount deployment search-engine-deployment jenkins ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kube...
list the replication controllers with the names "web" and "email-service-rc", and the pods with the name "web-app-pod"
Command: ```bash kubectl get rc/web service/email-service-rc pods/web-app-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 namespac...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8081 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8088: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 crit...
Retrieve the output from running the 'npm --version' command within the 'time-machine' container of the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c time-machine -- 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 'debug_mode' key from the 'app-name-config' ConfigMap and set it as an environment variable in the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-name-config 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 def...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/global-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 variable de...
Forward traffic from local port 8000 to port 6379 in a pod selected by the authentication-service-deployment deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8000 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, ...
Remove the taints with key 'cpu-type' from node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 cpu-type- ``` 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|y...
Add a label to the pod named 'web'. Set the label 'env' to the value 'production'.
Command: ```bash kubectl label pods web env=production ``` 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...
Update the pod 'frontend' by adding or updating the annotation 'custom-label' with the value 'my-custom-value', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods frontend custom-label='my-custom-value' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than label...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config-dev 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 de...
Get the output of the 'go version' command by running it within the 'api-service-pod' pod
Command: ```bash kubectl exec api-service-pod -- 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 omitted, use the kubect...
Start a pod with the name "hazelcast" using the WordPress image and expose port number 9091 on the container.
Command: ```bash kubectl run hazelcast --image=wordpress --port=9091 ``` 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": "...
Create a single ingress called 'public-ingress' that directs requests to website.com/bar to svc1:9090 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="website.com/bar=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": "", "usage...
Create a deployment named "web" that runs the "postgres" image and exposes port 9000
Command: ```bash kubectl create deployment web --image=postgres --port=9000 ``` 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: js...
Update the label of the 'backend' pod to 'release=v1.0'
Command: ```bash kubectl label pods backend release=v1.0 ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "...
Use the "code" editor to edit the "loadbalancer-service" service.
Command: ```bash KUBE_EDITOR="code" kubectl edit svc/loadbalancer-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 vari...
Copy the file ~/.config/kube from the remote pod named database-pod-2 to the local directory /tmp/bar.
Command: ```bash kubectl cp openfaas/database-pod-2:~/.config/kube :/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 kub...
Create a cluster role named "bar" with the verb "get" and the non-resource URL "/port-forward" specified
Command: ```bash kubectl create clusterrole "bar" --verb=get --non-resource-url=/port-forward ``` 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", "shor...
Delete the pod specified in the settings.json file.
Command: ```bash kubectl delete -f ./settings.json ``` 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 res...
Forward traffic from port 8000 on your local machine to port 5432 in the web-app-deployment pod.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8000 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 s...
Create a service for the replicated centos in the default namespace, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc centos --port=8000 --target-port=700000 ``` 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....
List the resources of a specific type and with specific names.
Command: ```bash kubectl get rc/web service/chat-app-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 namespac...
Update the pod 'analytics' by adding the annotation 'team' with the value 'frontend team'
Command: ```bash kubectl annotate pods analytics team='frontend team' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitra...
Create a service for the replicated ruby using the replica set
Command: ```bash kubectl expose rs ruby --port=7000 --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 local port 8080 to port 3000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 8080 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 automa...
Execute the 'npm --version' command within the 'lunar-launcher' container of the 'log-aggregator-pod' pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c lunar-launcher -- 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...
Set the CPU and memory limits to 200m and 512Mi respectively, and set the CPU and memory requests to 50m and 256Mi respectively, for all containers in the mysql deployment.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=50m,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 request...
Create a deployment named "registry" using the MySQL image, and expose port 5000.
Command: ```bash kubectl create deployment registry --image=mysql --port=5000 ``` 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: ...
Add a taint with key 'cpu-type' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 cpu-type=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":...
Update the 'gateway-deployment' deployment by setting the environment variable ENV to 'prod'.
Command: ```bash kubectl set env deployment/gateway-deployment ENV=prod ``` 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 repl...
Retrieve the output of the 'jenkins --version' command executed in the 'warp-drive' container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c warp-drive -- jenkins --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...
Set the label 'role' with the value 'frontend' to the pod named 'proxy'
Command: ```bash kubectl label pods proxy role=frontend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "I...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-dev deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Forward traffic from port 5000 on all addresses to port 8088 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Forward local ports to a pod port
Command: ```bash kubectl port-forward pod/e-commerce-pod 3000 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 aut...
Create an ingress called 'web-ingress' that routes requests from site.com/example to svc1:8083 with TLS encryption using the secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="site.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": "", "usage":...
Get the output from the cosmic-container in the pod named security-service-pod
Command: ```bash kubectl attach security-service-pod -c cosmic-container ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Add a taint with key 'cpu-type' on nodes having label customer=acme-corp.
Command: ```bash kubectl taint node -l customer=acme-corp cpu-type=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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/api-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 def...
Execute the command 'kafka-server-start /etc/kafka/server.properties' in the 'warp-drive' container of the 'proxy-service-pod' pod and display the output.
Command: ```bash kubectl exec proxy-service-pod -c warp-drive -- 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": "",...
Update the image of all containers in the daemonset "staging" to "debian:11.0"
Command: ```bash kubectl set image daemonset staging *=debian:11.0 ``` 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: `kube...
Create an ingress called 'public-ingress' that redirects requests for 'site.com/example' to 'svc1:8083' and uses the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress public-ingress --rule="site.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": "", "usag...
Embed the certificate authority data for the staging-cluster cluster entry, using the command "kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/edge-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 ...
Create a service for the replicated centos, serving on port 8181, and connecting to the containers on port 30010
Command: ```bash kubectl expose rc centos --port=8181 --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 port....
Forward connections from port 5432 on all addresses to port 3000 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5432: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 ...
Retrieve the snapshot logs from the container "cdn-service-pod-1" in the deployment "analytics-platform-deployment".
Command: ```bash kubectl logs deployment/analytics-platform-deployment -c cdn-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 fla...
Start a Ubuntu pod and expose port 7000 from the container
Command: ```bash kubectl run hazelcast --image=ubuntu --port=7000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
create a cron job that runs the command "nginx -g "daemon off;" every minute
Command: ```bash kubectl create cronjob data-processing --image=nginx --schedule="*/1 * * * *" -- nginx -g "daemon off;" ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", ...
Create an ingress resource named 'api-gateway-ingress' that directs requests to 'website.com/module' to the service named 'svc1' running on port 8010
Command: ```bash kubectl create ingress api-gateway-ingress --rule="website.com/module=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": ""...
Expose a service for a replicated php application on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose rc php --port=8080 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Create a service for the hazelcast replication controller specified in the "hazelcast-controller.yaml" file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8888 --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 ...
Add the annotation 'env' with the value 'staging' to the pod named 'foo'
Command: ```bash kubectl annotate pods foo env=staging ``` 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 arbitrary string value...
Forward local port 8080 to the target port of the "https" service port in the selected pod of the "order-service" service.
Command: ```bash kubectl port-forward service/order-service 8080: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 selected...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/proxy-service-rc pods/media-stream-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...
Set the resource request and limits for all containers in the 'hazelcast' deployment
Command: ```bash kubectl set resources deployment hazelcast --limits=cpu=200m,memory=512Mi --requests=cpu=2,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 reque...
Switch to the raw terminal mode and attach to the quantum-quark container in the proxy-server-pod
Command: ```bash kubectl attach proxy-server-pod -c quantum-quark -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Create a debug container in the 'cdn-service-pod' and copy it as 'debug-image-app'
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-app --image=debian --set-image=proxy=nginx:1.21,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 resour...
Create a new config map named "namespace-config" with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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 creat...
Create a copy of the monitoring-pod pod, adding a debug container and changing container images
Command: ```bash kubectl debug monitoring-pod -it --copy-to=dgb-img --image=debian --set-image=web=nginx:latest,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 na...
Scale the deployment named 'mysql' to 5 replicas if the current size of the deployment named 'bar' is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/bar ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is spec...
Set a custom TLS server name for the edge-cluster cluster entry.
Command: ```bash kubectl config set-cluster edge-cluster --tls-server-name=edge-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...
Forward local port 9090 to port 9090 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Set the cpu limits of the elasticsearch deployment's nginx container to "500m" and memory limits to "2Gi"
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=500m,memory=2Gi ``` 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...
List deployments in JSON output format, using the "alpha-2.0" version of the "third-party-apps" API group
Command: ```bash kubectl get deployments.alpha-2.0.third-party-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced...
Create a role named "bar" with ResourceName specified
Command: ```bash kubectl create role bar --verb=delete --resource=pods --resource-name=message-queue --resource-name=payment-processor ``` 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|...
Copy the '/tmp/foo' file from the local machine to the '/tmp/bar' directory in the 'payment-gateway-pod-19' pod in the 'cert-manager' namespace.
Command: ```bash kubectl cp :/tmp/foo cert-manager/payment-gateway-pod-19::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Update the annotation 'env' of pod 'email' to have the value 'staging', but keep in mind that if the same annotation is set multiple times, only the last value will be applied.
Command: ```bash kubectl annotate pods email env=staging ``` 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 arbitrary string val...
Forward local ports to a pod
Command: ```bash kubectl port-forward pod/frontend-pod 5432 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...