prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Retrieve the logs from the container database-pod-1 in the email-server-deployment-1 of the deployment named "database-pod"
Command: ```bash kubectl logs deployment/email-server-deployment -c database-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: "flag...
Update the cluster role binding for kube-controller-manager by adding the service account `namespace:kube-controller-manager` as a subject for the `admin` role.
Command: ```bash kubectl set subject clusterrolebinding admin --serviceaccount=namespace:kube-controller-manager ``` What it does: Update the user, group, or service account in a role binding or cluster role binding. Syntax: `kubectl set subject (-f FILENAME | TYPE NAME) [--user=username] [--group=groupname] [--servi...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=SECRET_KEY --from=configmap/app-config-dev deployment/web-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions ...
Remove all taints with key 'zone' from node 'worker-node-3'
Command: ```bash kubectl taint nodes worker-node-3 zone- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|na...
Partially update the configuration of a node using a strategic merge patch provided as a YAML file
Command: ```bash kubectl patch node storage-node-13 -p $'spec:\n rules:\n- http:\n paths:\n - path: /\n backend:\n service:\n name: new-service' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted....
Set the cluster for a specific context
Command: ```bash kubectl config set contexts.local-context.cluster my-k8s-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Create a copy of the 'chat-app-pod' pod with a debug container and change the container images
Command: ```bash kubectl debug chat-app-pod -it --copy-to=debug-image-1 --image=debian --set-image=proxy=nginx:1.21,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 and name. Po...
Add a taint with the key 'workload' to nodes that have the label tier=frontend
Command: ```bash kubectl taint node -l tier=frontend workload=kube-master-9: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 the MAX_CONNECTIONS key from the app-config config map into the order-processing-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-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 de...
Add a taint with key 'zone' on nodes having the label 'stack=tech-stack'
Command: ```bash kubectl taint node -l stack=tech-stack zone=edge-node-10: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 copy of the 'e-commerce-pod' pod, changing the command of the 'quantum-quark' container to run a shell session in the 'debug-image-app' container.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-app --container=quantum-quark -- sh ``` 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 ...
Create a single ingress called 'app-gateway-ingress' that directs requests to site.com/module and forwards them to svc1:9092 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app-gateway-ingress --rule="site.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": "", "...
Forward traffic from port 8000 on all addresses to port 8081 in the pod named e-commerce-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8000: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 wi...
Switch to raw terminal mode for the 'web-app-pod' pod, using the container 'stardust-shuttle'
Command: ```bash kubectl attach web-app-pod -c stardust-shuttle -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 om...
Create a priority class named emergency-priority with a value of 200000 and a description of "Immediate, emergency resource allocation".
Command: ```bash kubectl create priorityclass emergency-priority --value=200000 --description="Immediate, emergency resource allocation" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BO...
Run the 'postgres' command inside the 'security-service-pod' pod and get the output
Command: ```bash kubectl exec security-service-pod -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Create a deployment named jenkins-x with the wordpress image and expose port 5000.
Command: ```bash kubectl create deployment jenkins-x --image=wordpress --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...
Forward port 8888 in a pod to port 9090 locally
Command: ```bash kubectl port-forward pod/frontend-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 will be selected autom...
Begin streaming the logs of the 'quantum-quark' container in the 'backend-pod' pod.
Command: ```bash kubectl logs -f -c quantum-quark 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", "sh...
Create a job with a command
Command: ```bash kubectl create job audit-job --image=redis -- redis-cli ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Create an ingress called 'website-ingress' that routes requests for foo.com/example to svc1:5001 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="foo.com/example=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": "", "usag...
View the details of revision 5 for the daemonset 'namespace-1' by using the command 'kubectl rollout history daemonset/namespace-1 --revision=5'
Command: ```bash kubectl rollout history daemonset/namespace-1 --revision=5 ``` What it does: View previous rollout revisions and configurations. Syntax: `kubectl rollout history (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or UR...
Import the `database_url` key from the `env-vars` ConfigMap into the `proxy-service-deployment` Deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/env-vars 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...
Add a taint with the key 'dedicated' on nodes that have the label app=web-app with the value dedicated=dev-node-4:PreferNoSchedule
Command: ```bash kubectl taint node -l app=web-app dedicated=dev-node-4:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Ou...
Retrieve the output of the 'geth version' command from the nebula-navigator container running in the e-commerce-pod pod.
Command: ```bash kubectl exec e-commerce-pod -c nebula-navigator -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If om...
Display the details of the replication controller "web", the service "vpn-service-rc", and the pod "cdn-service-pod".
Command: ```bash kubectl get rc/web service/vpn-service-rc pods/cdn-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namesp...
Create a new NodePort service named monitoring-nodeport that maps port 5000 on the node to port 6379 in the service.
Command: ```bash kubectl create service nodeport monitoring-nodeport --tcp=6379:5000 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default": ...
Get output from lunar-launcher in the proxy-server-pod
Command: ```bash kubectl attach proxy-server-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 omitt...
Create an ingress named 'service-ingress' that directs requests to testing.com/module to svc1:9090 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/module=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": "", "u...
set the CPU limits of the nginx container in the nginx deployment to "10" and the memory limits to "4Gi"
Command: ```bash kubectl set resources deployment nginx -c=nginx --limits=cpu=10,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested, but may burst up to its...
Create a single ingress named 'rontend-ingress' that routes requests from 'site.com/input' to 'svc1:9092' using the TLS secret 'my-cert'
Command: ```bash kubectl create ingress rontend-ingress --rule="site.com/input=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...
View the logs of the previously terminated nebula-navigator container from the pod proxy-service-pod
Command: ```bash kubectl logs -p -c nebula-navigator proxy-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": "--contai...
Forward traffic from local port 8081 to port 8081 in the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Update the environment variable 'QUEUE_NAME' with the value 'task-queue' for the deployment 'load-balancer-deployment'
Command: ```bash kubectl set env deployment/load-balancer-deployment QUEUE_NAME=task-queue ``` 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 tem...
Create a new ClusterIP service named 'shipping-service-clusterip' that maps port 7000 on the cluster to port 5001 on the service.
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=7000:5001 ``` 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...
List deployments in JSON output format, using the "beta-1.0" version of the "api-v1" API group.
Command: ```bash kubectl get deployments.beta-1.0.api-v1 -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will o...
Forward local port 9090 to port 5000 in the pod selected by the authentication-service-deployment deployment.
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 9090 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, ...
Get the output of running the 'nginx -g "daemon off;"' command inside the media-stream-pod pod.
Command: ```bash kubectl exec media-stream-pod -- nginx -g "daemon off;" ``` 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...
Update the 'payment' pod by setting the annotation 'release-notes' with the value 'https://example.com/release-notes/v2.5.1'.
Command: ```bash kubectl annotate pods payment release-notes='https://example.com/release-notes/v2.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 larg...
Rename the context 'local-context' to 'client-1-context' in your kubeconfig file.
Command: ```bash kubectl config rename-context local-context client-1-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will al...
Create a role named "default_role" with API Group specified
Command: ```bash kubectl create role default_role --verb=list,create,update --resource=cronjobs.batch ``` 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|none]` Helpful flags: "fl...
Forward local port 8080 to the target port of the "https" service in the selected pod, and listen locally.
Command: ```bash kubectl port-forward service/web-service 8080:https ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Return the snapshot logs from the container web-app-deployment-1 of the deployment named gateway-pod
Command: ```bash kubectl logs deployment/web-app-deployment -c gateway-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: "flag": "--...
Switch to raw terminal mode; send stdin to 'bash' in mycontainer from pod frontend-pod and send stdout/stderr from 'bash' back to the client
Command: ```bash kubectl attach frontend-pod -c mycontainer -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 omitte...
Forward port 5432 on localhost and IP address 10.19.21.23 to port 8000 in the 'e-commerce-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 5432:8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the crit...
Set the resource request and limits for all containers in the 'python' deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=1,memory=2Gi ``` 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,...
Start a pod with custom specifications from JSON override
Command: ```bash kubectl run nginx --image=mcr.microsoft.com/dotnet/core/runtime --overrides='{ "apiVersion": "dev-2.2.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=i...
Set the custom TLS server name to "app-cluster" for the "cluster-gamma" cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=app-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate...
Update the taint of a node with a specific key, value, and effect
Command: ```bash kubectl taint nodes monitoring-node-15 special=backup: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 for...
Forward port 9090 to port 8080 on the cdn-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 9090: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 w...
Create a role named "custom_role" with the ability to patch pods and specifically named resources "nginx-proxy" and "database-master"
Command: ```bash kubectl create role custom_role --verb=patch --resource=pods --resource-name=nginx-proxy --resource-name=database-master ``` 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...
Import specific keys from a config map:
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/kube-system-config deployment/search-engine-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...
Create a pod disruption budget named batch-processing-pdb that will select all pods with the region=us-east label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget batch-processing-pdb --selector=region=us-east --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-availa...
Create a job called "scaling-job" using the MySQL image and run the command "mysql --version"
Command: ```bash kubectl create job scaling-job --image=mysql -- mysql --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output forma...
Create a pod disruption budget named "web-app-pdb" that will select all pods with the "region=us-east" label and require at least one of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget web-app-pdb --selector=region=us-east --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 [--...
Get the output from running the 'nginx' command on the first pod of the proxy-service-deployment deployment, using the first container by default.
Command: ```bash kubectl exec deploy/proxy-service-deployment -- nginx ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use...
View the previous terminated logs of the "cyber-sleuth" container from the "chat-app-pod" pod.
Command: ```bash kubectl logs -p -c cyber-sleuth 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", "sh...
Execute the 'geth version' command on the proxy-service-pod and display the output.
Command: ```bash kubectl exec proxy-service-pod -- geth version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Create a new NodePort service named proxy-server-nodeport that exposes port 27017 on the node and forwards traffic to port 5432 on the pods.
Command: ```bash kubectl create service nodeport proxy-server-nodeport --tcp=27017:5432 ``` What it does: Create a NodePort service with the specified name. Syntax: `kubectl create service nodeport NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "default...
Display the environment variables configured for the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env deployment/order-processing-deployment --list ``` 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 (with...
Create a deployment named "registry" with the image "node" and specify the command "node"
Command: ```bash kubectl create deployment registry --image=node -- node ``` 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|...
Create an ingress called 'app2-ingress' that routes requests from website.com/example to svc1:7000 using a TLS secret named "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/example=svc1:7000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Start a PHP pod and expose port 8088
Command: ```bash kubectl run hazelcast --image=php --port=8088 ``` 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": "--file...
Create a deployment named logging that runs the centos image and exposes port 8181
Command: ```bash kubectl create deployment logging --image=centos --port=8181 ``` 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: ...
create a service for a replicated nginx using replica set, which serves on port 3000 and connects to the containers on port 9090
Command: ```bash kubectl expose rs nginx --port=3000 --target-port=909000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. ...
Forward port 8088 on all addresses to port 8888 in a specific pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-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 ...
List resources (replication controller, service, and pods) by their type and names
Command: ```bash kubectl get rc/web service/backend-rc pods/monitoring-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 namespaced ...
Listen on port 8000 on your local machine and forward the traffic to port 9090 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward pod/web-app-pod 8000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a cron job named "cleanup-task" that runs the command "dotnet --list-runtimes" every minute.
Command: ```bash kubectl create cronjob cleanup-task --image=mcr.microsoft.com/dotnet/core/runtime --schedule="*/1 * * * *" -- dotnet --list-runtimes ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpfu...
Forward port 8080 on localhost and IP 10.19.21.23 to port 6379 in the pod named "frontend-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/frontend-pod 8080: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 criter...
Stream the logs of the "lunar-launcher" container in the "api-service-pod" pod.
Command: ```bash kubectl logs -f -c lunar-launcher api-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"...
Copy a local file to a remote pod in a specific namespace.
Command: ```bash kubectl cp /tmp/foo_dir ingress-nginx/worker-pod-4::/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...
Execute the command 'apache2ctl -D FOREGROUND' inside the container 'mycontainer' of the pod 'database-pod'
Command: ```bash kubectl exec database-pod -c mycontainer -- 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. ...
Start a postgres pod named nginx, using the postgres image and overload the spec with a partial set of values parsed from the provided JSON object
Command: ```bash kubectl run nginx --image=postgres --overrides='{ "apiVersion": "beta-1.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] [--command] -- [CO...
Create a job named "certificate-renewal" using the Ethereum client-go image, and run the command "geth version" inside the job container.
Command: ```bash kubectl create job certificate-renewal --image=ethereum/client-go -- geth 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": "", "usa...
Create an ingress called 'api-gateway-ingress' that directs requests to 'testing.com/example' to 'svc1:9000' with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/example=svc1:9000,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": "...
import the 'debug_mode' key from the 'api-config' config map and set it as an environment variable in the 'monitoring-stack-deployment' deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/api-config deployment/monitoring-stack-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 definit...
Forward the traffic between ports 5432 and 8000 on your local machine to the corresponding ports on a pod selected by the 'web-app-deployment' deployment.
Command: ```bash kubectl port-forward deployment/web-app-deployment 5432 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be s...
Configure the OpenID Connect authentication provider for the "system" entry with additional arguments
Command: ```bash kubectl config set-credentials system --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: --clie...
Display the merged kubeconfig settings and raw certificate data
Command: ```bash kubectl config view --raw ``` 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: "flag": "--output", "short": "-o", "default": "yaml"...
Create a new config map named log-config using the specified files
Command: ```bash kubectl create configmap log-config --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Create a single ingress named 'api-v1-ingress' that directs requests from website.com/input to svc1:9092 with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/input=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": "", "usa...
Copy the file ~/.config/kube to the container named 'task-processor' in the pod 'file-server-pod-14' and place it in the /tmp/bar directory.
Command: ```bash kubectl cp ~/.config/kube file-server-pod-14::/tmp/bar -c task-processor ``` 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...
Update the image of the container named "kubernetes-serve-hostname" in the pod with the name "gateway-pod" to "new image".
Command: ```bash kubectl patch pod gateway-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 FILENAME...
Set a custom TLS server name for the "prod-cluster" cluster entry in the kubeconfig file.
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=e2e ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certificate-authorit...
Import specific keys from a config map into a deployment's environment variables.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-secrets deployment/mydeployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Create a cluster role named "reader" with the ability to list configmaps and only access the specific resources named "notification-service" and "search-elasticsearch"
Command: ```bash kubectl create clusterrole reader --verb=list --resource=configmaps --resource-name=notification-service --resource-name=search-elasticsearch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-r...
Partially update a node using strategic merge patch by specifying the type and name in a JSON file and providing the patch data.
Command: ```bash kubectl patch -f node.json -p '{"stringData":{"password":"new-password"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` ...
Forward traffic from a local port to port 6379 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod :6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automatica...
Scale the 'payment-service-rs' deployment to 3 replicas if its current size is 7
Command: ```bash kubectl scale --current-replicas=7 --replicas=3 deployment/payment-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-...
Create a deployment named mattermost that runs the python image and exposes port 7000
Command: ```bash kubectl create deployment mattermost --image=python --port=7000 ``` 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 o...
Create an ingress called 'www-ingress' with a rule that directs requests to foo.com/input to the service 'svc1' on port 3001
Command: ```bash kubectl create ingress www-ingress --rule="foo.com/input=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Copy the local file /tmp/foo to the remote pod kube-flannel/monitoring-agent-pod-6 in the namespace, and save it as /tmp/bar.
Command: ```bash kubectl cp /tmp/foo kube-flannel/monitoring-agent-pod-6:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use th...
Add a taint with key 'zone' on nodes having the label 'service=auth'
Command: ```bash kubectl taint node -l service=auth zone=k8s-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...
Attach to a pod and get output from a specific container
Command: ```bash kubectl attach vpn-service-pod -c mycontainer ``` 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 omitted, ...
Add a new environment variable 'DB_USER=username' to the deployment 'order-processing-deployment'
Command: ```bash kubectl set env deployment/order-processing-deployment DB_USER=username ``` 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 templ...
Create an ingress called 'private-service-ingress' that directs requests to website.com/input to svc1:8082 with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-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":...
Copy local file to remote pod in specific container
Command: ```bash kubectl cp :/tmp/foo metrics-exporter-pod-10:/tmp/bar_dir -c monitoring-agent ``` 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 om...
Create an ingress called 'app-proxy-ingress' with a rule that directs requests from testing.com/input to the service 'svc1' on port '8080'
Command: ```bash kubectl create ingress app-proxy-ingress --rule="testing.com/input=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": "", "...
List the replication controller "web", service "media-stream-rc", and pod "backend-pod"
Command: ```bash kubectl get rc/web service/media-stream-rc pods/backend-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 namespace...