prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a cluster role named "custom_role" with specific resource names
Command: ```bash kubectl create clusterrole custom_role --verb=use --resource=configmaps --resource-name=file-uploader --resource-name=machine-learning ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serv...
Scale the replica set named 'api-service-rs' to 5 replicas
Command: ```bash kubectl scale --replicas=5 rs/api-service-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 valid...
Create a new ClusterIP service named inventory-service-clusterip, mapping port 3001 on the service to port 8080 on the pod
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=3001:8080 ``` 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 pod disruption budget named elastic-search-pdb that will select all pods with the release=1.0.0 label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=release=1.0.0 --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...
Forward local port 8088 to port 5000 of the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8088 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 a...
Forward traffic from port 8888 on localhost and IP 10.19.21.23 to port 8888 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/proxy-server-pod 8888:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cr...
Set the service account of the deployment order-processing-deployment to metrics-server
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment metrics-server ``` 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 Syn...
Remove all taints with key 'disktype' from node 'testing-node-11'
Command: ```bash kubectl taint nodes testing-node-11 disktype- ``` 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...
Create a cron job named database-maintenance with the image set to postgres
Command: ```bash kubectl create cronjob database-maintenance --image=postgres --schedule="*/1 * * * *" -- pg_dump --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": "--output...
Import environment variables from a secret for a specific deployment
Command: ```bash kubectl set env --from=secret/oauth-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 po...
Create a new config map named app-config using specified keys and file paths
Command: ```bash kubectl create configmap app-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/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 co...
Create a new LoadBalancer service named 'analytics-lb' with the TCP port mapping 27017:5001.
Command: ```bash kubectl create service loadbalancer analytics-lb --tcp=27017:5001 ``` 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...
Remove the 'disktype' taint with the 'NoSchedule' effect from the node 'web-node-8', if it exists
Command: ```bash kubectl taint nodes web-node-8 disktype: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 of: ...
Create a job named "cleanup" using the "golang" image, and run the "go version" command
Command: ```bash kubectl create job cleanup --image=golang -- go 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. One o...
Remove the label 'bar' from pod 'foo'
Command: ```bash kubectl label pods foo role- ``` 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 true, ch...
Update the container image for the 'php' deployment, setting the 'busybox' container image to 'busybox' and the 'php' container image to 'php:7.4.22'
Command: ```bash kubectl set image deployment/php busybox=busybox php=php:7.4.22 ``` 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) ...
Create a job with a command
Command: ```bash kubectl create job testing --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": "Output ...
Import the specific key 'config_file_path' from the 'ui-config' config map into the 'user-management-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/ui-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 def...
Retrieve the password for the 'e2e' user by running the command 'kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}'
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "e2e")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpful flags: "...
Add a taint with key 'workload' on nodes having label owner=john-doe
Command: ```bash kubectl taint node -l owner=john-doe workload=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": ...
Listen on port 9090 locally and forward the traffic to port 5432 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-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 will be selected autom...
Set the resource request and limits for all containers in the 'golang' deployment
Command: ```bash kubectl set resources deployment golang --limits=cpu=200m,memory=512Mi --requests=cpu=3,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...
Enable the OpenID Connect auth provider for the "developer" entry with the provided arguments: set the client ID to "foo" and the client secret to "bar" for the developer entry.
Command: ```bash kubectl config set-credentials developer --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: --c...
Create a deployment with the name "jenkins-x" using the nginx image
Command: ```bash kubectl create deployment jenkins-x --image=nginx ``` 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|n...
Display the most recent 43 lines of logs for the pod named payment-gateway-pod.
Command: ```bash kubectl logs --tail=43 payment-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", "shor...
Start a pod named nginx using the image 'confluentinc/cp-kafka', but override some of the specifications with a partial set of values taken from the provided JSON.
Command: ```bash kubectl run nginx --image=confluentinc/cp-kafka --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] [...
Retrieve the phase value of a specific pod
Command: ```bash kubectl get -o template pod/frontend-pod --template={{.status.phase}} ``` 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...
Update the image of the container named "kubernetes-serve-hostname" in the pod named "cdn-service-pod" with the new image specified.
Command: ```bash kubectl patch pod cdn-service-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}' ``` 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 FILE...
Retrieve the snapshot logs for the container named "vpn-service-pod-1" in the deployment named "backend-microservice-deployment"
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c vpn-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 f...
Forward local port 9090 to port 8888 in a pod selected by the 'database-deployment' deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 9090 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be ...
Check if the current user has the permission to list the specified job in the given namespace
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n cert-manager ``` 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 ...
Set the service account for the deployment "payment-processor-deployment" to "istio".
Command: ```bash kubectl set serviceaccount deployment payment-processor-deployment istio ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `ku...
Create a debug container for the 'frontend-pod' and make a copy of it called 'my-custom-dbg'
Command: ```bash kubectl debug frontend-pod -it --copy-to=my-custom-dbg --image=debian --set-image=api=api:v2,database=mysql:5.7 ``` 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. ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-secrets deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Remove the "client-secret" value for the OpenID Connect auth provider configuration for the "security-user" entry
Command: ```bash kubectl config set-credentials security-user --auth-provider=oidc --auth-provider-arg=client-secret- ``` 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 --clie...
Retrieve the status phase of the pod named 'vpn-service-pod'
Command: ```bash kubectl get -o template pod/vpn-service-pod --template={{.status.phase}} ``` 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...
Forward local ports 5432 and 6000 to ports 8088 and 6000 in a selected pod from the database-deployment deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 5432 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 ...
Set environment variables in a deployment by importing specific keys from a config map.
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/global-config deployment/email-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable de...
Copy the file "/tmp/foo" from the remote pod "web-app-pod-1" in the namespace "istio-system" to the local directory "/tmp/bar".
Command: ```bash kubectl cp istio-system/web-app-pod-1::/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 kubec...
Attach to a specific container in a pod and interact with it in raw terminal mode
Command: ```bash kubectl attach e-commerce-pod -c astro-container -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 ...
Switch to the context for the kube-cluster-2 cluster
Command: ```bash kubectl config use-context kube-cluster-2 ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Begin streaming the logs of the "lunar-launcher" container in the "email-service-pod" pod
Command: ```bash kubectl logs -f -c lunar-launcher 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": "--containe...
Forward traffic from port 5000 on all addresses to port 9090 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 5000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Update the image of all containers in the 'services' daemonset to 'ubuntu:20.04'
Command: ```bash kubectl set image daemonset services *=ubuntu:20.04 ``` 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: `ku...
Update the 'vpn' pod with the annotation 'app-version' and set its value to '2.5.1', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods vpn app-version='2.5.1' ``` 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 ar...
Create a pod disruption budget named cron-jobs-pdb that will select all pods with the app=rails label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cron-jobs-pdb --selector=app=rails --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 [--dry...
Create a deployment named "worker" with the Centos image and run the bash command inside the deployment.
Command: ```bash kubectl create deployment worker --image=centos -- bash ``` 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|...
Start streaming the logs of the 'ruby' container in the pod named 'chat-app-pod'
Command: ```bash kubectl logs -f -c ruby 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": "-...
Create a job named "testing" using the Ubuntu image and run the command "docker run -it ubuntu"
Command: ```bash kubectl create job testing --image=ubuntu -- docker run -it ubuntu ``` 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 fo...
Copy the local file /tmp/foo_dir to the /tmp/bar directory in the logging-agent-pod-7 pod in the kube-flannel namespace.
Command: ```bash kubectl cp /tmp/foo_dir kube-flannel/logging-agent-pod-7::/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 ...
Forward local port 5000 to port 5000 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 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 selected automa...
Create a pod disruption budget named statefulset-pdb that will select all pods with the release=1.0.0 label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget statefulset-pdb --selector=release=1.0.0 --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 copy of the proxy-service-pod with a debug container and attach to it
Command: ```bash kubectl debug proxy-service-pod -it --image=busybox --copy-to=my-custom-dbg ``` 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 r...
Create a single ingress called 'rontend-ingress' that directs requests to testing.com/bar to svc svc1:9091 with a tls secret "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="testing.com/bar=svc1:9091,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...
Get the output from running the 'mongo --version' command in the 'quantum-quark' container of the 'analytics-pod' pod
Command: ```bash kubectl exec analytics-pod -c quantum-quark -- 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 omi...
Scale a replica set to a specific number of replicas
Command: ```bash kubectl scale --replicas=5 rs/staging-app-rs ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is valid...
Import the EXTERNAL_API_URL key from the namespace-config ConfigMap and set it as an environment variable in the proxy-service-deployment deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/namespace-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 variabl...
Set the resource request and limits for a python deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=100m,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 reque...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/monitoring-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 defin...
Update the taint on a specific node to mark it as high-priority workload with a NoSchedule effect.
Command: ```bash kubectl taint nodes worker-node-3 workload=high-priority: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 ...
Forward local ports to a pod's ports
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Create a single ingress called 'service-ingress' that directs requests to website.com/module to svc1:8443 with a tls secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="website.com/module=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": "", "u...
Embed the certificate authority data for the "prod-cluster" cluster entry.
Command: ```bash kubectl config set-cluster prod-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 copy of a pod called "monitoring-pod" with a debug container, and change the image of the "logger" container to "logging-app:debug" and the image of the "scheduler" container to "my-scheduler:1.0"
Command: ```bash kubectl debug monitoring-pod -it --copy-to=debug-image-web --image=debian --set-image=logger=logging-app:debug,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identif...
Forward port 8088 on localhost and IP 10.19.21.23 to port 8088 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Forward local port to a port in the pod
Command: ```bash kubectl port-forward pod/mypod 8080:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Expose a deployment called "centos" by creating a service that listens on port 9000 and connects to the containers on port 8082.
Command: ```bash kubectl expose deployment centos --port=9000 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Listen on port 8888 on localhost and IP 10.19.21.23, and forward the traffic to port 8088 within the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8888: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 crit...
Forward local port 3000 to port 5432 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 3000: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 will be selected au...
Copy the local file ~/.config/kube to the /tmp/bar directory in the front-end-pod-12 pod in the prometheus namespace.
Command: ```bash kubectl cp ~/.config/kube prometheus/front-end-pod-12:/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 ...
Add a taint with key 'zone' on nodes having label stack=tech-stack
Command: ```bash kubectl taint node -l stack=tech-stack zone=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Embed the certificate authority data for the star-cluster cluster entry, with the certificate authority file located at "~/.kube/e2e/kubernetes.ca.crt".
Command: ```bash kubectl config set-cluster star-cluster --embed-certs --certificate-authority=~/.kube/e2e/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-cluster ...
Create a service for the replication controller specified in the "ubuntu-controller.yaml" file
Command: ```bash kubectl expose -f ubuntu-controller.yaml --port=9092 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Create a cluster role named "custom_role" with access to specific resource names
Command: ```bash kubectl create clusterrole custom_role --verb=list --resource=configmaps --resource-name=audit-logger --resource-name=content-delivery ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=serv...
Execute the 'node' command in the 'cyber-sleuth' container of the 'cdn-service-pod' pod
Command: ```bash kubectl exec cdn-service-pod -c cyber-sleuth -- node ``` 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 ...
Set the context cluster to a specific value
Command: ```bash kubectl config set contexts.staging-context.cluster data-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 ...
Create a new config map named app-settings with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/profiles/file1.txt --from-file=data=/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 con...
Add a taint with the key 'zone' and value 'gpu-node-12:PreferNoSchedule' on nodes that have the label 'app-type=microservice'
Command: ```bash kubectl taint node -l app-type=microservice zone=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...
Create a pod disruption budget named 'notification-service-pdb' that will select all pods with the 'owner=team-1' label and require at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget notification-service-pdb --selector=owner=team-1 --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-avai...
Scale the deployment named 'baz' from 5 replicas to 3 replicas
Command: ```bash kubectl scale --current-replicas=5 --replicas=3 deployment/baz ``` 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 priority class named 'backend-priority' with a value of 1000 and a preemption policy of 'Never'
Command: ```bash kubectl create priorityclass backend-priority --value=1000 --description="Priority for backend processing workloads" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=...
Create a new config map named global-config using the contents of the configs folder located at path/to/configs.
Command: ```bash kubectl create configmap global-config --from-file=path/to/configs ``` 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 basename...
Create an ingress called 'app-gateway-ingress' that directs requests to 'website.com/bar' to 'svc1:5001' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="website.com/bar=svc1:5001,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 new ClusterIP service named payment-service-clusterip that maps port 6379 on the service to port 8089 on the pods.
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=6379:8089 ``` 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"...
Create a new namespace called 'kube-ingress'
Command: ```bash kubectl create namespace kube-ingress ``` What it does: Create a namespace with the specified name. Syntax: `kubectl create namespace NAME [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|name|go-template|go-t...
Create a deployment named "registry" using the nginx image.
Command: ```bash kubectl create deployment registry --image=nginx ``` 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|na...
Forward port 6379 on all addresses to port 5432 in the pod named 'api-service-pod', and listen for incoming connections on all IP addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 6379: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...
Create a debug container of web-app-pod, copying it to debug-image-app and changing the container images for scheduler and api.
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-app --image=debian --set-image=scheduler=my-scheduler:1.0,api=api:v2 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Set the cluster field in the Staging context to "galaxy-cluster"
Command: ```bash kubectl config set contexts.staging-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 yo...
Check if the user has permission to list the "load-testing-job" job in the "kube-system" namespace
Command: ```bash kubectl auth can-i list jobs.batch/load-testing-job -n kube-system ``` 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 U...
Scale a resource to a specific number of replicas based on a configuration file
Command: ```bash kubectl scale --replicas=5 -f config.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 validate...
Forward local port 3000 to port 6379 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 3000: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 auto...
Set up autoscaling for the deployment "database", with a minimum of 3 pods and a maximum of 14 pods
Command: ```bash kubectl autoscale deployment database --min=3 --max=14 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Return the snapshot logs from the container vpn-service-pod-1 of the email-server-deployment deployment.
Command: ```bash kubectl logs deployment/email-server-deployment -c vpn-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 flags: "f...
Create a debug copy of 'mypod' by adding a 'debug' container and changing the container images
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-api --image=debian --set-image=scheduler=my-scheduler:1.0,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 resource a...
Create a new LoadBalancer service named 'proxy-service-lb' that will forward traffic from port 8010 to port 6379
Command: ```bash kubectl create service loadbalancer proxy-service-lb --tcp=8010:6379 ``` 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", "d...
Create a deployment named 'registry' with the 'php' image and expose port '5000'
Command: ```bash kubectl create deployment registry --image=php --port=5000 ``` 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: js...
Add a taint with the key 'zone' and value 'web-node-8:PreferNoSchedule' on nodes having the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta zone=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": "", "usage": "Output...
Use kubectl kustomize command to build the shared configuration directory located at /home/config/production.
Command: ```bash kubectl kustomize /home/config/production ``` What it does: Build a set of KRM resources using a 'kustomization.yaml' file. The DIR argument must be a path to a directory containing 'kustomization.yaml', or a git repository URL with a path suffix specifying same with respect to the repository root. If...
Forward traffic from port 8080 on localhost and IP address 10.19.21.23 to port 5000 in the e-commerce-pod pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8080: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 crit...