prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a deployment named "api" that runs the "ubuntu" image and exposes port 5001.
Command: ```bash kubectl create deployment api --image=ubuntu --port=5001 ``` 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...
Forward local port 5432 to port 6379 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 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 be selected automaticall...
Create a role named "default_role" that allows the user to perform "exec", "list", and "delete" actions on configmaps.
Command: ```bash kubectl create role default_role --verb=exec --verb=list --verb=delete --resource=configmaps ``` 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 fl...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/global-config deployment/analytics-platform-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 varia...
Import the 'config_file_path' key from the 'global-config' config map into the 'proxy-service-deployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/global-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 d...
Forward the traffic from the local port 5000 to the pod's port 8081 in the 'proxy-server-pod' pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 5000:8081 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Create a pod disruption budget named api-service-pdb that selects pods with the tier=frontend label and requires a minimum of 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget api-service-pdb --selector=tier=frontend --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 a pod and change all container images to php.
Command: ```bash kubectl debug mypod --copy-to=debug-image-web --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 is s...
Roll back the daemonset 'services' to revision 5
Command: ```bash kubectl rollout undo daemonset/services --to-revision=5 ``` 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 identifying th...
create a service for the python deployment, which serves on port 5432 and connects to the containers on port 8080
Command: ```bash kubectl expose deployment python --port=5432 --target-port=808000 ``` 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...
Create a debug version of the security-service-pod by adding a debug container and changing container images
Command: ```bash kubectl debug security-service-pod -it --copy-to=my-custom-dbg --image=debian --set-image=cache=redis:alpine,cache=redis:alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by res...
List the monitoring-pod in YAML format.
Command: ```bash kubectl get -o yaml pod 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 you will only see r...
Get the output from running the 'mysqld' command in the 'lunar-launcher' container of the 'monitoring-pod' pod
Command: ```bash kubectl exec monitoring-pod -c lunar-launcher -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Start a golang pod with the name 'nginx' and the golang image
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "legacy-1.0.0", "spec": { ... } }' ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [...
Listen on port 8888 on all addresses, and forward traffic to port 8080 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-pod 8888: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 wil...
Set up autoscaling for the 'proxy' deployment with a minimum of 4 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment proxy --min=4 --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 t...
Forward port 8888 to 8080 in the pod and listen on localhost and IP 10.19.21.23
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888: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 p...
Create a deployment named 'app' using the 'ubuntu' image and expose port 3000.
Command: ```bash kubectl create deployment app --image=ubuntu --port=3000 ``` 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 a priority class with the name "finance-priority" that prevents preemption of pods with lower priority
Command: ```bash kubectl create priorityclass finance-priority --value=250 --description="Priority for financial services and tasks" --preemption-policy="Never" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=V...
Execute 'go' command in the first pod of the 'email-service' service
Command: ```bash kubectl exec svc/email-service -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kube...
Copy the ~/.config/kube file from the remote pod "openfaas/payment-gateway-pod-19" to the local directory "/tmp/bar"
Command: ```bash kubectl cp openfaas/payment-gateway-pod-19:~/.config/kube :/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...
Add a taint with the key 'dedicated' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 dedicated=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a service for the replicated wordpress
Command: ```bash kubectl expose rc wordpress --port=9092 --target-port=500100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Forward local port 8888 to the target port of the service named "https" in the pod selected by the service named "backend-service"
Command: ```bash kubectl port-forward service/backend-service 8888: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...
Update the pod named 'payment' with the annotation 'expiration-date' and the value '2024-12-31', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods payment expiration-date='2024-12-31' ``` 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 a...
Create a cluster role named "admin_role" with the API Group specified as "networkpolicies.networking.k8s.io" and the verbs "proxy", "get", and "update".
Command: ```bash kubectl create clusterrole admin_role --verb=proxy,get,update --resource=networkpolicies.networking.k8s.io ``` 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 fl...
Return the snapshot logs from the container cache-cluster-deployment-1 of the deployment named chat-app-pod
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c chat-app-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: "fla...
Create a cluster role named "default_role" with the API Group specified, allowing the verbs list, create, and update on the replicasets.apps resource.
Command: ```bash kubectl create clusterrole default_role --verb=list,create,update --resource=replicasets.apps ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": ...
Update the pod named 'proxy-server' with the label 'role' and the value 'backend'
Command: ```bash kubectl label pods proxy-server role=backend ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usag...
Create a single ingress called 'private-api-ingress' that directs requests from foo.com/example to svc1:9091 and uses the TLS secret "my-cert"
Command: ```bash kubectl create ingress private-api-ingress --rule="foo.com/example=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": "", "...
Update the 'LoadBalancer' type of the node specified in the "node.json" file using the strategic merge patch, based on the information provided in the "containerd-config.toml" file.
Command: ```bash kubectl patch -f containerd-config.toml -p '{"spec":{"type":"LoadBalancer"}' ``` 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...
Provide a detailed description of all pods that have the label 'region' set to 'eu-west-2'
Command: ```bash kubectl describe po -l region=eu-west-2 ``` 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, prov...
Create a new secret named "docker-registry-secret" with keys for each file in the "path/to/data" folder
Command: ```bash kubectl create secret generic docker-registry-secret --from-file=path/to/data ``` 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 ...
Retrieve the resource configuration for the replica controller 'web', the service 'email-service-rc', and the pod 'e-commerce-pod'.
Command: ```bash kubectl get rc/web service/email-service-rc pods/e-commerce-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is names...
Create an ingress resource called 'app1-ingress' with a rule that directs requests for 'site.com/module' to the service 'svc1' on port 8443
Command: ```bash kubectl create ingress app1-ingress --rule="site.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": "", "usage":...
Create a cluster role named "reader" with the ability to create services and access to the "auth-service" and "file-storage" resources.
Command: ```bash kubectl create clusterrole reader --verb=create --resource=services --resource-name=auth-service --resource-name=file-storage ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Create an ingress resource called 'external-ingress' with a rule that directs requests to foo.com/module to svc1:9091
Command: ```bash kubectl create ingress external-ingress --rule="foo.com/module=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 information about specific resources by their type and names.
Command: ```bash kubectl get rc/web service/vpn-service-rc pods/email-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is name...
Create an ingress with a default backend
Command: ```bash kubectl create ingress ingdefault --class=default \ --default-backend=defaultsvc:http \ --rule="testing.com/*=svc:8083,tls=secret1" ``` 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": "...
Create a copy of the monitoring-pod called debug-image-api, changing all container images to busybox
Command: ```bash kubectl debug monitoring-pod --copy-to=debug-image-api --set-image=*=busybox ``` 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 ...
Set environment variables in a deployment by importing specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/app-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definition...
Create an ingress called 'rontend-ingress' that directs requests for 'testing.com/example' to a service named 'svc1' on port 5432, with a TLS secret named "my-cert".
Command: ```bash kubectl create ingress rontend-ingress --rule="testing.com/example=svc1:5432,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": "", "...
Set the CPU limits of the Kafka deployment container to "100m" and the memory limits to "64Mi"
Command: ```bash kubectl set resources deployment kafka -c=nginx --limits=cpu=100m,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, but may burst up to ...
Execute an 'irb' command inside the first pod of the deployment 'mydeployment' and get the output.
Command: ```bash kubectl exec deploy/mydeployment -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Drain the node named "foo", but only if all the pods running on it are managed by a replication controller, replica set, job, daemon set, or stateful set
Command: ```bash kubectl drain foo --grace-period=180 ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwis...
Update the annotation of the pod 'payment' with the 'compliance-level' key and the value 'PCI-DSS', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods payment compliance-level='PCI-DSS' ``` 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...
Update the 'authentication-service-deployment' deployment by setting a new environment variable named GOOGLE_API_KEY with the value of your Google API key.
Command: ```bash kubectl set env deployment/authentication-service-deployment GOOGLE_API_KEY=your-google-api-key ``` 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 ...
Attach to the cosmic-container in the email-service-pod to get its output
Command: ```bash kubectl attach email-service-pod -c cosmic-container ``` 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...
Start the nginx pod with the postgres image, using custom arguments arg1, arg2, ..., argN for the default command.
Command: ```bash kubectl run nginx --image=postgres -- <arg1> <arg2> ... <argN> ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags...
Delete a cluster configuration named kube-cluster-2
Command: ```bash kubectl config delete-cluster kube-cluster-2 ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Return the snapshot of the previous terminated logs from the 'ruby' container in the 'analytics-pod' pod.
Command: ```bash kubectl logs -p -c ruby 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", "short": "...
Create a copy of the e-commerce-pod and change all container images to mysql
Command: ```bash kubectl debug e-commerce-pod --copy-to=debug-image-1 --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 reso...
create a service for the 'centos' replica set that serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rs centos --port=5000 --target-port=909100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Create a copy of a pod with a debug container and change container images
Command: ```bash kubectl debug payment-gateway-pod -it --copy-to=debug-image-1 --image=debian --set-image=api=api:v2,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. P...
Create an ingress named 'website-ingress' with a rule that directs requests from site.com/example to svc1 at port 8000
Command: ```bash kubectl create ingress website-ingress --rule="site.com/example=svc1:8000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
List the API resources supported by Kubernetes, sorted by the 'namespaced' column.
Command: ```bash kubectl api-resources --sort-by=namespaced ``` What it does: Print the supported API resources on the server. Syntax: `kubectl api-resources` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: wide|name. "
Copy the file `/tmp/foo` from your local machine to the `/tmp/bar` directory within a specific container (`api-server-container`) in a remote pod (`payment-gateway-pod-19`).
Command: ```bash kubectl cp :/tmp/foo payment-gateway-pod-19:/tmp/bar -c api-server-container ``` 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 omi...
Get the output from running the 'npm --version' command in the first container of the 'load-balancer-deployment' deployment
Command: ```bash kubectl exec deploy/load-balancer-deployment -- npm --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 omit...
Import specific keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/ui-config 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 in one...
Set environment variables in a deployment from specific keys in a config map
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/db-config deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in on...
Create a pod disruption budget named worker-pdb that will select all pods with the role=worker label and require a minimum of 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget worker-pdb --selector=role=worker --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 an ingress that directs requests to a specific service and path with TLS enabled
Command: ```bash kubectl create ingress internal-ingress --rule="foo.com/example=svc1:8088,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...
Create a new LoadBalancer service named 'ingress-controller-lb' that listens on port 9091 and forwards traffic to port 9000
Command: ```bash kubectl create service loadbalancer ingress-controller-lb --tcp=9091:9000 ``` 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...
Return the snapshot of the previous terminated 'quantum-quark' container logs from the pod named 'frontend-pod'
Command: ```bash kubectl logs -p -c quantum-quark frontend-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", "s...
Execute the 'elasticsearch' command within the 'quantum-quark' container of the 'proxy-service-pod' pod and obtain the output.
Command: ```bash kubectl exec proxy-service-pod -c quantum-quark -- elasticsearch ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Run the command 'apk add curl' inside the email-service-pod and retrieve the output
Command: ```bash kubectl exec email-service-pod -- apk add curl ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Open the scheduler-service service for editing using the gedit editor
Command: ```bash KUBE_EDITOR="gedit" kubectl edit svc/scheduler-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 CPU limits of the 'mongo' deployment's 'nginx' container to "50m" and the memory limits to "2Gi"
Command: ```bash kubectl set resources deployment mongo -c=nginx --limits=cpu=50m,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, but may burst up to it...
Execute a 'bash' command in the 'cosmic-container' of the 'vpn-service-pod' pod and get the output.
Command: ```bash kubectl exec vpn-service-pod -c cosmic-container -- bash ``` 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, ...
Copy a directory from a remote pod to a local directory
Command: ```bash kubectl exec -n kube-flannel web-app-pod-1 -- tar cf - /tmp/foo_dir | tar xf - -C :/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": "Contain...
Create a copy of the email-service-pod and change all container images to node.
Command: ```bash kubectl debug email-service-pod --copy-to=my-custom-dbg --set-image=*=node ``` 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 re...
Create a job named 'cleanup' with the Alpine image, running the command 'ash'
Command: ```bash kubectl create job cleanup --image=alpine -- ash ``` 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 of: json...
Forward port 5432 on your local machine to port 8080 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-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 the criteria, a pod will be selected au...
Add a taint with the key 'special' on nodes that have the label role=database.
Command: ```bash kubectl taint node -l role=database special=backup-node-14: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":...
Check if you have permission to list the job named "log-rotation-job" in the "cert-manager" namespace
Command: ```bash kubectl auth can-i list jobs.batch/log-rotation-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 ...
Copy the local file /tmp/foo_dir to the /tmp/bar directory in the front-end-pod-12 pod in the cert-manager namespace.
Command: ```bash kubectl cp /tmp/foo_dir cert-manager/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...
Mark a node as schedulable
Command: ```bash kubectl uncordon gpu-node-12 ``` What it does: Mark node as schedulable. Syntax: `kubectl uncordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Expose a replica set named 'nginx' as a service, serving on port 5000, and connecting to the containers on port 909000.
Command: ```bash kubectl expose rs nginx --port=5000 --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. ...
Remove the label named 'bar' from the 'backend' pod
Command: ```bash kubectl label pods backend 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...
Update the pod 'chat-app' with the annotation 'alert-email' and set the value 'alerts@example.com', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods chat-app alert-email='alerts@example.com' ``` 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...
Open the user-service service for editing using the sublime editor
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/user-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 variables...
Import the "database_url" key from the "namespace-config" ConfigMap and set it as an environment variable in the "cache-cluster-deployment" deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/namespace-config 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...
Create a new config map with the specified keys using file contents from a specific location on disk
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/properties/file1.txt --from-file=data=/path/to/parameters/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 job "log-collection" using the image "node" and run the command "npm --version"
Command: ```bash kubectl create job log-collection --image=node -- npm --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...
Forward traffic between local ports 3000 and 6000 to ports 8888 and 6000 respectively in a pod selected by the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl port-forward deployment/monitoring-stack-deployment 3000 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 ...
Create an ingress named 'www-ingress' that routes requests from site.com/example to svc1:8084 and utilizes the tls secret "my-cert"
Command: ```bash kubectl create ingress www-ingress --rule="site.com/example=svc1:8084,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Forward local port 6379 to port 3000 in the pod named api-service-pod.
Command: ```bash kubectl port-forward pod/api-service-pod 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 will be selected au...
delete pods and services with names "proxy" and "analytics"
Command: ```bash kubectl delete pod,service proxy analytics ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector....
Create a copy of the `analytics-pod` with a debug container and modified container images
Command: ```bash kubectl debug analytics-pod -it --copy-to=my-custom-dbg --image=debian --set-image=api=api:v2,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Set the custom TLS server name "prod-cluster" for the "app-cluster" cluster entry
Command: ```bash kubectl config set-cluster app-cluster --tls-server-name=prod-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-...
Set the client-key field of the system entry in the kubeconfig file to the value of the ~/.kube/admin.key file, without modifying any other values.
Command: ```bash kubectl config set-credentials system --client-key=~/.kube/admin.key ``` 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 flag...
Create a service for a python deployment that serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment python --port=8888 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Update the image of all containers in the daemonset "prod" to "amazonlinux:2"
Command: ```bash kubectl set image daemonset prod *=amazonlinux:2 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubec...
Execute the 'wp' command inside the first pod of the 'email-server-deployment' deployment and display the output.
Command: ```bash kubectl exec deploy/email-server-deployment -- wp ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Update the 'api-server-deployment' deployment by adding a new environment variable LOG_LEVEL with a value of "info"
Command: ```bash kubectl set env deployment/api-server-deployment LOG_LEVEL=info ``` 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 (wi...
Embed the certificate authority data for the "galaxy-cluster" cluster entry.
Command: ```bash kubectl config set-cluster galaxy-cluster --embed-certs --certificate-authority=~/.kube/my-k8s-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config...
Import the DATABASE_URL key from the config map called db-config into the deployment named api-server-deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/db-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 definitions ...
Run the 'postgres' command in the 'code-explorer' container of the 'vpn-service-pod' pod
Command: ```bash kubectl exec vpn-service-pod -c code-explorer -- 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,...
Create a pod disruption budget named frontend-pdb that selects all pods with the component=web label and requires a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget frontend-pdb --selector=component=web --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--...
Expose a replication controller defined in a YAML file using the specified ports
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=3306 --target-port=909100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...