prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Get a single pod in YAML format.
Command: ```bash kubectl get -o yaml pod vpn-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 namespaced you will only see ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-name-config 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 def...
Start a pod with a customized configuration by providing a partial set of values in JSON format
Command: ```bash kubectl run nginx --image=centos --overrides='{ "apiVersion": "v3.0.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] -- [COMMAN...
update the 'search-engine-deployment' deployment by adding a new environment variable 'SMTP_USERNAME' with the value 'your-username'
Command: ```bash kubectl set env deployment/search-engine-deployment SMTP_USERNAME=your-username ``` 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 p...
Start a new pod using the ethereum/client-go image with the name "nginx"
Command: ```bash kubectl run nginx --image=ethereum/client-go ``` 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": "--filen...
Create a job named 'report-generation-job' using the 'ruby' image and running the command 'ruby --version'
Command: ```bash kubectl create job report-generation-job --image=ruby -- ruby --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Create a service for a replicated wordpress, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc wordpress --port=8888 --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 specified po...
Update the pod 'chat-app' by adding or updating the annotation 'release-notes' with the value 'https://example.com/release-notes/v2.5.1'
Command: ```bash kubectl annotate pods chat-app release-notes='https://example.com/release-notes/v2.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 lar...
Create an ingress resource named 'ingress1' with multiple hosts and set the pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="foo.com/path*=svc:3000" \ --rule="bar.com/admin*=svc2:http" ``` 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", "sh...
Create a service for a replicated hazelcast using replica set, which serves on port 8089 and connects to the containers on port 808400
Command: ```bash kubectl expose rs hazelcast --port=8089 --target-port=808400 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Create a service for the replicated php using the replica set called 'php', which serves on port 8010 and connects to the containers on port 8000
Command: ```bash kubectl expose rs php --port=8010 --target-port=8000 ``` 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 de...
Create a Jenkins pod and expose port 9090
Command: ```bash kubectl run hazelcast --image=jenkins --port=9090 ``` 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 the local port 8888 to the port 6379 in the pod named "e-commerce-pod".
Command: ```bash kubectl port-forward pod/e-commerce-pod 8888: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 aut...
Forward traffic from port 5000 on all addresses to port 3000 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5000: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 sel...
Create a deployment named "ingress" using the "mysql" image and expose port 6379
Command: ```bash kubectl create deployment ingress --image=mysql --port=6379 ``` 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: j...
Create a cron job that runs the specified command periodically
Command: ```bash kubectl create cronjob log-rotation --image=php --schedule="*/1 * * * *" -- composer --version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": ...
Return the snapshot logs from the container authentication-service-deployment-1 of the deployment named monitoring-pod.
Command: ```bash kubectl logs deployment/authentication-service-deployment -c monitoring-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 ...
Scale the replica set named 'bar' to a desired number of 7 replicas
Command: ```bash kubectl scale --replicas=7 rs/bar ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated before...
Create a new secret named private-key-secret and set the keys to the files in the bar folder
Command: ```bash kubectl create secret generic private-key-secret --from-file=path/to/options ``` 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...
Attach to a pod's container in raw terminal mode
Command: ```bash kubectl attach backend-pod -c warp-drive -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 omitted,...
Forward traffic from port 8000 on all addresses to port 9090 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8000: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...
Create an ingress called 'api-v1-ingress' that directs requests from testing.com/module to svc1:8084 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.com/module=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": "", "us...
View the logs of the previous terminated container named "warp-drive" in the pod named "cdn-service-pod"
Command: ```bash kubectl logs -p -c warp-drive 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", "s...
Retrieve the output from running the 'php --version' command in the nebula-navigator container of the chat-app-pod pod.
Command: ```bash kubectl exec chat-app-pod -c nebula-navigator -- php --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 omi...
Create an ingress resource named 'private-api-ingress' with a rule that directs requests to site.com/module to svc1:8089
Command: ```bash kubectl create ingress private-api-ingress --rule="site.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": "", "...
Start a pod named hazelcast using the mcr.microsoft.com/dotnet/core/runtime image and configure the container to expose port 7000.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=7000 ``` 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......
Create a deployment named "monitoring" with the Ethereum client image and run the "geth version" command.
Command: ```bash kubectl create deployment monitoring --image=ethereum/client-go -- geth version ``` 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": "Outp...
Add a taint with the key 'dedicated' on nodes that have the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 dedicated=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...
create a deployment named 'loadbalancer' using the image 'mcr.microsoft.com/dotnet/core/runtime' and run the command 'dotnet --list-sdks' inside the deployment
Command: ```bash kubectl create deployment loadbalancer --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet --list-sdks ``` 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", "d...
List the replication controller named "gateway-rc" in ps (process status) output format
Command: ```bash kubectl get replicationcontroller gateway-rc ``` 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 only...
Delete the pods and services with the names "gateway" and "monitoring"
Command: ```bash kubectl delete pod,service gateway monitoring ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label select...
Create a role binding called "custom_role" and assign the "custom_role" cluster role to the "app-operator", "sysadmin" users, and the "security-auditors" group.
Command: ```bash kubectl create rolebinding custom_role --clusterrole=custom_role --user=app-operator --user=sysadmin --group=security-auditors ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--gr...
Add a taint with key 'environment' and value 'dev-node-4:PreferNoSchedule' on nodes having label team=devops.
Command: ```bash kubectl taint node -l team=devops environment=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": "", "usage": "...
Forward port 3000 on your local machine to port 8888 in the pod named "e-commerce-pod"
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Embed the certificate authority data for the cluster-beta cluster entry with the command: "kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster cluster-beta --embed-certs --certificate-authority=~/.kube/edge-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set...
Open the frontend-service for editing using the Atom editor.
Command: ```bash KUBE_EDITOR="atom" kubectl edit svc/frontend-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variable...
Forward local port 9090 to port 8000 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 9090: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 a...
Copy the local directory `/tmp/foo_dir` to the remote pod `logging-agent-pod-7` in the default namespace, under the directory `/tmp/bar_dir`.
Command: ```bash kubectl cp :/tmp/foo_dir logging-agent-pod-7::/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...
Update the annotation 'last-deployment' of pod 'proxy-server' to '2023-03-15', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods proxy-server last-deployment='2023-03-15' ``` 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...
import specific keys from a config map for a deployment named web-app-deployment in the kube-system-config map.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Create a deployment named "proxy" using the "centos" image and expose port 3306.
Command: ```bash kubectl create deployment proxy --image=centos --port=3306 ``` 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: js...
Set up a port forwarding from your local machine's port 8888 to port 8088 in the pod named "log-aggregator-pod".
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8888: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...
List deployments in YAML output format for the "v1.1.1" version of the "sandbox-apps" API group
Command: ```bash kubectl get deployments.v1.1.1.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 wi...
Embed the certificate authority data for the "dev-cluster" cluster entry into the Kubernetes configuration.
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/data-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-...
Forward port 5000 on your local machine to port 6379 in the Kubernetes pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 5000: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 auto...
Create a new pod named 'hazelcast' using the 'amazonlinux' image and expose port 8088
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=8088 ``` 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":...
Start streaming the logs of the cosmic-container container in the payment-gateway-pod pod.
Command: ```bash kubectl logs -f -c cosmic-container payment-gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--cont...
Start a node pod and expose port 3001
Command: ```bash kubectl run hazelcast --image=node --port=3001 ``` 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...
Copy the file /tmp/foo from the cache-pod-5 pod in the istio-system namespace to the local /etc/kubernetes directory.
Command: ```bash kubectl cp istio-system/cache-pod-5::/tmp/foo /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, use the k...
Expose the hazelcast replica set as a service on port 9000, connecting to the containers on port 8080.
Command: ```bash kubectl expose rs hazelcast --port=9000 --target-port=808000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Create an ingress resource named 'default-ingress' with a rule that directs requests to 'site.com/example' to the service 'svc1' on port '8089'
Command: ```bash kubectl create ingress default-ingress --rule="site.com/example=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": "", "usa...
Get output from running the 'python' command in nebula-navigator from pod mypod.
Command: ```bash kubectl exec mypod -c nebula-navigator -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Unset the namespace for the client-2-context context
Command: ```bash kubectl config unset contexts.client-2-context.namespace ``` What it does: Unset 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. Syntax: `kubectl config unset PROPERTY_NA...
Create a pod disruption budget with the name "payment-gateway-pdb" that selects all pods with the label "app=rails" and requires at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget payment-gateway-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 ...
Set the CPU and memory resource requests and limits for all containers in the "node" deployment to be 100m CPU and 256Mi memory for requests, and 200m CPU and 512Mi memory for limits.
Command: ```bash kubectl set resources deployment node --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 request...
Set the CPU limits of the Ruby container to 5 and Memory to 4Gi for the deployment named "ruby".
Command: ```bash kubectl set resources deployment ruby -c=nginx --limits=cpu=5,memory=4Gi ``` 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 s...
Retrieve the snapshot logs from container 'analytics-pod-1' in deployment 'load-balancer-deployment'
Command: ```bash kubectl logs deployment/load-balancer-deployment -c analytics-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: "fl...
Create a debug session of the database pod and make a copy with all container images changed to "node"
Command: ```bash kubectl debug database-pod --copy-to=dgb-img --set-image=*=node ``` 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 is s...
Set the CPU limit of the nginx container in the wordpress deployment to "1" and the memory limit to "2Gi".
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=1,memory=2Gi ``` 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 ...
Forward traffic from local port 9090 to port 8080 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 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 pod will be selected...
Switch to raw terminal mode in the monitoring-pod, running the stardust-shuttle container, and start an interactive bash session with login shell
Command: ```bash kubectl exec monitoring-pod -c stardust-shuttle -i -t -- bash -il ``` 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 ...
Update the label of pod 'frontend' to 'frontend' for the 'tier' label
Command: ```bash kubectl label pods frontend tier=frontend ``` 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":...
Retrieve the output of the 'geth version' command from running in the 'quantum-quark' container of the 'log-aggregator-pod' pod.
Command: ```bash kubectl exec log-aggregator-pod -c quantum-quark -- 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 o...
Add a taint with the key 'hardware' on nodes having the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 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...
Set the service account of the deployment "proxy-service-deployment" to "metrics-server"
Command: ```bash kubectl set serviceaccount deployment proxy-service-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...
Open a raw terminal session with the 'mycontainer' container in the 'media-stream-pod' pod.
Command: ```bash kubectl attach media-stream-pod -c mycontainer -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 om...
Create a service for the replication controller specified in the "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=6379 --target-port=900000 ``` 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 copy of the 'database-pod' pod and add a debug container with the Debian image
Command: ```bash kubectl debug database-pod -it --copy-to=my-custom-dbg --image=debian --set-image=cache=redis:alpine,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 res...
Update the deployment 'scheduler-app-deployment' by setting a new environment variable LOG_LEVEL to 'info'
Command: ```bash kubectl set env deployment/scheduler-app-deployment LOG_LEVEL=info ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod templates ...
Copy the local file `/tmp/foo` to the remote pod `ingress-controller-pod-8` in the `rook-ceph` namespace, placing it in the `/tmp/bar_dir` directory.
Command: ```bash kubectl cp /tmp/foo rook-ceph/ingress-controller-pod-8:/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...
Start streaming the logs of the 'stardust-shuttle' container within the 'media-stream-pod' pod.
Command: ```bash kubectl logs -f -c stardust-shuttle media-stream-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": "--contain...
Create an ingress named 'internal-ingress' that directs requests from 'testing.com/example' to 'svc1:9000' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="testing.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": "", ...
forward port 8000 on all addresses to port 5432 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Expose a replicated hazelcast deployment as a service, serving on port 6379 and connecting to the containers on port 8081.
Command: ```bash kubectl expose rc hazelcast --port=6379 --target-port=808100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Set the cluster field of the testing-context context to prod-cluster
Command: ```bash kubectl config set contexts.testing-context.cluster prod-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Copy the local file '/tmp/foo' to '/tmp/bar' inside the 'metrics-exporter-pod-10' pod in the 'kube-server' namespace.
Command: ```bash kubectl cp /tmp/foo kube-server/metrics-exporter-pod-10:/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...
Retrieve output from running the 'jenkins-plugin-cli' command in the 'cosmic-container' container within the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c cosmic-container -- 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....
Import the environment variables from the 'azure-storage-secret' secret into the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl set env --from=secret/azure-storage-secret deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
Forward traffic from port 8888 on all addresses to port 3000 within the pod "proxy-server-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8888:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Set the service account of the deployment 'cache-cluster-deployment' to 'flux'
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment flux ``` 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...
Execute the command 'kafka-topics --list' in the warp-drive container of the pod 'proxy-server-pod' and display the output.
Command: ```bash kubectl exec proxy-server-pod -c warp-drive -- kafka-topics --list ``` 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...
Forward data between port 8081 locally and port 8000 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-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 criteria, a pod will be selected autom...
Configure autoscaling for the 'database' deployment with a minimum of 4 pods and a maximum of 10 pods
Command: ```bash kubectl autoscale deployment database --min=4 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Begin streaming the logs from all containers in pods that have the label stack=tech-stack.
Command: ```bash kubectl logs -f -l stack=tech-stack --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": "--co...
Forward local port 3000 to port 9090 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 3000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Check if you have permission to list the job named "queue-processing-job" in the "logging" namespace
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n logging ``` 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 U...
Delete the pods and services with the names "media-stream" and "chat-app"
Command: ```bash kubectl delete pod,service media-stream chat-app ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label sel...
Show the details for the replication controller 'web', service 'web-app-rc', and pod 'analytics-pod'.
Command: ```bash kubectl get rc/web service/web-app-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 y...
Return the previous terminated logs of the "code-explorer" container from the "frontend-pod" pod.
Command: ```bash kubectl logs -p -c code-explorer frontend-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...
Execute the 'python' command in the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -- python ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kuber...
Create a service exposing a replicated hazelcast using replica set, serving on port 8443 and connecting to containers on port 8000.
Command: ```bash kubectl expose rs hazelcast --port=8443 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Retrieve the output from running the 'pg_dump --version' command in the first container of the 'user-service' service.
Command: ```bash kubectl exec svc/user-service -- 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 omitted, use th...
Retrieve snapshot logs from the container "api-service-pod-1" of the deployment "cache-cluster-deployment".
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c api-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: "...
Execute the 'node' command in the astro-container of the payment-gateway-pod and get the output.
Command: ```bash kubectl exec payment-gateway-pod -c astro-container -- node ``` 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 omitte...
Set the service account of the payment-processor-deployment deployment to my-service-account
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment my-service-account ``` 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...
Add a taint with the key 'workload' to nodes that have the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster workload=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...
Execute the 'go version' command in the nebula-navigator container from the e-commerce-pod pod and display the output
Command: ```bash kubectl exec e-commerce-pod -c nebula-navigator -- go 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 omit...
Start a pod named "hazelcast" using the ethereum/client-go image, and set the labels "app=go" and "env=prod" in the container.
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --labels="app=go,env=prod" ``` 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...]` ...
Create an ingress resource named ingress1 with multiple hosts and set pathType as Prefix
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="site.com/path*=svc:8888" \ --rule="input.com/admin*=svc2:http" ``` 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", ...
Update the pod 'vpn' by adding or modifying the annotation 'deployment-script' with the value 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate --overwrite pods vpn deployment-script='https://example.com/deploy.sh' ``` 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 lar...