prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new config map named app-name-config using configurations from a specific folder
Command: ```bash kubectl create configmap app-name-config --from-file=path/to/configurations ``` 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...
Get the output from running the 'geth attach' command in the first container of the gateway-pod.
Command: ```bash kubectl exec gateway-pod -- geth attach ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Forward local port 8088 to the pod's port 3000 in the email-server-deployment deployment for listening and sending data.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8088 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...
Create a new config map named global-config with the specified keys and file paths
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/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 creatin...
Remove the 'bar' label from the pod named 'web'
Command: ```bash kubectl label pods web component- ``` 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 tru...
Copy the local file /tmp/foo to /tmp/bar in the remote pod named logging/security-scanner-pod-18
Command: ```bash kubectl cp /tmp/foo logging/security-scanner-pod-18:/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...
Forward local port 6379 to port 6379 on a pod selected by the analytics-platform-deployment deployment
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 6379 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Create an ingress resource named 'ingtls' with TLS enabled
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="foo.com/=svc:https,tls" \ --rule="website.com/path/subpath*=othersvc:9091" ``` 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": "-...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl cp istio-system/front-end-pod-12:/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": "Co...
Add a taint with the key 'zone' on nodes that have the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe zone=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": "Outp...
Create a new config map named env-vars with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/configs/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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=external_api_url --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 defi...
Create a deployment named 'db' that runs the 'redis' image and exposes port 9092
Command: ```bash kubectl create deployment db --image=redis --port=9092 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|y...
Forward traffic from local port 8081 to port 5432 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 8081: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...
Create a copy of the 'proxy-service-pod' and add a debug container
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-memcached --image=debian --set-image=logger=logging-app:debug,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identifi...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config-dev 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 defini...
Set specific environment variables from a config map for a deployment.
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/monitoring-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment v...
Forward traffic from local port 8080 to the pod's port 8080, listening on both localhost and IP 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8080: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 crit...
Set the last-applied-configuration of a resource by applying a file and creating the annotation if it doesn't exist
Command: ```bash kubectl apply set-last-applied -f params.yaml --create-annotation=true ``` What it does: Set the latest last-applied-configuration annotations by setting it to match the contents of a file. This results in the last-applied-configuration being updated as though 'kubectl apply -f ' was run, without upda...
Run the 'mysql' command in the 'cosmic-container' inside the 'monitoring-pod' and get the output.
Command: ```bash kubectl exec monitoring-pod -c cosmic-container -- mysql ``` 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, ...
Remove all taints with key 'disktype' from node 'app-node-6'
Command: ```bash kubectl taint nodes app-node-6 disktype- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|n...
Create a cron job named "database-maintenance" that runs a PHP command every minute.
Command: ```bash kubectl create cronjob database-maintenance --image=php --schedule="*/1 * * * *" -- php --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short...
Forward local port 3000 to port 8000 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 3000:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Copy the kube configuration file from the remote pod 'cache-pod-5' to the local directory '/tmp/bar'
Command: ```bash kubectl cp cert-manager/cache-pod-5:~/.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 ku...
Create a secret named "app-config-secret" using the environment variables from the file "path/to/configurations.env"
Command: ```bash kubectl create secret generic app-config-secret --from-env-file=path/to/configurations.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 ...
Forward locally listening port 9090 to the selected pod's port 8081 in the database-deployment deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 9090 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 ...
Begin streaming the logs of a specific container in a pod
Command: ```bash kubectl logs -f -c nebula-navigator analytics-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"...
Create a new config map named "app-name-config" with specific keys and their corresponding file paths.
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/configs/file1.txt --from-file=key1=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Scale the deployment named 'staging-app-rs' to 3 replicas if its current size is 5
Command: ```bash kubectl scale --current-replicas=5 --replicas=3 deployment/staging-app-rs ``` 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-vers...
Add a taint with key 'disktype' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp disktype=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Execute the 'elasticsearch' command on the chat-app-pod pod, using the first container by default.
Command: ```bash kubectl exec chat-app-pod -- elasticsearch ``` 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...
Update the annotation 'security-scan-status' of pod 'database' to 'pass', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods database security-scan-status='pass' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels a...
Create a new pod named "hazelcast" using the image "wordpress" and set the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container.
Command: ```bash kubectl run hazelcast --image=wordpress --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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] -- [...
create a new NodePort service named backend-nodeport
Command: ```bash kubectl create service nodeport backend-nodeport --tcp=8084:8010 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Import the DATABASE_URL key from the ui-config config map and set it as an environment variable in the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/ui-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 defini...
Import specific keys from a config map by setting environment variables in a deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/namespace-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 defi...
Execute the 'mongo --version' command in the rocket-ranger container of the mypod pod and retrieve the output.
Command: ```bash kubectl exec mypod -c rocket-ranger -- mongo --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Create a copy of 'proxy-service-pod' named 'debug-image-1' and change all container images to 'postgres'
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-1 --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 n...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/log-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 defin...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 5432 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8888: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 crit...
Create a job with a command
Command: ```bash kubectl create job indexing --image=wordpress -- mysql --version ``` 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 form...
Create a new config map named kube-system-config with specified key-value pairs from files.
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs....
Listen on all addresses on port 8080 and forward the traffic to port 8000 in the pod named 'api-service-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8080: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...
Expose a replication controller using a YAML file with specified ports
Command: ```bash kubectl expose -f alpine-controller.yaml --port=8089 --target-port=801000 ``` 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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/global-config 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 definitio...
Forward local port 9090 to port 6379 on the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 9090: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 select...
Import only the "my-example-key" key from the config map "api-config" into the environment variables of the "web-app-deployment" deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/api-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Create a new config map named "namespace-config"
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/configs/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 creati...
Create an ingress resource named 'public-ingress' that directs requests for 'foo.com/example' to the service 'svc1:7000', and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress public-ingress --rule="foo.com/example=svc1:7000,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 located at /var/run/secrets/kubernetes.io/serviceaccount/ from the local machine to the /tmp/bar directory in the remote pod named admin-dashboard-pod-16 in the metallb-system namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ metallb-system/admin-dashboard-pod-16:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usa...
Delete the pods and services named "log-aggregator" and "frontend"
Command: ```bash kubectl delete pod,service log-aggregator frontend ``` 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 s...
Import specific keys from a config map to an existing deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/log-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 one or ...
Run the 'python' command in the chat-app-pod pod.
Command: ```bash kubectl exec chat-app-pod -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kuber...
Get output from code-explorer of a pod named api-service-pod.
Command: ```bash kubectl attach api-service-pod -c code-explorer ``` 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...
Add a taint with key 'environment' on nodes having label service=auth
Command: ```bash kubectl taint node -l service=auth environment=storage-node-13: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...
Retrieve the output from running the 'mongod' command in the 'cyber-sleuth' container of the 'web-app-pod' pod.
Command: ```bash kubectl exec web-app-pod -c cyber-sleuth -- mongod ``` 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...
Create a deployment named "api" using the Ubuntu image and expose port 8084.
Command: ```bash kubectl create deployment api --image=ubuntu --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": "", "usage": "Output format. One of: json...
Create a deployment named "my-dep" with the "jenkins" image and expose port 9091.
Command: ```bash kubectl create deployment my-dep --image=jenkins --port=9091 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Forward local traffic from port 5432 to port 8000 on the selected pod by the 'log-aggregator-deployment' deployment
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 5432 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Listen on port 8081 on your local machine and forward the traffic to port 5000 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
List deployments in YAML format for the "hotfix-1.1.2" version of the "legacy-apps" API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.legacy-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 y...
Update the label of the pod 'log-aggregator' with the key 'component' and the value 'worker'
Command: ```bash kubectl label pods log-aggregator component=worker ``` 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",...
Create a copy of the 'monitoring-pod' and launch a shell session in the 'debug-image-app' container, using the 'astro-container' as the source.
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-app --container=astro-container -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used b...
Create a role named "bar" with specified resource names
Command: ```bash kubectl create role bar --verb=get --resource=pods --resource-name=auth-proxy --resource-name=order-fulfillment ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client...
Rename the context 'cluster-2-context' to 'team-beta-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cluster-2-context team-beta-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field wi...
Forward traffic from port 5432 on all addresses to port 3000 in the pod 'web-app-pod'
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-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 pod will ...
Embed the certificate authority data for the "cluster-gamma" cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/cluster-gamma/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 s...
Listen on port 8888 locally and forward the traffic to port 3000 in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 8888: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 automaticall...
Update the service account of the deployment named 'authentication-service-deployment' to 'tekton'
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment tekton ``` 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 Synta...
Create an ingress called 'frontend-ingress' that routes requests from site.com/example to svc1:9091 with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress rontend-ingress --rule="site.com/example=svc1:9091,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...
Forward local port 5432 to port 3000 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-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 pod will be selected autom...
Create a new ExternalName service named 'external-notification-service' with the external name 'document-company.com'.
Command: ```bash kubectl create service externalname external-notification-service --external-name document-company.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 refe...
Execute the 'elasticsearch' command in the stardust-shuttle container of the auth-service-pod and retrieve the output.
Command: ```bash kubectl exec auth-service-pod -c stardust-shuttle -- elasticsearch ``` 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...
Use vi as the editor to edit the proxy-service
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/proxy-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variables, or...
Remove the taint with key 'environment' and effect 'NoSchedule' from node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 environment: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 o...
Copy the directory '/tmp/foo' from the remote pod 'file-server-pod-14' in the 'default' namespace to the '/etc/kubernetes' directory locally.
Command: ```bash kubectl exec -n default file-server-pod-14 -- tar cf - :/tmp/foo | tar xf - -C /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": "Cont...
Import the specific keys (MAX_CONNECTIONS) from the config map (app-config) and set them as environment variables in the analytics-platform-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create a new NodePort service named cdn-service-nodeport that listens on port 8082 and forwards traffic to port 9000.
Command: ```bash kubectl create service nodeport cdn-service-nodeport --tcp=8082:9000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default":...
Create a debug copy of the media-stream-pod with the following modifications:
Command: ```bash kubectl debug media-stream-pod -it --copy-to=dgb-img --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 name. P...
Retrieve the previous terminated logs from the 'mycontainer' container in the 'payment-gateway-pod' pod.
Command: ```bash kubectl logs -p -c mycontainer payment-gateway-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...
Set a custom TLS server name for the kube-cluster-2 cluster entry
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=moon-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] [--certifica...
Create a cluster role named "bar" that allows a user to perform "list", "create", and "connect" operations on pods.
Command: ```bash kubectl create clusterrole bar --verb=list,create,connect --resource=pods ``` 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", "short":...
Check if the current user has permission to list the "certificates-renewal-job" job in the "default" namespace
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-job -n default ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
List the replication controller 'web', the service 'api-service-rc', and the pod 'log-aggregator-pod'
Command: ```bash kubectl get rc/web service/api-service-rc pods/log-aggregator-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...
Listen on port 8080 on all addresses and forward the traffic to port 9090 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 8080: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 w...
Open the gateway-service service for editing using the micro text editor.
Command: ```bash KUBE_EDITOR="micro" kubectl edit svc/gateway-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variable...
Create a deployment named "jenkins-x" using the "mysql" image and expose port 5001.
Command: ```bash kubectl create deployment jenkins-x --image=mysql --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 of:...
Forward local port 5432 to port 8000 of the pod selected by the database deployment and also forward local port 6000 to port 6000 of the same pod
Command: ```bash kubectl port-forward deployment/database-deployment 5432 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Update the server field of the app-cluster cluster entry while keeping other values intact
Command: ```bash kubectl config set-cluster app-cluster --server=https://1.2.3.4 ``` 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-author...
Update the label of a pod to assign it a specific component.
Command: ```bash kubectl label pods chat-app component=worker ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usag...
Rename the context 'cluster-2-context' to 'edge-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cluster-2-context edge-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will al...
Copy the local file /var/run/secrets/kubernetes.io/serviceaccount/ to the remote pod backend-pod-13 in the container backend-container and place it at /tmp/bar
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ backend-pod-13:/tmp/bar -c backend-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage...
provide details about the 'iot-node-11.iot-edge.local' node
Command: ```bash kubectl describe nodes iot-node-11.iot-edge.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 of that ...
Update the image of all containers in the daemonset 'app-v2' to 'nginx:1.21.3'.
Command: ```bash kubectl set image daemonset app-v2 *=nginx:1.21.3 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kube...
update the image of all deployments and replication controllers' nginx container to 'ubuntu:20.04'
Command: ```bash kubectl set image deployments,rc ubuntu=ubuntu:20.04 --all ``` 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) Synt...
Resume the paused deployment named 'prod'
Command: ```bash kubectl rollout resume deployment/prod ``` 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` Helpful ...
Create a new config map named api-config in the current namespace
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/properties/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 conf...
Edit the 'gateway-deployment' deployment in YAML format, and save the modified configuration in its annotation
Command: ```bash kubectl edit deployment/gateway-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 EDITOR environm...
Forward local port 3000 to port 5432 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod 3000: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 automa...
Import the 'secret_key' key from the 'env-vars' ConfigMap and set it as an environment variable in the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/env-vars 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 definitions...