prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Import the 'smtp_server' key from the 'app-name-config' config map and set it as an environment variable in the 'notification-handler-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-name-config 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 variab...
Forward local port 6379 to port 5432 in a pod selected by the api-server-deployment deployment
Command: ```bash kubectl port-forward deployment/api-server-deployment 6379 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 b...
Create a copy of mypod and enter debugging mode on the quantum-quark container
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-1 --container=quantum-quark -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if ...
Describe the details of a specific pod
Command: ```bash kubectl describe pods/cache-pod-5 ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, provide a ...
Import the API_KEY key from the db-config config map and set it as an environment variable for the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --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 definitions in...
Forward local ports 8081 and 6000 to ports 8088 and 6000 respectively on a pod selected by the deployment named "api-server-deployment"
Command: ```bash kubectl port-forward deployment/api-server-deployment 8081 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 b...
Retrieve the logs from the container named 'email-service-pod-1' in the 'mydeployment' deployment.
Command: ```bash kubectl logs deployment/mydeployment -c email-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--...
Set the cpu limit of the mysql deployment's nginx container to "50m" and memory limit to "256Mi"
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=50m,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 requested, but may burst up to ...
Create a copy of a pod named web-app-pod by changing all container images to hazelcast/hazelcast
Command: ```bash kubectl debug web-app-pod --copy-to=debug-image-web --set-image=*=hazelcast/hazelcast ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by defau...
Create a new config map named api-config using specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap api-config --from-file=properties=/path/to/properties/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 ...
Scale the replica set named 'dev-environment-rs' to a desired count of 7
Command: ```bash kubectl scale --replicas=7 rs/dev-environment-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-version is specified, it is v...
If the deployment named payment-service-rs's current size is 5, scale mysql to 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=5 deployment/payment-service-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-...
Copy the file located at /var/run/secrets/kubernetes.io/serviceaccount/ in your local machine to the /tmp/bar directory in the database-pod-2 pod within the kube-public namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ kube-public/database-pod-2::/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": "Cont...
Expose a replica set as a service for a Wordpress application
Command: ```bash kubectl expose rs wordpress --port=8088 --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 po...
Create a job named 'indexing' with the container image 'redis' and the command 'redis-server'
Command: ```bash kubectl create job indexing --image=redis -- redis-server ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Retrieve the output of the 'go version' command from the pod payment-gateway-pod, running in the cosmic-container.
Command: ```bash kubectl exec payment-gateway-pod -c cosmic-container -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If...
Set the cpu limits to "2" and memory limits to "64Mi" for the alpine container in the deployment named "alpine" with the command kubectl set resources deployment alpine -c=nginx --limits=cpu=2,memory=64Mi
Command: ```bash kubectl set resources deployment alpine -c=nginx --limits=cpu=2,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to it...
Create a cron job named "cleanup-task" that runs the "go" command every minute using the "golang" image
Command: ```bash kubectl create cronjob cleanup-task --image=golang --schedule="*/1 * * * *" -- go ``` 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", "defaul...
Create a job named scaling-job using the golang image, with the command "go"
Command: ```bash kubectl create job scaling-job --image=golang -- go ``` 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. One of: j...
Start a pod named 'hazelcast' using the 'alpine' image and expose port 8000 on the container
Command: ```bash kubectl run hazelcast --image=alpine --port=8000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Create an ingress that routes requests from site.com/input to svc1:5001 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="site.com/input=svc1:5001,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": ...
Update the pod named 'analytics' by adding a label with the key 'component' and the value 'web'
Command: ```bash kubectl label pods analytics 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"...
Create a cron job named 'system-health-check' using the 'jenkins' image that runs the 'jenkins --version' command every minute.
Command: ```bash kubectl create cronjob system-health-check --image=jenkins --schedule="*/1 * * * *" -- jenkins --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",...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=max_connections --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 ...
Forward traffic from port 8081 on all addresses to port 8080 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-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 criteria, a pod will...
Create an ingress rule named 'frontend-ingress' that routes requests from site.com/example to service svc1 on port 27017, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="site.com/example=svc1:27017,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
View resource utilization metrics for a specific node
Command: ```bash kubectl top node db-node-7 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (lab...
List the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/e-commerce-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 namesp...
Create an ingress named 'default-ingress' that directs requests from website.com/input to svc1:9091 with a tls secret called "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="website.com/input=svc1:9091,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...
Import environment variables from a config map with a specific prefix
Command: ```bash kubectl set env --from=configmap/db-config --prefix=MYSQL_ deployment/scheduler-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 i...
Execute the 'go' command inside the 'lunar-launcher' container in the 'media-stream-pod' pod
Command: ```bash kubectl exec media-stream-pod -c lunar-launcher -- 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...
Add a taint with the key 'zone' and value 'db-node-7:PreferNoSchedule' on nodes that have the label 'namespace=mynamespace'.
Command: ```bash kubectl taint node -l namespace=mynamespace zone=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":...
Open a raw terminal connection to the 'mycontainer' container in the 'log-aggregator-pod' pod, allowing you to send input to the 'bash' shell and receive output from it.
Command: ```bash kubectl attach log-aggregator-pod -c mycontainer -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If ...
Output the modified deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/log-aggregator-deployment DB_USER=username -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod...
Create a cron job that will execute a command on a specified schedule
Command: ```bash kubectl create cronjob alerts-cleanup --image=golang --schedule="*/1 * * * *" -- go version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o...
Forward local port 5432 to port 3000 in the pod
Command: ```bash kubectl port-forward pod/security-service-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 select...
Create an ExternalName service named external-logging-service with the external name "documentation-tech.tech"
Command: ```bash kubectl create service externalname external-logging-service --external-name documentation-tech.tech ``` 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 refere...
Create a deployment named "scheduler" using the "amazonlinux" image
Command: ```bash kubectl create deployment scheduler --image=amazonlinux -- yum install -y aws-cli ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Create a new config map named log-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap log-config --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 c...
Create a pod disruption budget named 'elastic-search-pdb' that will select all pods with the 'component=web' label and require at least four of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=component=web --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available...
Copy the ~/.config/kube local file to /etc/kubernetes in the remote pod named web-app-pod-1, located in the namespace kube-flannel.
Command: ```bash kubectl cp ~/.config/kube kube-flannel/web-app-pod-1:/etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Start a redis pod and expose port 8083 for container
Command: ```bash kubectl run hazelcast --image=redis --port=8083 ``` 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...
Create a job named 'image-build-job' using the 'redis' image and run the command 'redis-server --version' inside the container.
Command: ```bash kubectl create job image-build-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": "O...
Create an ingress called 'app-proxy-ingress' that directs requests to website.com/bar to svc1:9090 with a tls secret "my-cert"
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.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": "", "us...
Forward local port 5432 to port 9090 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 5432:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Set basic auth credentials for the "saas-admin" entry
Command: ```bash kubectl config set-credentials saas-admin --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 ...
view all logs from the pod named "gateway-pod" that were written in the last hour
Command: ```bash kubectl logs --since=1h gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c...
Switch to raw terminal mode and attach to the 'cosmic-container' in the 'api-service-pod' pod, allowing interaction with 'bash' inside the container.
Command: ```bash kubectl attach api-service-pod -c cosmic-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. I...
Embed the certificate authority data for the e2e cluster entry
Command: ```bash kubectl config set-cluster e2e --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 set-clust...
Auto-scale the replication controller 'cdn' with a target CPU utilization of 81% and a maximum of 6 pods.
Command: ```bash kubectl autoscale rc cdn --max=6 --cpu-percent=81 ``` 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...
List all the deployments in the "dev-2.2.0" version of the "custom-deployments" API group in YAML output format.
Command: ```bash kubectl get deployments.dev-2.2.0.custom-deployments -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 namespac...
Create a new config map named global-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap global-config --from-file=properties=/path/to/options/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 creat...
Create a cluster role named "foo" that allows the 'create' verb on non-resource URLs that match '/attach/*'.
Command: ```bash kubectl create clusterrole "foo" --verb=create --non-resource-url=/attach/* ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short...
Create an ingress named "private-ingress" with a rule that directs requests from "site.com/bar" to "svc1:8089" using the TLS secret "my-cert".
Command: ```bash kubectl create ingress private-ingress --rule="site.com/bar=svc1:8089,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Check if you have permission to list the "notification-sender-job" job in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n kube-system ``` 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...
Execute the command 'postgres' in the 'nano-bot' container from the 'vpn-service-pod' pod and display the output
Command: ```bash kubectl exec vpn-service-pod -c nano-bot -- 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 omitted, use ...
Create a cluster role named "bar" with the ability to delete services and specify specific resource names, such as "cache-redis" and "mail-server".
Command: ```bash kubectl create clusterrole bar --verb=delete --resource=services --resource-name=cache-redis --resource-name=mail-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none...
Import the EXTERNAL_API_URL key from the config map named app-config into the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-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 defi...
Add a taint with key 'environment' on nodes having label role=database.
Command: ```bash kubectl taint node -l role=database environment=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": "", "usag...
Import the API_KEY from the ui-config config map and set it as an environment variable in the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/ui-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 definitions in...
Create a service for a hazelcast deployment on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment hazelcast --port=8082 --target-port=330600 ``` 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 spec...
Forward traffic from your local port 6379 to port 5000 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 6379: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 be selected autom...
Set the resource request and limits for all containers in the mysql deployment
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=500m,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 reques...
Forward traffic from port 5432 on the local machine to port 8000 in the pod named "e-commerce-pod".
Command: ```bash kubectl port-forward pod/e-commerce-pod 5432:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Attach to a specific container in a pod and get output from it.
Command: ```bash kubectl attach cdn-service-pod -c warp-drive ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
create an ingress named 'ingress1' with the following rules:
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="testing.com/path*=svc:27017" \ --rule="module.com/admin*=svc2:http" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--outp...
Partially update the resource identified by the type and name specified in "kubelet-config.yaml" using strategic merge patch
Command: ```bash kubectl patch -f kubelet-config.yaml -p '{"spec":{"rules":[{"http":{"paths":[{"path":"/","backend":{"service": {"name": "new-service"}}}]}}' ``` 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: `kub...
Create a deployment named "jenkins-x" that runs the "nginx" image and exposes port 3306.
Command: ```bash kubectl create deployment jenkins-x --image=nginx --port=3306 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of:...
Scale the replica set 'backend-service-replicaset' to a desired number of 5 replicas.
Command: ```bash kubectl scale --replicas=5 rs/backend-service-replicaset ``` 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,...
Create a new config map named api-config by using the settings located in the specified folder.
Command: ```bash kubectl create configmap api-config --from-file=path/to/settings ``` 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 o...
Run a proxy to the Kubernetes API server on port 6379, serving static content from the './local/www/' directory.
Command: ```bash kubectl proxy --port=6379 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Set the resource request and limits for all containers in the 'alpine' deployment
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=2Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested,...
Import the specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/api-config deployment/analytics-platform-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...
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 6379 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 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 criter...
Forward local port 8080 to pod port 8000 for the analytics-pod
Command: ```bash kubectl port-forward pod/analytics-pod 8080: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 auto...
Import the SMTP server key from the `log-config` ConfigMap and update the environment variables of the `load-balancer-deployment` Deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/log-config 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...
Add a taint with the key 'special' on nodes having the label 'instance=app-instance-1'
Command: ```bash kubectl taint node -l instance=app-instance-1 special=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": "",...
Listen on port 8000 locally and forward data to/from port 3000 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward pod/security-service-pod 8000 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 select...
Get the output of the 'mysql --version' command from the 'warp-drive' container in the 'chat-app-pod' pod.
Command: ```bash kubectl exec chat-app-pod -c warp-drive -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Update the monitoring pod with the annotation "compliance-level" and the value "PCI-DSS", overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods monitoring 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 ...
Set the custom TLS server name for the staging-cluster cluster entry to "kube-cluster-1"
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=kube-cluster-1 ``` 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...
Forward traffic from port 9090 on localhost and IP 10.19.21.23 to port 8081 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=redis_host --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 debug container in a copy of the cdn-service-pod with modified container images
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=proxy=nginx:1.21,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource...
Update the deployment 'mydeployment' by adding a new environment variable 'GOOGLE_API_KEY' with the value 'your-google-api-key'
Command: ```bash kubectl set env deployment/mydeployment 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 more pod te...
List resources of different types by their names
Command: ```bash kubectl get rc/web service/security-service-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 name...
delete pods and services with names "log-aggregator" and "proxy-server"
Command: ```bash kubectl delete pod,service log-aggregator 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 lab...
View the most recent 43 lines of logs from the pod named "database-pod"
Command: ```bash kubectl logs --tail=43 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", "short": "-c...
Create an ingress called 'public-ingress' with a rule that directs requests for testing.com/bar to the service svc1 on port 3306
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/bar=svc1:3306,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...
Forward local port 3000 to port 9090 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 3000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Add the label 'component=web' to the pod named 'security'
Command: ```bash kubectl label pods security 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":...
Forward local port to a pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod :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 aut...
Import specific keys from a config map into an environment variable for a deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-config 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 definitions in...
Forward local port 6379 to port 8080 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 6379:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
View all logs from the pod "analytics-pod" that were written in the last hour
Command: ```bash kubectl logs --since=1h 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", "short": "...
Update the deployment 'api-server-deployment' by adding a new environment variable 'REDIS_HOST' with the value 'redis-server'.
Command: ```bash kubectl set env deployment/api-server-deployment REDIS_HOST=redis-server ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod temp...
Create a service for the replicated alpine pods, which serves on port 3306 and connects to the containers on port 9090
Command: ```bash kubectl expose rc alpine --port=3306 --target-port=909000 ``` 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 called indexing using the mongo image and the mongo command
Command: ```bash kubectl create job indexing --image=mongo -- mongo ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Output the modified deployment in YAML format without making any changes to the deployment on the server.
Command: ```bash kubectl set env deployment/proxy-service-deployment S3_BUCKET=my-s3-bucket -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or mor...
Set the resource limits to 200m cpu and 512Mi memory, and the resource requests to 50m cpu and 4Gi memory for all containers in the ubuntu deployment.
Command: ```bash kubectl set resources deployment ubuntu --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...