prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 5000 on all addresses to port 9090 in the pod named security-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Set the custom TLS server name to "sun-cluster" for the "staging-cluster" cluster entry.
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=sun-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Undo the previous deployment of a specific deployment, with a dry-run to simulate the changes without actually applying them
Command: ```bash kubectl rollout undo --dry-run=server deployment/my-deployment ``` 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 identif...
Execute the 'jenkins-plugin-cli' command in the stardust-shuttle container of the analytics-pod and retrieve the output.
Command: ```bash kubectl exec analytics-pod -c stardust-shuttle -- 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. ...
Scale the 'foo' deployment to 3 replicas if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=3 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...
List deployments in JSON output format, in the "v1.1.0" version of the "backup-apps" API group.
Command: ```bash kubectl get deployments.v1.1.0.backup-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 wil...
Create a new config map named app-secrets by reading the content of /path/to/preferences/file1.txt and /path/to/configurations/file2.txt, and associate them with the keys 'properties' and 'key1', respectively.
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/preferences/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 ...
Add a taint with key 'workload' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production workload=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Autoscale the replication controller "web" with a target CPU utilization of 40% and a maximum of 8 pods
Command: ```bash kubectl autoscale rc web --max=8 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Create an ingress called 'app1-ingress' that directs requests from site.com/input to svc1:8443 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/input=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": "", "usage": ...
Get the previous terminated logs from the "cosmic-container" container of the "log-aggregator-pod".
Command: ```bash kubectl logs -p -c cosmic-container log-aggregator-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": "--conta...
Start a pod with the image 'confluentinc/cp-kafka', but override the spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --overrides='{ "apiVersion": "v1.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] [--comm...
Expose the pod "proxy-server-pod" as a service named "frontend" that serves on port 444.
Command: ```bash kubectl expose pod proxy-server-pod --port=8081 --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...
Create a copy of a pod named log-aggregator-pod by adding a debug container and changing the container images for the `api` and `logger`.
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-memcached --image=debian --set-image=api=api:v2,logger=logging-app:debug ``` 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 resource called 'public-service-ingress' that directs requests to foo.com/input to the service 'svc1' on port 6379, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress public-service-ingress --rule="foo.com/input=svc1:6379,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 local port 5432 to port 3000 in the pod "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 5432:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a new ExternalName service with the name "external-metrics-service" pointing to the external DNS name "illustration-shop.shop"
Command: ```bash kubectl create service externalname external-metrics-service --external-name illustration-shop.shop ``` 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...
Forward all local traffic on port 8000 to port 8088 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 8000: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 autom...
Start a pod with a specific image, but customize the spec using values from a JSON file.
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "feature-branch-2.3.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--...
Copy the contents of "/tmp/foo_dir" from the "api-server-pod-3" pod in the "prometheus" namespace to the local machine's "/tmp/bar" directory.
Command: ```bash kubectl cp prometheus/api-server-pod-3:/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 the ku...
Forward port 8088 on all addresses to port 8000 in the analytics-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8088: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 wil...
Retrieve the snapshot logs from the container "email-server-deployment-1" of the deployment named "monitoring-pod"
Command: ```bash kubectl logs deployment/email-server-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 flags: "fl...
Create a new config map named kube-system-config using specified files as key-value pairs
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/parameters/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 cre...
List the deployments in the "v2.0.0" version of the "sandbox-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.v2.0.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 wi...
Execute the 'bash' command in the 'time-machine' container of the 'api-service-pod' pod and get the output
Command: ```bash kubectl exec api-service-pod -c time-machine -- bash ``` 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 ...
Copy the file ~/.config/kube from your local machine to the /tmp/bar directory in the monitoring-agent-pod-6 pod in the kube-public namespace.
Command: ```bash kubectl cp ~/.config/kube kube-public/monitoring-agent-pod-6::/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, ...
Set the custom TLS server name to 'galaxy-cluster' for validation for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --tls-server-name=galaxy-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-author...
Retrieve the snapshot logs from the 'gateway-pod-1' container of the 'payment-processor-deployment' deployment.
Command: ```bash kubectl logs deployment/payment-processor-deployment -c gateway-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: "...
Edit the 'docker-registry' service using the 'nano' editor
Command: ```bash KUBE_EDITOR="nano" kubectl edit svc/docker-registry ``` 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 NodePort service named backend-nodeport that maps port 9091 to port 3306
Command: ```bash kubectl create service nodeport backend-nodeport --tcp=9091:3306 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "",...
Connect to the raw terminal of the astro-container in the frontend-pod, allowing input and output communication with the 'bash' process.
Command: ```bash kubectl attach frontend-pod -c astro-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 name. If om...
Auto scale the 'database' deployment with a minimum of 6 pods and a maximum of 10 pods
Command: ```bash kubectl autoscale deployment database --min=6 --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...
Import specific keys from a config map into the environment of a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/monitoring-config 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 ...
Get output from running 'dotnet' command from the first pod of the deployment backend-microservice-deployment
Command: ```bash kubectl exec deploy/backend-microservice-deployment -- dotnet ``` 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...
Forward port 8080 on all addresses to port 5000 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8080:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
create a new config map named log-config and specify the keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/path/to/settings/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 config...
Create a new NodePort service with the name "proxy-server-nodeport" and map port 3000 of the service to port 9092 on the nodes.
Command: ```bash kubectl create service nodeport proxy-server-nodeport --tcp=9092:3000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default"...
Execute the 'mysql' command in the stardust-shuttle container from the gateway-pod pod.
Command: ```bash kubectl exec gateway-pod -c stardust-shuttle -- 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...
Create a service for a replicated hazelcast using replica set, which serves on port 9091 and connects to the containers on port 900000.
Command: ```bash kubectl expose rs hazelcast --port=9091 --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 specified po...
create a cron job named 'report-generation' using the 'python' image, with a schedule of running every minute, and executing the 'python' command
Command: ```bash kubectl create cronjob report-generation --image=python --schedule="*/1 * * * *" -- python ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o"...
Create a pod disruption budget named api-service-pdb that selects all pods with the tier=frontend 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=tier=frontend --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 ...
Add a taint with key 'datacenter' and value 'worker-node-3:PreferNoSchedule' on all nodes that have the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster datacenter=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Add a taint with the key 'hardware' on nodes having the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha hardware=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": "", "...
Get the snapshot logs from the container named 'security-service-pod-1' in the deployment 'monitoring-stack-deployment'.
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c security-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 ...
Forward port 8888 on all addresses to port 8888 in the chat-app-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 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...
Copy the local file "/tmp/foo" to the remote pod "task-processor-pod-17" in the "monitoring" namespace, and place it in the "/tmp/bar" directory.
Command: ```bash kubectl cp :/tmp/foo monitoring/task-processor-pod-17:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ...
Begin streaming the logs of the cyber-sleuth container in the web-app-pod pod
Command: ```bash kubectl logs -f -c cyber-sleuth web-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Update the label of the pod named 'api' with the key 'component' and the value 'web'.
Command: ```bash kubectl label pods api component=web ``` 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 ...
Execute the 'dotnet' command in the pod named 'database-pod' using the container 'nebula-navigator'
Command: ```bash kubectl exec database-pod -c nebula-navigator -- dotnet ``` 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, u...
Add a taint with the key 'environment' on the nodes having the label 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 environment=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": "O...
Embed the certificate authority data for the 'app-cluster' cluster entry by running the command 'kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/staging-cluster/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster app-cluster --embed-certs --certificate-authority=~/.kube/staging-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 s...
Execute the 'docker run -it ubuntu' command inside the first pod of the mydeployment deployment.
Command: ```bash kubectl exec deploy/mydeployment -- docker run -it ubuntu ``` 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,...
Import the specific keys 'my-example-key' from the 'app-secrets' config map to the 'search-engine-deployment' deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/app-secrets deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
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=properties=/path/to/configurations/file1.txt --from-file=key1=/path/to/settings/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. Wh...
Get the output of the 'composer --version' command from the first pod of the web-app-deployment deployment.
Command: ```bash kubectl exec deploy/web-app-deployment -- composer --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 omitt...
Import the DEBUG_MODE key from the configuration map named "app-name-config" and set it as an environment variable in the "search-engine-deployment" deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-name-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Create a service for a Python deployment, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment python --port=5001 --target-port=808900 ``` 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 specifi...
Run the command 'nginx -g "daemon off;"' in the 'mycontainer' of the 'mypod' pod and retrieve the output
Command: ```bash kubectl exec mypod -c mycontainer -- nginx -g "daemon off;" ``` 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 resource request and limits for all containers in a go deployment
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=10,memory=1Gi ``` 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, bu...
Auto scale the "monitoring" replication controller with a target CPU utilization of 60% and a maximum of 5 pods.
Command: ```bash kubectl autoscale rc monitoring --max=5 --cpu-percent=60 ``` 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 u...
Import the 'redis_host' key from the 'app-config-dev' ConfigMap into the environment variables of the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Set the service account of deployment frontend-deployment to gitlab-runner
Command: ```bash kubectl set serviceaccount deployment frontend-deployment gitlab-runner ``` 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: `kub...
Create a new config map named ui-config with the specified key-value pairs from files.
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/path/to/data/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 c...
Create an ingress rule that directs requests from foo.com/module to svc1:8083 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="foo.com/module=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": "", "usage...
Import the 'debug_mode' key from the 'app-name-config' configmap and set it as an environment variable in the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-name-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 definition...
Copy the ~/.config/kube directory from a remote pod named argocd/database-pod-2 to the /tmp/bar_dir directory on your local machine.
Command: ```bash kubectl cp argocd/database-pod-2:~/.config/kube /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 ku...
Set the service account of the 'monitoring-stack-deployment' deployment to 'tekton'
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment tekton ``` 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...
Add a taint with the key 'zone' and value 'monitoring-node-15:PreferNoSchedule' on all nodes with the label 'release=beta'.
Command: ```bash kubectl taint node -l release=beta zone=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": "", "usage":...
Set the resource request and limits for all containers in the hazelcast deployment
Command: ```bash kubectl set resources deployment hazelcast --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 re...
Set the service account of the deployment "scheduler-app-deployment" to "my-service-account"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-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 Sy...
Delete multiple resources (pod and service) with the names "gateway" and "email"
Command: ```bash kubectl delete pod,service gateway email ``` 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 selector. S...
Copy the local file /tmp/foo to the /tmp/bar_dir directory in the container named message-broker inside the security-scanner-pod-18 pod.
Command: ```bash kubectl cp /tmp/foo security-scanner-pod-18:/tmp/bar_dir -c message-broker ``` 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 omitt...
Create an ingress named 'web-ingress' with a rule that directs requests from 'testing.com/input' to the service 'svc1' running on port '8083'
Command: ```bash kubectl create ingress web-ingress --rule="testing.com/input=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": "", "usage"...
Delete the pods and services with the names "proxy" and "proxy"
Command: ```bash kubectl delete pod,service proxy proxy ``` 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 selector. Som...
Create a new config map named app-config-prod using specific files as key-value pairs
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/data/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 secret named database-secret from an environment file
Command: ```bash kubectl create secret generic database-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...
Auto scale the deployment "frontend" with a minimum of 5 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment frontend --min=5 --max=11 ``` 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...
Create a job named "log-processing-job" with the image "mongo" and run the command "mongod" inside the job
Command: ```bash kubectl create job log-processing-job --image=mongo -- mongod ``` 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....
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/db-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 definitions ...
Forward ports 5432 and 6000 from the local machine to the same ports in the pod named "api-service-pod".
Command: ```bash kubectl port-forward pod/api-service-pod 5432 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create an ingress called 'app-loadbalancer-ingress' that routes requests from testing.com/example to svc1:5000 with the TLS secret "my-cert"
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/example=svc1:5000,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", "defaul...
Update the 'release-notes' annotation of the 'media-stream' pod with the value 'https://example.com/release-notes/v2.5.1', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods media-stream 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...
Execute the 'wp' command in the pod 'database-pod' using the container 'rocket-ranger' and retrieve the output
Command: ```bash kubectl exec database-pod -c rocket-ranger -- wp ``` 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 ...
Check if you have the permission to list the job named "notification-sender-job" in the "development" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n development ``` 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 pa...
Set the service account for the deployment "email-server-deployment" to "jenkins"
Command: ```bash kubectl set serviceaccount deployment email-server-deployment jenkins ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubec...
Import the "SMTP_SERVER" key from the "ui-config" ConfigMap and set it as an environment variable for the "web-app-deployment" deployment.
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/ui-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 definitions in o...
Restart a daemon set
Command: ```bash kubectl rollout restart daemonset/my-deployment ``` 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 res...
Import environment from a secret for a deployment named "proxy-service-deployment"
Command: ```bash kubectl set env --from=secret/tls-certificate-secret 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 definitions in one ...
Configure autoscaling for a replication controller named "proxy"
Command: ```bash kubectl autoscale rc proxy --max=7 --cpu-percent=90 ``` 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 t...
Forward traffic from port 8081 on localhost and IP 10.19.21.23 to port 8080 on the pod named "api-service-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8081: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 cri...
Update the 'backend' pod by setting the annotation 'description' to 'Web server for marketing site'.
Command: ```bash kubectl annotate pods backend description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than label...
Create an ingress resource named 'app-proxy-ingress' that routes requests for website.com/module to the service 'svc1' on port 8181
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.com/module=svc1:8181,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": "", ...
Retrieve a list of deployments in the "dev-2.2.0" version of the "legacy-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.dev-2.2.0.legacy-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 ...
Create an ingress with TLS enabled using the default ingress certificate and different path types.
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="testing.com/path/subpath*=othersvc:8081" ``` 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": "...
create a cron job called email-notifications that runs the command "mongo --version" every minute using the mongo image
Command: ```bash kubectl create cronjob email-notifications --image=mongo --schedule="*/1 * * * *" -- mongo --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", "sh...
Forward port 8088 on the localhost and IP address 10.19.21.23 to port 8088 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8088: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 ...
Add the label 'tier=backend' to the pod named 'database'
Command: ```bash kubectl label pods database tier=backend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": ...
Listen on ports 5432 and 6000 on your local machine and forward the data to/from ports 8080 and 6000 in the pod selected by the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl port-forward deployment/log-aggregator-deployment 5432 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 wi...
Add a taint with key 'environment' on nodes having label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend environment=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": "Ou...
List deployments in YAML format for the "hotfix-1.1.2" version of the "experimental-apps" API group.
Command: ```bash kubectl get deployments.hotfix-1.1.2.experimental-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 namesp...