prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Partially update a node using a strategic merge patch by providing the patch as JSON.
Command: ```bash kubectl patch node monitoring-node-15 -p '{"data":{"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]` He...
Add a taint with the key 'dedicated' on nodes that have the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend 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": "...
Forward traffic from port 5000 on localhost and 10.19.21.23 to port 8081 in the backend-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-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 criteri...
Update the image of all containers in the app-v2 daemonset to 'redis:6.2.5'
Command: ```bash kubectl set image daemonset app-v2 *=redis:6.2.5 ``` 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...
Create an ingress with a default backend and routing rules
Command: ```bash kubectl create ingress ingdefault --class=default \ --default-backend=defaultsvc:http \ --rule="website.com/*=svc:8081,tls=secret1" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "...
Create a role named "reader" that grants permission to create pods with resource names "monitoring-prometheus" and "database-master"
Command: ```bash kubectl create role reader --verb=create --resource=pods --resource-name=monitoring-prometheus --resource-name=database-master ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-ru...
Begin streaming the logs of the quantum-quark container in the gateway-pod
Command: ```bash kubectl logs -f -c quantum-quark 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", "sh...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config deployment/authentication-service-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Partially update a resource using strategic merge patch
Command: ```bash kubectl patch -f kube-proxy-config.yaml -p '{"stringData":{"password":"new-password"}' ``` 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...
Forward port 5000 locally to port 9090 in the 'database-deployment' pods
Command: ```bash kubectl port-forward deployment/database-deployment 5000 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Run the 'postgres' command inside the media-stream-pod pod and print the output
Command: ```bash kubectl exec media-stream-pod -- 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 the kubectl...
Retrieve logs from a specific pod written in the last hour
Command: ```bash kubectl logs --since=1h mypod ``` 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", "de...
Retrieve information about the replication controller "web", the service "vpn-service-rc", and the pod "proxy-server-pod".
Command: ```bash kubectl get rc/web service/vpn-service-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 names...
Output the modified gateway-deployment deployment in YAML format with the environment variable S3_BUCKET set to my-s3-bucket
Command: ```bash kubectl set env deployment/gateway-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 more pod ...
Partially update the backup-node-14 node by changing the `replicas` value to 3 using a strategic merge patch provided in a YAML format.
Command: ```bash kubectl patch node backup-node-14 -p $'spec:\n replicas: 3' ``` 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...
Set the service account of a deployment named email-server-deployment to argocd
Command: ```bash kubectl set serviceaccount deployment email-server-deployment argocd ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubect...
Create a new config map named kube-system-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap kube-system-config --from-file=properties=/path/to/configurations/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 pa...
Create a job with a specific command
Command: ```bash kubectl create job backup --image=amazonlinux -- yum install -y aws-cli ``` 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": "Outp...
Set the CPU limit of the 'golang' deployment's 'nginx' container to "10" and the memory limit to "64Mi"
Command: ```bash kubectl set resources deployment golang -c=nginx --limits=cpu=10,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 i...
Create a ClusterIP service named "catalog-service-clusterip" that maps port 5432 on the service to port 8084 on the pods.
Command: ```bash kubectl create service clusterip catalog-service-clusterip --tcp=5432: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"...
Remove all the taints with key 'app' from the 'prod-node-5' node
Command: ```bash kubectl taint nodes prod-node-5 app- ``` 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 Pod Disruption Budget (PDB) named "web-app-pdb" that selects all pods with the label "region=us-east", and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=region=us-east --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 [--...
Listen on a random port locally and forward it to port 8081 in the security-service-pod pod.
Command: ```bash kubectl port-forward pod/security-service-pod :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 annotation 'last-deployment' of the pod 'payment' with the value '2023-03-15'
Command: ```bash kubectl annotate pods payment last-deployment=2023-03-15 ``` 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 arb...
Import specific keys from a config map to a deployment:
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-name-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Import the API_KEY from the db-config config map and set it as an environment variable in the api-server-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/db-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...
Begin streaming the logs of the 'stardust-shuttle' container in the 'api-service-pod' pod
Command: ```bash kubectl logs -f -c stardust-shuttle api-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": "--containe...
Update the image of all containers in the "namespace-3" DaemonSet to "debian:11.0"
Command: ```bash kubectl set image daemonset namespace-3 *=debian:11.0 ``` 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: `...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/log-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 defin...
Create a new config map named "app-name-config" and add the contents of the files "/path/to/properties/file1.txt" and "/path/to/parameters/file2.txt" to it, using the keys "properties" and "key1" respectively.
Command: ```bash kubectl create configmap app-name-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When c...
Execute the 'redis-cli' command inside the pod 'api-service-pod' and retrieve the output.
Command: ```bash kubectl exec api-service-pod -- redis-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 the kubectl...
List the deployments in the "v2.1.0" version of the "mobile-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.v2.1.0.mobile-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
Listen on port 9090 on localhost and IP address 10.19.21.23, and forward the traffic to port 9090 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 9090: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 cr...
List deployments in YAML output format using the "alpha-2.0" version of the "apps" API group.
Command: ```bash kubectl get deployments.alpha-2.0.apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will on...
Forward local port 8888 to port 8081 in the pod "backend-pod"
Command: ```bash kubectl port-forward pod/backend-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 criteria, a pod will be selected automa...
Set the service account of the deployment `proxy-service-deployment` to `vault`
Command: ```bash kubectl set serviceaccount deployment proxy-service-deployment vault ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubect...
Create a new ClusterIP service named billing-service-clusterip that will route traffic from port 8083 on the service to port 8088 on the backend pods.
Command: ```bash kubectl create service clusterip billing-service-clusterip --tcp=8083:8088 ``` 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"...
Partially update a node's settings using a strategic merge patch
Command: ```bash kubectl patch -f node-settings.json -p '{"spec":{"type":"LoadBalancer"}' ``` 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]` ...
Create a debug copy of the e-commerce-pod, changing all container images to node
Command: ```bash kubectl debug e-commerce-pod --copy-to=debug-image-app --set-image=*=node ``` 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 res...
Start port forwarding on port 9090 locally, forwarding traffic to port 6379 in the frontend-pod pod.
Command: ```bash kubectl port-forward pod/frontend-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 criteria, a pod will be selected autom...
Autoscale the deployment "analytics" with the number of pods between 4 and 14
Command: ```bash kubectl autoscale deployment analytics --min=4 --max=14 ``` 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...
Expose the replication controller specified in "node-controller.yaml" as a service, serving on port 8443 and forwarding traffic to containers on port 543200
Command: ```bash kubectl expose -f node-controller.yaml --port=8443 --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 s...
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=secret_key --from=configmap/kube-system-config deployment/email-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 def...
Add a taint with key 'dedicated' on nodes labeled with 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha dedicated=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Forward local port 5000 to port 8888 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 5000: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 a...
Create a cron job named 'report-generation' using the 'node' image, with a schedule of "every minute", and the command 'node'.
Command: ```bash kubectl create cronjob report-generation --image=node --schedule="*/1 * * * *" -- node ``` 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", "d...
Forward port 6379 in the pod "mypod" to port 8081 on localhost and IP address 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8081: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 p...
Set the custom TLS server name for a cluster entry
Command: ```bash kubectl config set-cluster my-k8s-cluster --tls-server-name=kube-cluster-2 ``` 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...
Create an ingress that directs requests to a specific service with TLS secret in the specified rule
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/module=svc1:3000,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":...
Create a copy of the auth-service-pod named debug-image-memcached, but change all container images to mysql.
Command: ```bash kubectl debug auth-service-pod --copy-to=debug-image-memcached --set-image=*=mysql ``` 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 ...
Delete the pods and services with the names "analytics" and "chat-app"
Command: ```bash kubectl delete pod,service analytics chat-app ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label select...
Create a cron job named "system-health-check" with the image "alpine" and a schedule that runs every minute
Command: ```bash kubectl create cronjob system-health-check --image=alpine --schedule="*/1 * * * *" -- apk add curl ``` 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", "shor...
Execute the 'irb' command in the 'stardust-shuttle' container of the 'log-aggregator-pod' pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c stardust-shuttle -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Execute the 'java -jar /usr/share/jenkins/jenkins.war' command inside the 'cosmic-container' container of the 'monitoring-pod' pod.
Command: ```bash kubectl exec monitoring-pod -c cosmic-container -- java -jar /usr/share/jenkins/jenkins.war ``` 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": "", "us...
Update the pod identified by the type and name specified in the "conf.json" file with the label "status=unhealthy"
Command: ```bash kubectl label -f conf.json status=unhealthy ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage...
Check if the user has permission to list the job named "database-indexing-job" in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/database-indexing-job -n kube-dns ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial...
Automatically adjust the number of pods in the "proxy-server" replication controller based on CPU utilization, with a maximum of 4 pods and target CPU utilization at 20%.
Command: ```bash kubectl autoscale rc proxy-server --max=4 --cpu-percent=20 ``` 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...
Set up autoscaling for the 'database' deployment with a minimum of 5 pods and a maximum of 14 pods
Command: ```bash kubectl autoscale deployment database --min=5 --max=14 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Import the SECRET_KEY from the 'app-name-config' config map into the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-name-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Set environment variable keys from a specific config map for a deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-config-dev deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Import the environment variables from the 'api-config' config map with the prefix 'MYSQL_' and apply them to the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --from=configmap/api-config --prefix=MYSQL_ 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 ...
Listen on port 8080 on localhost and IP address 10.19.21.23, and forward the traffic to port 8080 in the 'api-service-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-pod 8080:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Add a taint with key 'dedicated' on nodes having label cluster=my-cluster
Command: ```bash kubectl taint node -l cluster=my-cluster dedicated=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Create a copy of payment-gateway-pod with all container images changed to postgres
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-app --set-image=*=postgres ``` 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 ...
Return snapshot logs from container backend-pod-1 of a deployment named frontend-deployment
Command: ```bash kubectl logs deployment/frontend-deployment -c backend-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "-...
Roll back the 'development' deployment to the previous version using the dry-run option
Command: ```bash kubectl rollout undo --dry-run=server deployment/development ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifyi...
Forward local port 8088 to port 8081 in a pod.
Command: ```bash kubectl port-forward 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 pod will be selected automaticall...
Expose the Wordpress deployment as a service, serving on port 8443 and connecting to the containers on port 8082.
Command: ```bash kubectl expose deployment wordpress --port=8443 --target-port=808200 ``` 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 local port 8080 to port 8000 in a pod selected by the email-server-deployment deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 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...
Create a deployment named "nats" using the "ethereum/client-go" image with 3 replicas.
Command: ```bash kubectl create deployment nats --image=ethereum/client-go --replicas=3 ``` 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...
Delete the pods and services with the names "frontend" and "auth"
Command: ```bash kubectl delete pod,service frontend auth ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. S...
Create a role binding named "bar" that assigns the "bar" cluster role to the "admin" user, "devops-user" user, and the "operations-team" group.
Command: ```bash kubectl create rolebinding bar --clusterrole=bar --user=admin --user=devops-user --group=operations-team ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--serv...
Embed the certificate authority data for the 'data-cluster' cluster entry by running the command: kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/prod-cluster/kubernetes.ca.crt
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/prod-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...
Create a pod disruption budget named cache-cluster-pdb that selects all pods with the app=nginx label and requires at least half of the selected pods to be available at any point in time.
Command: ```bash kubectl create pdb cache-cluster-pdb --selector=app=nginx --min-available=50% ``` 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 [--dry-run=serve...
Retrieve the output from running the 'dotnet --list-runtimes' command in the frontend-pod.
Command: ```bash kubectl exec frontend-pod -- dotnet --list-runtimes ``` 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 t...
Create a service for the replication controller specified in the "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=80 --target-port=801000 ``` 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 s...
Create a pod named hazelcast using the amazonlinux image and expose port 8082
Command: ```bash kubectl run hazelcast --image=amazonlinux --port=8082 ``` 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":...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config 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 defi...
Create a copy of the mypod pod with a debug container and changed container images
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-app --image=debian --set-image=scheduler=my-scheduler:1.0,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Create an ingress named 'www-ingress' with a specific rule to direct requests from testing.com/bar to svc1:9090
Command: ```bash kubectl create ingress www-ingress --rule="testing.com/bar=svc1:9090,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Update the annotation 'env' of pod 'payment' to have the value 'staging'
Command: ```bash kubectl annotate pods payment env=staging ``` 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 string v...
Create a new ClusterIP service named my-cs, which will route incoming traffic on port 27017 to port 5001.
Command: ```bash kubectl create service clusterip my-cs --tcp=27017:5001 ``` 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", "default": "", "u...
Add a taint with key 'datacenter' on nodes having label component=proxy
Command: ```bash kubectl taint node -l component=proxy datacenter=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": "", "usage"...
Forward port 8088 on localhost and IP address 10.19.21.23 to port 8088 in the cdn-service-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Forward traffic from port 5000 on localhost and IP 10.19.21.23 to port 9090 in the frontend-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 5000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criter...
Forward port 8080 on all addresses to port 8088 in the 'analytics-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8080: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 wil...
Create a cron job named database-maintenance that runs the php image every minute
Command: ```bash kubectl create cronjob database-maintenance --image=php --schedule="*/1 * * * *" -- ``` 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", "defa...
Create a cluster role named "admin_role" with the specified resource name and permission verbs
Command: ```bash kubectl create clusterrole admin_role --verb=watch --resource=services --resource-name=database-master --resource-name=document-storage ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=ser...
Delete the pods and services with the names "email" and "proxy-server"
Command: ```bash kubectl delete pod,service email proxy-server ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label select...
Create a new NodePort service named gateway-nodeport
Command: ```bash kubectl create service nodeport gateway-nodeport --tcp=5432:8181 ``` 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": "",...
Import environment from a secret for a deployment named email-server-deployment.
Command: ```bash kubectl set env --from=secret/aws-credentials-secret deployment/email-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 one o...
Add a taint with the key 'dedicated' on nodes that have the label service=auth
Command: ```bash kubectl taint node -l service=auth dedicated=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Forward local port 3000 to port 5000 in the specified pod
Command: ```bash kubectl port-forward deployment/database-deployment 3000 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 ...
Create an ingress named 'app-proxy-ingress' with a rule that redirects requests to 'website.com/input' to the service 'svc1:8181' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress app-proxy-ingress --rule="website.com/input=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Forward the local port 6379 to port 9090 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-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 criteria, a pod will be selected aut...
Listen on port 9090 on all addresses and forward it to the 9090 port in the 'web-app-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 9090: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 ...
Create a new config map named db-config using the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating ...
Delete both the pod and service named "api"
Command: ```bash kubectl delete pod,service api api ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some re...
Forward traffic from port 6379 on localhost and IP 10.19.21.23 to port 8080 in the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 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 p...
Retrieve the output of the 'python --version' command executed within the 'nano-bot' container of the 'proxy-server-pod' pod
Command: ```bash kubectl exec proxy-server-pod -c nano-bot -- python --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 omit...