prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Unset the namespace in the team-beta-context context
Command: ```bash kubectl config unset contexts.team-beta-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...
Retrieve the details of a specific context in your kubeconfig file.
Command: ```bash kubectl config get-contexts admin-context ``` What it does: Display one or many contexts from the kubeconfig file. Syntax: `kubectl config get-contexts [(-o|--output=)name)]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: name "
Forward traffic from port 5432 on your local machine to port 3000 in the pod named chat-app-pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 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 selected autom...
Create a copy of the "auth-service-pod" and change all container images to "mysql" for debugging purposes
Command: ```bash kubectl debug auth-service-pod --copy-to=dgb-img --set-image=*=mysql ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource...
Create an ingress named 'app-proxy-ingress' with a rule that directs requests from testing.com/input to the service 'svc1:9090'
Command: ```bash kubectl create ingress app-proxy-ingress --rule="testing.com/input=svc1:9090,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "...
Check if you have permissions to list the job named "report-generation-job" in the namespace "kube-system"
Command: ```bash kubectl auth can-i list jobs.batch/report-generation-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 part...
Generate a Kubernetes manifest for the configuration directory located at /home/config/dev
Command: ```bash kubectl kustomize /home/config/dev ``` 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 DIR is...
Delete both the 'proxy' pod and service, as well as the 'payment' pod and service.
Command: ```bash kubectl delete pod,service proxy payment ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. S...
Create a copy of a pod, changing all container images to php for debugging.
Command: ```bash kubectl debug chat-app-pod --copy-to=my-debugger --set-image=*=php ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resource i...
Create a new config map named app-config with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config --from-file=properties=/path/to/data/file1.txt --from-file=key1=/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 ...
Start a proxy to the Kubernetes API server on port 7000, serving static content from the ./local/www/ directory
Command: ```bash kubectl proxy --port=7000 --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...
Port forward ports 6379 and 6000 from your local machine to ports 3000 and 6000 in the selected pod of the deployment.
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 6379 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 ...
Create a pod disruption budget named auth-service-pdb that selects all pods with the version=v2 label and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=version=v2 --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 job named "image-build-job" with the image "mysql" and run the command "mysql" inside the job
Command: ```bash kubectl create job image-build-job --image=mysql -- mysql ``` 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...
Add new exec auth plugin args for the "dev-user" entry
Command: ```bash kubectl config set-credentials dev-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 role named "reader" with the ability to delete pods and specific resources named "monitoring-prometheus"
Command: ```bash kubectl create role reader --verb=delete --resource=pods --resource-name=monitoring-prometheus --resource-name=monitoring-prometheus ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--...
Forward port 5432 on all addresses to port 6379 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-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 the criteria, a pod will...
Create a service for a replicated node, which serves on port 7000 and connects to the containers on port 8080.
Command: ```bash kubectl expose rc node --port=7000 --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 port. A...
View the details of the specified resources by their type and names.
Command: ```bash kubectl get rc/web service/auth-service-rc pods/vpn-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 names...
Create a role named "admin_role" with the ability to patch pods and specific resource names such as "auth-service" and "keycloak-server".
Command: ```bash kubectl create role admin_role --verb=patch --resource=pods --resource-name=auth-service --resource-name=keycloak-server ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=serv...
Forward local port 8088 to port 8088 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Run the command 'apache2ctl -D FOREGROUND' inside the pod 'monitoring-pod' and get the output
Command: ```bash kubectl exec monitoring-pod -- apache2ctl -D FOREGROUND ``` 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, u...
Forward port 9090 on all addresses to port 8888 in the analytics-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 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 wil...
Execute the 'dotnet --list-sdks' command inside the payment-gateway-pod to get the output, using the first container by default.
Command: ```bash kubectl exec payment-gateway-pod -- dotnet --list-sdks ``` 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...
Copy the directory /tmp/foo_dir from the remote file-server-pod-14 pod to the local /tmp/bar directory.
Command: ```bash kubectl cp kube-node-lease/file-server-pod-14:/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...
Forward traffic from local port 3000 to the targetPort of the "https" port in the pod selected by the "search-service" service
Command: ```bash kubectl port-forward service/search-service 3000:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selecte...
Create a secret named password-secret using files from the path/to/settings folder
Command: ```bash kubectl create secret generic password-secret --from-file=path/to/settings ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basename of ...
Create a cron job named 'report-generation' with the image 'ethereum/client-go' that runs the command 'geth' every minute.
Command: ```bash kubectl create cronjob report-generation --image=ethereum/client-go --schedule="*/1 * * * *" -- geth ``` 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", "sh...
Forward traffic from all addresses on port 5000 to port 3000 in the frontend-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5000: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...
Create an ingress named 'myapp-ingress' with a rule that directs requests from 'foo.com/input' to service 'svc1' on port 5000
Command: ```bash kubectl create ingress myapp-ingress --rule="foo.com/input=svc1:5000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": ...
Add a taint with key 'special' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 special=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": "", "usage": "O...
Delete the pods and services with the names "log-aggregator" and "api"
Command: ```bash kubectl delete pod,service log-aggregator 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 select...
Create a deployment named "jenkins" using the "amazonlinux" image and expose port number 3001.
Command: ```bash kubectl create deployment jenkins --image=amazonlinux --port=3001 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One...
Import the specific key 'REDIS_HOST' from the 'app-name-config' config map and set it as an environment variable for the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-name-config deployment/backend-microservice-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
Approve a certificate signing request (CSR) with the name 'csr-kubelet-14'.
Command: ```bash kubectl certificate approve csr-kubelet-14 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the att...
Create a job named 'database-seeding-job' with the image 'jenkins' and the command 'java -jar /usr/share/jenkins/jenkins.war'
Command: ```bash kubectl create job database-seeding-job --image=jenkins -- java -jar /usr/share/jenkins/jenkins.war ``` 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", "...
Create a job named log-collection using the centos image, and run the command "yum install -y wget" within the job
Command: ```bash kubectl create job log-collection --image=centos -- yum install -y wget ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Outp...
import the SMTP_SERVER key from the config map named "app-name-config" into the deployment named "order-processing-deployment"
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/app-name-config deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create an ingress called 'service-ingress' that directs requests from 'website.com/input' to service 'svc1' on port '8082', and use the TLS secret 'my-cert' for secure communication.
Command: ```bash kubectl create ingress service-ingress --rule="website.com/input=svc1:8082,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...
Forward traffic from port 8088 on all addresses to port 5432 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 8088: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 sel...
Partially update a node by applying a YAML patch
Command: ```bash kubectl patch node kube-master-9 -p $'spec:\n containers:\n- name: container-name\n resources:\n limits:\n cpu: 200m' ``` 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...
Forward port 6379 on all addresses to port 5000 in the pod
Command: ```bash kubectl port-forward --address 0.0.0.0 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 po...
Return the snapshot of previous terminated 'lunar-launcher' container logs from the 'media-stream-pod' pod.
Command: ```bash kubectl logs -p -c lunar-launcher media-stream-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container...
Create a new LoadBalancer service named web-app-lb, which maps port 5000 on the LoadBalancer to port 9092 on the pods
Command: ```bash kubectl create service loadbalancer web-app-lb --tcp=5000:9092 ``` 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", "default...
Get the output from running the 'redis-server' command in the 'nano-bot' container from the 'email-service-pod' pod.
Command: ```bash kubectl exec email-service-pod -c nano-bot -- redis-server ``` 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...
Mark the node "kube-master-9" as unschedulable.
Command: ```bash kubectl cordon kube-master-9 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Port forward from localhost and selected IP to the pod's port 8080, where the source port is 5432.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/security-service-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 th...
List the replication controller named "e-commerce-rc" in the ps output format.
Command: ```bash kubectl get replicationcontroller e-commerce-rc ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will o...
create a new config map named 'app-secrets' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-secrets --from-file=properties=/path/to/profiles/file1.txt --from-file=key1=/path/to/options/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...
Retrieve the logs of the previously terminated 'nebula-navigator' container from the 'monitoring-pod' pod.
Command: ```bash kubectl logs -p -c nebula-navigator monitoring-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...
delete pods and services with names "chat-app" and "email"
Command: ```bash kubectl delete pod,service chat-app email ``` 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. ...
Forward local port 5432 to port 5432 in a pod selected by the 'notification-handler-deployment' deployment.
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 5432 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 ...
Create a pod disruption budget named 'frontend-pdb' that will select all pods with the 'project=my-project' label and require a minimum of 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget frontend-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=...
Forward local port 8088 to port 8888 in the pod "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 8088 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 select...
Get the output from running the 'ash' command in the first container of the first pod of the user-management-deployment deployment.
Command: ```bash kubectl exec deploy/user-management-deployment -- ash ``` 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...
Retrieve logs from the pod named 'backend-pod' that were written within the last hour.
Command: ```bash kubectl logs --since=1h backend-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c...
Create a secret named ssl-key-secret using a file and a literal value
Command: ```bash kubectl create secret generic ssl-key-secret --from-file=ssh-privatekey=path/to/id_rsa --from-literal=passphrase=topsecret ``` 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 ...
Run the 'mysqld' command in the cosmic-container from the pod auth-service-pod
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- 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 omitte...
Remove all taints with key 'cpu-type' from node 'dev-node-4'
Command: ```bash kubectl taint nodes dev-node-4 cpu-type- ``` 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...
Forward local port 5432 to the targetPort of service "https" in the pod selected by the service "payment-service"
Command: ```bash kubectl port-forward service/payment-service 5432:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=secret_key --from=configmap/app-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...
Listen on port 8000 locally and forward the traffic to port 8888 in the backend-pod
Command: ```bash kubectl port-forward pod/backend-pod 8000: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 automa...
Set the CPU limit of the PostgreSQL container in the deployment to "1" and the memory limit to "256Mi".
Command: ```bash kubectl set resources deployment postgres -c=nginx --limits=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, but may burst up to...
Create a config map named "app-secrets" with specified keys from file contents on disk
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a...
Describe all pods that have the label 'cluster=my-cluster'
Command: ```bash kubectl describe po -l cluster=my-cluster ``` 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 that type, pr...
Expose the hazelcast deployment as a service on port 5001, connecting to containers on port 8080.
Command: ```bash kubectl expose deployment hazelcast --port=5001 --target-port=808300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the spec...
Remove the 'role' label from the 'proxy-server' pod
Command: ```bash kubectl label pods proxy-server 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...
Open the `payment-service` service for editing using the "notepad" editor as an alternative to the default editor.
Command: ```bash KUBE_EDITOR="notepad" kubectl edit svc/payment-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment variab...
Set the service account of the 'scheduler-app-deployment' deployment to 'default'.
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment default ``` 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: `kube...
Create a copy of the payment-gateway-pod with all container images changed to php for debugging
Command: ```bash kubectl debug payment-gateway-pod --copy-to=debug-image-1 --set-image=*=php ``` 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 service for a replicated CentOS using a replica set, which will serve on port 8443 and connect to the containers on port 8080.
Command: ```bash kubectl expose rs centos --port=8443 --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 port....
Import the specific keys "external_api_url" from the config map "app-settings" into the deployment "cache-cluster-deployment"
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-settings deployment/cache-cluster-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...
Add the taint with key 'zone' and value 'storage-node-13:PreferNoSchedule' on the nodes that have the label 'project=project-alpha'
Command: ```bash kubectl taint node -l project=project-alpha zone=storage-node-13:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Create a new config map named log-config with the specified keys conf and data, using the files file1.txt and file2.txt located at /path/to/preferences/ and /path/to/properties/ respectively.
Command: ```bash kubectl create configmap log-config --from-file=conf=/path/to/preferences/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 ...
Create a deployment named 'prometheus' using the 'nginx' image, and expose port 5000 for the deployment
Command: ```bash kubectl create deployment prometheus --image=nginx --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...
Update pod 'database' with description 'my frontend running nginx' only if the resource is unchanged from version 1
Command: ```bash kubectl annotate pods database description='my frontend running nginx' --resource-version=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...
Create a new ExternalName service named external-security-service
Command: ```bash kubectl create service externalname external-security-service --external-name governmental-demo.gov ``` 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 referen...
Add a taint with key 'dedicated' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice dedicated=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": "", "...
Create a new config map with the name "app-secrets" using the properties from the folder located at "path/to/properties"
Command: ```bash kubectl create configmap app-secrets --from-file=path/to/properties ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basenam...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/global-config deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Attach to a running pod and switch to a raw terminal mode
Command: ```bash kubectl attach proxy-service-pod -c cosmic-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....
Create a pod running the golang image, and customize the pod specifications using a JSON override file.
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "feature-branch-2.3.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] [--comma...
Update the image of all containers in the daemonset named 'prod' to 'ruby:3.0.2'
Command: ```bash kubectl set image daemonset prod *=ruby:3.0.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: `kubectl ...
Remove the 'bar' label from the 'email' pod
Command: ```bash kubectl label pods email app- ``` 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, c...
Add the label 'app: myapp' to the pod 'web'
Command: ```bash kubectl label pods web 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": "If true...
Add the annotation 'deployment-script' with the value 'https://example.com/deploy.sh' to the pod named 'vpn'
Command: ```bash kubectl annotate pods vpn deployment-script='https://example.com/deploy.sh' ``` 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 lab...
Create a cluster role named "reader" with an AggregationRule specified
Command: ```bash kubectl create clusterrole reader --aggregation-rule="rbac.example.com/aggregate-to-security=true" ``` 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: "fl...
Get the output from the lunar-launcher container in the security-service-pod pod
Command: ```bash kubectl attach security-service-pod -c lunar-launcher ``` 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 o...
Create a single ingress named 'api-v1-ingress' that directs requests from foo.com/module to svc1:9092
Command: ```bash kubectl create ingress api-v1-ingress --rule="foo.com/module=svc1:9092,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"...
Create a role named "default_role" with the API Group specified as "clusterroles.rbac.authorization.k8s.io" and set the verbs to "list", "create", and "connect".
Command: ```bash kubectl create role default_role --verb=list,create,connect --resource=clusterroles.rbac.authorization.k8s.io ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|n...
Begin streaming the logs of the 'quantum-quark' container in the 'analytics-pod' pod.
Command: ```bash kubectl logs -f -c quantum-quark analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "...
Roll back the deployment in namespace-1, performing a dry run to simulate the process.
Command: ```bash kubectl rollout undo --dry-run=server deployment/namespace-1 ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifyi...
Execute the command 'python --version' in the pod named 'chat-app-pod' using the container 'nano-bot' and display the output.
Command: ```bash kubectl exec chat-app-pod -c nano-bot -- python --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create a pod named "hazelcast" using the Centos image and expose port 8083 on the container.
Command: ```bash kubectl run hazelcast --image=centos --port=8083 ``` 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...
Forward traffic from port 5000 to port 8888 on a specific pod, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 5000:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Auto scale the deployment named "vpn" with a minimum of 6 pods and a maximum of 10 pods
Command: ```bash kubectl autoscale deployment vpn --min=6 --max=10 ``` 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...
Copy the ~/.config/kube local file to /tmp/bar in the remote pod named 'file-server-pod-14' in the 'metallb-system' namespace
Command: ```bash kubectl cp ~/.config/kube metallb-system/file-server-pod-14:/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, us...
Create a new ClusterIP service named database-service-clusterip with TCP port mapping from 6379 to 9090.
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=6379:9090 ``` 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...
Set the cpu limit of the 'nginx' container in the 'redis' deployment to "100m" and the memory limit to "512Mi".
Command: ```bash kubectl set resources deployment redis -c=nginx --limits=cpu=100m,memory=512Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to...
List the specified replication controller in ps output format
Command: ```bash kubectl get replicationcontroller database-rc ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will onl...