prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create an ingress named "web-ingress" with a rule that directs requests from "foo.com/input" to "svc1:9092" using the TLS secret "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/input=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Retrieve the snapshot logs from the container backend-pod-1 of the notification-handler-deployment deployment.
Command: ```bash kubectl logs deployment/notification-handler-deployment -c backend-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...
Update the 'email-server-deployment' deployment with a new environment variable, `GOOGLE_API_KEY=your-google-api-key`.
Command: ```bash kubectl set env deployment/email-server-deployment GOOGLE_API_KEY=your-google-api-key ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or ...
Add a taint with the key 'environment' on nodes having the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster environment=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":...
View the last-applied-configuration annotations of the 'ubuntu' deployment in YAML format
Command: ```bash kubectl apply view-last-applied deployment/ubuntu ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view-last-applied...
Execute 'irb' in the media-stream-pod and display the output
Command: ```bash kubectl exec media-stream-pod -- irb ``` 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.kube...
Add a taint with key 'disktype', value 'ssd' and effect 'NoSchedule' to the node 'kube-master-9'
Command: ```bash kubectl taint nodes kube-master-9 disktype=ssd: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. On...
Add a taint with the key 'disktype' and value 'worker-node-3:PreferNoSchedule' on nodes having the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy disktype=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": "", "usage...
Create a new ExternalName service named external-authentication-service pointing to sample-domain.net
Command: ```bash kubectl create service externalname external-authentication-service --external-name sample-domain.net ``` 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 refer...
Add a taint with the key 'environment' and value 'kube-master-9:PreferNoSchedule' on all nodes that have the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 environment=kube-master-9:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default":...
Delete the pods and services with the names "proxy" and "cdn"
Command: ```bash kubectl delete pod,service proxy cdn ``` 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. Some ...
Create a new config map named api-config with the provided keys instead of file basenames on disk
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/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 c...
List the specified resources by their types and names
Command: ```bash kubectl get rc/web service/chat-app-rc pods/proxy-server-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespac...
Create an ingress named 'public-ingress' that directs requests for website.com/module to the service 'svc1' on port 9092
Command: ```bash kubectl create ingress public-ingress --rule="website.com/module=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Forward local port 8080 to port 9090 of a pod selected by the search-engine-deployment deployment
Command: ```bash kubectl port-forward deployment/search-engine-deployment 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 wil...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/namespace-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...
Execute the 'psql' command in the 'code-explorer' container of the 'api-service-pod'.
Command: ```bash kubectl exec api-service-pod -c code-explorer -- psql ``` 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...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-name-config deployment/authentication-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...
Set the service account of the deployment "monitoring-stack-deployment" to "vault"
Command: ```bash kubectl set serviceaccount deployment monitoring-stack-deployment vault ``` 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 debug copy of the pod "auth-service-pod" by adding a debug container and changing container images.
Command: ```bash kubectl debug auth-service-pod -it --copy-to=dgb-img --image=debian --set-image=web=nginx:latest,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name...
Edit the data in conf.json in JSON format, then create the resource using the edited data in the 'conf.json' file
Command: ```bash kubectl create -f conf.json --edit -o json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to us...
Create an ingress named "ingsecret" with TLS enabled using the secret "secret1" and the pathType as Prefix
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="website.com/*=svc:8010,tls=secret1" ``` 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 using the image "mcr.microsoft.com/dotnet/core/runtime"
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime ``` 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 flag...
Execute the 'mongo' command inside the 'media-stream-pod' pod and retrieve its output.
Command: ```bash kubectl exec media-stream-pod -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Add a taint with key 'cpu-type' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 cpu-type=node-2:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
create a cronjob named 'log-rotation' using the image 'redis', running the command 'redis-server' every minute
Command: ```bash kubectl create cronjob log-rotation --image=redis --schedule="*/1 * * * *" -- redis-server ``` 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"...
Add a taint with key 'zone' and value 'storage-node-13:PreferNoSchedule' on nodes having label 'environment=production'
Command: ```bash kubectl taint node -l environment=production zone=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": "", "...
Create an ingress resource called 'public-ingress' with a rule that directs requests from testing.com/input to the service svc1 on port 8888
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/input=svc1:8888,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...
Forward traffic from local port 8080 to a pod selected by the deployment "notification-handler-deployment" on port 8080
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8080 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 ...
Forward local port 9090 to port 8081 in the analytics-platform-deployment pod
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 9090 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 po...
Execute the 'jenkins-plugin-cli' command inside the 'lunar-launcher' container running in the 'api-service-pod' pod.
Command: ```bash kubectl exec api-service-pod -c lunar-launcher -- 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. ...
Create a new redis pod named "hazelcast" and expose port 5000 on the container.
Command: ```bash kubectl run hazelcast --image=redis --port=5000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--fi...
Set the CPU limits to "100m" and memory limits to "1Gi" for the nginx container in the mongo deployment.
Command: ```bash kubectl set resources deployment mongo -c=nginx --limits=cpu=100m,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, but may burst up to i...
Create an ingress called 'app2-ingress' that directs requests from 'site.com/bar' to 'svc1:9000' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/bar=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": "", "usage": "O...
Add a new taint to the 'web-node-8' node with the key 'special', value 'backup', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes web-node-8 special=backup: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...
retrieve the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/chat-app-rc pods/database-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...
Update the annotation of pod 'analytics' to set the compliance level to 'PCI-DSS', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods analytics compliance-level='PCI-DSS' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels a...
Expose a pod named "cdn-service-pod" as a service with the name "frontend" on port 444.
Command: ```bash kubectl expose pod cdn-service-pod --port=8000 --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 ...
Set the service account of the deployment 'order-processing-deployment' to 'elasticsearch'
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment elasticsearch ``` 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 Synt...
Check the list of allowed actions in the "cert-manager" namespace
Command: ```bash kubectl auth can-i --list --namespace=cert-manager ``` 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 URL that starts w...
Create a service for the replicated hazelcast replica set, which serves on port 8089 and connects to the containers on port 700000.
Command: ```bash kubectl expose rs hazelcast --port=8089 --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 specified po...
Forward the local port 6379 to port 8000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 6379: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...
Create an ingress called 'website-ingress' with a rule that directs requests from foo.com/bar to the service 'svc1' on port 9090
Command: ```bash kubectl create ingress website-ingress --rule="foo.com/bar=svc1:9090,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Scale the deployment named "web" to 7 replicas
Command: ```bash kubectl scale --current-replicas=1 --replicas=7 deployment/web ``` 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...
Create a new config map named 'db-config' using the specified keys instead of the file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/parameters/file1.txt --from-file=key1=/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...
Listen on port 9090 locally and forward the traffic to port 6379 in the 'mypod' pod
Command: ```bash kubectl port-forward pod/mypod 9090: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 automaticall...
Update a pod identified by type and name in "pod.json" by adding an annotation for contact email.
Command: ```bash kubectl annotate -f pod.json 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 labels and inclu...
Update the pod 'log-aggregator' by adding or updating the annotation 'security-scan-status' to 'pass', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods log-aggregator security-scan-status='pass' ``` 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 la...
Switch to raw terminal mode and attach to the 'nebula-navigator' container in the 'auth-service-pod' pod
Command: ```bash kubectl attach auth-service-pod -c nebula-navigator -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. ...
Create a new config map named app-config using the configurations in the path/to/configurations folder.
Command: ```bash kubectl create configmap app-config --from-file=path/to/configurations ``` 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 base...
Create a deployment named logging that runs the redis image and expose port 3000.
Command: ```bash kubectl create deployment logging --image=redis --port=3000 ``` 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...
Set the basic authentication for the "prod-user" entry with the username "admin" and password "uXFGweU9l35qcif"
Command: ```bash kubectl config set-credentials prod-user --username=admin --password=uXFGweU9l35qcif ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile B...
import the 'my-example-key' key from the 'db-config' config map and set it as environment variable in the 'proxy-service-deployment' deployment
Command: ```bash kubectl set env --keys=my-example-key --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 definit...
Display the deployments in the "v3.0.0" version of the "experimental-apps" API group using JSON output format.
Command: ```bash kubectl get deployments.v3.0.0.experimental-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 y...
Create a new secret named ssl-key-secret with key1=supersecret and key2=topsecret
Command: ```bash kubectl create secret generic ssl-key-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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 ...
Create a new config map named app-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-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 creat...
List the deployments in the "v1.1.0" version of the "my-apps" API group in JSON output format
Command: ```bash kubectl get deployments.v1.1.0.my-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 will on...
View the resources by their type and names
Command: ```bash kubectl get rc/web service/web-app-rc pods/frontend-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 yo...
Copy the ~/.config/kube folder from a remote pod to the /tmp/bar_dir directory locally.
Command: ```bash kubectl exec -n kube-flannel file-server-pod-14 -- tar cf - ~/.config/kube | tar xf - -C /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"...
Get the output from running the 'postgres' command in the 'rocket-ranger' container of the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c rocket-ranger -- postgres ``` 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 custom TLS server name to 'on-prem-cluster' for the 'galaxy-cluster' cluster entry
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=on-prem-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] [--certif...
Create a pod named "hazelcast" using the "php" image, and expose port 8010
Command: ```bash kubectl run hazelcast --image=php --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": "--file...
Create a debug copy of a pod, with a different container image and a debug container
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-app --image=debian --set-image=worker=my-custom-worker:1.2.3,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified b...
Import the 'debug_mode' key from the 'app-secrets' config map to the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/app-secrets deployment/load-balancer-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...
Get the output of the 'npm --version' command from the cyber-sleuth container in the analytics-pod
Command: ```bash kubectl exec analytics-pod -c cyber-sleuth -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitte...
Import the DATABASE_URL key from the app-secrets config map into the environment variables of the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --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 defini...
Update the pod identified by the type and name in the "setup.json" file and set the label "status" to "unhealthy"
Command: ```bash kubectl label -f setup.json status=unhealthy ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usag...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-config-prod 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 definition...
Create an ingress resource with the name 'public-ingress' that routes requests from site.com/example to svc1:7000, and uses the TLS certificate 'my-cert' for secure communication.
Command: ```bash kubectl create ingress public-ingress --rule="site.com/example=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Scale a resource to 3 replicas based on the configuration specified in "config.json"
Command: ```bash kubectl scale --replicas=3 -f config.json ``` 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 validate...
Create a new ExternalName service named 'external-caching-service' with the external name 'sample-domain.net'
Command: ```bash kubectl create service externalname external-caching-service --external-name sample-domain.net ``` 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 reference se...
Delete the pods and services named "analytics" and "web" simultaneously
Command: ```bash kubectl delete pod,service analytics web ``` 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...
Forward traffic from port 5432 on all addresses to port 6379 in the e-commerce-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 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 wi...
Start a python pod with custom spec from JSON
Command: ```bash kubectl run nginx --image=python --overrides='{ "apiVersion": "dev-2.2.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] -- [COM...
Execute the command "apache2ctl -D FOREGROUND" on the first pod of the deployment "monitoring-stack-deployment" and display the output.
Command: ```bash kubectl exec deploy/monitoring-stack-deployment -- apache2ctl -D FOREGROUND ``` 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...
Create a copy of the email-service-pod named my-custom-dbg and change all container images to golang using the kubectl debug command
Command: ```bash kubectl debug email-service-pod --copy-to=my-custom-dbg --set-image=*=golang ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no ...
Import specific keys from a config map into the deployment's environment variables.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/env-vars 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...
Add a 'dedicated' taint on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production dedicated=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": ...
Create a service for the replicated alpine using a replica set
Command: ```bash kubectl expose rs alpine --port=8084 --target-port=500000 ``` 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 new configmap named db-config with the specified keys from the provided files
Command: ```bash kubectl create configmap db-config --from-file=conf=/path/to/profiles/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 config ...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/api-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 variable def...
Import environment variables from the ui-config config map with a MYSQL_ prefix into the web-app-deployment deployment
Command: ```bash kubectl set env --from=configmap/ui-config --prefix=MYSQL_ 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 one ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/api-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...
Forward traffic from port 8081 on your local machine to port 8081 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8081: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 autom...
Create a service for the replicated python containers, which will serve on port 8081 and connect to the containers on port 300100.
Command: ```bash kubectl expose rc python --port=8081 --target-port=300100 ``` 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....
Remove the label 'release-' from the pod named 'analytics'
Command: ```bash kubectl label pods analytics release- ``` 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...
Taint nodes with label service=auth with a taint key 'dedicated' and a taint value 'PreferNoSchedule'
Command: ```bash kubectl taint node -l service=auth dedicated=db-node-7: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...
Create a deployment named grafana with the confluentinc/cp-kafka image and 6 replicas.
Command: ```bash kubectl create deployment grafana --image=confluentinc/cp-kafka --replicas=6 ``` 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 ...
Set the service account of the deployment named 'api-server-deployment' to 'argocd'
Command: ```bash kubectl set serviceaccount deployment api-server-deployment argocd ``` 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 ...
Delete both the pod and service with the names "security" and "proxy-server"
Command: ```bash kubectl delete pod,service security proxy-server ``` 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...
Edit the data in setup.json file in JSON format and create the resource using the edited data.
Command: ```bash kubectl create -f setup.json --edit -o json ``` What it does: Create a resource from a file or from stdin. JSON and YAML formats are accepted. Syntax: `kubectl create -f FILENAME` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files to u...
Create a debug container in the payment-gateway-pod and change container images.
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=dgb-img --image=debian --set-image=mailer=mailer:latest,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified ...
Edit the last-applied-configuration annotations using the settings.yaml file in JSON format.
Command: ```bash kubectl apply edit-last-applied -f settings.yaml -o json ``` What it does: Edit the latest last-applied-configuration annotations of resources from the default editor. The edit-last-applied command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open t...
Update the pod 'proxy' and add a description only if the pod's resource version is still 1.
Command: ```bash kubectl annotate pods proxy description='my frontend running nginx' --resource-version=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 la...
Import the key 'DEBUG_MODE' from the 'app-settings' config map and set it as an environment variable in the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-settings deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Start a nginx pod with the image docker.elastic.co/elasticsearch/elasticsearch, but overload the spec with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=docker.elastic.co/elasticsearch/elasticsearch --overrides='{ "apiVersion": "alpha-2.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] [--ove...
Scale the replication controller 'web' to automatically manage the number of pods between 1 and 5, targeting a CPU utilization of 40%
Command: ```bash kubectl autoscale rc web --max=5 --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...
Execute the 'go' command in the first pod of the email-server-deployment.
Command: ```bash kubectl exec deploy/email-server-deployment -- go ``` 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...
Create a new config map named 'log-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/path/to/configs/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 a role named "reader" with API Group specified
Command: ```bash kubectl create role reader --verb=update,get,patch --resource=replicasets.apps ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "...