prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new ClusterIP service named catalog-service-clusterip and map the port 8083 to the target port 8083.
Command: ```bash kubectl create service clusterip catalog-service-clusterip --tcp=8083: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"...
Create a copy of the 'web-app-pod' pod, adding a debug container and changing container images
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-1 --image=debian --set-image=cache=redis:alpine,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
create a cron job named cron-task that runs the command "apache2ctl -D FOREGROUND" using the wordpress image every minute
Command: ```bash kubectl create cronjob cron-task --image=wordpress --schedule="*/1 * * * *" -- apache2ctl -D FOREGROUND ``` 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", ...
Forward the local port 6379 to the pod's port 8088 in the 'cdn-service-pod' pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 6379: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 au...
Create an ingress named 'api-v1-ingress' that routes requests for 'site.com/bar' to 'svc1:8081' and uses the TLS secret 'my-cert'
Command: ```bash kubectl create ingress api-v1-ingress --rule="site.com/bar=svc1:8081,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": ...
Update the pod 'monitoring' by setting the annotation 'owner' to 'alice-smith', replacing any previous value that might exist.
Command: ```bash kubectl annotate --overwrite pods monitoring owner='alice-smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and inc...
Set the cluster field in the "my-context" context to "kube-cluster-2"
Command: ```bash kubectl config set contexts.edge-context.cluster kube-cluster-2 ``` 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...
Remove the label 'release-' from the pod named 'web'
Command: ```bash kubectl label pods web release- ``` 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 true,...
Run the 'psql' command in the 'quantum-quark' container of the 'media-stream-pod' pod and get the output
Command: ```bash kubectl exec media-stream-pod -c quantum-quark -- psql ``` 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 new config map named app-config-dev with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/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. Whe...
Set the cluster field in the dev-context context to my-k8s-cluster
Command: ```bash kubectl config set contexts.dev-context.cluster my-k8s-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 wa...
Create an ingress called 'app-gateway-ingress' that directs requests to the path '/bar' of 'website.com' to the service 'svc1' with port '8443'
Command: ```bash kubectl create ingress app-gateway-ingress --rule="website.com/bar=svc1:8443,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": "", "...
Scale a resource specified in the "setup.json" file to 1 replica
Command: ```bash kubectl scale --replicas=1 -f setup.json ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated...
Create an ingress called 'website-ingress' that redirects requests to foo.com/example to svc1:8083 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="foo.com/example=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a new config map named global-config with the contents of /path/to/data/file1.txt mapped to the key "settings" and the contents of /path/to/profiles/file2.txt mapped to the key "key2"
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/data/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 creating a co...
Update the image of all containers in the daemonset named 'app-v2' to 'mysql:5.7.35'
Command: ```bash kubectl set image daemonset app-v2 *=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: `kube...
Port forward from local port 8888 to port 3000 in the pod named web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 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 automa...
Apply the environment variables from the 'ui-config' ConfigMap to the 'payment-processor-deployment' deployment, prefixing the variables with 'MYSQL_'
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Update the deployment 'payment-processor-deployment' in the current namespace by setting the environment variable QUEUE_NAME to 'task-queue'.
Command: ```bash kubectl set env deployment/payment-processor-deployment QUEUE_NAME=task-queue ``` 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...
Edit the web-service service using the "code" editor.
Command: ```bash KUBE_EDITOR="code" kubectl edit svc/web-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...
Copy the local file "foo" located at "/tmp" to the remote pod named "security-scanner-pod-18" in the namespace "kube-public" at the path "/etc/kubernetes".
Command: ```bash kubectl cp :/tmp/foo kube-public/security-scanner-pod-18:/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...
Retrieve the output of the command 'redis-server --version' running inside the astro-container in the pod named 'gateway-pod'.
Command: ```bash kubectl exec gateway-pod -c astro-container -- redis-server --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....
Forward port 8888 on your local machine and selected IP to port 5432 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-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 criter...
Create a single ingress named 'app2-ingress' with a rule that directs requests to site.com/module to the svc1 service on port 9091, and use the TLS secret named "my-cert".
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/module=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": "", "usage":...
Execute the 'irb' command in the 'quantum-quark' container of the 'api-service-pod' pod and get the output.
Command: ```bash kubectl exec api-service-pod -c quantum-quark -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Create a role named "default_role" with API Group specified
Command: ```bash kubectl create role default_role --verb=update,get,patch --resource=persistentvolumes.storage.k8s.io ``` 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|none]` He...
Get the output from the 'lunar-launcher' container in the 'cdn-service-pod' pod
Command: ```bash kubectl attach cdn-service-pod -c lunar-launcher ``` 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 omitte...
Create a new LoadBalancer service named frontend-lb that maps port 8083 to port 6379
Command: ```bash kubectl create service loadbalancer frontend-lb --tcp=8083:6379 ``` 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...
Create a deployment named 'monitoring' with 2 replicas, using the 'postgres' image.
Command: ```bash kubectl create deployment monitoring --image=postgres --replicas=2 ``` 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. On...
Run the 'elasticsearch --version' command in the email-service-pod pod and display the output
Command: ```bash kubectl exec email-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,...
Update the image of all containers in the 'app-v2' DaemonSet to 'ubuntu:20.04'
Command: ```bash kubectl set image daemonset app-v2 *=ubuntu:20.04 ``` 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...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=DEBUG_MODE --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 defini...
Create a new config map named app-config-dev with specific keys from specified file paths
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/settings/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 creatin...
Create a dump of the current cluster state and save it to the directory /tmp/foo.
Command: ```bash kubectl cluster-info dump --output-directory=/tmp/foo ``` What it does: Dump cluster information out suitable for debugging and diagnosing cluster problems. By default, dumps everything to stdout. You can optionally specify a directory with --output-directory. If you specify a directory, Kubernetes ...
Add a taint with the key 'app' on nodes having the label component=proxy, specifically on the node-1 with a taint effect of PreferNoSchedule.
Command: ```bash kubectl taint node -l component=proxy app=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": "Output f...
Start a new pod named 'hazelcast' using the 'amazonlinux' image and expose port 8089 in the container.
Command: ```bash kubectl run hazelcast --image=amazonlinux --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":...
Create a pod disruption budget named frontend-pdb that selects all pods with the component=web label and requires at least 4 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=component=web --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 [--...
Auto scale the replication controller "security" with a target CPU utilization of 90%, allowing between 1 and 7 pods.
Command: ```bash kubectl autoscale rc security --max=7 --cpu-percent=90 ``` 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...
Remove a specific taint from a node
Command: ```bash kubectl taint nodes dev-node-4 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: ...
Create an ingress resource called 'app-loadbalancer-ingress' with a rule that directs requests from 'site.com/input' to 'svc1:3001' and uses the TLS secret 'my-cert'
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="site.com/input=svc1:3001,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": "...
Update the 'vpn' pod by adding or updating the annotation 'expiration-date' with the value '2024-12-31', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods vpn expiration-date='2024-12-31' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
create a service for a replicated ruby application, serving on port 8088, and connecting to the containers on port 808400
Command: ```bash kubectl expose rc ruby --port=8088 --target-port=808400 ``` 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...
Run the 'composer --version' command in the 'time-machine' container of the 'database-pod' pod and display the output.
Command: ```bash kubectl exec database-pod -c time-machine -- composer --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...
forward traffic from port 3000 on all addresses to port 6379 in the frontend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 3000: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...
Set the custom TLS server name "my-k8s-cluster" to use for validation for the "dev-cluster" cluster entry.
Command: ```bash kubectl config set-cluster dev-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] [--certificat...
Create a new service account named kube-controller-manager
Command: ```bash kubectl create serviceaccount kube-controller-manager ``` What it does: Create a service account with the specified name. Syntax: `kubectl create serviceaccount NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json...
Create an ingress called 'public-service-ingress' that directs requests to 'site.com/module' to 'svc1:9000' with a tls secret named "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="site.com/module=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": ""...
Embed the certificate authority data for the kube-cluster-1 cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-1 --embed-certs --certificate-authority=~/.kube/star-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 s...
Forward traffic from port 5000 on your local machine to port 9090 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 5000: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 au...
Set the environment variables DEBUG_MODE on the payment-processor-deployment deployment, importing the value from the app-name-config configmap.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-name-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Execute the command 'java -jar /usr/share/jenkins/jenkins.war' within the 'quantum-quark' container in the 'backend-pod' pod
Command: ```bash kubectl exec backend-pod -c quantum-quark -- java -jar /usr/share/jenkins/jenkins.war ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": ...
Forward local port 5432 to port 5000 in the pod "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 5432: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 auto...
Import the 'secret_key' key from the 'global-config' config map and set it as an environment variable for the 'email-server-deployment' deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/global-config deployment/email-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 definiti...
Create a copy of the mypod pod, changing the command of the cosmic-container to start an interactive shell session
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-web --container=cosmic-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 by defaul...
Update pod annotations.
Command: ```bash kubectl annotate -f config.json owner='alice smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrar...
Partially update a node by applying a strategic merge patch in JSON format
Command: ```bash kubectl patch node testing-node-11 -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]` ...
Embed the certificate authority data for the "web-cluster" cluster entry
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/data-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 set-...
Create a new config map named 'env-vars' using the files 'file1.txt' and 'file2.txt' for the keys 'conf' and 'data' respectively.
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/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 co...
Create a new ClusterIP service named security-service-clusterip, mapping port 27017 on the service to port 7000 on the backend
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=27017:7000 ``` 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": "-...
Forward traffic from local port 9090 to port 9090 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod 9090:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a debugging container based on the 'frontend-pod' with all container images changed to 'ubuntu'
Command: ```bash kubectl debug frontend-pod --copy-to=debug-image-app --set-image=*=ubuntu ``` 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 res...
Create a new config map named 'ui-config' using the specified files
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/profiles/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 ...
Forward traffic between local ports 8088 and 6000 to ports 8080 and 6000 respectively in the pod "log-aggregator-pod".
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8088 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...
Create a copy of the "web-app-pod" and change the command of "nano-bot" for debugging purposes.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-1 --container=nano-bot -- 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 by default if...
Forward traffic from local port 5432 to port 8888 in a pod selected by the deployment "analytics-platform-deployment".
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5432 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 po...
Forward port 5432 on all addresses to port 8888 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5432: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 sel...
Forward port 3000 of the pod "frontend-pod" to port 9090 on localhost and IP address 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 9090: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 criter...
Create a new secret with keys for each file in folder
Command: ```bash kubectl create secret generic cert-manager-secret --from-file=path/to/profiles ``` 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...
Create a copy of the pod 'proxy-service-pod' adding a debug container and changing container images
Command: ```bash kubectl debug proxy-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=scheduler=my-scheduler:1.0,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified b...
Switch to raw terminal mode and attach to the 'stardust-shuttle' container inside the 'media-stream-pod' pod.
Command: ```bash kubectl attach media-stream-pod -c stardust-shuttle -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. ...
Create a job named 'data-migration-job' with the image 'ruby' and the command 'ruby --version'
Command: ```bash kubectl create job data-migration-job --image=ruby -- ruby --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 ...
Remove all taints with key 'datacenter' from node 'web-node-8'
Command: ```bash kubectl taint nodes web-node-8 datacenter- ``` 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...
Forward port 5000 on all addresses to port 8088 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
create a service for the replication controller specified in the "wordpress-controller.yaml" file, which serves on port 6379 and connects to the containers on port 808000.
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=6379 --target-port=808000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
Embed the certificate authority data for the e2e cluster entry.
Command: ```bash kubectl config set-cluster e2e --embed-certs --certificate-authority=~/.kube/data-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 set-cluster ...
Start listening on port 8081 locally and forward the traffic to the targetPort of the "https" port in the "user-service" service.
Command: ```bash kubectl port-forward service/user-service 8081: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 service for the replicated node 'node' using replica set, which will serve on port 7000 and connect to the containers on port 801000.
Command: ```bash kubectl expose rs node --port=7000 --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 specified port. A...
Create a new config map named 'db-config' using the files '/path/to/data/file1.txt' and '/path/to/configs/file2.txt' as the values for the keys 'conf' and 'data', respectively.
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/data/file1.txt --from-file=data=/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 config map ...
Expose the replica set "wordpress" as a service on port 8089, with connections to the containers on port 801000.
Command: ```bash kubectl expose rs wordpress --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 specified po...
Apply the configuration in the manifest.yaml file to resources that have the label 'release' set to 'beta'
Command: ```bash kubectl apply --prune -f manifest.yaml -l release=beta ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'c...
Delete the pods and services with the names "chat-app" and "vpn"
Command: ```bash kubectl delete pod,service chat-app vpn ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. So...
Import the 'log_level' key from the 'app-config' config map into the 'database-deployment' deployment's environment variables
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-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 definitions in o...
Forward port 8081 on all addresses to port 8088 in the specified pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8081: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 ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/env-vars deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Create a service named "frontend" to expose the pod "vpn-service-pod" on port 8888.
Command: ```bash kubectl expose pod vpn-service-pod --port=8888 --name=frontend ``` 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 ...
List the replication controller named 'web', the service named 'api-service-rc', and the pod named 'proxy-service-pod'
Command: ```bash kubectl get rc/web service/api-service-rc pods/proxy-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is name...
Create an ingress called 'public-service-ingress' that directs requests to testing.com/bar to svc1:8084 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/bar=svc1:8084,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": ""...
Create a copy of the "email-service-pod" with all container images changed to "mysql"
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-memcached --set-image=*=mysql ``` 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...
Import specific keys from a config map and set them as environment variables for a deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-secrets 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 defi...
Edit the last-applied-configuration annotations of a specific deployment in YAML format.
Command: ```bash kubectl apply edit-last-applied deployment/nginx ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the edito...
Copy the local file located at ~/.config/kube to the remote pod named 'payment-gateway-pod-19' in the 'cert-manager' namespace
Command: ```bash kubectl cp ~/.config/kube cert-manager/payment-gateway-pod-19::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create a new config map named app-config-dev in the default namespace with the specified keys and their corresponding file paths
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/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 ...
Create a config map named "app-name-config" using specified keys and file paths.
Command: ```bash kubectl create configmap app-name-config --from-file=conf=/path/to/parameters/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...
Import specific keys from a config map to set environment variables for a deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/ui-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Add a taint with the key 'app' on nodes that have the label feature=feature-xyz.
Command: ```bash kubectl taint node -l feature=feature-xyz app=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": "", "usag...
Create a service for a replication controller using a yaml file, exposing it on port 8081 and connecting to containers on port 330600.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=8081 --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...
If the current size of the deployment named api-service-rs is 7, scale the mysql deployment to 3 replicas.
Command: ```bash kubectl scale --current-replicas=7 --replicas=3 deployment/api-service-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...
Forward local ports 8000 to port 5432 in the selected pod of the 'database-deployment' deployment
Command: ```bash kubectl port-forward deployment/database-deployment 8000 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Forward local port 5432 to port 8088 in the pod "cdn-service-pod" and listen on local port 6000, forwarding data to/from port 6000 in the pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 5432 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 au...
Apply the last-applied configuration to each file in a directory
Command: ```bash kubectl apply set-last-applied -f path/ ``` 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 updating any other parts of the obj...