prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward local traffic from port 5432 to port 8080 in the pod "frontend-pod"
Command: ```bash kubectl port-forward pod/frontend-pod 5432:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Get the output from running the 'go' command in the 'warp-drive' container from the 'mypod' pod
Command: ```bash kubectl exec mypod -c warp-drive -- 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 kubectl.ku...
Forward traffic from your local machine's port 8081 to port 8888 in the CDN service pod.
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Edit the last-applied-configuration annotations of a deployment named "ethereum/client-go" in YAML format.
Command: ```bash kubectl apply edit-last-applied deployment/ethereum/client-go ``` 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 o...
Set the cluster name for a specific context
Command: ```bash kubectl config set contexts.local-context.cluster kube-cluster-2 ``` 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 ...
Scale the resource identified by type and name specified in the "parameters.yaml" file to 7 replicas.
Command: ```bash kubectl scale --replicas=7 -f parameters.yaml ``` 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 vali...
Create a debug version of the 'log-aggregator-pod' by adding a 'debian' based debug container and changing container images for 'mailer' and 'logger' to 'mailer:latest' and 'logging-app:debug' respectively
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-memcached --image=debian --set-image=mailer=mailer:latest,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects ide...
View the documentation for the 'conditions' field in the 'status' section of the 'services' resource.
Command: ```bash kubectl explain resource=services.status.conditions ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive fla...
Display the last 31 lines of logs for the pod named security-service-pod
Command: ```bash kubectl logs --tail=31 security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Attach to the first pod of a replica set named "ruby" and view its output.
Command: ```bash kubectl attach rs/ruby ``` 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 kubectl.kuberne...
Create a deployment named 'gateway' with the 'golang' image and expose port 8000.
Command: ```bash kubectl create deployment gateway --image=golang --port=8000 ``` 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: ...
Set the service account for the 'gateway-deployment' deployment to 'istio'
Command: ```bash kubectl set serviceaccount deployment gateway-deployment istio ``` 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 set ...
Delete a cluster from the kubeconfig file.
Command: ```bash kubectl config delete-cluster web-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Switch to raw terminal mode and attach to the rocket-ranger container in the proxy-server-pod
Command: ```bash kubectl attach proxy-server-pod -c rocket-ranger -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 ...
Forward traffic from port 8000 on all addresses to port 5000 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8000:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a new config map named "app-config-dev" using the environment variables defined in the "profiles.env" file.
Command: ```bash kubectl create configmap app-config-dev --from-env-file=path/to/profiles.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to th...
Update the deployment 'database-deployment' by setting a new environment variable 'CACHE_SIZE' with the value '64MB'
Command: ```bash kubectl set env deployment/database-deployment CACHE_SIZE=64MB ``` 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 templates (wit...
Run the 'jenkins-plugin-cli' command in the pod named log-aggregator-pod.
Command: ```bash kubectl exec log-aggregator-pod -- 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. If omitted, use...
Add an annotation to a pod in the "docker-registry.yaml" file
Command: ```bash kubectl annotate -f docker-registry.yaml monitoring-tool=Prometheus ``` 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 ...
Annotate a pod identified by type and name in "settings.json"
Command: ```bash kubectl annotate -f settings.json backup-strategy='daily backups' ``` 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 in...
Add a taint with key 'zone' on nodes having label team=devops, for example on the monitoring-node-15 node, and set the taint to PreferNoSchedule.
Command: ```bash kubectl taint node -l team=devops zone=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Create a role named "view" with the ability to list, use, and connect to pods and execute commands in pods.
Command: ```bash kubectl create role view --verb=list,use,connect --resource=pods,pods/exec ``` 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": "--ou...
Create a service for the "centos" deployment, which serves on port 5001 and connects to the containers on port 8089
Command: ```bash kubectl expose deployment centos --port=5001 --target-port=808900 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Create an ingress called 'app1-ingress' that directs requests to site.com/module to a specific service with a TLS secret
Command: ```bash kubectl create ingress app1-ingress --rule="site.com/module=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":...
Create a new ClusterIP service named ldap-service-clusterip, mapping TCP port 5432 on the service to port 8083 on the pods.
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=5432:8083 ``` 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", "...
Update the owner annotation of the pod specified in the "settings.json" file to 'alice smith'
Command: ```bash kubectl annotate -f settings.json owner='alice smith' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitr...
Embed the certificate authority data for the 'staging-cluster' cluster entry using the certificate authority file located at '~/.kube/cluster-alpha/kubernetes.ca.crt'
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/cluster-alpha/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...
Create a cluster role named "reader" with SubResource specified
Command: ```bash kubectl create clusterrole reader --verb=proxy,update,patch --resource=pods,pods/status ``` 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": "--out...
Display the last 5 lines of logs for the pod named "proxy-server-pod"
Command: ```bash kubectl logs --tail=5 proxy-server-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": ...
List all deployments in the "v2.0.0" version of the "custom-deployments" API group and output the results in YAML format.
Command: ```bash kubectl get deployments.v2.0.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 namespaced ...
Create a deployment named 'cache' using the 'mongo' image and expose port 8082.
Command: ```bash kubectl create deployment cache --image=mongo --port=8082 ``` 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: jso...
Update the 'expiration-date' annotation of the 'web' pod to '2024-12-31', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods web expiration-date='2024-12-31' ``` 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 i...
Auto scale the replication controller "email" with the number of pods ranging from 1 to 4, targeting a CPU utilization of 81%.
Command: ```bash kubectl autoscale rc email --max=4 --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 t...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 8081 in the pod "mypod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8088: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 p...
Output the modified web-app-deployment deployment in YAML format without making any changes to the object on the server
Command: ```bash kubectl set env deployment/web-app-deployment MONGO_URI=mongodb://localhost:27017/mydb -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 i...
Update a specific field of a node using a strategic merge patch in YAML format
Command: ```bash kubectl patch node monitoring-node-15 -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]` H...
Taint the nodes labeled 'environment=production' with the taint key 'hardware' and value 'dev-node-4' to prefer no scheduling
Command: ```bash kubectl taint node -l environment=production hardware=dev-node-4:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Create a deployment named 'jenkins' using the 'golang' image and expose port number '8000'
Command: ```bash kubectl create deployment jenkins --image=golang --port=8000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Create a cluster role named "view" with SubResource specified
Command: ```bash kubectl create clusterrole view --verb=list,create,update --resource=pods,pods/log ``` 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",...
Create an ingress named 'web-ingress' that redirects requests from foo.com/module to svc1:8082 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/module=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Copy the local file /tmp/foo_dir to the remote pod worker-pod-4 in the prometheus namespace at the location /tmp/bar
Command: ```bash kubectl cp /tmp/foo_dir prometheus/worker-pod-4:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubect...
Scale the deployment named staging-app-rs to 1 replica if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=1 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...
Start a python pod named hazelcast using the python image and expose port 9091
Command: ```bash kubectl run hazelcast --image=python --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": "--f...
Create an ingress with the name 'app-gateway-ingress' that forwards requests for 'site.com/bar' to service 'svc1' on port '8888'
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.com/bar=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...
Copy a directory from a remote pod to a local directory.
Command: ```bash kubectl cp argocd/backend-pod-13:/tmp/foo_dir /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, use the k...
Expose a deployment named "ruby" as a service on port 3001, forwarding traffic to containers on port 9092.
Command: ```bash kubectl expose deployment ruby --port=3001 --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...
Remove all the taints with the key 'zone' from the node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 zone- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|...
Create a new ClusterIP service named `analytics-service-clusterip` that maps the port `8083` on the service to port `8010` on the pods.
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=8083: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": "-...
Set resource requests and limits for all containers in the "alpine" deployment.
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=50m,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource request...
Return the snapshot logs from the 'proxy-service-pod' with the only container
Command: ```bash kubectl logs proxy-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c", "d...
Import the secret_key key from the app-name-config config map and set it as an environment variable in the gateway-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-name-config deployment/gateway-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...
Set the 'server' field of the 'prod-cluster' cluster to 'https://1.2.3.4'
Command: ```bash kubectl config set clusters.prod-cluster.server https://1.2.3.4 ``` 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 w...
Output the modified payment-processor-deployment in YAML format after setting the SMTP_PASSWORD environment variable to "your-password"
Command: ```bash kubectl set env deployment/payment-processor-deployment SMTP_PASSWORD=your-password -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 o...
Return snapshot logs from a specific container of a deployment named proxy-service-pod.
Command: ```bash kubectl logs deployment/authentication-service-deployment -c proxy-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]` Helpf...
Stream the logs of the "astro-container" container in the "backend-pod" pod
Command: ```bash kubectl logs -f -c astro-container backend-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", "...
Forward traffic between local ports 6379 and 8888 to the pod selected by the deployment called 'authentication-service-deployment' on the same ports
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 6379 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, ...
Create a role named "reader" with the ability to create pods and specifically target the "payment-processor" and "backup-service" resources.
Command: ```bash kubectl create role reader --verb=create --resource=pods --resource-name=payment-processor --resource-name=backup-service ``` 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=ser...
Create a service for a replicated nginx using a replica set, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rs nginx --port=8000 --target-port=844300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Create an ingress with TLS enabled using the default ingress certificate and different path types
Command: ```bash kubectl create ingress ingtls --class=default \ --rule="site.com/=svc:https,tls" \ --rule="site.com/path/subpath*=othersvc:9092" ``` 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": "--o...
Delete the context for the "app-2-context" cluster
Command: ```bash kubectl config delete-context app-2-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Create a service for the replication controller specified in "python-controller.yaml", serving on port 3000 and connecting to the containers on port 818100
Command: ```bash kubectl expose -f python-controller.yaml --port=3000 --target-port=818100 ``` 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...
Get the output from running the 'sleep 3600' command in the 'mycontainer' container from the 'security-service-pod' pod
Command: ```bash kubectl exec security-service-pod -c mycontainer -- sleep 3600 ``` 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 omi...
Execute the command "pg_dump --version" inside the container of the pod named "frontend-pod" and display the output.
Command: ```bash kubectl exec frontend-pod -- pg_dump --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, use the ku...
Create a copy of the payment-gateway-pod named debug-image-api, changing all container images to php.
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-api --set-image=*=php ``` 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 environment variables of a deployment named "user-management-deployment".
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-settings 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 variable definit...
List the supported API resources for the "apps" API group
Command: ```bash kubectl api-resources --api-group=apps ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Apply a taint with the key 'disktype' on nodes that have the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp disktype=backup-node-14: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...
Update the label of pod 'cdn' to have the label 'release' with the value 'v1.0'
Command: ```bash kubectl label pods cdn release=v1.0 ``` 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 t...
Create a job named "security-scan-job" using the image "confluentinc/cp-kafka"
Command: ```bash kubectl create job security-scan-job --image=confluentinc/cp-kafka -- kafka-console-producer --broker-list localhost:9092 --topic test ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "...
Create a new config map named env-vars with the specified keys and file paths
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/path/to/profiles/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 creati...
Import the SECRET_KEY key from the kube-system-config config map and set it as an environment variable in the web-app-deployment deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/kube-system-config deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Set the cpu limits for the 'mongo' container in the 'deployment' to "500m" and memory limits to "128Mi"
Command: ```bash kubectl set resources deployment mongo -c=nginx --limits=cpu=500m,memory=128Mi ``` 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 role named "default_role" with the ability to create pods and specific resource names "staging-app-server" and "prod-api-gateway"
Command: ```bash kubectl create role default_role --verb=create --resource=pods --resource-name=staging-app-server --resource-name=prod-api-gateway ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dr...
Display detailed information about the 'database-pod' pod
Command: ```bash kubectl describe pods/database-pod ``` 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...
List deployments in the "web-apps" API group, using the "beta-1.0" version and display the output in JSON format
Command: ```bash kubectl get deployments.beta-1.0.web-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...
Forward traffic from port 8081 on your local machine and IP 10.19.21.23 to port 8000 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 8081: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 criter...
Create an ingress called 'rontend-ingress' with a rule that directs requests from foo.com/input to svc1:9000
Command: ```bash kubectl create ingress rontend-ingress --rule="foo.com/input=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Create a service for the replicated wordpress using the replica set 'wordpress', expose it on port 3306, and connect to the containers on port 900000.
Command: ```bash kubectl expose rs wordpress --port=3306 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Scale the deployment "backend-service-replicaset" to 5 replicas if its current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/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 --r...
List the replication controller named "web", the service named "web-app-rc", and the pod named "payment-gateway-pod".
Command: ```bash kubectl get rc/web service/web-app-rc pods/payment-gateway-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...
Attach to a specific container in a pod and interact with it using a raw terminal mode.
Command: ```bash kubectl attach database-pod -c warp-drive -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 omitted...
Retrieve the output from running the 'mongod' command in the time-machine container of the payment-gateway-pod.
Command: ```bash kubectl exec payment-gateway-pod -c time-machine -- mongod ``` 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...
Autoscale the deployment "proxy-server" with a minimum of 1 and maximum of 9 pods
Command: ```bash kubectl autoscale deployment proxy-server --min=1 --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 ...
Copy the content of the /var/run/secrets/kubernetes.io/serviceaccount/ directory from the "message-broker-pod-15" pod to the /etc/kubernetes directory locally.
Command: ```bash kubectl cp velero/message-broker-pod-15:/var/run/secrets/kubernetes.io/serviceaccount/ /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...
Create a cron job named "data-processing" using the image "redis" that runs the command "redis-server" every minute
Command: ```bash kubectl create cronjob data-processing --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": "...
Start a mysql pod with the name "hazelcast" using the mysql image and set the environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container.
Command: ```bash kubectl run hazelcast --image=mysql --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default" ``` 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] -- [COMM...
Check if the current user has permission to list the "queue-processing-job" job in the "monitoring" namespace
Command: ```bash kubectl auth can-i list jobs.batch/queue-processing-job -n monitoring ``` 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 partia...
Create a pod disruption budget named 'messaging-pdb' that will select all pods with the 'component=web' label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=component=web --min-available=9 ``` 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 [-...
Autoscale the replication controller "gateway" with a target CPU utilization of 90% and a minimum of 1 pod and a maximum of 4 pods.
Command: ```bash kubectl autoscale rc gateway --max=4 --cpu-percent=90 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses...
Partially update the prod-node-5 node by specifying a strategic merge patch in YAML format
Command: ```bash kubectl patch node prod-node-5 -p $'data:\n key: new-value' ``` 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]` Helpful flags...
Create an ingress named "ingress1" with two rules
Command: ```bash kubectl create ingress ingress1 --class=default \ --rule="website.com/path*=svc:8000" \ --rule="example.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...
Create a debug container in the 'database-pod', using the 'debian' image and copying it to 'debug-image-memcached'
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-memcached --image=debian --set-image=proxy=nginx:1.21,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and ...
Forward traffic from port 6379 on your local machine and IP address 10.19.21.23 to port 9090 in the pod named "api-service-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 6379: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 cri...
Update the criticality annotation to "high" for the pod specified in the "params.json" file.
Command: ```bash kubectl annotate -f params.json criticality=high ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary s...
Set the environment variables for a deployment by importing specific keys from a config map.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/namespace-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 ...
Create a new config map named app-config-dev with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --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 crea...
Create a job with the name 'batch-processing' and use the 'jenkins' image. Run the command 'jenkins --version' inside the job.
Command: ```bash kubectl create job batch-processing --image=jenkins -- jenkins --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": "Out...
Display the supported API resources sorted by a specific column.
Command: ```bash kubectl api-resources --sort-by=singularName ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Create a service for the replicated php pods, where the service listens on port 8888 and forwards the traffic to the pods on port 8080.
Command: ```bash kubectl expose rc php --port=8888 --target-port=808000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Set the custom TLS server name to use for validation for the 'galaxy-cluster' cluster entry to 'kube-cluster-1'
Command: ```bash kubectl config set-cluster galaxy-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] [--certifi...