prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Copy the file '/tmp/foo' from the pod 'api-server-pod-3' in the 'kubeapps' namespace to the local machine and save it as '/tmp/bar'
Command: ```bash kubectl cp kubeapps/api-server-pod-3::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Get the output from running the 'elasticsearch --version' command in the vpn-service-pod pod.
Command: ```bash kubectl exec vpn-service-pod -- elasticsearch --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, u...
Get the output from running the 'go version' command from the first container of the first pod of the 'email-service' service.
Command: ```bash kubectl exec svc/email-service -- 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 kube...
Display the most recent 5 lines of logs for the pod named "media-stream-pod"
Command: ```bash kubectl logs --tail=5 media-stream-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": ...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config 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 definition...
Create a deployment with a specific image and port
Command: ```bash kubectl create deployment my-dep --image=amazonlinux --port=5001 ``` 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 service for the 'node' replicated controller which serves on port 8443 and connects to the containers on port 300000.
Command: ```bash kubectl expose rc node --port=8443 --target-port=300000 ``` 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...
Start a postgres pod named 'nginx' using the 'postgres' image, but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=postgres --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] [--command] -- [C...
create a new ClusterIP service named database-service-clusterip listening on port 8088 and forwarding to port 8000
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=8000:8088 ``` 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...
Copy a file from a remote pod to a local directory.
Command: ```bash kubectl cp kube-dns/backend-pod-13:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "Containe...
Return the snapshot logs from the container gateway-pod-1 of the load-balancer-deployment deployment.
Command: ```bash kubectl logs deployment/load-balancer-deployment -c gateway-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...
Forward traffic from local port 3000 to the targetPort of the "https" port in a pod selected by the "api-service" service.
Command: ```bash kubectl port-forward service/api-service 3000: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 a...
Create a service for a replicated PHP using a replica set
Command: ```bash kubectl expose rs php --port=9091 --target-port=330600 ``` 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 8081 to port 8081 in the pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8081: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 selected autom...
Create an ingress that directs requests to a specific service with a TLS secret
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.com/example=svc1:8080,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": "", ...
Import the `redis_host` key from the `monitoring-config` config map and set it as an environment variable in the `mydeployment` deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/monitoring-config 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 ...
Create a service for the replicated 'alpine' using a replica set, which will serve on port 80 and connect to the containers on port 8000.
Command: ```bash kubectl expose rs alpine --port=80 --target-port=330600 ``` 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...
import the 'redis_host' key from the 'app-secrets' config map and set it as environment variable in the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env --keys=redis_host --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 definitio...
Edit the 'authentication-service-deployment' deployment in YAML format, save the modified configuration and store it as an annotation.
Command: ```bash kubectl edit deployment/authentication-service-deployment -o yaml --save-config ``` 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 ...
Partially update a node by specifying a strategic merge patch in JSON format
Command: ```bash kubectl patch node prod-node-5 -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]` Help...
Create a debug copy of the payment-gateway-pod, interactively attach to it, and add a debug container with the debian image
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=my-custom-dbg --image=debian --set-image=proxy=nginx:1.21,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 ...
Import environment variables from a config map with a specified prefix
Command: ```bash kubectl set env --from=configmap/monitoring-config --prefix=MYSQL_ 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 variabl...
Add a taint to the 'prod-node-5' node with the key 'workload' and no value
Command: ```bash kubectl taint nodes prod-node-5 workload:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Update the service account for the 'email-server-deployment' deployment to 'elasticsearch'
Command: ```bash kubectl set serviceaccount deployment email-server-deployment elasticsearch ``` 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: ...
Forward traffic from local port 6379 to port 8000 in the pod named "backend-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 6379: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 ...
Get the password for the kube-cluster-1 user
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "kube-cluster-1")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpf...
Import specific keys from a config map into a deployment for the specified app
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-name-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Create a copy of the security-service-pod with all container images changed to php
Command: ```bash kubectl debug security-service-pod --copy-to=debug-image-1 --set-image=*=php ``` 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 ...
Forward traffic from local port 8088 to port 8088 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Add a taint to the node 'testing-node-11' with the key 'dedicated', value 'special-user', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes testing-node-11 dedicated=special-user:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outpu...
Import the `api_key` key from the `namespace-config` ConfigMap into the `authentication-service-deployment` Deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/namespace-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 variabl...
Forward port 8088 on all addresses to port 5000 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8088: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 po...
Output the modified deployment config in YAML format without making any changes to the deployment on the server.
Command: ```bash kubectl set env deployment/user-management-deployment PORT=8080 -o yaml ``` 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 copy of the 'api-service-pod' pod with a debug container and change the container images
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-web --image=debian --set-image=mailer=mailer:latest,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Retrieve the output from running the 'bash' command inside the first pod of the 'authentication-service-deployment' deployment.
Command: ```bash kubectl exec deploy/authentication-service-deployment -- bash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Create a pod disruption budget named 'statefulset-pdb' that will select all pods with the 'region=us-east' label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-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...
Update the annotation 'git-repo' for pod 'proxy-server' with the value 'https://github.com/example/my-app'.
Command: ```bash kubectl annotate pods proxy-server 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 than...
Output the modified log-aggregator-deployment in YAML format, without making any changes to the object on the server
Command: ```bash kubectl set env deployment/log-aggregator-deployment SMTP_USERNAME=your-username -o yaml ``` 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 ...
Display the most recent 43 lines of logs for the 'proxy-server-pod' pod
Command: ```bash kubectl logs --tail=43 proxy-server-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":...
Begin streaming the logs of the rocket-ranger container in the proxy-server-pod pod
Command: ```bash kubectl logs -f -c rocket-ranger proxy-server-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"...
Get output from running the 'wp' command in the cosmic-container of the media-stream-pod.
Command: ```bash kubectl exec media-stream-pod -c cosmic-container -- 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, u...
Create a new secret named 'my-secret' with keys for each file in the 'bar' folder located at 'path/to/options'.
Command: ```bash kubectl create secret generic my-secret --from-file=path/to/options ``` 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 the fil...
Create a new config map named ui-config with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/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 con...
Forward connections from all addresses on port 8000 to port 5000 in the proxy-server-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8000: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 ...
Set the environment variables of the 'notification-handler-deployment' deployment using the 'encryption-key-secret' secret.
Command: ```bash kubectl set env --from=secret/encryption-key-secret deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions i...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/api-config 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 definiti...
Begin streaming the logs of the "code-explorer" container in the pod "web-app-pod"
Command: ```bash kubectl logs -f -c code-explorer web-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", "sh...
Add a taint to a node called 'web-node-8' with the key 'special' and no value.
Command: ```bash kubectl taint nodes web-node-8 special:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
create a LoadBalancer service named database-lb on port 8089 that forwards traffic to port 8083
Command: ```bash kubectl create service loadbalancer database-lb --tcp=8089:8083 ``` 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", "defaul...
Set the service account of the deployment "api-server-deployment" to "fluentd"
Command: ```bash kubectl set serviceaccount deployment api-server-deployment fluentd ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl...
Update the pod named 'media-stream' by adding a label named 'role' with the value 'frontend'
Command: ```bash kubectl label pods media-stream 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", "usa...
Taint nodes in the 'us-east-1' zone with the key 'workload' and value 'monitoring-node-15' to prefer no scheduling
Command: ```bash kubectl taint node -l zone=us-east-1 workload=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Import the `DATABASE_URL` key from the `monitoring-config` config map and set it as an environment variable in the `notification-handler-deployment` deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/monitoring-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment var...
Listen on port 6379 on all addresses and forward the traffic to port 8000 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 6379: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 w...
Create a cluster role named "reader" with specified resource name permissions
Command: ```bash kubectl create clusterrole reader --verb=exec --resource=configmaps --resource-name=app-worker-1 --resource-name=log-aggregator ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Start a pod named 'nginx' using the 'wordpress' image, but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=wordpress --overrides='{ "apiVersion": "custom-version", "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]...
Start an alpine pod and configure the container to expose port 9090.
Command: ```bash kubectl run hazelcast --image=alpine --port=9090 ``` 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...
Forward local port 6379 to port 8888 in the pod selected by the 'notification-handler-deployment' deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 6379 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Copy the local kube config file to a specific container in a remote pod.
Command: ```bash kubectl cp ~/.config/kube message-broker-pod-15:/tmp/bar -c task-processor ``` 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 omitt...
Autoscale the deployment "monitoring" with a minimum of 5 pods and a maximum of 14 pods.
Command: ```bash kubectl autoscale deployment monitoring --min=5 --max=14 ``` 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 u...
Copy the local file ~/.config/kube to the remote pod named monitoring-agent-pod-6 in the default namespace
Command: ```bash kubectl cp ~/.config/kube default/monitoring-agent-pod-6:/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...
Create an ingress called 'app-ingress' that directs requests from foo.com/bar to svc1:9092 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="foo.com/bar=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": "Out...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config-dev 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 defi...
List the deployments in the "extensions" API group in the "beta-1.0" version, and display the output in JSON format.
Command: ```bash kubectl get deployments.beta-1.0.extensions -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wi...
Listen on port 5000 locally and forward the traffic to the targetPort "https" of the service named "order-service" in a pod selected by the service.
Command: ```bash kubectl port-forward service/order-service 5000: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...
Create a new config map named "namespace-config" using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/settings/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 ...
Create a debug container in the log-aggregator-pod by using kubectl debug command and specify the debug image as debian
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-1 --image=debian --set-image=logger=logging-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 identif...
Reconcile the RBAC resources from the rbac.yaml file.
Command: ```bash kubectl auth reconcile -f rbac.yaml ``` What it does: Reconciles rules for RBAC role, role binding, cluster role, and cluster role binding objects. Missing objects are created, and the containing namespace is created for namespaced objects, if required. Existing roles are updated to include the permis...
Create a deployment called "ingress" with the image mcr.microsoft.com/dotnet/core/runtime and expose port 5000.
Command: ```bash kubectl create deployment ingress --image=mcr.microsoft.com/dotnet/core/runtime --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": "", "u...
Forward local port 8088 to port 5432 in the mypod pod
Command: ```bash kubectl port-forward pod/mypod 8088: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 selected automaticall...
View the CPU and memory usage metrics for the containers of a specific pod
Command: ```bash kubectl top pod media-stream-pod --containers ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top ...
Start a php pod and expose port 8089
Command: ```bash kubectl run hazelcast --image=php --port=8089 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--file...
Scale the backend-service-replicaset deployment to 3 replicas
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/backend-service-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --r...
Start a pod named nginx with the centos image, but override some of its specifications with the values provided in the JSON format.
Command: ```bash kubectl run nginx --image=centos --overrides='{ "apiVersion": "v1.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] -- [COMMAN...
Forward local ports 8088 to pod ports 8088 in order to listen and forward data
Command: ```bash kubectl port-forward pod/e-commerce-pod 8088 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Embed the certificate authority data for the kube-cluster-2 cluster entry into the kubectl configuration
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/galaxy-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 new ExternalName service named 'external-caching-service' with the external name 'example-domain.com'
Command: ```bash kubectl create service externalname external-caching-service --external-name example-domain.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference s...
Create a new config map named "app-secrets" using the specified parameter files
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Set the service account of the 'web-app-deployment' deployment to 'vault'
Command: ```bash kubectl set serviceaccount deployment web-app-deployment vault ``` 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 set ...
Copy the local file /tmp/foo to the /tmp/bar directory in the load-balancer-pod-9 pod in the kube-public namespace
Command: ```bash kubectl cp /tmp/foo kube-public/load-balancer-pod-9:/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 ku...
Update the annotation of pod 'payment' with the value 'auto-horizontal-scaling', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods payment 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 t...
Forward local port 8088 to port 9090 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 8088:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Forward port 8081 in the 'security-service-pod' pod to port 3000 on localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 3000: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 th...
List the specified resources of the given types and names.
Command: ```bash kubectl get rc/web service/api-service-rc pods/frontend-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 namespace...
Create a copy of the "auth-service-pod" with a debug container and update the container images
Command: ```bash kubectl debug auth-service-pod -it --copy-to=my-debugger --image=debian --set-image=scheduler=my-scheduler:1.0,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Create a job named 'data-migration-job' using the 'busybox' image.
Command: ```bash kubectl create job data-migration-job --image=busybox ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
import specific keys from a config map
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/global-config 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 definiti...
Delete pods and services with the names "database" and "monitoring"
Command: ```bash kubectl delete pod,service database monitoring ``` 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 selec...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/database-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 namespaced ...
Create a debug version of the `gateway-pod` by adding a debug container and changing container images.
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-web --image=debian --set-image=mailer=mailer:latest,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified ...
create an ingress with two annotations ingress.annotation1 and ingress.annotation2
Command: ```bash kubectl create ingress annotated --class=default --rule="site.com/module=svc:port" \ --annotation ingress.annotation1=site \ --annotation ingress.annotation2=bla ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secre...
Forward traffic from localhost and IP 10.19.21.23 on port 8000 to the pod named cdn-service-pod on port 8000
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8000: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 cri...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-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 variabl...
Attach to the api-service-pod container named cyber-sleuth and get output from it
Command: ```bash kubectl attach api-service-pod -c cyber-sleuth ``` 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 omitted,...
Copy the /tmp/foo_dir directory from the image-resizer-pod-20 pod in the istio-system namespace to the /tmp/bar directory on the local machine.
Command: ```bash kubectl cp istio-system/image-resizer-pod-20:/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, use...
Create an ingress called 'app-proxy-ingress' with a rule that directs requests from foo.com/bar to svc1:9090, using the tls secret named "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="foo.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"...
Copy the file '/tmp/foo' from your local machine to '/tmp/bar' inside the 'api-server-pod-3' pod, specifically in the 'ingress-controller' container.
Command: ```bash kubectl cp /tmp/foo api-server-pod-3:/tmp/bar -c ingress-controller ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Create a service for a replicated node that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose rc node --port=9000 --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. A...
Get the output from the "mycontainer" container in the "web-app-pod" pod
Command: ```bash kubectl attach web-app-pod -c mycontainer ``` 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 omitted, use ...
Auto scale the deployment "chat-app" with a minimum of 5 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment chat-app --min=5 --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 use...