prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Return the previous terminated logs of the Ruby container from the "auth-service-pod" pod.
Command: ```bash kubectl logs -p -c ruby auth-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short"...
Execute the 'mysql' command in the 'cosmic-container' from the pod 'vpn-service-pod' and retrieve the output.
Command: ```bash kubectl exec vpn-service-pod -c cosmic-container -- mysql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create and run a pod using the Ruby image, with the container exposing port 3306.
Command: ```bash kubectl run hazelcast --image=ruby --port=3306 ``` 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...
List deployments in YAML output format for the "sandbox-apps" API group, using version "alpha-2.0"
Command: ```bash kubectl get deployments.alpha-2.0.sandbox-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you...
Forward local port 9090 to port 9090 in the selected pod of the deployment "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Add a taint with key 'special' on nodes having label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster special=edge-node-10: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...
Copy the directory '/tmp/foo_dir' from the pod 'argocd/metrics-exporter-pod-10' to the local directory '/tmp/bar'.
Command: ```bash kubectl cp argocd/metrics-exporter-pod-10:/tmp/foo_dir :/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 th...
import the 'secret_key' key from the 'app-config-dev' ConfigMap into the 'analytics-platform-deployment' deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-config-dev 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 d...
Create a copy of the "gateway-pod" pod with a debug container and change the container images.
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,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 reso...
Taint nodes with label 'project=project-alpha' using the key 'hardware' and value 'monitoring-node-15' with a taint effect of 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l project=project-alpha hardware=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default":...
Import specific keys from a config map to a deployment named "monitoring-stack-deployment" in the "default" namespace
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-config-prod deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
Set environment variables for a specific deployment using a config map with a given prefix
Command: ```bash kubectl set env --from=configmap/app-config-dev --prefix=MYSQL_ 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 definiti...
Display the CPU and memory usage metrics for all pods in the "external-payment-gateway-service" namespace.
Command: ```bash kubectl top pod --namespace=external-payment-gateway-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...
Forward traffic from local port 8000 to port 8080 in the pod monitoring-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Create a cluster role named "admin_role" with the verb "get" and the non-resource URL of "/api-docs/*".
Command: ```bash kubectl create clusterrole "admin_role" --verb=get --non-resource-url=/api-docs/* ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", ...
Create a copy of the 'gateway-pod' pod and change all container images to 'golang'. Name the new debugger pod 'my-debugger'.
Command: ```bash kubectl debug gateway-pod --copy-to=my-debugger --set-image=*=golang ``` 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 resource...
Edit the user field of the staging-context context entry
Command: ```bash kubectl config set-context staging-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nickna...
Create a secret named ldap-credentials-secret with keys for each file in the folder "bar"
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-file=path/to/configs ``` 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 basen...
Start a mongo pod with the name 'nginx' using the 'mongo' image, but overload the spec with a partial set of values parsed from JSON.
Command: ```bash kubectl run nginx --image=mongo --overrides='{ "apiVersion": "beta-1.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] -- [COMMA...
Remove a label named 'role' from the pods with the name 'media-stream'
Command: ```bash kubectl label pods media-stream role- ``` 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...
Run the command 'apk add curl' in the 'time-machine' container of the 'analytics-pod' pod and get the output.
Command: ```bash kubectl exec analytics-pod -c time-machine -- apk add curl ``` 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...
Create a secret named oauth-secret from an env file
Command: ```bash kubectl create secret generic oauth-secret --from-env-file=path/to/profiles.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basenam...
Copy the file 'foo' from the '/tmp' directory inside the remote pod 'payment-gateway-pod-19' to the '/etc/kubernetes' directory, specifically in the 'task-processor' container.
Command: ```bash kubectl cp :/tmp/foo payment-gateway-pod-19:/etc/kubernetes -c task-processor ``` 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 om...
Create a copy of the 'proxy-server-pod' pod and start a debug session in the 'debug-image-1' pod with the 'stardust-shuttle' container, running the 'sh' command
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=debug-image-1 --container=stardust-shuttle -- 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 ...
Import specific keys from a config map into an environment variable of a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/app-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Set the custom TLS server name 'star-cluster' for validation for the e2e cluster entry.
Command: ```bash kubectl config set-cluster e2e --tls-server-name=star-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] [--certificate-authorit...
Forward local port 8888 to port 9090 in a pod selected by the deployment "analytics-platform-deployment"
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 8888 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 po...
Update the annotation 'app-version' with the value '2.5.1' for the pod 'frontend', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods frontend app-version='2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and inclu...
Create an ingress called 'default-ingress' with a rule that directs requests from 'foo.com/example' to the service 'svc1' on port 9000
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/example=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": "", "usag...
Check if you have permission to list the jobs in the "monitoring" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-job -n monitoring ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial UR...
Listen on port 8080 on the local machine and forward the traffic to port 8000 in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 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 automaticall...
Create a pod disruption budget named api-service-pdb that selects all pods with the region=us-east label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=region=us-east --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Create a new secret with keys for each file in a specified folder
Command: ```bash kubectl create secret generic password-secret --from-file=path/to/properties ``` 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 o...
Copy the local file /tmp/foo_dir to the remote pod named auth-service-pod-11 in the namespace monitoring, and place it in the /etc/kubernetes directory.
Command: ```bash kubectl cp /tmp/foo_dir monitoring/auth-service-pod-11:/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, ...
Get output from running a command inside the first pod of the 'monitoring-service' service
Command: ```bash kubectl exec svc/monitoring-service -- npm --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 ...
List all deployments in the "testing-apps" API group, version "v1.1.1" and output the results in JSON format.
Command: ```bash kubectl get deployments.v1.1.1.testing-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 wi...
List deployments in the "v1.1.0" version of the "legacy-apps" API group and display the output in YAML format.
Command: ```bash kubectl get deployments.v1.1.0.legacy-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Create a deployment named "proxy" that runs the "ethereum/client-go" image and exposes port 8084.
Command: ```bash kubectl create deployment proxy --image=ethereum/client-go --port=8084 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format...
Create a debug version of the chat-app-pod by adding a debug container and changing container images.
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-api --image=debian --set-image=cache=redis:alpine,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource ...
Create an ingress called 'public-api-ingress' that directs requests to site.com/module to a service with the IP address svc1:9091, and use the TLS secret "my-cert" for secure communication.
Command: ```bash kubectl create ingress public-api-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": "", "u...
Start a pod named 'hazelcast' with the nginx image and have the container inside expose port 8888.
Command: ```bash kubectl run hazelcast --image=nginx --port=8888 ``` 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": "--fi...
Forward local port 8080 to port 8081 in the pod 'mypod'.
Command: ```bash kubectl port-forward pod/mypod 8080: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 automaticall...
List the replication controller 'web', service 'auth-service-rc', and pod 'monitoring-pod'
Command: ```bash kubectl get rc/web service/auth-service-rc pods/monitoring-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 namesp...
Expose a service for a replication controller specified in a YAML file, with port mappings specified.
Command: ```bash kubectl expose -f node-controller.yaml --port=8010 --target-port=500100 ``` 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 s...
Create a new ClusterIP service named my-cs with a TCP port mapping of 9092 to 8088
Command: ```bash kubectl create service clusterip my-cs --tcp=9092:8088 ``` 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", "default": "", "us...
Update the service account for the deployment "database-deployment" to "metrics-server".
Command: ```bash kubectl set serviceaccount deployment database-deployment metrics-server ``` 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: `ku...
Set up port forwarding to listen on port 8888 on all addresses and forward traffic to port 8888 in the "mypod" pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8888: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...
Update the annotation 'compliance-level' of the pod 'log-aggregator' to 'PCI-DSS', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods log-aggregator compliance-level='PCI-DSS' ``` 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 lab...
Auto scale the deployment "chat-app" with 7 to 9 pods
Command: ```bash kubectl autoscale deployment chat-app --min=7 --max=9 ``` 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...
Open the 'loadbalancer-service' service for editing using the Atom editor.
Command: ```bash KUBE_EDITOR="atom" kubectl edit svc/loadbalancer-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 vari...
Create an ingress resource called 'private-api-ingress' with the following rule: foo.com/example should be directed to svc1:8010
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/example=svc1:8010,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": "", "...
Execute the command 'elasticsearch --version' in the 'warp-drive' container of the 'proxy-server-pod' pod and retrieve the output.
Command: ```bash kubectl exec proxy-server-pod -c warp-drive -- 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...
Get the logs of the previous terminated container named 'astro-container' from the pod named 'chat-app-pod'
Command: ```bash kubectl logs -p -c astro-container chat-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", ...
Run the 'mongo' command inside the 'chat-app-pod' pod and display the output.
Command: ```bash kubectl exec chat-app-pod -- mongo ``` 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.kubern...
Forward ports 8080 and 6000 on your local machine to ports 8888 and 6000 respectively on a pod selected by the "web-app-deployment" deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 8080 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be s...
Create a copy of the 'mypod' pod and name it 'my-custom-dbg', with all container images changed to 'postgres'.
Command: ```bash kubectl debug mypod --copy-to=my-custom-dbg --set-image=*=postgres ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource i...
Copy the file "/tmp/foo" from the remote pod "api-server-pod-3" and paste it in the local directory "/tmp/bar_dir".
Command: ```bash kubectl cp logging/api-server-pod-3::/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Create a service for a replicated python application on port 80, connecting to containers on port 8000.
Command: ```bash kubectl expose rc python --port=8181 --target-port=500100 ``` 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 the environment variables of a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/kube-system-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment varia...
Create a single ingress called 'api-gateway-ingress' that directs requests to 'testing.com/bar' to the service 'svc1' on port 8080, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/bar=svc1:8080,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 deployment named db using the mysql image
Command: ```bash kubectl create deployment db --image=mysql ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-...
Forward traffic from port 8088 on all addresses to port 6379 in the pod named "log-aggregator-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8088:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Get the output from running the 'pg_dump --version' command in the 'lunar-launcher' container of the 'database-pod' pod.
Command: ```bash kubectl exec database-pod -c lunar-launcher -- pg_dump --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 o...
Create a service named 'python' for the replicated Python containers using a ReplicaSet
Command: ```bash kubectl expose rs python --port=9000 --target-port=909000 ``` 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....
Create an ingress resource called 'app-gateway-ingress' with a rule that directs requests from foo.com/example to svc1:8083
Command: ```bash kubectl create ingress app-gateway-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": "", "...
Create a new secret named password-secret from an env file
Command: ```bash kubectl create secret generic password-secret --from-env-file=path/to/profiles.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the base...
Scale the deployment named foo to 5 replicas, assuming the current size is 7.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/foo ``` 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 spec...
Set the cpu limits of the 'ruby' deployment's 'nginx' container to "500m" and memory limits to "64Mi"
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=500m,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 i...
Add a new annotation 'git-repo' to the pod 'media-stream' with the value 'https://github.com/example/my-app'
Command: ```bash kubectl annotate pods media-stream git-repo='https://github.com/example/my-app' ``` 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...
Retrieve the logs of the previous terminated nebula-navigator container from the email-service-pod pod.
Command: ```bash kubectl logs -p -c nebula-navigator email-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--contai...
Create a new config map named 'app-config-dev' using the specified files for keys
Command: ```bash kubectl create configmap app-config-dev --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Create a deployment named 'drupal' using the image 'docker.elastic.co/elasticsearch/elasticsearch' and run the command 'elasticsearch-plugin --list' inside the container.
Command: ```bash kubectl create deployment drupal --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch-plugin --list ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short...
Attach to the first pod of the replica set named jenkins
Command: ```bash kubectl attach rs/jenkins ``` 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, use the kubectl.kube...
Get the output of the 'mongo --version' command from the stardust-shuttle container within the security-service-pod.
Command: ```bash kubectl exec security-service-pod -c stardust-shuttle -- mongo --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container na...
forward local port 3000 to port 8088 in the pod named "analytics-pod".
Command: ```bash kubectl port-forward pod/analytics-pod 3000: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 auto...
List the replication controller named 'web', the service named 'proxy-server-rc', and the pod named 'proxy-service-pod'
Command: ```bash kubectl get rc/web service/proxy-server-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 nam...
Create a service for a replicated node, with the specified ports configuration.
Command: ```bash kubectl expose rc node --port=8082 --target-port=818100 ``` 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 8000 to the pod selected by the log-aggregator-deployment deployment's port 6379.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 8000 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wi...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ file from the local system to the /tmp/bar_dir directory in the monitoring-agent-pod-6 pod in the metallb-system namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ metallb-system/monitoring-agent-pod-6:/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": "", ...
Forward traffic from port 9090 on all addresses to port 8088 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 9090: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 new ClusterIP service named shipping-service-clusterip with port mapping 9090:8084
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=9090:8084 ``` 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...
List all the contexts in your kubeconfig file
Command: ```bash kubectl config get-contexts ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Edit the load-testing-job job in JSON format using the v1 API format
Command: ```bash kubectl edit job.v1.batch/load-testing-job -o json ``` 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,...
Create a copy of the chat-app-pod and add a debug container
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-debugger --image=debian --set-image=mailer=mailer:latest,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by ...
Create an ingress called 'internal-ingress' with a rule that directs requests to website.com/example to the service svc1:8084 using TLS secret "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/example=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 an ingress rule that directs requests from testing.com/example to svc1:9092 with a tls secret called 'my-cert'
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/example=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": ""...
Remove the taint with key 'special' and effect 'NoSchedule' from the node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 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 ...
Create a pod disruption budget named logging-pdb that will select all pods with the app=rails label and require a minimum of four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=app=rails --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 [--dry-r...
Create a single ingress called 'default-ingress' that directs requests to testing.com/module to svc1:8443 with a tls secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="testing.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": "", "u...
Forward port 3000 on localhost and IP 10.19.21.23 to port 8888 in the security-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-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 th...
List deployments in YAML output format using the "kubectl get" command
Command: ```bash kubectl get deployments.legacy-1.0.0.prod-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you...
Import the 'api_key' key from the 'api-config' config map to the 'database-deployment' deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/api-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 one...
Execute the 'elasticsearch' command inside the first pod of the 'load-balancer-deployment' deployment and get the output.
Command: ```bash kubectl exec deploy/load-balancer-deployment -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Set the resource requests and limits for all containers in the nginx deployment
Command: ```bash kubectl set resources deployment nginx --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=256Mi ``` 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 reques...
Import the LOG_LEVEL key from the log-config config map into the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/log-config deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Attach to the running container "astro-container" in the pod "auth-service-pod" and view its output
Command: ```bash kubectl attach auth-service-pod -c astro-container ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Copy the file located at "/var/run/secrets/kubernetes.io/serviceaccount/" on the local machine to "/tmp/bar" in the "payment-gateway-pod-19" pod in the "kube-server" namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-server/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"...
Forward traffic from local ports 8888 to port 5432 in the 'backend-pod' pod, and from local port 6000 to port 6000 in the 'backend-pod' pod.
Command: ```bash kubectl port-forward pod/backend-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 criteria, a pod will be selected automa...
View previous terminated logs from the "cosmic-container" container in the "e-commerce-pod" pod.
Command: ```bash kubectl logs -p -c cosmic-container e-commerce-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container...
Create a role named "custom_role" with the verb "update" and the resource "pods"
Command: ```bash kubectl create role custom_role --verb=update --resource=pods --resource-name=nginx-proxy --resource-name=notification-service ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-ru...