prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a cron job named "system-health-check" with a command to run every minute using the "golang" image.
Command: ```bash kubectl create cronjob system-health-check --image=golang --schedule="*/1 * * * *" -- go ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", ...
Forward local traffic on port 8888 to port 5000 in a pod selected by the 'notification-handler-deployment' deployment.
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 8888 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 ...
List all deployments in the "custom-version" version of the "testing-apps" API group in JSON output format.
Command: ```bash kubectl get deployments.custom-version.testing-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 namespace...
Start a new pod named hazelcast using the node image, and expose port 9091
Command: ```bash kubectl run hazelcast --image=node --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": "--fil...
Create a new config map named env-vars using specified files
Command: ```bash kubectl create configmap env-vars --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/path/to/settings/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...
Copy the file '/tmp/foo' from the remote pod 'file-server-pod-14' in the 'kube-server' cluster to the local directory '/tmp/bar'
Command: ```bash kubectl cp kube-server/file-server-pod-14::/tmp/foo /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Create a pod disruption budget named 'monitoring-pdb' that will select all pods with the 'app=rails' label and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=app=rails --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 [--dr...
Remove the taints with key 'workload' from node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 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|y...
Configure autoscaling for the replication controller "web" with a target CPU utilization of 81% and a minimum of 1 pod and a maximum of 5 pods.
Command: ```bash kubectl autoscale rc web --max=5 --cpu-percent=81 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses the...
List deployments in the "rc-1.1.0" version of the "extensions" API group in YAML output format
Command: ```bash kubectl get deployments.rc-1.1.0.extensions -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 wi...
Verify if you have permission to list the job named "data-migration-job" in the namespace "development"
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n development ``` 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...
Embed certificate authority data for the cluster-alpha cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/edge-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 se...
Create a new ExternalName service with the name "external-authentication-service" and set its external name to "bar.com"
Command: ```bash kubectl create service externalname external-authentication-service --external-name bar.com ``` 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...
Create a cluster role named "admin_role" with the specified NonResourceURL of "/proxy/*" and the verb "update"
Command: ```bash kubectl create clusterrole "admin_role" --verb=update --non-resource-url=/proxy/* ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", ...
Update the label of the pod 'media-stream' by setting the 'app' label to 'myapp'
Command: ```bash kubectl label pods media-stream app=myapp ``` 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":...
Listen on port 8081 on localhost and IP 10.19.21.23, forwarding traffic to port 5000 in the specified pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8081: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 cri...
Create a Pod Disruption Budget named 'notification-service-pdb' that will select all pods with the 'app=nginx' label and require at least 50% of the selected pods to be available at any point in time.
Command: ```bash kubectl create pdb notification-service-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-ru...
Create a job named 'log-processing-job' using the 'ruby' image, and run the command 'ruby --version' inside the job container.
Command: ```bash kubectl create job log-processing-job --image=ruby -- ruby --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 ...
Define new exec auth plugin arguments for the "api-user" entry.
Command: ```bash kubectl config set-credentials api-user --exec-arg=arg1 --exec-arg=arg2 ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token f...
Create a copy of the vpn-service-pod, add a debug container with the image debian, and change the container images for mailer to mailer:latest and cache to redis:alpine.
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-1 --image=debian --set-image=mailer=mailer:latest,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resour...
Interact with a pod's shell in raw terminal mode
Command: ```bash kubectl attach analytics-pod -c rocket-ranger -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Copy the local file '/tmp/foo' to the remote pod 'task-processor-pod-17' in the container 'ingress-controller' at the path '/tmp/bar'
Command: ```bash kubectl cp :/tmp/foo task-processor-pod-17:/tmp/bar -c ingress-controller ``` 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 omitte...
Copy the local file /var/run/secrets/kubernetes.io/serviceaccount/ to the remote pod velero/ingress-controller-pod-8 in the /tmp/bar_dir directory.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ velero/ingress-controller-pod-8:/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...
Get the output from running the 'redis-server --version' command on the first pod of the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl exec deploy/backend-microservice-deployment -- redis-server --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": "Contain...
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/log-config 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 definitio...
Mark node "db-node-7" as schedulable
Command: ```bash kubectl uncordon db-node-7 ``` 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 "
Import specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=SMTP_SERVER --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 o...
Create a golang pod and expose port 9092.
Command: ```bash kubectl run hazelcast --image=golang --port=9092 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Check if the current user has permission to list the job named "cleanup-job" in the "kube-ingress" namespace
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-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 partial URL t...
Scale the deployment named "foo" from 3 replicas to 1 replica
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/foo ``` 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...
Start a hazelcast pod with the image "hazelcast/hazelcast", but override the pod spec with a partial set of values parsed from JSON
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "v3.0.0", "spec": { ... } }' ``` 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] [--comman...
Import the specific keys 'config_file_path' from the config map 'app-settings' into the deployment 'authentication-service-deployment'
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-settings 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 va...
Get the description of a specific node
Command: ```bash kubectl describe nodes backup-node-18.backup-farm.net ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of t...
Get the output from running the 'yum install -y aws-cli' command in the cosmic-container from the email-service-pod pod.
Command: ```bash kubectl exec email-service-pod -c cosmic-container -- yum install -y aws-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": "Containe...
Get the output of running the 'python' command in the 'quantum-quark' container from the 'backend-pod' pod.
Command: ```bash kubectl exec backend-pod -c quantum-quark -- python ``` 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...
Copy the file '/tmp/foo' from the remote pod named 'security-scanner-pod-18' in the 'cert-manager' namespace to the local directory '/tmp/bar_dir'.
Command: ```bash kubectl cp cert-manager/security-scanner-pod-18:/tmp/foo /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, u...
set environment variables in a deployment using a secret
Command: ```bash kubectl set env --from=secret/aws-credentials-secret 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 definitions in one or mo...
Import specific keys from a config map into the environment of a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/log-config 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 definitio...
Expose a replica set named "alpine" as a service, serving on port 9091 and connecting to the containers on port 800000.
Command: ```bash kubectl expose rs alpine --port=9091 --target-port=800000 ``` 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....
Update the service account of the frontend-deployment deployment to "dashboard"
Command: ```bash kubectl set serviceaccount deployment frontend-deployment dashboard ``` 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...
Run a proxy to the Kubernetes API server on port 9000, serving static content from the specified directory
Command: ```bash kubectl proxy --port=9000 --www=./local/www/ ``` What it does: Creates a proxy server or application-level gateway between localhost and the Kubernetes API server. It also allows serving static content over specified HTTP path. All incoming data enters through one port and gets forwarded to the remote...
Update the 'mydeployment' deployment by setting the environment variable SMTP_PASSWORD to 'your-password'
Command: ```bash kubectl set env deployment/mydeployment 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 templates...
View the resource utilization metrics for all pods with the label "release=beta"
Command: ```bash kubectl top pod -l release=beta ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `kubectl top pod [NAME | -l...
Import the keys 'smtp_server' from the 'app-secrets' config map and set them as environment variables for the 'database-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-secrets 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 i...
Forward local port 8081 to port 8081 in the specified pod
Command: ```bash kubectl port-forward pod/api-service-pod 8081: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 au...
Expose the service for the specified replication controller with the given configuration.
Command: ```bash kubectl expose -f alpine-controller.yaml --port=8083 --target-port=800000 ``` 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...
Add a taint with key 'environment' on nodes having label role=database
Command: ```bash kubectl taint node -l role=database environment=db-node-7:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Start a ruby pod named 'hazelcast' with the image 'ruby' and expose port 3000
Command: ```bash kubectl run hazelcast --image=ruby --port=3000 ``` 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": "--fil...
Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment nginx --port=8088 --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 specifie...
Create an ingress called 'public-api-ingress' with a rule that directs requests from 'site.com/input' to 'svc1:3306', and use the TLS secret "my-cert".
Command: ```bash kubectl create ingress public-api-ingress --rule="site.com/input=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "us...
Set the certificate authority data for the 'web-cluster' cluster entry
Command: ```bash kubectl config set-cluster web-cluster --embed-certs --certificate-authority=~/.kube/sun-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-c...
Delete the pods and services with the names "email" and "web"
Command: ```bash kubectl delete pod,service email web ``` 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 an ingress called 'www-ingress' that directs requests for 'foo.com/module' to service 'svc1' on port '3306' using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/module=svc1:3306,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Watch the logs of a specific container in a pod
Command: ```bash kubectl logs -f -c mycontainer 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": "--container", ...
Create a copy of a pod with a debug container and change container images
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-memcached --image=debian --set-image=mailer=mailer:latest,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
Scale a resource to 1 based on the configuration file "docker-registry.yaml"
Command: ```bash kubectl scale --replicas=1 -f docker-registry.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...
Create a new config map named "app-name-config" using the environment variables defined in the file "path/to/configs.env"
Command: ```bash kubectl create configmap app-name-config --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 th...
Listen on port 8081 locally, forwarding to port 8080 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8081:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Create a service for a WordPress deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment wordpress --port=8083 --target-port=500000 ``` 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...
Update the pod 'media-stream' with the label 'release' and set the value to 'v2.0'
Command: ```bash kubectl label pods media-stream release=v2.0 ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usag...
Set the service account of the deployment named "gateway-deployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment gateway-deployment 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 s...
Create a deployment named 'proxy' that runs the 'confluentinc/cp-kafka' image
Command: ```bash kubectl create deployment proxy --image=confluentinc/cp-kafka ``` 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:...
Add a taint with the key 'special' and value 'worker-node-3:PreferNoSchedule' on nodes that have the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 special=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...
Create a single ingress called 'public-ingress' that directs requests to site.com/module to svc1:8080 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="site.com/module=svc1:8080,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 to a pod
Command: ```bash kubectl port-forward pod/backend-pod 8088 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 automa...
create a LoadBalancer service named e-commerce-lb that forwards traffic from port 8089 to port 8181.
Command: ```bash kubectl create service loadbalancer e-commerce-lb --tcp=8089:8181 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "defa...
Start the amazonlinux pod named nginx using a different command and custom arguments
Command: ```bash kubectl run nginx --image=amazonlinux --command -- <cmd> <arg1> ... <argN> ``` 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...]` H...
Set resource limits and requests for all containers in php deployment
Command: ```bash kubectl set resources deployment php --limits=cpu=200m,memory=512Mi --requests=cpu=100m,memory=1Gi ``` 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,...
Create a deployment named 'jenkins-x' using the nginx image, and expose port 27017.
Command: ```bash kubectl create deployment jenkins-x --image=nginx --port=27017 ``` 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...
List specific resources by their type and names
Command: ```bash kubectl get rc/web service/auth-service-rc pods/e-commerce-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...
Switch to raw terminal mode and attach to the code-explorer container in the security-service-pod.
Command: ```bash kubectl attach security-service-pod -c code-explorer -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
set resource requests and limits for all containers in the mongo deployment
Command: ```bash kubectl set resources deployment mongo --limits=cpu=200m,memory=512Mi --requests=cpu=1,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...
Forward traffic from port 8088 on localhost and IP 10.19.21.23 to port 3000 in the pod named cdn-service-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8088: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 cri...
Create a new config map named app-config-prod from the key-value pairs in the file "path/to/settings"
Command: ```bash kubectl create configmap app-config-prod --from-file=path/to/settings ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basen...
Import the EXTERNAL_API_URL key from the app-name-config ConfigMap and set it as an environment variable in the log-aggregator-deployment deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-name-config 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 variabl...
Start a Jenkins pod with some custom specifications using a partial set of values parsed from a JSON object
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "hotfix-1.1.2", "spec": { ... } }' ``` 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] -- ...
Create a service for the replicated ubuntu pods on port 80, connecting to the containers on port 8000.
Command: ```bash kubectl expose rc ubuntu --port=7000 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Import the specific keys 'EXTERNAL_API_URL' from the config map 'app-settings' into the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-settings deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definiti...
Taint nodes with label 'namespace=mynamespace' with a taint key 'cpu-type' and value 'web-node-8:PreferNoSchedule'
Command: ```bash kubectl taint node -l namespace=mynamespace cpu-type=web-node-8: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...
Add a taint with the key 'hardware' and value 'gpu-node-12:PreferNoSchedule' to nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 hardware=gpu-node-12: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": ...
Attach to the 'nebula-navigator' container in the 'media-stream-pod' pod to view its output
Command: ```bash kubectl attach media-stream-pod -c nebula-navigator ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Unset the namespace for the cluster-2-context context.
Command: ```bash kubectl config unset contexts.cluster-2-context.namespace ``` What it does: Unset 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. Syntax: `kubectl config unset PROPERTY_N...
Create a service for the 'hazelcast' replicated controller by exposing port 8181, which will be connected to the containers on port 808800.
Command: ```bash kubectl expose rc hazelcast --port=8181 --target-port=808800 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Create a service for a replicated nginx, which serves on port 3000 and connects to the containers on port 300000
Command: ```bash kubectl expose rc nginx --port=3000 --target-port=300000 ``` 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. ...
Set the cluster field in the context "prod-context" to "galaxy-cluster"
Command: ```bash kubectl config set contexts.prod-context.cluster galaxy-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 w...
Add a taint with the key 'zone' and value 'node-1:PreferNoSchedule' on nodes that have the label 'app=web-app'.
Command: ```bash kubectl taint node -l app=web-app zone=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": "Output form...
Set the custom TLS server name to 'kube-cluster-2' for the 'cluster-beta' cluster entry
Command: ```bash kubectl config set-cluster cluster-beta --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] [--certifica...
Forward local port 6379 to port 5000 in the 'chat-app-pod' pod
Command: ```bash kubectl port-forward pod/chat-app-pod 6379:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Forward traffic from port 8081 to port 5432 in the pod named "proxy-server-pod", listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8081: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 ...
Create a job with a specified command to be executed.
Command: ```bash kubectl create job audit-job --image=ethereum/client-go -- geth attach ``` 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": "Outpu...
Create a new config map with specified keys and files
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/data/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 config ...
Create a pod disruption budget named "worker-pdb" that selects all pods with the label "project=my-project" and ensures that at least 9 of them are available at any given time.
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=project=my-project --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 ...
Create a service for the replication controller specified in "node-controller.yaml" file, which listens on port 8089 and forwards traffic to the containers on port 909100.
Command: ```bash kubectl expose -f node-controller.yaml --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 s...
Add a taint with key 'special' and value 'prod-node-5:PreferNoSchedule' on nodes having the label 'component=proxy'
Command: ```bash kubectl taint node -l component=proxy special=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": "", "usage": ...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=log_level --from=configmap/namespace-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 defin...
Import specific keys from a config map into an environment variable of a deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-dev 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 ...
Update the label of pod 'api' to include 'tier=database'
Command: ```bash kubectl label pods api tier=database ``` 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 ...
delete the pods and services named "analytics" and "database"
Command: ```bash kubectl delete pod,service analytics database ``` 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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-name-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 de...
Create a service for a replicated alpine using replica set, serving on port 80 and connecting to the containers on port 8000.
Command: ```bash kubectl expose rs alpine --port=8000 --target-port=300000 ``` 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....