prompt
stringlengths
13
282
response
stringlengths
128
3.11k
create a job named 'scaling-job' with the image 'python' and run the command 'pip --version'
Command: ```bash kubectl create job scaling-job --image=python -- pip --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format...
Return the logs of the previous terminated container named 'time-machine' from the 'analytics-pod' pod
Command: ```bash kubectl logs -p -c time-machine 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", "s...
Remove all the taints with the key 'environment' from the node 'node-2'
Command: ```bash kubectl taint nodes node-2 environment- ``` 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|na...
Run the 'elasticsearch' command inside the first pod of the 'email-service' service.
Command: ```bash kubectl exec svc/email-service -- elasticsearch ``` 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 k...
Start a pod using the image "confluentinc/cp-kafka" and expose port 5001.
Command: ```bash kubectl run hazelcast --image=confluentinc/cp-kafka --port=5001 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flag...
Create a service for the php deployment that serves on port 8083 and connects to the containers on port 543200.
Command: ```bash kubectl expose deployment php --port=8083 --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 specified ...
Retrieve the output of the 'npm --version' command from the first pod of the 'user-management-deployment' deployment.
Command: ```bash kubectl exec deploy/user-management-deployment -- npm --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Update the pod specified in the "params.json" file by adding the annotation "expiration-date" with the value "2024-12-31".
Command: ```bash kubectl annotate -f params.json 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 include...
Remove all taints with the key 'workload' from the 'dev-node-4' node.
Command: ```bash kubectl taint nodes dev-node-4 workload- ``` 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|n...
Apply a taint to nodes with the label instance=app-instance-1
Command: ```bash kubectl taint node -l instance=app-instance-1 workload=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": ...
Expose the replication controller specified in "node-controller.yaml" as a service on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose -f node-controller.yaml --port=8000 --target-port=700000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Create a new ClusterIP service named security-service-clusterip and expose port 8089 to port 6379.
Command: ```bash kubectl create service clusterip security-service-clusterip --tcp=8089:6379 ``` 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...
Scale the deployment named webapp-replicaset to have 3 replicas, only if its current size is 1.
Command: ```bash kubectl scale --current-replicas=1 --replicas=3 deployment/webapp-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-v...
Create a copy of the auth-service-pod with a debug container and change the container images
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-app --image=debian --set-image=cache=redis:alpine,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 res...
Create a deployment named "api" using the "node" image and expose port 3000
Command: ```bash kubectl create deployment api --image=node --port=3000 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|y...
Apply a taint with key 'zone' on nodes that have the label 'role=database'.
Command: ```bash kubectl taint node -l role=database zone=testing-node-11:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Create a job with a command that runs inside an Ubuntu container
Command: ```bash kubectl create job data-migration-job --image=ubuntu -- docker run ubuntu echo "Hello ``` 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": "", ...
Display the last 23 lines of logs for the pod named chat-app-pod.
Command: ```bash kubectl logs --tail=23 chat-app-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 'app-loadbalancer-ingress' that directs requests from foo.com/input to a service named svc1 on port 8888, and uses the TLS secret named "my-cert".
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="foo.com/input=svc1:8888,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": ""...
Rename the context 'cloud-context' to 'app-1-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cloud-context app-1-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will also ...
Create a new config map named ui-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap ui-config --from-file=conf=/path/to/configurations/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Update the 'webapp-replicaset' deployment to have 3 replicas, if the current size is 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=3 deployment/webapp-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-v...
Make a node available for scheduling
Command: ```bash kubectl uncordon app-node-6 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Update the deployment named "elasticsearch", specifically the nginx container, to set its CPU limit to "3" and its memory limit to "512Mi".
Command: ```bash kubectl set resources deployment elasticsearch -c=nginx --limits=cpu=3,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst ...
Forward traffic from port 9090 on all network addresses to port 5432 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 9090:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
stream the logs of the "cyber-sleuth" container in the "proxy-server-pod" pod
Command: ```bash kubectl logs -f -c cyber-sleuth 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",...
Expose the CentOS replica set as a service, serving on port 3001 and connecting to the containers on port 888800
Command: ```bash kubectl expose rs centos --port=3001 --target-port=888800 ``` 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....
Import the 'database_url' key from the 'log-config' config map into the environment variables of the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/log-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...
Create a single ingress with the name 'app-ingress' that directs requests for 'site.com/example' to the service 'svc1' running on port 3001
Command: ```bash kubectl create ingress app-ingress --rule="site.com/example=svc1:3001,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":...
Add a taint on nodes with the label 'environment=production' using the key 'hardware' and value 'backup-node-14' with the effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l environment=production hardware=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": ""...
Create a deployment named gitlab using the ruby image and expose port 3001.
Command: ```bash kubectl create deployment gitlab --image=ruby --port=3001 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: jso...
Create a service for a replication controller named "wordpress-controller.yaml" with the following specifications:
Command: ```bash kubectl expose -f wordpress-controller.yaml --port=8081 --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 ...
Create a role binding for multiple users and a group using a specific cluster role
Command: ```bash kubectl create rolebinding default_role --clusterrole=default_role --user=user1 --user=user2 --group=group1 ``` 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] [--s...
Set the cluster field in the client-1-context context to my-k8s-cluster
Command: ```bash kubectl config set contexts.client-1-context.cluster my-k8s-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value y...
Add a taint with the key 'workload' and value 'prod-node-5:PreferNoSchedule' on all nodes that have the label 'namespace=mynamespace'
Command: ```bash kubectl taint node -l namespace=mynamespace workload=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Create a single ingress called 'www-ingress' with a rule that directs requests for foo.com/bar to svc1:7000, and use the tls secret "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/bar=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Add an annotation to the pod specified in "preferences.json"
Command: ```bash kubectl annotate -f preferences.json SLA='99.9% uptime' ``` 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 arbi...
Import the 'SECRET_KEY' key from the 'env-vars' config map to the environment variables of the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/env-vars deployment/database-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...
Expose the replication controller specified in "ubuntu-controller.yaml" as a service on port 9091, connecting to the containers on port 844300.
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=9091 --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...
Forward the traffic from port 6379 on localhost and IP 10.19.21.23 to port 6379 in the pod named 'cdn-service-pod'.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 6379: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 cri...
Return the previous terminated container logs from the pod "auth-service-pod" for the "astro-container" container.
Command: ```bash kubectl logs -p -c astro-container auth-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...
Create a pod disruption budget named api-service-pdb that will select all pods with the app=rails label and require a minimum of four of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=app=rails --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=N [--d...
Create a new config map named monitoring-config based on the files in the specified folder.
Command: ```bash kubectl create configmap monitoring-config --from-file=path/to/data ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basenam...
Copy a file named "foo" from the "/tmp" directory of the pod named "logging/cache-pod-5" to the "/etc/kubernetes" directory of the local machine.
Command: ```bash kubectl cp logging/cache-pod-5::/tmp/foo /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 kubect...
Create a copy of the database-pod and name it my-debugger, changing all container images to hazelcast/hazelcast.
Command: ```bash kubectl debug database-pod --copy-to=my-debugger --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 default ...
Forward local port 8088 to pod port 8080
Command: ```bash kubectl port-forward pod/proxy-server-pod 8088: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 a...
Create a new secret using files from a folder
Command: ```bash kubectl create secret generic payment-gateway-secret --from-file=path/to/configurations ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the...
Set the cpu and memory limits of the hazelcast container in the deployment to "1" and "4Gi" respectively.
Command: ```bash kubectl set resources deployment hazelcast -c=nginx --limits=cpu=1,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 requested, but may burst up to ...
Add a taint to the 'prod-node-5' node with the key 'disktype', value 'ssd', and effect 'NoSchedule'
Command: ```bash kubectl taint nodes prod-node-5 disktype=ssd:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One ...
Add a taint with the key 'disktype' and value 'dev-node-4:PreferNoSchedule' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 disktype=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": "...
Create a cron job named "report-generation" using the ethereum/client-go image, with a schedule of running every minute, and executing the command "geth version".
Command: ```bash kubectl create cronjob report-generation --image=ethereum/client-go --schedule="*/1 * * * *" -- geth 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": "--outp...
Create a job called 'indexing' using the mysql image. The job should run the command 'mysql --version'.
Command: ```bash kubectl create job indexing --image=mysql -- mysql --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. ...
Create a debug container called 'dgb-img' based on the e-commerce-pod with all container images set to 'nginx'
Command: ```bash kubectl debug e-commerce-pod --copy-to=dgb-img --set-image=*=nginx ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource i...
Create a deployment named 'proxy' using the 'mysql' image and expose port 8080
Command: ```bash kubectl create deployment proxy --image=mysql --port=8080 ``` 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...
Create an ingress resource called 'api-ingress' with a rule that directs requests to website.com/module to the service svc1:8000, and use the tls secret "my-cert"
Command: ```bash kubectl create ingress api-ingress --rule="website.com/module=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Forward local ports 5000 to a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/mydeployment 5000 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 selecte...
Delete the pods and services with the names "media-stream" and "gateway"
Command: ```bash kubectl delete pod,service media-stream gateway ``` 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 sele...
Create a job named "report-generation-job" with the image "jenkins" and the command "jenkins-plugin-cli"
Command: ```bash kubectl create job report-generation-job --image=jenkins -- jenkins-plugin-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"...
Execute the 'wp' command inside the first container of the first pod in the 'gateway-service' service and display the output.
Command: ```bash kubectl exec svc/gateway-service -- wp ``` 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...
Create a service for a replicated Ubuntu using a replica set
Command: ```bash kubectl expose rs ubuntu --port=8000 --target-port=808400 ``` 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....
Forward port 6379 to port 8081 in the pod named "analytics-pod", and listen on both localhost and 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-pod 6379:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crite...
Create a service for a replicated hazelcast using replica set, which serves on port 8084 and connects to the containers on port 330600.
Command: ```bash kubectl expose rs hazelcast --port=8084 --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 specified po...
Update the pod named 'proxy-server' by adding or updating the annotation 'alert-email' with the value 'alerts@example.com'
Command: ```bash kubectl annotate --overwrite pods proxy-server alert-email='alerts@example.com' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than...
List the deployments in the "hotfix-1.1.2" version of the "third-party-apps" API group, and display the output in JSON format.
Command: ```bash kubectl get deployments.hotfix-1.1.2.third-party-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 namespa...
Forward local port 9090 to pod port 5432 for a specific deployment
Command: ```bash kubectl port-forward deployment/search-engine-deployment 9090 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod wil...
Update the 'database-deployment' deployment by adding a new environment variable 'SMTP_PASSWORD' with the value 'your-password'
Command: ```bash kubectl set env deployment/database-deployment SMTP_PASSWORD=your-password ``` 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...
Create a job named 'data-migration-job' using the 'redis' image, running the command 'redis-cli'
Command: ```bash kubectl create job data-migration-job --image=redis -- redis-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": "Output form...
Listen on port 5432 locally and forward data to/from port 9090 in the email-server deployment.
Command: ```bash kubectl port-forward deployment/email-server-deployment 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...
Import specific keys from a config map to an environment variable in a deployment.
Command: ```bash kubectl set env --keys=api_key --from=configmap/global-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 definitions in o...
Create a new TLS secret named 'tls-secret' using the TLS certificate located at 'path/to/tls.cert' and the private key located at 'path/to/tls.key'
Command: ```bash kubectl create secret tls tls-secret --cert=path/to/tls.cert --key=path/to/tls.key ``` What it does: Create a TLS secret from the given public/private key pair. The public/private key pair must exist beforehand. The public key certificate must be .PEM encoded and match the given private key. Syntax: ...
Update the image of all containers in daemonset "app-v2" to "golang:1.17".
Command: ```bash kubectl set image daemonset app-v2 *=golang:1.17 ``` 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...
Display the most recent 3 lines of logs for pod media-stream-pod.
Command: ```bash kubectl logs --tail=3 media-stream-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": ...
Create a service for an ubuntu deployment. The service will serve on port 9091 and connect to the containers on port 8000.
Command: ```bash kubectl expose deployment ubuntu --port=9091 --target-port=8000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified...
Create a pod disruption budget named messaging-pdb that will select all pods with the project=my-project label and require at least four of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=project=my-project --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...
Check the rollout status of a deployment
Command: ```bash kubectl rollout status deployment/nginx ``` What it does: Show the status of the rollout. By default 'rollout status' will watch the status of the latest rollout until it's done. If you don't want to wait for the rollout to finish then you can use --watch=false. Note that if a new rollout starts in-be...
Get the output from running the 'mongod' command in the 'time-machine' container of the 'gateway-pod' pod.
Command: ```bash kubectl exec 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, use th...
Set the server field for the galaxy-cluster cluster to the provided https://1.2.3.4 address.
Command: ```bash kubectl config set clusters.galaxy-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...
Create a Pod Disruption Budget named 'auth-service-pdb' that will select all pods with the 'component=web' label, and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=component=web --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N...
Add a taint on nodes with label "version=v1.0.0" with the key "disktype" and value "testing-node-11:PreferNoSchedule"
Command: ```bash kubectl taint node -l version=v1.0.0 disktype=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": "", "usag...
Set the cpu limits of the mongo container in the deployment named "mongo" to 5 and the memory limit to 64Mi.
Command: ```bash kubectl set resources deployment mongo -c=nginx --limits=cpu=5,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 its...
Partially update the configuration of a node by applying a strategic merge patch in JSON format.
Command: ```bash kubectl patch node storage-node-13 -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: `kubec...
Create a cron job named "metrics-collection" that runs the command "elasticsearch-plugin --list" every minute using the image "docker.elastic.co/elasticsearch/elasticsearch"
Command: ```bash kubectl create cronjob metrics-collection --image=docker.elastic.co/elasticsearch/elasticsearch --schedule="*/1 * * * *" -- elasticsearch-plugin --list ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND]...
Update the 'analytics' pod by adding the annotation 'criticality' with the value 'high'
Command: ```bash kubectl annotate pods analytics 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...
Create a copy of the cdn-service-pod by adding a debug container and changing the container images.
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-web --image=debian --set-image=proxy=nginx:1.21,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified ...
Create a new ClusterIP service named monitoring-service-clusterip with the port mapping of TCP 8888 to 8010.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8888: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": "...
Execute the 'mongo' command in the 'nebula-navigator' container in the 'web-app-pod' pod
Command: ```bash kubectl exec web-app-pod -c nebula-navigator -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
Forward all traffic coming to port 5432 on any address to port 9090 in the 'proxy-server-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 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 ...
Import the 'debug_mode' key from the 'log-config' config map into the 'user-management-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/log-config deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Import the environment from the 'password-secret' secret into the 'load-balancer-deployment' deployment
Command: ```bash kubectl set env --from=secret/password-secret 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 one or more...
Create a new config map named env-vars with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap env-vars --from-file=properties=/path/to/data/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 creating a confi...
Display the deployments in the "backup-apps" API group with the version "alpha-2.0" in JSON format.
Command: ```bash kubectl get deployments.alpha-2.0.backup-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 ...
Listen on port 8080 on the local machine and forward traffic to the "https" targetPort of the "email-service" service.
Command: ```bash kubectl port-forward service/email-service 8080:https ``` 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...
Create a service for a node deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment node --port=8089 --target-port=909100 ``` 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...
import the database_url key from the db-config config map to the load-balancer-deployment deployment
Command: ```bash kubectl set env --keys=database_url --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 definitio...
Forward ports 8888 and 6000 locally to ports 8081 and 6000 respectively in a pod selected by the deployment named "authentication-service-deployment"
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Scale the replica set 'frontend-rs' to 7 replicas.
Command: ```bash kubectl scale --replicas=7 rs/frontend-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 validate...
Create a service for the replicated alpine containers on port 80, which connects to the containers on port 8000.
Command: ```bash kubectl expose rc alpine --port=8181 --target-port=808300 ``` 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....
Forward local traffic on a random port to port 6379 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward pod/e-commerce-pod :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 automat...
Begin streaming the logs of the "cyber-sleuth" container in the "media-stream-pod" pod
Command: ```bash kubectl logs -f -c cyber-sleuth media-stream-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",...
Taint a node with a specific key-value pair and effect
Command: ```bash kubectl taint nodes worker-node-3 hardware=gpu:NoExecute ``` 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...