prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Retrieve the updated configuration of the nginx container image, specified in the 'path/to/file.yaml' file, without making any changes to the server
Command: ```bash kubectl set image -f path/to/file.yaml ruby=ruby:3.0.2 --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), replicase...
Remove the annotation 'description' from the pod 'vpn' if it exists
Command: ```bash kubectl annotate pods vpn description- ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary string valu...
Forward local port to pod
Command: ```bash kubectl port-forward pod/cdn-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 will be selected au...
Update the pod 'proxy' by overwriting its annotation 'env' with the value 'staging'
Command: ```bash kubectl annotate --overwrite pods proxy env='staging' ``` 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 arbitr...
Forward data between local port 3000 and pod port 8888
Command: ```bash kubectl port-forward pod/proxy-server-pod 3000 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Start a pod using the Alpine image and expose port 3000
Command: ```bash kubectl run hazelcast --image=alpine --port=3000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Listen on a random port locally and forward traffic to the port 6379 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-pod :6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automati...
Import specific keys from a config map by specifying the keys and the source config map, and apply it to a deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-config-dev deployment/frontend-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 ...
Remove all the taints with the key 'dedicated' from the node 'storage-node-13'
Command: ```bash kubectl taint nodes storage-node-13 dedicated- ``` 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|...
View the rollout history of the app-v2 deployment
Command: ```bash kubectl rollout history deployment/app-v2 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identi...
Forward local port 8081 to port 8888 in the pod
Command: ```bash kubectl port-forward pod/mypod 8081 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Copy the local file :/tmp/foo to :/tmp/bar inside the 'message-broker-pod-15' pod, specifically in the 'metrics-exporter' container.
Command: ```bash kubectl cp :/tmp/foo message-broker-pod-15::/tmp/bar -c metrics-exporter ``` 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 ExternalName service named 'external-caching-service' with the external name 'governmental-demo.gov'
Command: ```bash kubectl create service externalname external-caching-service --external-name governmental-demo.gov ``` 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 referenc...
Add a taint with key 'hardware' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe hardware=app-node-6: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": "...
Rename the context 'testing-context' to 'client-1-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context testing-context client-1-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 ...
Create a deployment named 'my-dep' with 2 replicas running the 'jenkins' image
Command: ```bash kubectl create deployment my-dep --image=jenkins --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. One of:...
Add a taint with the key 'app' on nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice app=prod-node-5: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"...
Add a taint with the key 'app' on nodes that have the label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster app=node-2: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": "Outpu...
Rename the context 'cluster-1-context' to 'team-beta-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context cluster-1-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...
Update a node with a strategic merge patch
Command: ```bash kubectl patch -f cni.conf -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]` Helpful f...
Create a service for the replication controller specified in "centos-controller.yaml" file
Command: ```bash kubectl expose -f centos-controller.yaml --port=8080 --target-port=844300 ``` 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...
Create a job named 'cleanup' with the image 'mcr.microsoft.com/dotnet/core/runtime' and the command 'dotnet'
Command: ```bash kubectl create job cleanup --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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": "", "us...
Autoscale the replication controller "analytics" with a minimum of 1 and a maximum of 5 pods, targeting 50% CPU utilization.
Command: ```bash kubectl autoscale rc analytics --max=5 --cpu-percent=50 ``` 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 us...
Start a pod named "hazelcast" using the Ruby image, and expose port 5000 within the pod.
Command: ```bash kubectl run hazelcast --image=ruby --port=5000 ``` 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": "--fil...
Update the annotation 'SLA' on the 'proxy-server' pod with the value '99.9% uptime', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server SLA='99.9% uptime' ``` 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 in...
Create a copy of the cdn-service-pod named dgb-img, and change all container images to mcr.microsoft.com/dotnet/core/runtime.
Command: ```bash kubectl debug cdn-service-pod --copy-to=dgb-img --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. Pods will be...
Add a taint with the key 'dedicated' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production dedicated=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default...
Update the deployment 'monitoring-stack-deployment' with a new environment variable named SECRET_KEY, and set it to 'your-secret-key'
Command: ```bash kubectl set env deployment/monitoring-stack-deployment SECRET_KEY=your-secret-key ``` 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...
Forward port 9090 on localhost and IP 10.19.21.23 to port 9090 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
Partially update the node specified in 'kube-proxy-config.yaml' using a strategic merge patch, setting the 'unschedulable' field to 'true'
Command: ```bash kubectl patch -f kube-proxy-config.yaml -p '{"spec":{"unschedulable":true}}' ``` 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...
Copy a file or directory from a remote pod to a local directory.
Command: ```bash kubectl exec -n kube-system admin-dashboard-pod-16 -- tar cf - :/tmp/foo | tar xf - -C /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": "Con...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/api-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
List all deployments in the "rc-1.1.0" version of the "api-v1" API group in JSON output format
Command: ```bash kubectl get deployments.rc-1.1.0.api-v1 -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 will o...
Attach to a specific container within a pod, in interactive mode, to send input to 'bash' and receive output
Command: ```bash kubectl attach backend-pod -c quantum-quark -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. If omitt...
Forward traffic from port 8088 on all addresses to port 3000 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 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...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl cp kube-proxy/front-end-pod-12:/tmp/foo_dir /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Set the CPU and memory limits for the Kafka container in the deployment "kafka" to "2" and "64Mi" respectively.
Command: ```bash kubectl set resources deployment kafka -c=nginx --limits=cpu=2,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...
Set the custom TLS server name to "data-cluster" for the "galaxy-cluster" cluster entry.
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=data-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 new secret named git-credentials-secret with keys for each file in the specified folder
Command: ```bash kubectl create secret generic git-credentials-secret --from-file=path/to/data ``` 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 ...
Start streaming the logs from all containers in the pods labeled with app=web-app, including the containers in all pods
Command: ```bash kubectl logs -f -l app=web-app --all-containers=true ``` 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": "--contain...
Edit the data in settings.json, convert it to JSON format, and create a resource using the edited data.
Command: ```bash kubectl create -f settings.json --edit -o json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files t...
Get the modified deployment in YAML format without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/analytics-platform-deployment DB_HOST=localhost -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or mor...
Remove the taint with the key 'zone' and effect 'PreferNoSchedule' from the node 'storage-node-13'
Command: ```bash kubectl taint nodes storage-node-13 zone: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 format. O...
Get the output from running the 'redis-cli' command in the 'email-service-pod' pod. Use the first container in the pod.
Command: ```bash kubectl exec email-service-pod -- redis-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. If omitted, use the kubec...
List specific resources by their type and names
Command: ```bash kubectl get rc/web service/api-service-rc pods/media-stream-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 names...
Create a job using the busybox image
Command: ```bash kubectl create job deployment-rollout-job --image=busybox ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Create an ingress named 'api-ingress' with a rule that directs requests from testing.com/example to svc1 on port 3000
Command: ```bash kubectl create ingress api-ingress --rule="testing.com/example=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": "", "usag...
Partially update the 'app-node-6' node by specifying the patch as YAML with the following content: 'spec:\n replicas: 3'
Command: ```bash kubectl patch node app-node-6 -p $'spec:\n replicas: 3' ``` 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]` Helpful flags: "f...
Get output from running 'nginx -t' command in the 'nano-bot' container of the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c nano-bot -- nginx -t ``` 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...
Rename a context in your kubeconfig file
Command: ```bash kubectl config rename-context staging-context user-a-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...
Create a copy of the 'monitoring-pod' pod and enter into it interactively
Command: ```bash kubectl debug monitoring-pod -it --copy-to=my-debugger --container=quantum-quark -- 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 defa...
Label pod 'gateway' with the label 'env' and value 'staging'
Command: ```bash kubectl label pods gateway env=staging ``` 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": "I...
Create a new ClusterIP service named 'messaging-service-clusterip' with the TCP port mapping from 7000 to 8000.
Command: ```bash kubectl create service clusterip messaging-service-clusterip --tcp=7000:8000 ``` 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": "-...
Create a cron job named 'data-processing' that runs the command 'postgres' every minute using the 'postgres' image
Command: ```bash kubectl create cronjob data-processing --image=postgres --schedule="*/1 * * * *" -- postgres ``` 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 an environment variable for a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/db-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Retrieve information about the replication controller `web`, service `email-service-rc`, and pod `gateway-pod`.
Command: ```bash kubectl get rc/web service/email-service-rc pods/gateway-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 namespac...
Return the snapshot logs from the container 'vpn-service-pod-1' of the deployment 'cache-cluster-deployment'.
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c vpn-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "...
Scale the deployment named app-v2-replicaset to 3 replicas while the current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=3 deployment/app-v2-replicaset ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-v...
Create a new NodePort service named "cdn-service-nodeport"
Command: ```bash kubectl create service nodeport cdn-service-nodeport --tcp=8181:8083 ``` 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":...
Update the annotation of the pod named 'payment' with the key 'SLA' and the value '99.9% uptime', ensuring that any existing value is overwritten.
Command: ```bash kubectl annotate --overwrite pods payment SLA='99.9% uptime' ``` 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...
Retrieve information about specific resources by their types and names
Command: ```bash kubectl get rc/web service/media-stream-rc pods/email-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 nam...
Create a single ingress called 'app-gateway-ingress' that directs requests to site.com/bar to svc # svc1:9090 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.com/bar=svc1:9090,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Get the output of the command 'geth version' from the first container of the pod running the service 'cache-service'.
Command: ```bash kubectl exec svc/cache-service -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Retrieve the documentation of the "conditions" field in the status subresource of the configmaps resource.
Command: ```bash kubectl explain resource=configmaps.status.conditions ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive f...
View the resource usage metrics for all pods in the "external-notification-service" namespace.
Command: ```bash kubectl top pod --namespace=external-notification-service ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `...
Retrieve logs from all containers in pods with the label "region=eu-west-2"
Command: ```bash kubectl logs -l region=eu-west-2 --all-containers=true ``` 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": "--conta...
Output the modified deployment for the 'analytics-platform-deployment' in YAML format, with the environment variable 'S3_BUCKET' set to 'my-s3-bucket', without making any changes to the object on the server.
Command: ```bash kubectl set env deployment/analytics-platform-deployment S3_BUCKET=my-s3-bucket -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...
Forward traffic from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/backend-pod :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 automatica...
Start port forwarding to the 'security-service-pod', listening on port 3000 locally and forwarding to port 6379 in the pod.
Command: ```bash kubectl port-forward pod/security-service-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 be select...
Create a new config map named 'global-config' using the configurations from the 'path/to/configurations.env' file
Command: ```bash kubectl create configmap global-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 ...
Create a new secret named encryption-key-secret with keys for each file in the folder path/to/profiles.
Command: ```bash kubectl create secret generic encryption-key-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 basena...
Start streaming the logs of the "ruby" container in the "backend-pod" pod
Command: ```bash kubectl logs -f -c ruby backend-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...
Execute the command 'jenkins-plugin-cli' in the 'time-machine' container of the 'analytics-pod' pod and retrieve the output
Command: ```bash kubectl exec analytics-pod -c time-machine -- 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. If o...
Create a service for a replicated python using replica set
Command: ```bash kubectl expose rs python --port=8000 --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 specified port....
Import specific keys from a config map to a deployment:
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-secrets deployment/proxy-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Remove the label named "bar" from the pod named "backend"
Command: ```bash kubectl label pods backend unhealthy- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If...
Get the output from running the 'sleep 3600' command in the e-commerce-pod pod, using the first container by default.
Command: ```bash kubectl exec e-commerce-pod -- sleep 3600 ``` 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...
Start a pod with postgres image and expose port 9092
Command: ```bash kubectl run hazelcast --image=postgres --port=9092 ``` 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": "-...
Forward local port 6379 to port 8088 in the pod named "cdn-service-pod", listening on localhost and IP address 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 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 cri...
Create a new nginx pod with the centos image, but customize the pod specification by providing a partial set of values parsed from a JSON file using the overrides flag.
Command: ```bash kubectl run nginx --image=centos --overrides='{ "apiVersion": "v1.1.1", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAN...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/env-vars 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 de...
Create a new pod named 'hazelcast' using the 'confluentinc/cp-kafka' image and expose port 27017.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=27017 ``` 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 fla...
Start port forwarding from local port 3000 to port 5432 in the 'cdn-service-pod' pod
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Create an ingress resource called 'website-ingress' with a rule that directs requests to site.com/input to the service svc1 on port 3306
Command: ```bash kubectl create ingress website-ingress --rule="site.com/input=svc1:3306,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 local port 8088 to port 8081 of the security-service-pod pod in the cluster
Command: ```bash kubectl port-forward pod/security-service-pod 8088 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 select...
Retrieve output from the code explorer container inside the VPN service pod
Command: ```bash kubectl attach vpn-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...
Taint nodes with customer label acme-corp in zone node-2 with PreferNoSchedule
Command: ```bash kubectl taint node -l customer=acme-corp zone=node-2: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 an ingress resource called 'app-proxy-ingress' that directs requests to 'website.com/module' to the service 'svc1' on port 3001, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.com/module=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": "", ...
Create a copy of the "payment-gateway-pod" pod with a debug container and changing container images.
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-memcached --image=debian --set-image=cache=redis:alpine,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by reso...
Execute the 'pip --version' command on the first pod of the service 'notification-service' using the default container.
Command: ```bash kubectl exec svc/notification-service -- pip --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...
Run a golang pod with the name nginx and the image golang, but override the specification with a partial set of values parsed from the given JSON.
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "hotfix-1.1.2", "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] -- [...
Create an ingress resource called "internal-ingress" that routes requests from testing.com/module to svc1:8089 and uses the "my-cert" secret for TLS encryption.
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/module=svc1:8089,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 database-pod with a debug container and change container images
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-app --image=debian --set-image=logger=logging-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 resou...
Copy the service account file from the local machine to a remote pod in a given namespace
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ ingress-nginx/load-balancer-pod-9:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usa...
Create a debug copy of the database pod by adding a new container and modifying container images.
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-api --image=debian --set-image=worker=my-custom-worker:1.2.3,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Create a copy of the 'email-service-pod' pod and change all container images to 'wordpress'
Command: ```bash kubectl debug email-service-pod --copy-to=dgb-img --set-image=*=wordpress ``` 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...
Add a taint on nodes with the label 'namespace=mynamespace' with the key 'disktype' and value 'kube-master-9:PreferNoSchedule'
Command: ```bash kubectl taint node -l namespace=mynamespace disktype=kube-master-9: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": "", ...
Change the service account of the 'web-app-deployment' deployment to 'jenkins'.
Command: ```bash kubectl set serviceaccount deployment web-app-deployment jenkins ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl se...
Forward port 8080 on localhost and selected IP to port 3000 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8080: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 cri...
Remove the deploy-bot user from the kubectl configuration
Command: ```bash kubectl config delete-user deploy-bot ``` What it does: Delete the specified user from the kubeconfig. Syntax: `kubectl config delete-user NAME`