prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Set the service account of the deployment "backend-microservice-deployment" to "tiller"
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment tiller ``` 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:...
Update the alert-email annotation of the pod identified by the type and name specified in the "conf.json" file to "alerts@example.com"
Command: ```bash kubectl annotate -f conf.json alert-email=alerts@example.com ``` 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...
Run a proxy to the Kubernetes API server on port 8000, serving static content from the ./local/www/ directory.
Command: ```bash kubectl proxy --port=8000 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Begin streaming the logs of the "ruby" container in the "api-service-pod" pod
Command: ```bash kubectl logs -f -c ruby api-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":...
Import the 'redis_host' key from the 'app-settings' config map and set it as an environment variable in the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-settings deployment/order-processing-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...
Create a deployment named db with 2 replicas running the alpine image
Command: ```bash kubectl create deployment db --image=alpine --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: json...
Start streaming the logs of the "warp-drive" container in the "gateway-pod" pod.
Command: ```bash kubectl logs -f -c warp-drive 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": "--container", "short...
Create a new config map named 'global-config' with the specified keys from the given file paths
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/configurations/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Retrieve the output of the `jenkins --version` command from the `cyber-sleuth` container in the `e-commerce-pod` pod.
Command: ```bash kubectl exec e-commerce-pod -c cyber-sleuth -- jenkins --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Create a new config map named 'monitoring-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/options/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Create a service for the hazelcast replication controller specified in the "hazelcast-controller.yaml" file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8010 --target-port=909200 ``` 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 ...
Execute the 'mysql' command from the nano-bot container in the auth-service-pod pod.
Command: ```bash kubectl exec auth-service-pod -c nano-bot -- 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, use th...
Set cpu and memory limits for the nginx container in the wordpress deployment to "50m" and "64Mi", respectively.
Command: ```bash kubectl set resources deployment wordpress -c=nginx --limits=cpu=50m,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 ...
Create a service for a replicated Ubuntu container, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc ubuntu --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 specified port....
Create a job to process logs using a MongoDB container image
Command: ```bash kubectl create job log-processing-job --image=mongo -- mongo ``` 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. ...
Forward traffic from local port 9090 to port 8080 on the pod named "proxy-server-pod" and listen on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-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 ...
Forward data between local port 3000 and pod port 8080 in the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 3000 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Set the cluster field in the 'my-context' context to 'dev-cluster'
Command: ```bash kubectl config set contexts.user-a-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Attach to the lunar-launcher container in the frontend-pod and get the output.
Command: ```bash kubectl attach frontend-pod -c lunar-launcher ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Create a deployment named logging that runs the python image and exposes port 8888.
Command: ```bash kubectl create deployment logging --image=python --port=8888 ``` 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: ...
Create an ingress called 'public-api-ingress' that routes requests from foo.com/input to the service named 'svc1' on port 9000
Command: ```bash kubectl create ingress public-api-ingress --rule="foo.com/input=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": "", "usa...
Create a new ExternalName service named external-geolocation-service with the external name mockup-cloud.cloud
Command: ```bash kubectl create service externalname external-geolocation-service --external-name mockup-cloud.cloud ``` 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 referen...
Embed the certificate authority data for the "galaxy-cluster" cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/on-prem-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 confi...
Scale the deployment named payment-service-rs to 3 replicas
Command: ```bash kubectl scale --current-replicas=3 --replicas=3 deployment/payment-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-...
Create a service for a replication controller based on the configuration in "ruby-controller.yaml" file, which will listen on port 8088 and forward traffic to the containers on port 888800.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8088 --target-port=888800 ``` 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...
Switch to raw terminal mode and connect to the 'cosmic-container' inside the 'payment-gateway-pod' pod.
Command: ```bash kubectl attach payment-gateway-pod -c cosmic-container -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 nam...
Set the cluster field in a specific context to a desired value
Command: ```bash kubectl config set contexts.dev-context.cluster app-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 want ...
Retrieve the output from the 'warp-drive' container in the 'security-service-pod' pod
Command: ```bash kubectl attach security-service-pod -c warp-drive ``` 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...
Import specific keys from a config map into a deployment's environment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/monitoring-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Create a copy of the chat-app-pod and launch an interactive shell inside the warp-drive container in the debug-image-api pod
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-api --container=warp-drive -- 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 defau...
Update the 'payment' pod with the annotation 'contact-email' and the value 'support@example.com', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods payment contact-email='support@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than l...
Retrieve the previous terminated logs of the "nebula-navigator" container in the "vpn-service-pod" pod.
Command: ```bash kubectl logs -p -c nebula-navigator vpn-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": "--containe...
Disable certificate checking for the cluster called "on-prem-cluster" in the kubeconfig file.
Command: ```bash kubectl config set-cluster on-prem-cluster --insecure-skip-tls-verify=true ``` 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] [--certifi...
Create a config map named app-config from an environment file
Command: ```bash kubectl create configmap app-config --from-env-file=path/to/configs.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the bas...
Add a taint with the key 'dedicated' on nodes that have the label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz dedicated=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":...
Start a php pod with the name nginx and overload the spec with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=php --overrides='{ "apiVersion": "v2.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] -- [COMMAND] ...
Switch to the context for the staging-cluster cluster
Command: ```bash kubectl config use-context staging-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Forward all traffic from port 8088 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 8088: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...
Copy the local file /tmp/foo_dir to the remote pod payment-gateway-pod-19 in the prometheus namespace and place it at /tmp/bar.
Command: ```bash kubectl cp /tmp/foo_dir prometheus/payment-gateway-pod-19::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
expose a replication controller as a service with specified port mappings
Command: ```bash kubectl expose -f centos-controller.yaml --port=8888 --target-port=700000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Approve a CSR with the name 'csr-abc123'
Command: ```bash kubectl certificate approve csr-abc123 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the attribu...
Import specific keys from a config map to the environment variables of a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-name-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment va...
Import the environment variables from the 'oauth-secret' secret into the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --from=secret/oauth-secret deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or ...
Forward traffic from local port 5000 to port 8081 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Forward data between local port 5432 and pod port 6379 for a specific deployment named "web-app-deployment".
Command: ```bash kubectl port-forward deployment/web-app-deployment 5432 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 s...
Forward traffic from port 8888 on all addresses to port 8081 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8888: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 ...
Create an ingress resource called 'app1-ingress' with a rule that directs requests to 'site.com/input' to service 'svc1' on port 8010, and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/input=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": "", "usage": ...
Copy the directory "/tmp/foo_dir" from the remote pod "metallb-system/metrics-exporter-pod-10" to the local directory "/tmp/bar".
Command: ```bash kubectl cp metallb-system/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...
Create a job with the given command
Command: ```bash kubectl create job data-migration-job --image=ethereum/client-go -- geth 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": "", "usag...
Restart a daemon set by initiating a rolling update
Command: ```bash kubectl rollout restart daemonset/namespace-2 ``` What it does: Restart a resource. Resource rollout will be restarted. Syntax: `kubectl rollout restart RESOURCE` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resou...
Retrieve the snapshot logs from the container "log-aggregator-pod-1" of the deployment named "api-server-deployment".
Command: ```bash kubectl logs deployment/api-server-deployment -c log-aggregator-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: "...
Add a taint with key 'disktype' and no value to the node 'web-node-8'
Command: ```bash kubectl taint nodes web-node-8 disktype:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: j...
create a deployment named 'app' with the 'jenkins' image and run the 'jenkins-plugin-cli' command inside the pods
Command: ```bash kubectl create deployment app --image=jenkins -- jenkins-plugin-cli ``` 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. O...
Roll back a deployment with a dry run to preview the changes
Command: ```bash kubectl rollout undo --dry-run=server deployment/services ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying ...
Create a debug copy of gateway-pod with a different container image and additional debug container.
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-web --image=debian --set-image=worker=my-custom-worker:1.2.3,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...
View the modified deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/authentication-service-deployment LOG_LEVEL=info -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 mo...
Get the output from the command 'kafka-topics --list' running in the first container of the pod named svc/notification-service.
Command: ```bash kubectl exec svc/notification-service -- 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 omitt...
Add a taint with the key 'workload' on nodes that have the label 'cluster=my-cluster'.
Command: ```bash kubectl taint node -l cluster=my-cluster workload=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": "...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/global-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...
Update the 'payment-processor-deployment' deployment by adding a new environment variable REDIS_HOST=redis-server.
Command: ```bash kubectl set env deployment/payment-processor-deployment REDIS_HOST=redis-server ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more p...
Create a service for the python replication controller specified in the "python-controller.yaml" file
Command: ```bash kubectl expose -f python-controller.yaml --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...
Retrieve logs from container cdn-service-pod-1 in the web-app-deployment deployment.
Command: ```bash kubectl logs deployment/web-app-deployment -c cdn-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: "flag":...
Forward traffic from port 5432 on all addresses to port 8000 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 5432: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 ...
Create a service for the php replica set, which serves on port 5000 and connects to the containers on port 8080
Command: ```bash kubectl expose rs php --port=5000 --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 port. A ...
Set the service account of a deployment named "backend-microservice-deployment" to the default service account.
Command: ```bash kubectl set serviceaccount deployment backend-microservice-deployment default ``` 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...
Display the modified YAML configuration of the log-aggregator-deployment deployment, with the updated S3_BUCKET environment variable value set to "my-s3-bucket"
Command: ```bash kubectl set env deployment/log-aggregator-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 or mo...
Copy the file "/tmp/foo" from the remote pod "admin-dashboard-pod-16" in the "istio-system" namespace to the local directory "/tmp/bar".
Command: ```bash kubectl cp istio-system/admin-dashboard-pod-16::/tmp/foo :/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-dev deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment va...
Add a taint with key 'disktype' on nodes having label customer=acme-corp
Command: ```bash kubectl taint node -l customer=acme-corp disktype=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 traffic from local port 5000 to port 8080 in the pod named backend-pod, listening on localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 5000:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Return the snapshot logs from the container gateway-deployment-1 of the deployment named proxy-server-pod
Command: ```bash kubectl logs deployment/gateway-deployment -c proxy-server-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag"...
Edit the 'content-import-job' job using the v1 API format in JSON
Command: ```bash kubectl edit job.v1.batch/content-import-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 variable...
Retrieve the output from running the command 'php --version' in the cosmic-container from the pod named analytics-pod
Command: ```bash kubectl exec analytics-pod -c cosmic-container -- 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 om...
Create a new service named "ubuntu-https" that exposes the container port 8443 as port 443.
Command: ```bash kubectl expose service ubuntu --port=443 --target-port=8089 --name=nginx-https ``` 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 o...
Forward local port 8000 to pod port 9090
Command: ```bash kubectl port-forward pod/api-service-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 pod will be selected au...
Start a golang pod named "hazelcast" with the golang image and expose port 5001
Command: ```bash kubectl run hazelcast --image=golang --port=5001 ``` 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...
Create a debug container based on the existing 'gateway-pod' pod, but with the 'cyber-sleuth' container replaced with a shell prompt.
Command: ```bash kubectl debug gateway-pod -it --copy-to=debug-image-memcached --container=cyber-sleuth -- 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 b...
Label the pod named 'media-stream' with the label 'component' and the value 'worker'
Command: ```bash kubectl label pods media-stream component=worker ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "...
Create a service for a pod named "vpn-service-pod" that serves on port 444 with the name "frontend"
Command: ```bash kubectl expose pod vpn-service-pod --port=3306 --name=frontend ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified ...
Add a taint with key 'environment' and value 'storage-node-13:PreferNoSchedule' on nodes having the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster environment=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Import the SECRET_KEY key from the app-config-dev config map into the cache-cluster-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-config-dev deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Create a role binding named custom_role which grants access to the cluster role called custom_role
Command: ```bash kubectl create rolebinding custom_role --clusterrole=custom_role --user=admin --user=devops-user --group=operations-team ``` 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] [--group=gr...
Add a taint with key 'special' on the nodes that have the label feature=feature-xyz
Command: ```bash kubectl taint node -l feature=feature-xyz special=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": "...
Create a job named 'security-scan-job' with the image 'redis' and the command 'redis-server'
Command: ```bash kubectl create job security-scan-job --image=redis -- redis-server ``` 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 fo...
Create a new ClusterIP service named analytics-service-clusterip that forwards traffic from port 3000 to port 27017.
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=3000:27017 ``` 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": "...
Import the REDIS_HOST key from the config map 'monitoring-config' into the environment variables of the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/monitoring-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 definiti...
import the LOG_LEVEL key from the app-secrets config map and set it as an environment variable for the log-aggregator-deployment deployment
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-secrets 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 definitio...
Add a taint with the key 'workload' to the nodes that have the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe workload=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
Port forward from a local port to a specific port in a pod
Command: ```bash kubectl port-forward pod/analytics-pod :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 automati...
Create a pod named "hazelcast" using the Python image and expose port 8010
Command: ```bash kubectl run hazelcast --image=python --port=8010 ``` 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...
Return a snapshot of the previous terminated logs from the 'cosmic-container' container inside the 'frontend-pod' pod.
Command: ```bash kubectl logs -p -c cosmic-container 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",...
Import the specific key 'database_url' from the config map 'monitoring-config' into the environment variables of the 'payment-processor-deployment' deployment
Command: ```bash kubectl set env --keys=database_url --from=configmap/monitoring-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variab...
Create a cluster role named "bar" that allows connecting to configmaps with resource names "auth-service" and "file-storage"
Command: ```bash kubectl create clusterrole bar --verb=connect --resource=configmaps --resource-name=auth-service --resource-name=file-storage ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Add the label 'role' with the value 'cache' to the pod named 'chat-app'
Command: ```bash kubectl label pods chat-app role=cache ``` 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...
Forward port 8080 on your local machine to port 9090 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 8080: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 automaticall...
Create a new config map named app-config and populate it with the contents of the files specified
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Forward local port 8000 to port 5432 in the pod named 'e-commerce-pod'
Command: ```bash kubectl port-forward pod/e-commerce-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 pod will be selected aut...
Edit the 'virus-scan-job' job using the v1 API format in JSON by running the command: kubectl edit job.v1.batch/virus-scan-job -o json
Command: ```bash kubectl edit job.v1.batch/virus-scan-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, o...
Forward traffic from port 9090 on your local machine (localhost) and IP address 10.19.21.23 to port 8080 in the pod named chat-app-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-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 criter...
Add a taint with key 'app' on nodes having label myLabel
Command: ```bash kubectl taint node -l myLabel app=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output ...