prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 8000 on all addresses to port 9090 in the pod named security-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-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 ...
Forward local port 8000 to port 8081 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-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 will be selected a...
This command is used to import specific keys from a ConfigMap into an environment variable for a specified deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/env-vars 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 in one...
Create a new secret named azure-storage-secret with file keys from a specific folder
Command: ```bash kubectl create secret generic azure-storage-secret --from-file=path/to/parameters ``` 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...
List deployments in JSON output format for a specific version and API group.
Command: ```bash kubectl get deployments.feature-branch-2.3.0.mobile-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 name...
Modify the cluster field in the prod-context context to sun-cluster.
Command: ```bash kubectl config set contexts.prod-context.cluster sun-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 want...
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --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 definit...
Remove the label 'release-' from the 'backend' pod
Command: ```bash kubectl label pods backend release- ``` 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 t...
Embed the certificate authority data for the edge-cluster cluster entry
Command: ```bash kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/staging-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 secret_key from the monitoring-config config map into the search-engine-deployment deployment.
Command: ```bash kubectl set env --keys=secret_key --from=configmap/monitoring-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 def...
Forward traffic from local port 8088 to port 8088 in the pod named security-service-pod
Command: ```bash kubectl port-forward pod/security-service-pod 8088:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create a new config map named 'db-config' using the key=value pairs from the file located at 'path/to/properties'.
Command: ```bash kubectl create configmap db-config --from-file=path/to/properties ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the basename ...
View the last-applied-configuration annotations for the deployment/hazelcast/hazelcast in YAML format.
Command: ```bash kubectl apply view-last-applied deployment/hazelcast/hazelcast ``` What it does: View the latest last-applied-configuration annotations by type/name or file. The default output will be printed to stdout in YAML format. You can use the -o option to change the output format. Syntax: `kubectl apply view...
Forward traffic from port 6379 on localhost and IP address 10.19.21.23 to port 8888 inside the 'mypod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 6379: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 p...
Set the custom TLS server name to "app-cluster" for the "data-cluster" cluster entry
Command: ```bash kubectl config set-cluster data-cluster --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-...
Create a service for a replication controller using the configuration specified in "hazelcast-controller.yaml" file, which serves on port 8082 and connects to the containers on port 818100.
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8082 --target-port=818100 ``` 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 ...
Create an ingress that directs requests to a specific service and URL path, with TLS enabled using a specified secret.
Command: ```bash kubectl create ingress myapp-ingress --rule="website.com/bar=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": "", "usage"...
Create a new pod named "hazelcast" using a python image and expose port 8181
Command: ```bash kubectl run hazelcast --image=python --port=8181 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Execute the 'geth attach' command in the 'quantum-quark' container from the 'media-stream-pod' pod
Command: ```bash kubectl exec media-stream-pod -c quantum-quark -- geth attach ``` 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...
Start a nginx pod and customize its configuration using JSON overrides
Command: ```bash kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v3.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] -- [COMMAND...
Specify the custom TLS server name "web-cluster" to use for validation for the "testing-cluster" cluster entry.
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=web-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...
Generate Kubernetes configuration files from a directory containing shared configuration files.
Command: ```bash kubectl kustomize /etc/kube/config/production ``` What it does: Build a set of KRM resources using a 'kustomization.yaml' file. The DIR argument must be a path to a directory containing 'kustomization.yaml', or a git repository URL with a path suffix specifying same with respect to the repository root...
List the deployments in the "v3.0.0" version of the "testing-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.v3.0.0.testing-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 wi...
Configure the sun-cluster cluster entry with embedded certificate authority data
Command: ```bash kubectl config set-cluster sun-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-1/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 se...
Forward port 8888 on localhost and IP 10.19.21.23 to port 5000 in the 'e-commerce-pod' pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 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 crit...
Start a golang pod with the name "nginx" and the golang image, but override the spec with a partial set of values parsed from the provided JSON.
Command: ```bash kubectl run nginx --image=golang --overrides='{ "apiVersion": "v1.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] -- [COMMAN...
Add a taint with the key 'workload' on nodes having the label release=beta
Command: ```bash kubectl taint node -l release=beta workload=db-node-7: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...
Mark node "backup-node-14" as unschedulable
Command: ```bash kubectl cordon backup-node-14 ``` What it does: Mark node as unschedulable. Syntax: `kubectl cordon NODE` Helpful flags: "flag": "--selector", "short": "-l", "default": "", "usage": "Selector (label query) to filter on "
Check if you have permission to list the job named "log-analysis-job" in the "namespace-1" namespace using the command `kubectl auth can-i list jobs.batch/log-analysis-job -n namespace-1`
Command: ```bash kubectl auth can-i list jobs.batch/log-analysis-job -n namespace-1 ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial U...
Forward local port 8081 to port 3000 in the log-aggregator-pod pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8081 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...
Forward traffic from port 5432 on all addresses to port 8080 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5432:8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Create a copy of the log-aggregator-pod and start an interactive debugging session
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=my-custom-dbg --image=debian --set-image=mailer=mailer:latest,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 an...
Scale the deployment named 'mysql' from its current size of 7 replicas to 5 replicas.
Command: ```bash kubectl scale --current-replicas=7 --replicas=5 deployment/mysql ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is sp...
Create an ingress resource called 'internal-ingress' with a rule that directs requests from 'testing.com/input' to 'svc1:8088', using the TLS secret "my-cert".
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/input=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": "", "u...
Set the server field of the testing-cluster cluster entry to "https://1.2.3.4" while keeping all other values unchanged.
Command: ```bash kubectl config set-cluster testing-cluster --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-au...
Expose a replication controller specified in the "python-controller.yaml" file, which serves on port 3001 and connects to the containers on port 909000
Command: ```bash kubectl expose -f python-controller.yaml --port=3001 --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...
create a cron job named "metrics-collection" that runs every minute using the "amazonlinux" image and executes the command "echo 'Hello
Command: ```bash kubectl create cronjob metrics-collection --image=amazonlinux --schedule="*/1 * * * *" -- /bin/bash -c "echo 'Hello ``` 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": ...
List the specified resources by their types and names
Command: ```bash kubectl get rc/web service/proxy-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...
Expose a replication controller as a service with specific port mappings
Command: ```bash kubectl expose rc python --port=8083 --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....
Import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=max_connections --from=configmap/app-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 in on...
Get the output from running the 'geth' command in the 'cosmic-container' from the pod 'api-service-pod'
Command: ```bash kubectl exec api-service-pod -c cosmic-container -- geth ``` 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, ...
List the API resources available in the 'certificates.k8s.io' APIGroup
Command: ```bash kubectl api-resources --api-group=certificates.k8s.io ``` 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. "
Set the service account of the deployment "order-processing-deployment" to "kube-dns"
Command: ```bash kubectl set serviceaccount deployment order-processing-deployment kube-dns ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `...
Forward local port 5000 to port 8081 in the e-commerce-pod pod
Command: ```bash kubectl port-forward pod/e-commerce-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 aut...
Create a deployment named my-dep that runs the postgres image and exposes port 8089
Command: ```bash kubectl create deployment my-dep --image=postgres --port=8089 ``` 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 cron job that runs the command "go version" every minute using the golang image
Command: ```bash kubectl create cronjob log-rotation --image=golang --schedule="*/1 * * * *" -- go version ``` What it does: Create a cron job with the specified name. Syntax: `kubectl create cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o",...
Forward traffic from port 9090 on all addresses to port 5432 in the mypod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 9090:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be sel...
Embed the certificate authority data for the cluster-alpha cluster entry by running the command:
Command: ```bash kubectl config set-cluster cluster-alpha --embed-certs --certificate-authority=~/.kube/app-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 set...
Create a new ClusterIP service named 'catalog-service-clusterip' with the port mapping tcp:9090 to tcp:8080
Command: ```bash kubectl create service clusterip catalog-service-clusterip --tcp=9090:8080 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Get output from running a command in a specific container in a pod.
Command: ```bash kubectl exec cdn-service-pod -c cosmic-container -- kafka-server-start /etc/kafka/server.properties ``` 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":...
Import specific keys from a config map into the environment of a deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-config-prod 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 v...
Retrieve snapshot logs from the container "payment-processor-deployment-1" in the deployment named "auth-service-pod".
Command: ```bash kubectl logs deployment/payment-processor-deployment -c auth-service-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful fla...
Create a new config map with specified keys from files on disk
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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...
Set the cluster field in the local-context context to galaxy-cluster
Command: ```bash kubectl config set contexts.local-context.cluster galaxy-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you ...
Update node 'app-node-6' with a taint
Command: ```bash kubectl taint nodes app-node-6 disktype=ssd:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Remove the 'bar' label from the 'analytics' pod
Command: ```bash kubectl label pods analytics env- ``` 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 tru...
Create a copy of the auth-service-pod by adding a debug container and changing container images.
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-api --image=debian --set-image=web=nginx:latest,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource ...
Copy the local file '/tmp/foo' to the '/etc/kubernetes' directory in the remote pod 'file-server-pod-14' in the 'openfaas' namespace.
Command: ```bash kubectl cp /tmp/foo openfaas/file-server-pod-14:/etc/kubernetes ``` 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...
Execute the command 'go run hello.go' on the first pod of the user-service service, using the first container
Command: ```bash kubectl exec svc/user-service -- go run hello.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 ...
Listen on port 8081 locally, forwarding data to/from port 8080 in the 'log-aggregator-pod' pod
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8081 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...
Create a service for the replication controller specified in the "alpine-controller.yaml" file
Command: ```bash kubectl expose -f alpine-controller.yaml --port=9091 --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...
Create a cluster role named "admin_role" with API Group specified for the horizontalpodautoscalers.autoscaling resource
Command: ```bash kubectl create clusterrole admin_role --verb=update,get,patch --resource=horizontalpodautoscalers.autoscaling ``` 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...
Remove all the taints with key 'cpu-type' from the 'gpu-node-12' node
Command: ```bash kubectl taint nodes gpu-node-12 cpu-type- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|...
Copy a file from a pod to a local directory
Command: ```bash kubectl cp ingress-nginx/load-balancer-pod-9::/tmp/foo /etc/kubernetes ``` 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, ...
Forward traffic from local port 8088 to the email-server-deployment on port 8080.
Command: ```bash kubectl port-forward deployment/email-server-deployment 8088 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...
Create an ingress called 'api-v2-ingress' that directs requests to website.com/module to a service named 'svc1:9091', using a TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress api-v2-ingress --rule="website.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": "", "us...
Create a copy of a pod called email-service-pod, but change all container images to alpine
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-1 --set-image=*=alpine ``` 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 ...
Add a taint with key 'environment' and value 'node-1:PreferNoSchedule' on nodes having label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster environment=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"...
Create a cluster role named "custom_role" with the verb "delete" and the resource "configmaps" with the resource names "app-analytics" and "mail-server"
Command: ```bash kubectl create clusterrole custom_role --verb=delete --resource=configmaps --resource-name=app-analytics --resource-name=mail-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server...
Retrieve the previous terminated logs of the 'cyber-sleuth' container from the 'gateway-pod' pod.
Command: ```bash kubectl logs -p -c cyber-sleuth gateway-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "sho...
Import specific keys from a config map for a deployment.
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/log-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 variable defini...
Taint nodes labeled with 'owner=john-doe' with the 'hardware=edge-node-10' taint.
Command: ```bash kubectl taint node -l owner=john-doe hardware=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":...
Return the snapshot logs from the container "log-aggregator-pod-1" of the deployment "cache-cluster-deployment"
Command: ```bash kubectl logs deployment/cache-cluster-deployment -c log-aggregator-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...
Set the custom TLS server name "my-k8s-cluster" to use for validation for the "cloud-cluster" cluster entry.
Command: ```bash kubectl config set-cluster cloud-cluster --tls-server-name=my-k8s-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...
Copy the local file /var/run/secrets/kubernetes.io/serviceaccount/ to the remote pod 'cache-pod-5' in the container 'task-processor' at the path /tmp/bar
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ cache-pod-5::/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": "C...
Create a deployment named 'db' with the 'node' image and the '--version' flag set to 'node'
Command: ```bash kubectl create deployment db --image=node -- node --version ``` 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: j...
create a cron job named daily-report that runs the jenkins-plugin-cli command every minute using the jenkins image
Command: ```bash kubectl create cronjob daily-report --image=jenkins --schedule="*/1 * * * *" -- jenkins-plugin-cli ``` 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", "shor...
Update the annotation of pod 'cdn' with the value 'https://example.com/release-notes/v2.5.1', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods cdn 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...
Remove the taint with key 'special' and effect 'NoSchedule' from node 'prod-node-5' if it exists
Command: ```bash kubectl taint nodes prod-node-5 special:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: ...
Delete the pods and services with the names "email" and "cdn"
Command: ```bash kubectl delete pod,service email cdn ``` 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. Some ...
Create a pod named "hazelcast" using the Centos image and expose port 3306 on the container
Command: ```bash kubectl run hazelcast --image=centos --port=3306 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Update the annotation of the pod 'backend' with the key 'scaling-policy' and the value 'auto-horizontal-scaling', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods backend scaling-policy='auto-horizontal-scaling' ``` 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 t...
Forward local ports 8080 to 8088 in the pod "web-app-pod"
Command: ```bash kubectl port-forward pod/web-app-pod 8080 8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Set the service account of the deployment "frontend-deployment" to "istio".
Command: ```bash kubectl set serviceaccount deployment frontend-deployment istio ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl set...
Create a deployment named "registry" with the Redis image and 7 replicas.
Command: ```bash kubectl create deployment registry --image=redis --replicas=7 ``` 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 new config map named env-vars using the specified key-value pairs instead of file basenames on disk.
Command: ```bash kubectl create configmap env-vars --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/settings/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ...
Create a new ExternalName service named 'external-caching-service' and set the external name to 'demo-service.dev'
Command: ```bash kubectl create service externalname external-caching-service --external-name demo-service.dev ``` 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 ser...
Set the CPU and memory limits for a container in a deployment.
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=1,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 its...
Set up basic authentication for the "cluster-admin" entry
Command: ```bash kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif ``` 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=keyfi...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/api-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 defin...
List the deployments in the "custom-version" version of the "prod-apps" API group in YAML output format.
Command: ```bash kubectl get deployments.custom-version.prod-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 deployment named wordpress with the amazonlinux image
Command: ```bash kubectl create deployment wordpress --image=amazonlinux ``` 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 new secret named git-credentials-secret with keys for each file in the folder path/to/options
Command: ```bash kubectl create secret generic git-credentials-secret --from-file=path/to/options ``` 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 basena...
Partially update the node configuration specified in "node.json" using strategic merge patch
Command: ```bash kubectl patch -f cni.conf -p '{"spec":{"replicas":3}' ``` 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]` Helpful flags: "fla...
Create a new config map named app-config-dev with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap app-config-dev --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/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. Whe...
Forward local port 8088 to port 8081 inside the 'frontend-pod' pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8088: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 autom...
Create a job named 'scaling-job' with the command 'irb' using the 'ruby' image
Command: ```bash kubectl create job scaling-job --image=ruby -- irb ``` 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: js...
Create a role named "admin_role" with ResourceName specified
Command: ```bash kubectl create role admin_role --verb=get --resource=pods --resource-name=staging-app-server --resource-name=app-worker-2 ``` 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=ser...
Create a new secret named tls-certificate-secret from an environment file located at path/to/options.env
Command: ```bash kubectl create secret generic tls-certificate-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 th...
Listen on port 8080 on your local machine and forward the traffic to the targetPort of the "https" port in the "analytics-service" service.
Command: ```bash kubectl port-forward service/analytics-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 sele...