prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a new ClusterIP service named 'shipping-service-clusterip' that directs traffic from port 8080 to port 8181
Command: ```bash kubectl create service clusterip shipping-service-clusterip --tcp=8080:8181 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o...
Create a new config map named app-name-config from the specified files
Command: ```bash kubectl create configmap app-name-config --from-file=settings=/path/to/profiles/file1.txt --from-file=key2=/path/to/profiles/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creatin...
Create a new secret named 'tls-certificate-secret' using the environment variables defined in the 'path/to/properties.env' file.
Command: ```bash kubectl create secret generic tls-certificate-secret --from-env-file=path/to/properties.env ``` 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...
Add a taint with key 'zone' on nodes having label zone=us-east-1
Command: ```bash kubectl taint node -l zone=us-east-1 zone=node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output f...
Update the image of all containers in the 'services' daemonset to 'redis:6.2.5'
Command: ```bash kubectl set image daemonset services *=redis:6.2.5 ``` 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: `kub...
Get the output from running the 'composer --version' command in the nano-bot container in the pod api-service-pod.
Command: ```bash kubectl exec api-service-pod -c nano-bot -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Add a taint with a key 'datacenter' on nodes having label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace datacenter=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Forward local port 8080 to port 8081 in the pod named "security-service-pod"
Command: ```bash kubectl port-forward pod/security-service-pod 8080: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 select...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/kube-system-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 var...
Embed the client certificate data from the `~/.kube/admin.crt` file into the "system" entry using the `kubectl config set-credentials` command.
Command: ```bash kubectl config set-credentials system --client-certificate=~/.kube/admin.crt --embed-certs=true ``` 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-ke...
Add an annotation to the pod named 'web' with the key 'description' and the value 'Web server for marketing site'
Command: ```bash kubectl annotate pods web description='Web server for marketing site' ``` 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 an...
Set the cluster field in the context to a specific cluster
Command: ```bash kubectl config set contexts.cloud-context.cluster web-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 wan...
Import the 'API_KEY' key from the 'app-config-dev' config map into the 'cache-cluster-deployment' deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-dev 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 definitio...
Delete the pods and services with the names "log-aggregator" and "monitoring"
Command: ```bash kubectl delete pod,service log-aggregator monitoring ``` 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...
List deployments in YAML format using the "v2.0.0" version of the "beta-apps" API group
Command: ```bash kubectl get deployments.v2.0.0.beta-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will ...
Set the cluster field in the 'team-alpha-context' context to 'dev-cluster'
Command: ```bash kubectl config set contexts.team-alpha-context.cluster dev-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/log-config deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable def...
Create a service for the replicated hazelcast resource named 'hazelcast', which serves on port 8084 and connects to the containers on port 808200.
Command: ```bash kubectl expose rc hazelcast --port=8084 --target-port=808200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Create an ingress called 'service-ingress' that directs requests to foo.com/input to 'svc1' on port 9000, using the TLS secret "my-cert".
Command: ```bash kubectl create ingress service-ingress --rule="foo.com/input=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": "", "usage"...
Autoscale the replication controller "foo" with a minimum of 1 and a maximum of 5 pods, targeting a CPU utilization of 40%.
Command: ```bash kubectl autoscale rc foo --max=5 --cpu-percent=40 ``` 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...
Forward traffic from local port 8081 to port 9090 in the cdn-service-pod pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 8081: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 au...
Set specific environment variables from a config map for a deployment
Command: ```bash kubectl set env --keys=external_api_url --from=configmap/app-config-dev 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 defin...
Create a new ingress resource named 'api-v1-ingress' and add a rule that directs requests to 'testing.com/example' to the service 'svc1' on port 8084
Command: ```bash kubectl create ingress api-v1-ingress --rule="testing.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": "", "u...
List deployments in the "custom-apps" API group with the version "stable-2.0.0" and display the output in YAML format.
Command: ```bash kubectl get deployments.stable-2.0.0.custom-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced y...
Create a debug session for the analytics-pod, copying it to a new debug image called debug-image-memcached, and targeting the quantum-quark container.
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-memcached --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 use...
Show the resource usage metrics for the app-node-6 node
Command: ```bash kubectl top node app-node-6 ``` What it does: Display resource (CPU/memory) usage of nodes. The top-node command allows you to see the resource consumption of nodes. Syntax: `kubectl top node [NAME | -l label]` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (la...
Attach to a specific container in a pod and enter the raw terminal mode.
Command: ```bash kubectl attach security-service-pod -c quantum-quark -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....
Import specific keys from a config map
Command: ```bash kubectl set env --keys=CONFIG_FILE_PATH --from=configmap/namespace-config deployment/load-balancer-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variabl...
Forward traffic from local port 9090 to port 8000 in the pod named 'chat-app-pod'
Command: ```bash kubectl port-forward pod/chat-app-pod 9090: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 selected autom...
Import the 'database_url' key from the 'env-vars' ConfigMap into the 'backend-microservice-deployment' deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/env-vars 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 variable def...
Execute the 'wp' command in the first container of the 'notification-handler-deployment' deployment
Command: ```bash kubectl exec deploy/notification-handler-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,...
Create an ingress with a default backend and a rule for the domain "testing.com"
Command: ```bash kubectl create ingress ingdefault --class=default \ --default-backend=defaultsvc:http \ --rule="testing.com/*=svc:27017,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 new ExternalName service named external-logging-service with the external name travel-sample.travel
Command: ```bash kubectl create service externalname external-logging-service --external-name travel-sample.travel ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference...
Set the server field for the cluster-alpha cluster entry to "https://1.2.3.4" without modifying any other values.
Command: ```bash kubectl config set-cluster cluster-alpha --server=https://1.2.3.4 ``` 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-auth...
Forward local traffic from port 6379 to port 8081 in the specified pod
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379 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...
Set the server field on the kube-cluster-2 cluster to a specific URL
Command: ```bash kubectl config set clusters.kube-cluster-2.server https://1.2.3.4 ``` 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...
Forward port 8081 on all addresses to port 5432 in the pod named "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8081:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a job named test-job based on the cron job named daily-report
Command: ```bash kubectl create job test-job --from=cronjob/daily-report ``` 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 a copy of the "proxy-server-pod" pod, with the command of "quantum-quark" container changed for debugging, interactively.
Command: ```bash kubectl debug proxy-server-pod -it --copy-to=dgb-img --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 defaul...
create a service that exposes the replicated wordpress using a replica set, on port 5432, and connects to the containers on port 888800
Command: ```bash kubectl expose rs wordpress --port=5432 --target-port=888800 ``` 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 traffic from port 8088 to port 6379 in the pod named "security-service-pod" and make it accessible on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 8088:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
View the supported non-namespaced resources
Command: ```bash kubectl api-resources --kindspaced=false ``` 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. "
Forward local port 8088 to port 8888 in the pod named "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...
Set the CPU limits for the Elasticsearch container in the deployment to "100m" and the memory limits to "512Mi".
Command: ```bash kubectl set resources deployment elasticsearch -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 bur...
Add a taint with key 'hardware' on nodes having label app-type=microservice
Command: ```bash kubectl taint node -l app-type=microservice hardware=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default":...
Enter interactive mode and attach to a specific container in a pod to interact with it
Command: ```bash kubectl attach gateway-pod -c nano-bot -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 omitted, u...
Update the image version (tag) of the 'monitoring-pod' pod to 'v4'
Command: ```bash kubectl get pod monitoring-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtained by ...
Execute the 'irb' command in the first container of the 'cache-service' service.
Command: ```bash kubectl exec svc/cache-service -- 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.kub...
Forward local port 8000 to port 9090 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Retrieve the logs from the first container of a job named "queue-processing-job"
Command: ```bash kubectl logs job/queue-processing-job ``` 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 service for the replication controller specified in the "node-controller.yaml" file, which serves on port 8181 and connects to the containers on port 808300.
Command: ```bash kubectl expose -f node-controller.yaml --port=8181 --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 s...
Forward local port 8000 to port 8080 in the pod named "analytics-pod"
Command: ```bash kubectl port-forward pod/analytics-pod 8000: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 auto...
Import the 'max_connections' key from the 'app-name-config' ConfigMap into the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-name-config 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 ...
Create an ingress with a rule that directs requests from 'testing.com/module' to 'svc1:8089' using the tls secret 'my-cert'
Command: ```bash kubectl create ingress app1-ingress --rule="testing.com/module=svc1:8089,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...
Create a deployment named 'ingress' using the 'ruby' image and exposing port 8080
Command: ```bash kubectl create deployment ingress --image=ruby --port=8080 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Attach to the payment-gateway-pod container named rocket-ranger
Command: ```bash kubectl attach payment-gateway-pod -c rocket-ranger ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omi...
Listen on all addresses for incoming connections on port 8081 and forward them to port 8000 in the 'web-app-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8081: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 ...
Create an ingress called 'public-ingress' with a rule that directs requests to testing.com/bar to svc1:8888, and use the tls secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/bar=svc1:8888,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...
Update the pod 'web' by adding or overwriting the annotation 'deployment-script' with the value 'https://example.com/deploy.sh'
Command: ```bash kubectl annotate --overwrite pods web 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 lar...
create a new ExternalName service named 'external-notification-service' that points to the external domain 'blog-test.blog'
Command: ```bash kubectl create service externalname external-notification-service --external-name blog-test.blog ``` What it does: Create an ExternalName service with the specified name. ExternalName service references to an external DNS address instead of only pods, which will allow application authors to reference ...
Auto scale the deployment "vpn" with the number of pods between 2 and 11.
Command: ```bash kubectl autoscale deployment vpn --min=2 --max=11 ``` 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...
Set the custom TLS server name to "on-prem-cluster" for the "web-cluster" cluster entry.
Command: ```bash kubectl config set-cluster web-cluster --tls-server-name=on-prem-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] [--certifica...
Create a debug copy of the frontend pod with a different command for the nebula-navigator container
Command: ```bash kubectl debug frontend-pod -it --copy-to=debug-image-api --container=nebula-navigator -- 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...
Display the last 31 lines of logs from the 'chat-app-pod' pod.
Command: ```bash kubectl logs --tail=31 chat-app-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-c...
Import the 'DEBUG_MODE' key from the 'app-config-dev' config map into the 'log-aggregator-deployment' deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config-dev deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Forward traffic from port 3000 on all addresses to port 5432 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 3000:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod ...
Listen on a random port locally, forwarding to port 5000 in the mypod pod.
Command: ```bash kubectl port-forward pod/mypod :5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automatically. T...
Create a cron job called "data-processing" that runs a "node" command every minute
Command: ```bash kubectl create cronjob data-processing --image=node --schedule="*/1 * * * *" -- node ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "def...
Add the 'monitoring-tool' annotation with the value 'Prometheus' to the pod named 'frontend'
Command: ```bash kubectl annotate pods frontend monitoring-tool=Prometheus ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include ar...
Copy the file "foo" from the remote pod named "database-pod-2" in the namespace "prometheus" to the local directory "/tmp/bar_dir".
Command: ```bash kubectl cp prometheus/database-pod-2:/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kube...
Update the image version (tag) of the 'payment-gateway-pod' pod to 'v4'
Command: ```bash kubectl get pod payment-gateway-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f - ``` What it does: Replace a resource by file name or stdin. JSON and YAML formats are accepted. If replacing an existing resource, the complete resource spec must be provided. This can be obtaine...
Set custom TLS server name for cluster entry "prod-cluster" to "testing-cluster"
Command: ```bash kubectl config set-cluster prod-cluster --tls-server-name=testing-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] [--certific...
Create a new NodePort service named email-service-nodeport with the port mappings of 8082 to 8443.
Command: ```bash kubectl create service nodeport email-service-nodeport --tcp=8082:8443 ``` 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...
Add a taint with the key 'workload' on nodes having the label stack=tech-stack, and set the taint effect to PreferNoSchedule.
Command: ```bash kubectl taint node -l stack=tech-stack workload=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": "", "usag...
Copy cdn-service-pod to debug-image-api and run the nano-bot container with an interactive shell
Command: ```bash kubectl debug cdn-service-pod -it --copy-to=debug-image-api --container=nano-bot -- 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 defa...
List deployments in JSON output format in a specific version of an API group.
Command: ```bash kubectl get deployments.v1.1.1.alpha-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you will...
Create a service for the replication controller specified in "centos-controller.yaml" file, serving on port 9092 and connecting to the containers on port 900000.
Command: ```bash kubectl expose -f centos-controller.yaml --port=9092 --target-port=900000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the...
Execute the 'psql' command in the 'rocket-ranger' container of the 'cdn-service-pod' pod and get the output.
Command: ```bash kubectl exec cdn-service-pod -c rocket-ranger -- psql ``` 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...
List the deployments in the "alpha-2.0" version of the "internal-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.alpha-2.0.internal-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced yo...
Create a single ingress named 'www-ingress' that directs requests to website.com/input to the service 'svc1' on port 9091 with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress www-ingress --rule="website.com/input=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": "", "usage"...
Create a new config map called `api-config` using specific keys instead of file basenames on disk
Command: ```bash kubectl create configmap api-config --from-file=settings=/path/to/data/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 con...
Create a Wordpress pod and expose it on port 8082.
Command: ```bash kubectl run hazelcast --image=wordpress --port=8082 ``` 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": "...
Forward local port 8888 to port 5000 in the pod named "mypod"
Command: ```bash kubectl port-forward pod/mypod 8888:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automaticall...
Set the custom TLS server name for the "data-cluster" cluster entry to "e2e".
Command: ```bash kubectl config set-cluster data-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...
Create a single ingress called 'public-api-ingress' with a rule that directs requests to "site.com/module" to the service "svc1" on port 6379, using the TLS secret "my-cert".
Command: ```bash kubectl create ingress public-api-ingress --rule="site.com/module=svc1:6379,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...
Create a pod disruption budget named monitoring-pdb with the following criteria:
Command: ```bash kubectl create poddisruptionbudget monitoring-pdb --selector=role=worker --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 [--...
Import the 'EXTERNAL_API_URL' key from the 'db-config' config map into the 'scheduler-app-deployment' deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/db-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defin...
Add a taint with key 'zone' on nodes having label 'myLabel' and value 'monitoring-node-15' with effect 'PreferNoSchedule'
Command: ```bash kubectl taint node -l myLabel zone=monitoring-node-15:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Out...
Import the DEBUG_MODE key from the app-config config map and set it as an environment variable in the frontend-deployment deployment.
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/app-config deployment/frontend-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in ...
Set the resource request and limits for all containers in the 'mysql' deployment: limit the CPU to 200 milliCPU and memory to 512 Mebibytes, and set the request for CPU to 100 milliCPU and memory to 512 Mebibytes.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=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 reques...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/global-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 de...
Create a config map named app-config-dev with key1=config1 and key2=config2
Command: ```bash kubectl create configmap app-config-dev --from-literal=conf=config1 --from-literal=data=config2 ``` 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...
Create a new config map named "kube-system-config" using the key-value pairs from the "preferences.env" file located at "path/to/preferences.env"
Command: ```bash kubectl create configmap kube-system-config --from-env-file=path/to/preferences.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will defaul...
Check if you have permission to list a specific job in a namespace.
Command: ```bash kubectl auth can-i list jobs.batch/data-migration-job -n staging ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL...
Execute the command 'dotnet --list-sdks' in the 'proxy-server-pod' pod and retrieve the output.
Command: ```bash kubectl exec proxy-server-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, use t...
Create a secret named "database-secret" from an environment file.
Command: ```bash kubectl create secret generic database-secret --from-env-file=path/to/options.env ``` 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 basen...
Create a single ingress called 'app-ingress' that directs requests from foo.com/example to the service 'svc1' on port 9000 using the TLS certificate secret named "my-cert"
Command: ```bash kubectl create ingress app-ingress --rule="foo.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": "", "usage": ...
Execute the 'nginx' command inside the 'astro-container' container running in the 'security-service-pod' pod and retrieve the output.
Command: ```bash kubectl exec security-service-pod -c astro-container -- 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 omit...
Create an ingress called 'api-v1-ingress' with a rule that directs requests to website.com/bar to svc1:9091
Command: ```bash kubectl create ingress api-v1-ingress --rule="website.com/bar=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Start a pod with a Redis image and expose port 8082
Command: ```bash kubectl run hazelcast --image=redis --port=8082 ``` 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": "--fi...