prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new config map named app-secrets with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/profiles/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...
update the environment variable 'DB_USER' in the 'gateway-deployment' deployment
Command: ```bash kubectl set env deployment/gateway-deployment DB_USER=username ``` 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 (wit...
Create an ingress called 'default-ingress' that directs requests for 'site.com/example' to 'svc1:8082' with a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress default-ingress --rule="site.com/example=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Update the label of the 'proxy' pod to 'status=unhealthy', overwriting any existing value
Command: ```bash kubectl label --overwrite pods proxy 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": "fals...
Forward port 8081 on all addresses to port 8888 in the pod named 'analytics-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8081: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 wil...
Create a new ExternalName service named "external-ldap-service" with the external name "sandbox-site.co"
Command: ```bash kubectl create service externalname external-ldap-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 service...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-config-dev deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Create a pod disruption budget named "payment-gateway-pdb" that selects all pods with the "project=my-project" label and requires a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-pdb --selector=project=my-project --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-ava...
Import environment variables from a secret to a deployment
Command: ```bash kubectl set env --from=secret/git-credentials-secret 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 definitions in one or ...
List deployments in YAML output format, using the "v1.1.0" version of the "custom-apps" API group
Command: ```bash kubectl get deployments.v1.1.0.custom-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Create a debug container in chat-app-pod with a copied image and changed container images
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-api --image=debian --set-image=app=app:debug,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 resource and nam...
Forward traffic from port 8888 on all addresses to port 6379 in the pod "backend-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 8888:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will ...
Retrieve the output of the 'geth version' command executed inside the nebula-navigator container of the proxy-server-pod pod.
Command: ```bash kubectl exec proxy-server-pod -c nebula-navigator -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
import specific keys from a config map to set environment variables for a deployment
Command: ```bash kubectl set env --keys=log_level --from=configmap/global-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 definit...
Create a new config map named "ui-config" with specific key-value pairs from files
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/data/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 config...
Create a copy of the 'gateway-pod' and change all container images to 'postgres'. Name the copied pod 'my-custom-dbg'.
Command: ```bash kubectl debug gateway-pod --copy-to=my-custom-dbg --set-image=*=postgres ``` 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...
Create a new ClusterIP service named 'cache-service-clusterip' with the TCP port mapping from 5001 to 8181.
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=5001:8181 ``` 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", ...
Add a taint with key 'environment' on nodes having label tier=frontend.
Command: ```bash kubectl taint node -l tier=frontend environment=backup-node-14: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 pod disruption budget named elastic-search-pdb that will select all pods with the region=us-east label and require a minimum of four of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget elastic-search-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-availabl...
Roll back the staging daemonset to revision 5.
Command: ```bash kubectl rollout undo daemonset/staging --to-revision=5 ``` 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 the...
Execute the 'nginx' command in the 'rocket-ranger' container of the 'gateway-pod' pod and get the output.
Command: ```bash kubectl exec gateway-pod -c rocket-ranger -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Update the image version (tag) of a single-container pod to v4
Command: ```bash kubectl get pod cdn-service-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by...
Retrieve the snapshot logs from the 'auth-service-pod-1' container in the 'api-server-deployment' deployment.
Command: ```bash kubectl logs deployment/api-server-deployment -c auth-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: "fl...
Retrieve the logs from the container named cdn-service-pod-1 of the mydeployment-1 pods in the deployment named mydeployment
Command: ```bash kubectl logs deployment/mydeployment -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 flags: "flag": "--co...
Auto scale the deployment "media-stream" with a minimum of 6 pods and a maximum of 8 pods
Command: ```bash kubectl autoscale deployment media-stream --min=6 --max=8 ``` 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 ...
Create an ingress called 'myapp-ingress' that directs requests from 'website.com/example' to 'svc1:27017' with a TLS secret called 'my-cert'
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/example=svc1:27017,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Set a custom TLS server name for the "galaxy-cluster" cluster entry in the Kubernetes configuration.
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=my-k8s-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...
Set the cluster field in the 'testing-context' context to 'edge-cluster'
Command: ```bash kubectl config set contexts.testing-context.cluster edge-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 ...
Create a new ClusterIP service named messaging-service-clusterip and expose port 3000 of the service to port 8888
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=3000:8888 ``` 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": "-...
Import the specific key 'config_file_path' from the 'ui-config' config map into the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/ui-config deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Get the output of the 'mysql --version' command from the 'astro-container' in the 'chat-app-pod' pod
Command: ```bash kubectl exec chat-app-pod -c astro-container -- 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 om...
Create a new config map named 'log-config' using the files in the 'configs' folder.
Command: ```bash kubectl create configmap log-config --from-file=path/to/configs ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename of...
Update the 'container-name' container in the 'web-node-8' node by setting the CPU limit to '200m'
Command: ```bash kubectl patch node web-node-8 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 F...
Create a config map named env-vars with specified keys by providing the path to the parameter and configuration files.
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Update the environment variable 'DB_HOST' to 'localhost' for the deployment named 'search-engine-deployment'.
Command: ```bash kubectl set env deployment/search-engine-deployment DB_HOST=localhost ``` 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 templat...
Get output from running the 'apache2ctl -D FOREGROUND' command in rocket-ranger container of the web-app-pod pod
Command: ```bash kubectl exec web-app-pod -c rocket-ranger -- apache2ctl -D FOREGROUND ``` 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 service for the alpine-controller replication controller specified in the alpine-controller.yaml file
Command: ```bash kubectl expose -f alpine-controller.yaml --port=9091 --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...
Set the cluster field in a specific context to a new value
Command: ```bash kubectl config set contexts.local-context.cluster cloud-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you w...
Add a taint with key 'environment' on nodes that have the label instance=app-instance-1.
Command: ```bash kubectl taint node -l instance=app-instance-1 environment=testing-node-11: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...
Create a copy of the backend-pod with a debug container and updated container images
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-1 --image=debian --set-image=worker=my-custom-worker:1.2.3,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...
Forward local traffic on ports 8080 and 6000 to a pod selected by the deployment named "notification-handler-deployment" on ports 8888 and 6000 respectively.
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8080 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Create a new ClusterIP service named catalog-service-clusterip that maps the port 8081 to the port 27017 for TCP traffic
Command: ```bash kubectl create service clusterip catalog-service-clusterip --tcp=8081:27017 ``` 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 the directory /tmp/foo_dir from the remote pod api-server-pod-3 in the cert-manager namespace to the local directory /etc/kubernetes.
Command: ```bash kubectl cp cert-manager/api-server-pod-3:/tmp/foo_dir /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, u...
Add a taint with the key 'cpu-type' and value 'k8s-node-1:PreferNoSchedule' on nodes with the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe cpu-type=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": "...
Update the 'proxy-service-deployment' deployment by adding a new environment variable 'CACHE_SIZE' with a value of '64MB'
Command: ```bash kubectl set env deployment/proxy-service-deployment CACHE_SIZE=64MB ``` 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...
Update the image of all containers in the 'nginx' DaemonSet to 'mysql:5.7.35'
Command: ```bash kubectl set image daemonset nginx *=mysql:5.7.35 ``` 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: `kubec...
Create an ingress named 'internal-ingress' that routes requests from website.com/bar to svc1:9000, using the tls secret 'my-cert'
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/bar=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Create a Pod Disruption Budget named 'monitoring-pdb' that will select all pods with the 'owner=team-1' label and require a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=owner=team-1 --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 [-...
Create a new config map named "ui-config" and populate it with the content of the files provided
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a confi...
Create a cron job named 'database-maintenance' with the image 'confluentinc/cp-kafka'
Command: ```bash kubectl create cronjob database-maintenance --image=confluentinc/cp-kafka --schedule="*/1 * * * *" -- kafka-server-start /etc/kafka/server.properties ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [...
Attach to the `astro-container` in the `log-aggregator-pod` and get the output
Command: ```bash kubectl attach log-aggregator-pod -c astro-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 om...
Create a new config map named api-config using the contents of the settings.env file located at path/to/settings.env.
Command: ```bash kubectl create configmap api-config --from-env-file=path/to/settings.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the ba...
forward data between the local port 3000 and the pod/proxy-server-pod port 9090
Command: ```bash kubectl port-forward pod/proxy-server-pod 3000 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...
Create a new ClusterIP service named cache-service-clusterip that forwards traffic from port 3001 on the cluster to port 8888 on the cache-service
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=3001:8888 ``` 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 the local file '/tmp/foo' to the remote pod 'api-server-pod-3' in the 'kube-dns' namespace, with the destination path '/tmp/bar'.
Command: ```bash kubectl cp /tmp/foo kube-dns/api-server-pod-3:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Create a single ingress called 'private-ingress' that directs requests to website.com/example to svc1:8181, using the tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="website.com/example=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": "", "...
Forward traffic from port 5432 on all addresses to port 8081 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5432: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...
Create a new config map named 'app-secrets' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=conf=/path/to/properties/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 creatin...
Import specific keys from a config map into an environment variable of a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/ui-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in...
Create a new config map named monitoring-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/data/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...
Expose a deployment named alpine as a service, serving on port 8081 and connecting to the containers on port 808300.
Command: ```bash kubectl expose deployment alpine --port=8081 --target-port=808300 ``` 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...
Forward local port 8088 to port 8888 in a pod selected by the web-app-deployment deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8088 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 s...
Rollback the deployment named "test" to the previous version.
Command: ```bash kubectl rollout undo deployment/test ``` What it does: Manage the rollout of a resource. Valid resource types include: Syntax: `kubectl rollout SUBCOMMAND`
Create a copy of the vpn-service-pod with a debug container using the debian image, and change the container image for mailer to mailer:latest
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=mailer=mailer: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 reso...
Enable Google Compute Platform auth provider for api-user by running "kubectl config set-credentials api-user --auth-provider=gcp"
Command: ```bash kubectl config set-credentials api-user --auth-provider=gcp ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags: --to...
Forward local traffic from port 8080 to port 8088 in a pod named "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 8080:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a debug container in the mypod pod, copy the pod to a new pod named debug-image-memcached, and change the container images for the worker container to my-custom-worker:1.2.3 and the database container to mysql:5.7
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-memcached --image=debian --set-image=worker=my-custom-worker:1.2.3,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by...
Forward local port 3000 to the pod's port 3000
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...
Retrieve the snapshot logs from the container "monitoring-pod-1" in the deployment "user-management-deployment"
Command: ```bash kubectl logs deployment/user-management-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: ...
Update the environment variable DB_USER to 'username' in the 'cache-cluster-deployment' deployment
Command: ```bash kubectl set env deployment/cache-cluster-deployment DB_USER=username ``` 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 template...
Create a new ClusterIP service named 'database-service-clusterip' that maps port 8084 of the service to port 8083 of the pods
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=8084:8083 ``` 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...
Import the redis_host key from the app-secrets config map into the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-secrets deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Set the service account of the deployment "analytics-platform-deployment" to "gitlab-runner"
Command: ```bash kubectl set serviceaccount deployment analytics-platform-deployment gitlab-runner ``` 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 Sy...
Display only the most recent 43 lines of logs for the pod named email-service-pod
Command: ```bash kubectl logs --tail=43 email-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short"...
Copy a file named "foo" from a remote pod to a local directory named "bar_dir"
Command: ```bash kubectl cp logging/file-server-pod-14:/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Create a service for the 'ruby' deployment, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment ruby --port=8084 --target-port=637900 ``` 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...
Retrieve logs from the container named `proxy-service-pod-1` in the `backend-microservice-deployment` Deployment
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c proxy-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...
Forward traffic from local port 8081 to port 8080 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-pod 8081: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 aut...
Forward traffic from port 8000 on all addresses to port 8080 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8000: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 wil...
Listen on a random port locally, forwarding traffic to port 8888 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod :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 aut...
Start a mongo pod with the name nginx and the image mongo, but override some values in the pod's specification using a JSON object.
Command: ```bash kubectl run nginx --image=mongo --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] -- ...
Add a "PreferNoSchedule" taint with the key "hardware" on nodes having the label "version=v1.0.0" and the name "db-node-7".
Command: ```bash kubectl taint node -l version=v1.0.0 hardware=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Copy the local directory /tmp/foo_dir to the remote pod api-server-pod-3 in the default namespace, and place it in the /tmp/bar_dir_dir directory.
Command: ```bash kubectl cp /tmp/foo_dir api-server-pod-3:/tmp/bar_dir_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Output the modified analytics-platform-deployment in YAML format with the updated JWT_SECRET environment variable
Command: ```bash kubectl set env deployment/analytics-platform-deployment JWT_SECRET=your-jwt-secret -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 o...
Execute the 'python' command on the first pod of the 'proxy-service-deployment' deployment.
Command: ```bash kubectl exec deploy/proxy-service-deployment -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Update the 'frontend-deployment' with a new environment variable 'CACHE_SIZE' set to '64MB'
Command: ```bash kubectl set env deployment/frontend-deployment CACHE_SIZE=64MB ``` 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 (wit...
Create a new secret named password-secret using the values from an environment file
Command: ```bash kubectl create secret generic password-secret --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 b...
Create a deployment named 'app' using the 'docker.elastic.co/elasticsearch/elasticsearch' image and expose port '8084'
Command: ```bash kubectl create deployment app --image=docker.elastic.co/elasticsearch/elasticsearch --port=8084 ``` 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": ""...
Copy the local file '/tmp/foo_dir' to the remote pod 'cert-manager/task-processor-pod-17' in the 'cert-manager' namespace, and save it as '/tmp/bar'
Command: ```bash kubectl cp /tmp/foo_dir cert-manager/task-processor-pod-17::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Remove the annotation named 'description' from the pod named 'backend' if it exists, without overwriting it with an empty value.
Command: ```bash kubectl annotate pods backend description- ``` 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 ...
Create a cluster role named "default_role" with the ResourceName specified as "nginx-proxy" and "mail-server" for the "pods" resource and allow the "connect" verb for these resources
Command: ```bash kubectl create clusterrole default_role --verb=connect --resource=pods --resource-name=nginx-proxy --resource-name=mail-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clien...
Set the cpu limits for the kafka container in the deployment to "50m" and memory limits to "512Mi"
Command: ```bash kubectl set resources deployment kafka -c=nginx --limits=cpu=50m,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to ...
Execute the 'postgres' command in the first container of the first pod of the 'web-service' service.
Command: ```bash kubectl exec svc/web-service -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Forward traffic from local port 3000 to port 8081 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-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 the criteria, a pod will be selected automa...
Set the annotation 'backup-strategy' to 'daily backups' on the pod named 'database'
Command: ```bash kubectl annotate pods database backup-strategy='daily backups' ``` 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 inclu...
Update the image of all containers in the daemonset named "staging" to "centos:8.4.2105"
Command: ```bash kubectl set image daemonset staging *=centos:8.4.2105 ``` 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: `...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Forward local port 8000 to port 6379 in the pod named "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 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, a pod will be selected automa...
Add a taint with key 'hardware' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database hardware=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": "", "us...
Forward local port 5432 to port 5432 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 5432: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 autom...