prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Print the result of updating a container image using a local file in YAML format without hitting the server.
Command: ```bash kubectl set image -f path/to/file.yaml centos=centos:8.4.2105 --local -o yaml ``` 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), re...
List the replication controller 'web', service 'frontend-rc' and pod 'analytics-pod'
Command: ```bash kubectl get rc/web service/frontend-rc pods/analytics-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced ...
Copy the local file /tmp/foo_dir to /tmp/bar_dir in the remote pod worker-pod-4, specifically in the web-app-container container.
Command: ```bash kubectl cp /tmp/foo_dir worker-pod-4:/tmp/bar_dir -c web-app-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": "Container name. If omitted, ...
Add the annotation "description='Web server for marketing site'" to the pod identified by type and name in the "settings.json" file.
Command: ```bash kubectl annotate -f settings.json description='Web server for marketing site' ``` 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 l...
create a new ExternalName service with the name external-authentication-service and the external name example-domain.com
Command: ```bash kubectl create service externalname external-authentication-service --external-name example-domain.com ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to refe...
Forward local port 6379 to port 3000 in the pod named "web-app-pod".
Command: ```bash kubectl port-forward pod/web-app-pod 6379 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...
Create a copy of the "log-aggregator-pod" with all container images changed to "alpine"
Command: ```bash kubectl debug log-aggregator-pod --copy-to=my-debugger --set-image=*=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 name. Pods will be used by default if no r...
Execute the 'ash' command in the 'code-explorer' container of the 'frontend-pod' pod and display the output.
Command: ```bash kubectl exec frontend-pod -c code-explorer -- ash ``` 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...
Create a copy of e-commerce-pod with a debug container and different container images
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Add a taint with the key 'disktype' and the value 'storage-node-13:PreferNoSchedule' on nodes having the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz disktype=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": "", ...
Create a copy of the "api-service-pod" pod, replacing all container images with "mcr.microsoft.com/dotnet/core/runtime".
Command: ```bash kubectl debug api-service-pod --copy-to=debug-image-memcached --set-image=*=mcr.microsoft.com/dotnet/core/runtime ``` 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...
Remove all taints with the key 'cpu-type' from the node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 cpu-type- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|n...
Update the label of pod named 'chat-app' with 'role=backend'
Command: ```bash kubectl label pods chat-app role=backend ``` 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": ...
Create a service for a replicated node that serves on port 9000 and connects to the containers on port 801000.
Command: ```bash kubectl expose rc node --port=9000 --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...
Switch to the raw terminal mode and attach to the 'log-aggregator-pod' container 'nebula-navigator' from the pod.
Command: ```bash kubectl attach log-aggregator-pod -c nebula-navigator -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...
Remove the taint on node 'app-node-6' with the key 'special' and effect 'NoSchedule' if there is one.
Command: ```bash kubectl taint nodes app-node-6 special:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
Open an interactive session with the 'stardust-shuttle' container in the 'email-service-pod' pod, allowing raw terminal input and output.
Command: ```bash kubectl attach email-service-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....
Copy a file from a remote pod to your local machine
Command: ```bash kubectl cp kube-proxy/worker-pod-4::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl....
Forward local port 6379 to port 8081 in the pod "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379: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 a...
Start a pod using the Amazon Linux image and expose port 8083
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=8083 ``` 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":...
Set the environment variable REDIS_HOST to "redis-server" in the deployment 'monitoring-stack-deployment'
Command: ```bash kubectl set env deployment/monitoring-stack-deployment REDIS_HOST=redis-server ``` 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 po...
Forward local port 8081 to port 5000 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-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 automa...
Import specific keys from a config map to the specified deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-prod deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
create a job with the name 'security-scan-job' using the 'nginx' image and run the 'nginx -t' command.
Command: ```bash kubectl create job security-scan-job --image=nginx -- nginx -t ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format...
Create a service for a PHP deployment, serving on port 80 and connecting to containers on port 8000
Command: ```bash kubectl expose deployment php --port=9090 --target-port=808800 ``` 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 ...
Create a service for the 'hazelcast' deployment that listens on port 7000 and forwards traffic to the containers on port 808200.
Command: ```bash kubectl expose deployment hazelcast --port=7000 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Create an ingress named 'api-ingress' that routes requests from testing.com/module to svc1:3000 with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-ingress --rule="testing.com/module=svc1:3000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create an ingress called 'private-service-ingress' with a rule that directs requests to website.com/bar to svc1:8083 and uses the TLS secret "my-cert"
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/bar=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": "...
Autoscale the deployment "security" with a minimum of 6 pods and a maximum of 8 pods.
Command: ```bash kubectl autoscale deployment security --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 uses...
Create a job called "database-seeding-job" using the Python image, and run the command "python" within the job.
Command: ```bash kubectl create job database-seeding-job --image=python -- python ``` 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 pod named "hazelcast" using the "docker.elastic.co/elasticsearch/elasticsearch" image and expose port 8082 on the container.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8082 ``` 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] ...
Set the minimum and maximum number of pods for the "api" deployment to 5 and 13, respectively, and enable autoscaling.
Command: ```bash kubectl autoscale deployment api --min=5 --max=13 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Add a taint with key 'zone' on nodes having label owner=john-doe with the value 'storage-node-13:PreferNoSchedule'
Command: ```bash kubectl taint node -l owner=john-doe zone=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": "", "usage": ...
Forward the local port 5432 to the pod's port 5432 and listen on both localhost and IP address 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-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 criteri...
Create an ingress resource called 'web-ingress' with a rule that directs requests to 'site.com/example' to 'svc1:5432'
Command: ```bash kubectl create ingress web-ingress --rule="site.com/example=svc1:5432,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":...
Forward port 5000 on all addresses to port 5000 in the backend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 5000: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 ...
Set the custom TLS server name to "cloud-cluster" for the "cluster-alpha" cluster entry in the kubectl configuration
Command: ```bash kubectl config set-cluster cluster-alpha --tls-server-name=cloud-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 deployment named "web" with the "amazonlinux" image and expose port 9000.
Command: ```bash kubectl create deployment web --image=amazonlinux --port=9000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Execute the command 'kafka-server-start /etc/kafka/server.properties' inside the first container of the logging-service pod and display the output.
Command: ```bash kubectl exec svc/logging-service -- kafka-server-start /etc/kafka/server.properties ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "C...
Forward local port 8000 to port 8081 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000 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...
Forward traffic from port 5432 on localhost and IP 10.19.21.23 to port 5432 inside the pod named cdn-service-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-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 cri...
Forward local port 5000 to port 8081 in the pod 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 5000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a new config map named app-config-dev using the key=value pairs in the file located at path/to/preferences.
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/preferences ``` 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 bas...
Set the custom TLS server name to 'my-k8s-cluster' for the 'app-cluster' cluster entry
Command: ```bash kubectl config set-cluster app-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...
Get the password for a specific user in the kubeconfig
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "cluster-alpha")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpfu...
Create a single ingress called 'public-service-ingress' that directs requests to testing.com/bar to svc1:9092 using the tls secret "my-cert"
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/bar=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Create a cron job named "database-maintenance" that runs a command using the provided image "centos" every minute.
Command: ```bash kubectl create cronjob database-maintenance --image=centos --schedule="*/1 * * * *" -- bash ``` 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": "-o...
Update the image of a container in a pod using a JSON patch with positional arrays.
Command: ```bash kubectl patch pod database-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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...
Continuously stream the logs of the time-machine container in the analytics-pod
Command: ```bash kubectl logs -f -c time-machine 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", "s...
Create a new config map named ui-config from an env file
Command: ```bash kubectl create configmap ui-config --from-env-file=path/to/configurations.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 t...
Create a pod disruption budget named monitoring-pdb that will select all pods with the component=web label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-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 [...
Add a taint with key 'cpu-type' and value 'dev-node-4:PreferNoSchedule' on nodes having the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz cpu-type=dev-node-4:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create an ingress called 'api-gateway-ingress' that directs requests to foo.com/example to svc1 on port 8088 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="foo.com/example=svc1:8088,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 an ingress named 'api-ingress' that directs requests from 'testing.com/bar' to 'svc1:8081' with TLS enabled using the secret 'my-cert'.
Command: ```bash kubectl create ingress api-ingress --rule="testing.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": ...
Set the cluster field in the 'client-1-context' context to 'cloud-cluster'
Command: ```bash kubectl config set contexts.client-1-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 yo...
Create a new ClusterIP service named frontend-service-clusterip, mapping port 5432 on the service to port 9000 on the target
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=5432:9000 ``` 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...
Dump all namespaces information to standard output
Command: ```bash kubectl cluster-info dump --all-namespaces ``` 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 will build ...
Create an ingress called 'app1-ingress' that directs requests to site.com/input to svc1:8084 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/input=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": "", "usage": ...
Create a single ingress called 'app-proxy-ingress' that directs requests to site.com/module to svc1:8443 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="site.com/module=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": "", "us...
Create a cluster role named "bar" with the option to patch services and specify the resource names "blog-backend" and "auth-proxy".
Command: ```bash kubectl create clusterrole bar --verb=patch --resource=services --resource-name=blog-backend --resource-name=auth-proxy ``` 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]...
Scale the deployment named payment-service-rs to 5 replicas if its current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/payment-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-...
Retrieve the snapshot logs from a specific container in a deployment named "scheduler-app-deployment"
Command: ```bash kubectl logs deployment/scheduler-app-deployment -c web-app-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...
Get the output from running the `jenkins --version` command from the pod named `mypod`.
Command: ```bash kubectl exec mypod -- jenkins --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
View the last 5 lines of logs for the pod `web-app-pod`
Command: ```bash kubectl logs --tail=5 web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c",...
Retrieve the previous terminated logs for a specific container in a pod
Command: ```bash kubectl logs -p -c mycontainer proxy-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",...
Set the custom TLS server name to 'app-cluster' for the 'staging-cluster' cluster entry.
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=app-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 cron job named 'system-health-check' with an image of 'ubuntu', a schedule of running every minute, and a command to echo "Hello".
Command: ```bash kubectl create cronjob system-health-check --image=ubuntu --schedule="*/1 * * * *" -- docker run ubuntu echo "Hello ``` 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": ...
Start streaming the logs of the 'lunar-launcher' container in the 'cdn-service-pod' pod
Command: ```bash kubectl logs -f -c lunar-launcher cdn-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"...
Copy the ~/.config/kube file from the auth-service-pod-11 pod in the istio-system namespace to the /tmp/bar directory on your local machine
Command: ```bash kubectl cp istio-system/auth-service-pod-11:~/.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...
Create a cron job called 'log-rotation' in the default namespace, with the 'golang' image, scheduled to run the command 'go run hello.go' every minute.
Command: ```bash kubectl create cronjob log-rotation --image=golang --schedule="*/1 * * * *" -- go run hello.go ``` 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": ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-config-prod deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a pod disruption budget named 'messaging-pdb' that will select all pods with the 'component=web' label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-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 [-...
Import the specific key values from a config map
Command: ```bash kubectl set env --keys=max_connections --from=configmap/ui-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...
Set the cpu and memory limits for the nginx container in a deployment.
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=1,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its...
Listen on port 8081 on localhost and IP 10.19.21.23, forwarding to port 8000 in the pod named 'api-service-pod'
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8081:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Create a service for the replicated node using a replica set
Command: ```bash kubectl expose rs node --port=9090 --target-port=700000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Forward traffic from local port 5000 to port 9090 in the "analytics-pod" pod, listening on both localhost and IP 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
Update the label of the pod 'proxy-server' to have the key 'component' and the value 'worker'
Command: ```bash kubectl label pods proxy-server 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", "...
Forward port 5432 on localhost and IP 10.19.21.23 to port 8088 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Output the modified deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/search-engine-deployment SMTP_PASSWORD=your-password -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
Update the label of the 'proxy-server' pod to set 'unhealthy' as 'true'
Command: ```bash kubectl label pods proxy-server unhealthy=true ``` 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", "us...
Create a copy of the e-commerce-pod with a debug container and different container images for the API and scheduler.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-app --image=debian --set-image=api=api:v2,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Listen on port 8081 on all addresses and forward the traffic to port 3000 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8081: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 ...
Create a ClusterIP service named frontend-service-clusterip with the TCP port mapping 8089:9000
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=8089:9000 ``` 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...
Get the output from running the 'jenkins-plugin-cli' command in the 'rocket-ranger' container from the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c rocket-ranger -- jenkins-plugin-cli ``` 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. ...
Add a taint with the key 'cpu-type' on nodes that have the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta cpu-type=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": "", "usage": ...
Start a php pod with customized specifications by providing partial values in JSON format.
Command: ```bash kubectl run nginx --image=php --overrides='{ "apiVersion": "feature-branch-2.3.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command]...
Update the node 'web-node-8' with a taint with the key 'zone' and the value 'us-west-1a' and the effect 'PreferNoSchedule'
Command: ```bash kubectl taint nodes web-node-8 zone=us-west-1a: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 form...
Update the cluster role binding for the dashboard service account
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:dashboard ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--serviceaccount=name...
List deployments in JSON output format, using the "beta-1.0" version of the "custom-apps" API group.
Command: ```bash kubectl get deployments.beta-1.0.custom-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you w...
Listen on port 9090 on your local machine and forward the traffic to port 5000 in the 'frontend-pod' pod.
Command: ```bash kubectl port-forward pod/frontend-pod 9090: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 autom...
Forward local port 8000 to port 5000 in a pod selected by the deployment named "email-server-deployment"
Command: ```bash kubectl port-forward deployment/email-server-deployment 8000 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-config-prod deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/db-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Listen on ports 3000 on your localhost and 10.19.21.23 IP address and forward the traffic to port 8080 of the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 3000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Create a job using the Jenkins image with a specific command
Command: ```bash kubectl create job monitoring-job --image=jenkins -- jenkins-plugin-cli ``` 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": "Outp...
Create a deployment named loadbalancer that runs the mongo image with 7 replicas
Command: ```bash kubectl create deployment loadbalancer --image=mongo --replicas=7 ``` 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...
Forward traffic from port 9090 on localhost and IP address 10.19.21.23 to port 8080 in the pod named "mypod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 9090: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 p...
Set the context to edge-cluster for future kubectl commands.
Command: ```bash kubectl config use-context edge-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Get output from rocket-ranger running in the security-service-pod
Command: ```bash kubectl attach security-service-pod -c rocket-ranger ``` 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...