prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Return snapshot logs from a specific container within a deployment
Command: ```bash kubectl logs deployment/analytics-platform-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 flag...
Create a pod disruption budget named batch-processing-pdb that will select all pods with the 'version=v2' label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=version=v2 --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=...
Set the "operator" entry's credentials to use the new exec auth plugin
Command: ```bash kubectl config set-credentials operator --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 ``` 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: --...
create a service for the replication controller specified in "centos-controller.yaml"
Command: ```bash kubectl expose -f centos-controller.yaml --port=7000 --target-port=543200 ``` 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...
Listen on port 9090 locally and forward the traffic to port 5432 in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 9090: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 automaticall...
Create a pod disruption budget named 'notification-service-pdb' that will select all pods with the label 'role=worker' and ensure that at least four of them are available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=role=worker --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-avail...
View the revision history details of a daemonset for revision 7
Command: ```bash kubectl rollout history daemonset/app-v2 --revision=7 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to ...
Add a taint with the key 'hardware' on nodes that have the label 'myLabel'. Set the taint to 'web-node-8:PreferNoSchedule'.
Command: ```bash kubectl taint node -l myLabel hardware=web-node-8: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 ...
Attach to the nano-bot container in the mypod pod and get its output
Command: ```bash kubectl attach mypod -c nano-bot ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubec...
Create a job named "log-processing-job" using the image "docker.elastic.co/elasticsearch/elasticsearch"
Command: ```bash kubectl create job log-processing-job --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch ``` 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"...
Configure autoscaling for the replication controller "analytics"
Command: ```bash kubectl autoscale rc analytics --max=7 --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 us...
Add a taint with key 'app' on nodes having label app=web-app
Command: ```bash kubectl taint node -l app=web-app app=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": "Outpu...
Copy the ~/.config/kube directory from the remote pod monitoring/database-pod-2 to the /tmp/bar_dir directory locally.
Command: ```bash kubectl cp monitoring/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 th...
Add a taint with the key 'disktype' and value 'k8s-node-1:PreferNoSchedule' on nodes that have the label 'myLabel'
Command: ```bash kubectl taint node -l myLabel disktype=k8s-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": "Output ...
Set the cluster field in the "my-context" context to "staging-cluster"
Command: ```bash kubectl config set contexts.cluster-1-context.cluster staging-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...
Edit the data in the docker-registry.yaml file using JSON, then create the resource using the edited data.
Command: ```bash kubectl create -f docker-registry.yaml --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 ...
Copy the local file /tmp/foo to the remote pod with the name cache-pod-5 in the /tmp/bar directory, in the container named admin-dashboard.
Command: ```bash kubectl cp /tmp/foo cache-pod-5:/tmp/bar -c admin-dashboard ``` 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 kub...
Create a new config map named db-config with specified keys from file paths
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/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...
Create a service for the replicated ubuntu using a replica set
Command: ```bash kubectl expose rs ubuntu --port=8888 --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 specified port....
Create a job named log-processing-job with the python image and run the command "python" inside the job
Command: ```bash kubectl create job log-processing-job --image=python -- python ``` 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...
Create a config map named monitoring-config with 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/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 ...
Create a new ClusterIP service named api-service-clusterip with the specified port mapping.
Command: ```bash kubectl create service clusterip api-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": "-o", "...
Create a new ClusterIP service named backend-service-clusterip with a TCP port mapping from port 7000 to port 8010.
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=7000:8010 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Create a new config map named log-config using the data from a specific folder.
Command: ```bash kubectl create configmap log-config --from-file=path/to/data ``` 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 basename of th...
Import the 'api_key' key from the 'ui-config' config map into the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/ui-config 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 definitions in on...
Add a taint with the key 'special' on all nodes with the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace special=prod-node-5: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": "", "us...
Begin streaming the logs of the specific container in a pod
Command: ```bash kubectl logs -f -c code-explorer analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Create a pod disruption budget named api-service-pdb that will select all pods with the region=us-east label and require at least one of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=region=us-east --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Create a new config map named api-config using the key=value pairs in the file located in the path/to/configurations directory.
Command: ```bash kubectl create configmap api-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 copy of the 'backend-pod' pod, adding a debug container and changing the container images
Command: ```bash kubectl debug backend-pod -it --copy-to=debug-image-memcached --image=debian --set-image=api=api:v2,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
Create a debug copy of the email-service-pod with all container images changed to nginx
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-api --set-image=*=nginx ``` 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...
create a new ClusterIP service named cache-service-clusterip
Command: ```bash kubectl create service clusterip cache-service-clusterip --tcp=8000:3306 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", ...
Create a pod named hazelcast running an amazonlinux image and expose port 9091.
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=9091 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag":...
Forward traffic from port 9090 on all addresses to port 8081 in the 'backend-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/backend-pod 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 pod will ...
Create a new LoadBalancer service named 'my-lbs' that forwards TCP traffic from port 9090 to port 3306.
Command: ```bash kubectl create service loadbalancer my-lbs --tcp=9090:3306 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Update the environment variables of the "notification-handler-deployment" deployment by importing the specific keys "REDIS_HOST" from the "env-vars" config map.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/env-vars 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 defin...
Create a new config map named global-config using the key=value pairs from a file
Command: ```bash kubectl create configmap global-config --from-file=path/to/data ``` 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 basename of...
Create a new secret named jwt-secret with keys for each file in folder path/to/configs
Command: ```bash kubectl create secret generic jwt-secret --from-file=path/to/configs ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of the fi...
Create a LoadBalancer service named monitoring-lb
Command: ```bash kubectl create service loadbalancer monitoring-lb --tcp=27017:8443 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "def...
import the "debug_mode" key from the "monitoring-config" ConfigMap and set it as an environment variable in the "frontend-deployment" deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/monitoring-config deployment/frontend-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...
Taint the nodes labeled with owner=john-doe with a taint key of 'hardware' and value of 'monitoring-node-15' to prefer pods to not be scheduled on them.
Command: ```bash kubectl taint node -l owner=john-doe hardware=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Set the resource request and limits for all containers in jenkins
Command: ```bash kubectl set resources deployment jenkins --limits=cpu=200m,memory=512Mi --requests=cpu=3,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource request...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/data/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 co...
Update the image of all containers in the daemonset 'test' to 'postgres:13.4'
Command: ```bash kubectl set image daemonset test *=postgres:13.4 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubec...
Begin streaming the logs of the nano-bot container in the frontend-pod pod
Command: ```bash kubectl logs -f -c nano-bot 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", "short"...
Import the API_KEY key from the app-config config map into the mydeployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config deployment/mydeployment ``` 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 mor...
Create a job called security-scan-job with the image redis and the command redis-server --version.
Command: ```bash kubectl create job security-scan-job --image=redis -- redis-server --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/api-config 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 definit...
Create an ingress called 'public-service-ingress' and set up a rule that directs requests to 'website.com/example' to 'svc1:8000' with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress public-service-ingress --rule="website.com/example=svc1:8000,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 8088 to port 6379 in the pod named log-aggregator-pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8088:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Attach to the pod named "proxy-service-pod" and get the output from the container named "nebula-navigator"
Command: ```bash kubectl attach proxy-service-pod -c nebula-navigator ``` 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...
Start a pod named "hazelcast" using the "postgres" image and expose port 5000.
Command: ```bash kubectl run hazelcast --image=postgres --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": "-...
Copy the /tmp/foo_dir directory from the openfaas/admin-dashboard-pod-16 pod to the /tmp/bar directory locally
Command: ```bash kubectl cp openfaas/admin-dashboard-pod-16:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Import the API_KEY key from the app-config-prod config map and set it as an environment variable in the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-prod deployment/monitoring-stack-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Add a taint with key 'zone' on nodes having label app=web-app to prefer no scheduling on the node 'testing-node-11'
Command: ```bash kubectl taint node -l app=web-app zone=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": "Ou...
Create a new config map named kube-system-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/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. Whe...
Create a service for a replica set of Ruby that serves on port 3306 and connects to the containers on port 909200.
Command: ```bash kubectl expose rs ruby --port=3306 --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 the specified port. A...
Port forward from port 8080 on localhost and IP 10.19.21.23 to port 3000 in the pod named "log-aggregator-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8080: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 ...
Apply a strategic merge patch to update a field (someField) with a new value (newValue) for the 'backup-node-14' node
Command: ```bash kubectl patch node backup-node-14 -p $'spec:\n someField: newValue' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpf...
create a LoadBalancer service named "e-commerce-lb" that maps port 8010 to port 27017
Command: ```bash kubectl create service loadbalancer e-commerce-lb --tcp=8010:27017 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "def...
Create a deployment named monitoring with 2 replicas running the php image
Command: ```bash kubectl create deployment monitoring --image=php --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:...
Import specific keys from a config map to an environment variable in a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-secrets 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 definitions ...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 8081 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
Create a new config map named app-config by specifying keys and their corresponding files
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/properties/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 con...
Add a taint with key 'special' on nodes having the label feature=feature-xyz and value prod-node-5 with the effect 'PreferNoSchedule'.
Command: ```bash kubectl taint node -l feature=feature-xyz special=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Import the 'config_file_path' key from the 'db-config' ConfigMap and set it as an environment variable in the 'search-engine-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/db-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 local traffic from port 5000 to port 8081 inside the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward pod/proxy-server-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 a...
Update the resource limits for the nginx container in the amazonlinux deployment to set the CPU limit to "200m" and the memory limit to "64Mi".
Command: ```bash kubectl set resources deployment amazonlinux -c=nginx --limits=cpu=200m,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 ...
Add a taint with key 'dedicated' on nodes having label stack=tech-stack where the taint value is 'k8s-node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack dedicated=k8s-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"...
Create a config map named kube-system-config using specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When crea...
Update the image of all containers of the 'nginx' daemonset to 'alpine:3.14'.
Command: ```bash kubectl set image daemonset nginx *=alpine:3.14 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubect...
Forward port 3000 locally to port 6379 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 3000: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 autom...
View the previous terminated logs of the "code-explorer" container from the "database-pod" pod
Command: ```bash kubectl logs -p -c code-explorer database-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "s...
Set the cluster field in the my-context context to prod-cluster
Command: ```bash kubectl config set contexts.cloud-context.cluster prod-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Create a new NodePort service named `cdn-service-nodeport` that maps port 8080 on the cluster nodes to port 6379 on the service
Command: ```bash kubectl create service nodeport cdn-service-nodeport --tcp=6379:8080 ``` 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":...
Listen on port 5000 locally and forward data to/from port 6379 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 5000 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create a cron job with a command
Command: ```bash kubectl create cronjob weekly-summary --image=confluentinc/cp-kafka --schedule="*/1 * * * *" -- kafka-server-start /etc/kafka/server.properties ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args.....
Set the service account of the 'database-deployment' deployment to 'gitlab-runner'
Command: ```bash kubectl set serviceaccount deployment database-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 app-config-dev from the key=value pairs in the file located at path/to/profiles
Command: ```bash kubectl create configmap app-config-dev --from-file=path/to/profiles ``` 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 basena...
Create a new config map and include specific keys from files
Command: ```bash kubectl create configmap monitoring-config --from-file=conf=/path/to/properties/file1.txt --from-file=data=/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 an ingress resource called 'api-v1-ingress' with a single rule that directs requests for website.com/example to the service 'svc1' on port 9000, and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/example=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Forward traffic from port 8081 on localhost and IP 10.19.21.23 to port 9090 in the pod named "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8081: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 p...
Execute the 'nginx' command in the first container of the 'frontend-deployment' deployment and display the output.
Command: ```bash kubectl exec deploy/frontend-deployment -- nginx ``` 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 ...
Set up autoscaling for the 'api' deployment with a minimum of 5 pods and a maximum of 9 pods.
Command: ```bash kubectl autoscale deployment api --min=5 --max=9 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the ...
Autoscale the deployment named "payment" with a minimum of 7 pods and a maximum of 13 pods.
Command: ```bash kubectl autoscale deployment payment --min=7 --max=13 ``` 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...
Scale the deployment named staging-app-rs to 5 replicas if its current size is 3
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/staging-app-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-vers...
Create a new ClusterIP service named payment-service-clusterip, mapping port 9092 to port 8084.
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=9092:8084 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Create a job named 'cleanup' using the 'docker.elastic.co/elasticsearch/elasticsearch' image
Command: ```bash kubectl create job cleanup --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch-plugin --list ``` 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", "sho...
Create a deployment named gitlab using the nginx image
Command: ```bash kubectl create deployment gitlab --image=nginx ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name...
Create a job named deployment-rollout-job with the nginx image, and run the command "nginx -g 'daemon off;'"
Command: ```bash kubectl create job deployment-rollout-job --image=nginx -- nginx -g "daemon off;" ``` 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": "", "usa...
Create a service to expose a deployment called 'node', which will serve on port 9000 and connect to the containers on port 500000
Command: ```bash kubectl expose deployment node --port=9000 --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...
Create an ingress resource named 'public-api-ingress' that directs requests for 'website.com/example' to the service 'svc1:8083' using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress public-api-ingress --rule="website.com/example=svc1:8083,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Begin streaming the logs of the code-explorer container in the e-commerce-pod pod.
Command: ```bash kubectl logs -f -c code-explorer e-commerce-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", ...
Create a job named "image-build-job" with the image "php" and run the command "composer --version" in the job.
Command: ```bash kubectl create job image-build-job --image=php -- composer --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output ...
Create a new deployment named 'my-dep' using the 'centos' image and expose port 3000.
Command: ```bash kubectl create deployment my-dep --image=centos --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...
Remove the "client-secret" value for the OpenID Connect auth provider for the "dev-user" entry in the Kubernetes config.
Command: ```bash kubectl config set-credentials dev-user --auth-provider=oidc --auth-provider-arg=client-secret- ``` 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-ke...
Copy the contents of "/var/run/secrets/kubernetes.io/serviceaccount/" on your local machine to the "/etc/kubernetes" directory in the "cache-pod-5" pod, specifically in the "payment-gateway" container.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cache-pod-5:/etc/kubernetes -c payment-gateway ``` 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": "", "usa...
Create a new config map named ui-config with the specified keys
Command: ```bash kubectl create configmap ui-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/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 config ...
Create a deployment named "registry" using the "node" image and expose port 3001.
Command: ```bash kubectl create deployment registry --image=node --port=3001 ``` 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...
Forward local port 5432 to port 8081 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432: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...