prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a pod disruption budget named 'critical-services-pdb' that will select all pods with the 'env=production' label and require a minimum of 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget critical-services-pdb --selector=env=production --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-avail...
Begin streaming the logs of the cyber-sleuth container in the email-service-pod pod
Command: ```bash kubectl logs -f -c cyber-sleuth email-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"...
Execute the 'go' command in the astro-container from the 'cdn-service-pod' pod and display the output
Command: ```bash kubectl exec cdn-service-pod -c astro-container -- 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...
Delete the pods and services with the names "email" and "api"
Command: ```bash kubectl delete pod,service email 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 ...
Create a new ExternalName service named 'external-dns-service' with the external name 'mockup-cloud.cloud'
Command: ```bash kubectl create service externalname external-dns-service --external-name mockup-cloud.cloud ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference servi...
View the last 20 lines of logs for the 'security-service-pod' pod.
Command: ```bash kubectl logs --tail=20 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...
Set the CPU and memory resource limits and requests for all containers in the MySQL deployment.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested...
update the image of all containers in daemonset namespace-2 to 'amazonlinux:2'
Command: ```bash kubectl set image daemonset namespace-2 *=amazonlinux:2 ``` 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:...
Create a new ClusterIP service named frontend-service-clusterip
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=9091:27017 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-...
Create a cluster role named "custom_role" with the following permissions: allow proxy access to pods and restrict the access to two specific resources named "machine-learning" and "file-processing"
Command: ```bash kubectl create clusterrole custom_role --verb=proxy --resource=pods --resource-name=machine-learning --resource-name=file-processing ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server...
Set the custom TLS server name to 'galaxy-cluster' for the 'kube-cluster-2' cluster entry in the kubectl configuration
Command: ```bash kubectl config set-cluster kube-cluster-2 --tls-server-name=galaxy-cluster ``` 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...
List all deployments in the "v1.0.0" version of the "legacy-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.v1.0.0.legacy-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...
Rename the context 'on-prem-context' to 'user-a-context' in your kubeconfig file
Command: ```bash kubectl config rename-context on-prem-context user-a-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 al...
Execute the command 'apk add curl' in the 'nebula-navigator' container of the 'cdn-service-pod' pod and retrieve the output
Command: ```bash kubectl exec cdn-service-pod -c nebula-navigator -- apk add curl ``` 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 o...
Scale the deployment named "web" to have the same number of replicas as the current size of the deployment "mysql"
Command: ```bash kubectl scale --current-replicas=5 --replicas=5 deployment/web ``` 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 spec...
Create a new NodePort service named database-nodeport with the TCP port mapping of 6379:9000.
Command: ```bash kubectl create service nodeport database-nodeport --tcp=6379:9000 ``` 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": ""...
Set the service account of the deployment "mydeployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment mydeployment kube-dns ``` 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 ser...
Create a new ClusterIP service named order-service-clusterip that forwards traffic from port 8080 to port 6379
Command: ```bash kubectl create service clusterip order-service-clusterip --tcp=8080: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", ...
Get the output of the 'mongo --version' command from the first pod of the email-service service.
Command: ```bash kubectl exec svc/email-service -- mongo --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...
Create a new secret named "monitoring-credentials-secret" using the environment variables specified in the file "path/to/configurations.env"
Command: ```bash kubectl create secret generic monitoring-credentials-secret --from-env-file=path/to/configurations.env ``` 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...
Create a new config map named 'app-secrets' using the key=value pairs from the file located at 'path/to/preferences'
Command: ```bash kubectl create configmap app-secrets --from-file=path/to/preferences ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basena...
Copy the local file /tmp/foo_dir to the remote pod security-scanner-pod-18 in the kube-dns namespace, and place it at /tmp/bar
Command: ```bash kubectl cp /tmp/foo_dir kube-dns/security-scanner-pod-18::/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 ...
Set the cluster field in the specified context to the specified cluster.
Command: ```bash kubectl config set contexts.local-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wan...
Create a config map named env-vars from an env file
Command: ```bash kubectl create configmap env-vars --from-env-file=path/to/configs.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 the basen...
Retrieve the snapshot of the previous terminated logs from the 'cosmic-container' container in the 'gateway-pod' pod.
Command: ```bash kubectl logs -p -c cosmic-container 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", ...
Create a job named 'audit-job' using the 'ubuntu' image. The job will run the command 'docker run ubuntu echo "Hello".
Command: ```bash kubectl create job audit-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": "", "usage": ...
Forward local traffic on port 5000 to port 8081 of the selected pod in the deployment "monitoring-stack-deployment"
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 5000 8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Execute the 'nginx' command within the 'web-app-pod' pod
Command: ```bash kubectl exec web-app-pod -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kuberne...
Retrieve the logs from the container monitoring-stack-deployment-1 of the email-service-pod deployment.
Command: ```bash kubectl logs deployment/monitoring-stack-deployment -c email-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful fla...
Copy the ~/.config/kube local file to the /tmp/bar_dir directory in the rook-ceph/auth-service-pod-11 pod in the specified namespace.
Command: ```bash kubectl cp ~/.config/kube rook-ceph/auth-service-pod-11:/tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Update the label 'status' to 'unhealthy' for the pod 'cdn' only if the current resource version is 1
Command: ```bash kubectl label pods cdn status=unhealthy --resource-version=1 ``` 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"...
Import the 'debug_mode' key from the 'api-config' config map and set it as an environment variable for the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/api-config deployment/proxy-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 definition...
Create an ingress called 'api-v2-ingress' with a rule that directs requests from testing.com/input to svc1:3001
Command: ```bash kubectl create ingress api-v2-ingress --rule="testing.com/input=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": "", "usa...
List all deployments in the "alpha-2.0" version of the "prod-apps" API group in JSON output format
Command: ```bash kubectl get deployments.alpha-2.0.prod-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 wi...
Taint a specific node with a preference for no scheduled workloads
Command: ```bash kubectl taint node -l project=project-alpha workload=node-2: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 deployment named "db" using the Ubuntu image
Command: ```bash kubectl create deployment db --image=ubuntu ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go...
Create an ingress called 'public-api-ingress' that directs requests for 'site.com/bar' to 'svc1:8000' with the tls secret "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="site.com/bar=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": "", "usag...
Create a new service with the name "nginx-https" that exposes port 443 and redirects traffic to port 8888 of the ubuntu container.
Command: ```bash kubectl expose service ubuntu --port=443 --target-port=8888 --name=nginx-https ``` 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 o...
Run the 'wp' command in the 'stardust-shuttle' container of the 'cdn-service-pod' pod
Command: ```bash kubectl exec cdn-service-pod -c stardust-shuttle -- 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, us...
Forward traffic from port 8080 on your local machine, as well as IP address 10.19.21.23, to port 3000 in the pod named e-commerce-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8080:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Get output from running the 'nginx' command from the pod named 'chat-app-pod'
Command: ```bash kubectl exec chat-app-pod -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubern...
Create a service with the name "frontend" for the analytics-pod, serving on port 8083.
Command: ```bash kubectl expose pod analytics-pod --port=8083 --name=frontend ``` 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...
Delete the pods and services with the names "frontend" and "gateway"
Command: ```bash kubectl delete pod,service frontend 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 selector...
Create a copy of web-app-pod and change all container images to docker.elastic.co/elasticsearch/elasticsearch
Command: ```bash kubectl debug web-app-pod --copy-to=debug-image-app --set-image=*=docker.elastic.co/elasticsearch/elasticsearch ``` 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. ...
create a service for the replication controller specified in "python-controller.yaml" that serves on port 3306 and connects to the containers on port 8888
Command: ```bash kubectl expose -f python-controller.yaml --port=3306 --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...
Check if you have permission to list the job named "notification-sender-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n kube-ingress ``` 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 p...
Create an ingress that directs requests to a specific service with TLS encryption.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/input=svc1:8443,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"...
Remove the label 'env' from the 'proxy-server' pod
Command: ```bash kubectl label pods proxy-server env- ``` 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 ...
Scale the resource specified in the "preferences.yaml" file to 3 replicas.
Command: ```bash kubectl scale --replicas=3 -f preferences.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 val...
Embed the certificate authority data for the cluster entry named "moon-cluster".
Command: ```bash kubectl config set-cluster moon-cluster --embed-certs --certificate-authority=~/.kube/cluster-beta/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 job named database-seeding-job with the image wordpress and run the command "apache2ctl -D FOREGROUND" inside the job.
Command: ```bash kubectl create job database-seeding-job --image=wordpress -- apache2ctl -D FOREGROUND ``` 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": "", ...
Set the environment variable 'log_level' in the 'mydeployment' deployment using the value from the 'app-name-config' config map.
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-name-config deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one...
Start a pod named 'hazelcast' using the 'docker.elastic.co/elasticsearch/elasticsearch' image, and configure the container to expose port 5001.
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --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] ...
Create a new ClusterIP service named api-service-clusterip that forwards traffic from port 7000 of any node to port 27017 of the pods associated with the service.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=7000:27017 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "...
Listen on port 5432 on both localhost and IP address 10.19.21.23, and forward the traffic to port 6379 in the security-service-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-pod 5432: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 th...
forward local port 8000 to port 8088 in the pod
Command: ```bash kubectl port-forward pod/api-service-pod 8000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Create a pod named "hazelcast" using the image "mcr.microsoft.com/dotnet/core/runtime" and expose port 3001.
Command: ```bash kubectl run hazelcast --image=mcr.microsoft.com/dotnet/core/runtime --port=3001 ``` 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......
Remove a specific taint from a node
Command: ```bash kubectl taint nodes gpu-node-12 special- ``` 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...
Set the custom TLS server name for the testing-cluster cluster entry to "cluster-beta".
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=cluster-beta ``` 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] [--certific...
Start a pod named "hazelcast" using the nginx image and expose port 9091
Command: ```bash kubectl run hazelcast --image=nginx --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": "--fi...
Output the modified 'gateway-deployment' deployment in YAML format, without making any changes to the deployment on the server
Command: ```bash kubectl set env deployment/gateway-deployment SMTP_USERNAME=your-username -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more...
Add a taint with key 'disktype' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace disktype=app-node-6:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Create a new config map named global-config with specified keys instead of file basenames on the disk
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating...
expose the centos deployment as a service, serving on port 8083, and connecting to the containers on port 8000.
Command: ```bash kubectl expose deployment centos --port=8083 --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...
Get output from running the 'mysqld' command in nebula-navigator from the pod gateway-pod
Command: ```bash kubectl exec gateway-pod -c nebula-navigator -- mysqld ``` 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, us...
Create a copy of the pod 'gateway-pod', changing all container images to 'mongo'.
Command: ```bash kubectl debug gateway-pod --copy-to=dgb-img --set-image=*=mongo ``` 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 is s...
Create a new config map with specific key-value pairs
Command: ```bash kubectl create configmap db-config --from-literal=settings=config1 --from-literal=key2=config2 ``` 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 ...
Set the service account of the deployment "gateway-deployment" to "vault"
Command: ```bash kubectl set serviceaccount deployment gateway-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: `kubectl set ...
view the rollout history of the 'test' deployment
Command: ```bash kubectl rollout history deployment/test ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identify...
Forward local port 8080 to port 3000 in the pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 8080:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Import the 'redis_host' key from the 'app-config-dev' ConfigMap into the 'gateway-deployment' Deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-config-dev 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 ...
Forward local traffic on port 5432 to port 3000 in the pod selected by the database-deployment deployment
Command: ```bash kubectl port-forward deployment/database-deployment 5432 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/api-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
Partially update the node named node-2 by setting the "unschedulable" field to true using a strategic merge patch in JSON format.
Command: ```bash kubectl patch node node-2 -p '{"spec":{"unschedulable":true}}' ``` 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 fl...
Copy a file named "foo" from the local directory "/tmp" to the remote directory "/tmp/bar" in the pod named "ingress-controller-pod-8" in the "kube-dns" namespace.
Command: ```bash kubectl cp :/tmp/foo kube-dns/ingress-controller-pod-8::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Copy the kube configuration file from a remote pod to a directory on your local machine.
Command: ```bash kubectl cp kubeapps/monitoring-agent-pod-6:~/.config/kube /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Set the resource request and limits for all containers in the deployment named "go"
Command: ```bash kubectl set resources deployment go --limits=cpu=200m,memory=512Mi --requests=cpu=5,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, b...
Update the label of pod 'web' with the label 'component' set to 'worker'
Command: ```bash kubectl label pods web component=worker ``` 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": "...
Set the cluster field in the 'my-context' context to 'cluster-alpha'
Command: ```bash kubectl config set contexts.app-1-context.cluster cluster-alpha ``` 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...
View the output of the 'psql' command running in the 'time-machine' container in the 'analytics-pod' pod.
Command: ```bash kubectl exec analytics-pod -c time-machine -- psql ``` 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...
Copy the '/tmp/foo_dir' directory from the 'kube-flannel/load-balancer-pod-9' pod to the '/tmp/bar' directory locally
Command: ```bash kubectl cp kube-flannel/load-balancer-pod-9:/tmp/foo_dir /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Listen on port 5432 on localhost and IP address 10.19.21.23, and forward the traffic to port 8080 inside the analytics-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/analytics-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 crite...
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/star-cluster/kubernetes.ca.crt`
Command: ```bash kubectl config set-cluster data-cluster --embed-certs --certificate-authority=~/.kube/star-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...
Embed the certificate authority data for the cluster-gamma cluster entry
Command: ```bash kubectl config set-cluster cluster-gamma --embed-certs --certificate-authority=~/.kube/testing-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...
Forward traffic from port 8080 on all addresses to port 5432 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/log-aggregator-pod 8080: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 po...
Set a custom TLS server name for the "dev-cluster" cluster entry in the kubeconfig file.
Command: ```bash kubectl config set-cluster dev-cluster --tls-server-name=moon-cluster ``` 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] [--certificate-...
Create a role binding for jane.doe, bob.smith, and developers using the custom_role cluster role
Command: ```bash kubectl create rolebinding custom_role --clusterrole=custom_role --user=jane.doe --user=bob.smith --group=developers ``` 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=groupn...
Scale the resource specified in the "setup.json" file to 3 replicas
Command: ```bash kubectl scale --replicas=3 -f setup.json ``` 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 validated...
Set the CPU and memory limits for the Jenkins container in the deployment named "jenkins".
Command: ```bash kubectl set resources deployment jenkins -c=nginx --limits=cpu=3,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 it...
Create a pod disruption budget named api-service-pdb that selects all pods with the version=v2 label and requires at least four of them to be available at any point in time
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=version=v2 --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 [--...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/analytics-rc pods/email-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namesp...
Create a new config map named app-secrets with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Auto scale deployment "foo" with a minimum of 7 pods and a maximum of 11 pods.
Command: ```bash kubectl autoscale deployment foo --min=7 --max=11 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
Apply a taint to nodes with the label 'stack=tech-stack' where the taint key is 'zone' and the value is 'worker-node-3' with the effect of 'PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack zone=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Forward local port 9090 to port 6379 in the 'web-app-deployment' pod, and listen on port 6000 locally, forwarding data to/from port 6000 in the same pod.
Command: ```bash kubectl port-forward deployment/web-app-deployment 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 s...
Update the annotation 'last-deployment' of pod 'security' with the value '2023-03-15', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods security 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 ...
Create an ingress called 'internal-ingress' that redirects requests to website.com/module to service named svc1 on port 8081
Command: ```bash kubectl create ingress internal-ingress --rule="website.com/module=svc1:8081,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 job with a specific command to run
Command: ```bash kubectl create job monitoring-job --image=wordpress -- apache2ctl -D FOREGROUND ``` 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...
Listen on port 5000 on localhost and the IP address 10.19.21.23, forwarding the traffic to port 8000 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 5000: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 cr...
Execute the 'kafka-server-start /etc/kafka/server.properties' command in the first container of the 'analytics-platform-deployment' deployment and retrieve the output.
Command: ```bash kubectl exec deploy/analytics-platform-deployment -- kafka-server-start /etc/kafka/server.properties ``` 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"...