prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Execute the command 'gem --version' in the container 'warp-drive' within the pod 'mypod' and retrieve the output.
Command: ```bash kubectl exec mypod -c warp-drive -- gem --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Retrieve the pod specified in the "config.yaml" file and display its details in YAML format.
Command: ```bash kubectl get -f config.yaml -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 only see resul...
Partially update the 'web-node-8' node by specifying the patch as a YAML file, where the 'spec' field will be updated to set 'replicas' to 3.
Command: ```bash kubectl patch node web-node-8 -p $'spec:\n 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: "f...
Import the keys 'smtp_server' from the 'monitoring-config' config map to the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/monitoring-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...
Forward data between the local port 8080 and the pod port 3000 in the web-app-pod pod.
Command: ```bash kubectl port-forward pod/web-app-pod 8080 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 automa...
Create an ingress resource that directs requests to a specific service using a specified tls secret
Command: ```bash kubectl create ingress app-proxy-ingress --rule="testing.com/module=svc1:9092,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Create a new ClusterIP service named backend-service-clusterip that maps port 5432 on the service to port 5000 on the backend
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=5432:5000 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Set the custom TLS server name to use for validation for the 'dev-cluster' cluster entry as 'on-prem-cluster'
Command: ```bash kubectl config set-cluster dev-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...
Start a pod from the elastic.co/elasticsearch/elasticsearch image and expose port 8000
Command: ```bash kubectl run hazelcast --image=docker.elastic.co/elasticsearch/elasticsearch --port=8000 ``` 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] ...
Create a service for the replication controller specified in the file "nginx-controller.yaml" in the current namespace, serving on port 8080 and connecting to the containers on port 500000
Command: ```bash kubectl expose -f nginx-controller.yaml --port=8080 --target-port=500000 ``` 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 'geth' command in the rocket-ranger container of the payment-gateway-pod and get the output
Command: ```bash kubectl exec payment-gateway-pod -c rocket-ranger -- 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,...
Set up auto scaling for the 'analytics' replication controller with a maximum of 8 pods and a target CPU utilization of 20%
Command: ```bash kubectl autoscale rc analytics --max=8 --cpu-percent=20 ``` 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 us...
Diff the contents of the options.yaml file with the current state of the cluster
Command: ```bash cat options.yaml | kubectl diff -f - ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own dif...
Create a deployment named "drupal" using the Redis image and expose port 27017.
Command: ```bash kubectl create deployment drupal --image=redis --port=27017 ``` 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 new NodePort service named security-service-nodeport that maps port 27017 on the host to port 8084 on the service.
Command: ```bash kubectl create service nodeport security-service-nodeport --tcp=27017:8084 ``` 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", "def...
Create a service for the replicated nginx, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rc nginx --port=6379 --target-port=500000 ``` 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 an ingress called 'private-ingress' that directs requests to 'website.com/input' to 'svc1:9000' with a tls secret "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="website.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": "", "us...
List deployments in JSON format in the "rc-1.1.0" version of the "experimental-apps" API group.
Command: ```bash kubectl get deployments.rc-1.1.0.experimental-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...
Set the service account of the deployment "gateway-deployment" to "flux"
Command: ```bash kubectl set serviceaccount deployment gateway-deployment flux ``` 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 s...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-name-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 def...
Listen on port 3000 on all addresses, forwarding to port 8088 in the frontend-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-pod 3000: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...
Forward local port 5000 to the port 5000 in the pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 5000: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 au...
Copy the local directory '~/.config/kube_dir' to the '/etc/kubernetes_dir' directory inside the 'task-processor-pod-17' pod in the default namespace
Command: ```bash kubectl cp ~/.config/kube_dir task-processor-pod-17:/etc/kubernetes_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,...
Forward traffic from port 3000 on all addresses to port 5432 in the analytics-pod pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/analytics-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 wil...
Copy the "~/.config/kube" local file to the "/tmp/bar_dir" directory in a remote pod named "file-server-pod-14" in the "monitoring" namespace.
Command: ```bash kubectl cp ~/.config/kube monitoring/file-server-pod-14:/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, us...
Expose a replica set named nginx as a service, so that it can be accessed on port 5001 with traffic directed to the containers on port 808200.
Command: ```bash kubectl expose rs nginx --port=5001 --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 port. ...
Create a cluster role named "reader" with specific resource names
Command: ```bash kubectl create clusterrole reader --verb=exec --resource=pods --resource-name=file-storage --resource-name=search-elasticsearch ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|clie...
Add a taint with key 'zone' and no value to the node 'db-node-7'
Command: ```bash kubectl taint nodes db-node-7 zone: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: json|y...
Create a service for a replication controller identified by the type and name specified in the "php-controller.yaml", which serves on port 5001 and connects to the containers on port 8000
Command: ```bash kubectl expose -f php-controller.yaml --port=5001 --target-port=800000 ``` 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 sp...
Copy the local file '/tmp/foo_dir' to '/tmp/bar' inside the 'auth-service-pod-11' pod in the 'prometheus' namespace
Command: ```bash kubectl cp /tmp/foo_dir prometheus/auth-service-pod-11:/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...
List deployments in YAML output format using the "v3.0.0" version of the "extensions" API group.
Command: ```bash kubectl get deployments.v3.0.0.extensions -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...
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 8888 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 8000:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the cri...
Set up autoscaling for the "email" deployment with a minimum of 4 pods and a maximum of 15 pods.
Command: ```bash kubectl autoscale deployment email --min=4 --max=15 ``` 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...
Copy the file '/tmp/foo' from the 'kubeapps/payment-gateway-pod-19' pod to the local directory '/tmp/bar'
Command: ```bash kubectl cp kubeapps/payment-gateway-pod-19:/tmp/foo /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the ku...
Get the output from running the 'mysql' command in the analytics-pod pod, using the first container by default
Command: ```bash kubectl exec analytics-pod -- mysql ``` 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.kuber...
Set up autoscaling for a deployment named "database", with the minimum number of pods set to 6 and the maximum number of pods set to 14.
Command: ```bash kubectl autoscale deployment database --min=6 --max=14 ``` 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 use...
Create a new LoadBalancer service named cdn-service-lb with a TCP port mapping of 8181:3001
Command: ```bash kubectl create service loadbalancer cdn-service-lb --tcp=8181:3001 ``` 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", "def...
Create a copy of a pod named "api-service-pod" and change the command of the container named "mycontainer" by launching an interactive debugging session.
Command: ```bash kubectl debug api-service-pod -it --copy-to=debug-image-1 --container=mycontainer -- 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 def...
Set a custom TLS server name for the "cluster-alpha" cluster entry
Command: ```bash kubectl config set-cluster cluster-alpha --tls-server-name=edge-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] [--certificat...
Copy the local file /tmp/foo_dir to the /tmp/bar directory inside the 'load-balancer-pod-9' pod in the 'rook-ceph' namespace.
Command: ```bash kubectl cp /tmp/foo_dir rook-ceph/load-balancer-pod-9::/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...
Retrieve snapshot logs from all containers in pods labeled with app-type=microservice.
Command: ```bash kubectl logs -l app-type=microservice --all-containers=true ``` 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": "--...
Embed the certificate authority data for the my-k8s-cluster cluster entry with the provided certificate authority file.
Command: ```bash kubectl config set-cluster my-k8s-cluster --embed-certs --certificate-authority=~/.kube/web-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 se...
Import the REDIS_HOST key from the config map app-config-prod into the environment variables of the payment-processor-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-config-prod deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Create a single ingress called 'service-ingress' with the following rules:
Command: ```bash kubectl create ingress service-ingress --rule="site.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...
Set the resource requests and limits for all containers in the centos deployment.
Command: ```bash kubectl set resources deployment centos --limits=cpu=200m,memory=512Mi --requests=cpu=5,memory=256Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requeste...
Expose the ubuntu deployment as a service, serving on port 3001 and connecting to the containers on port 8081
Command: ```bash kubectl expose deployment ubuntu --port=3001 --target-port=808100 ``` 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...
Add a taint with the key 'dedicated' and no value to the node 'k8s-node-1'.
Command: ```bash kubectl taint nodes k8s-node-1 dedicated: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: ...
set the CPU and memory limits and requests for all containers in the node deployment to 200m CPU and 512Mi memory for limits, and 500m CPU and 1Gi memory for requests.
Command: ```bash kubectl set resources deployment node --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=1Gi ``` 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...
Switch to raw terminal mode and connect to the 'code-explorer' container inside the 'frontend-pod' pod
Command: ```bash kubectl attach frontend-pod -c code-explorer -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 omit...
Create a new ExternalName service named external-git-service with the external domain name sample-domain.net
Command: ```bash kubectl create service externalname external-git-service --external-name sample-domain.net ``` 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 servic...
import the config_file_path key from the app-name-config ConfigMap and set it as an environment variable in the api-server-deployment deployment
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-name-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 de...
Execute the command 'mysql --version' on the first pod of the backend-service service.
Command: ```bash kubectl exec svc/backend-service -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use t...
Create a copy of the "monitoring-pod" with all container images changed to "php" and name it "debug-image-memcached"
Command: ```bash kubectl debug monitoring-pod --copy-to=debug-image-memcached --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 n...
Update the 'analytics-platform-deployment' deployment by setting the environment variable DB_USER to 'username'
Command: ```bash kubectl set env deployment/analytics-platform-deployment DB_USER=username ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod tem...
Set the log_level environment variable in the payment-processor-deployment deployment using the log_level key from the app-secrets config map
Command: ```bash kubectl set env --keys=log_level --from=configmap/app-secrets deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Check if you have the permission to list the job named "certificates-renewal-job" in the "logging" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/certificates-renewal-job -n logging ``` 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 parti...
Create a single ingress called 'website-ingress' that directs requests to site.com/module to svc1:3001 with a tls secret "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="site.com/module=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Taint the nodes with the label 'version=v1.0.0' by adding a taint with the key 'hardware' and value 'monitoring-node-15:PreferNoSchedule'
Command: ```bash kubectl taint node -l version=v1.0.0 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": "", "u...
Create a new secret named private-key-secret from the env file located at path/to/parameters.env
Command: ```bash kubectl create secret generic private-key-secret --from-env-file=path/to/parameters.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...
Create a pod named 'hazelcast' using the 'wordpress' image, and expose port 8088.
Command: ```bash kubectl run hazelcast --image=wordpress --port=8088 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "...
Create a debug container for the email-service-pod, and attach to it for troubleshooting
Command: ```bash kubectl debug email-service-pod -it --image=busybox --copy-to=debug-image-1 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no r...
Get the output of the 'ruby --version' command from the 'mycontainer' container inside the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c mycontainer -- ruby --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...
Forward traffic from port 3000 on all addresses to port 8888 in the pod named chat-app-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 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 will...
Listen on port 8888 locally and forward data to/from port 5000 in the 'analytics-pod' pod.
Command: ```bash kubectl port-forward pod/analytics-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 criteria, a pod will be selected auto...
Forward traffic from port 8088 on all addresses to port 8088 in the e-commerce pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-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 wi...
Create a new secret named 'aws-credentials-secret' from the environment file located at 'path/to/configs.env'
Command: ```bash kubectl create secret generic aws-credentials-secret --from-env-file=path/to/configs.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...
Forward port 6379 on your local machine to port 5000 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 6379:5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected a...
Copy a local file to a remote pod
Command: ```bash kubectl cp /tmp/foo_dir kube-dns/ingress-controller-pod-8:/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 ...
Import the `redis_host` key from the `env-vars` config map into the `search-engine-deployment` deployment.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/env-vars 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 definitions ...
List deployments in YAML output format for the "feature-branch-2.3.0" version of the "web-apps" API group
Command: ```bash kubectl get deployments.feature-branch-2.3.0.web-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 namespa...
Create an ingress named 'app-gateway-ingress' that routes requests from 'website.com/example' to the service 'svc1:8082' with a TLS certificate named 'my-cert'.
Command: ```bash kubectl create ingress app-gateway-ingress --rule="website.com/example=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "...
Create a new config map named 'app-settings' using the contents of '/path/to/preferences/file1.txt' and '/path/to/configs/file2.txt' as values for the 'conf' and 'data' keys respectively.
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Attach to the log-aggregator-pod container named time-machine and start receiving output from it
Command: ```bash kubectl attach log-aggregator-pod -c time-machine ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitt...
Create an ingress called 'public-ingress' that redirects requests from testing.com/input to svc1:8082 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/input=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Attach to the terminal of a specific container in a pod and interact with it in raw mode from the client
Command: ```bash kubectl attach proxy-service-pod -c astro-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. ...
Forward local port 8000 to port 6379 in the pod web-app-pod
Command: ```bash kubectl port-forward pod/web-app-pod 8000 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 automa...
Set the CPU and memory resource limits and requests for all containers in the "wordpress" deployment
Command: ```bash kubectl set resources deployment wordpress --limits=cpu=200m,memory=512Mi --requests=cpu=5,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 request...
Create a role named "view" with specific API Group and resource access
Command: ```bash kubectl create role view --verb=proxy,get,update --resource=persistentvolumes.storage.k8s.io ``` What it does: Create a role with single rule. Syntax: `kubectl create role NAME --verb=verb --resource=resource.group/subresource [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful fl...
Create a job named "database-seeding-job" using the image "mcr.microsoft.com/dotnet/core/runtime" and run the command "dotnet --list-sdks" inside the job.
Command: ```bash kubectl create job database-seeding-job --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet --list-sdks ``` 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":...
Copy the ~/.config/kube directory from the file-server-pod-14 pod to the local machine's /tmp/bar directory
Command: ```bash kubectl cp argocd/file-server-pod-14:~/.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 the k...
Forward traffic from local port 8888 to port 9090 in the pod "backend-pod"
Command: ```bash kubectl port-forward pod/backend-pod 8888:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Create a job named 'indexing' using the 'alpine' image and run the command 'ash' within the job.
Command: ```bash kubectl create job indexing --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: jso...
Update the 'frontend' pod by setting the annotation 'compliance-level' to 'PCI-DSS'.
Command: ```bash kubectl annotate pods frontend 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 include arbi...
Display the most recent 53 lines of logs for the pod named "database-pod"
Command: ```bash kubectl logs --tail=53 database-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...
Retrieve only the phase value of the backend-pod pod.
Command: ```bash kubectl get -o template pod/backend-pod --template={{.status.phase}} ``` 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 ...
Create an ingress named 'www-ingress' with a rule that directs requests for website.com/example to the service svc1 on port 5432, and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress www-ingress --rule="website.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": "", "usag...
Create a single ingress called 'www-ingress' that directs requests to testing.com/bar to svc1:3000
Command: ```bash kubectl create ingress www-ingress --rule="testing.com/bar=svc1:3000,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": ...
Remove all taints with the key 'hardware' from node 'app-node-6'
Command: ```bash kubectl taint nodes app-node-6 hardware- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml|n...
Create an ingress resource called 'private-api-ingress' with a rule that directs requests from testing.com/example to svc1:8443
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/example=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": "...
Update the pod 'email' only if the resource is unchanged from version 1 by adding the label 'status=unhealthy'
Command: ```bash kubectl label pods email status=unhealthy --resource-version=1 ``` 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", "defaul...
Create a single ingress called 'api-gateway-ingress' with a rule that directs requests for 'testing.com/bar' to 'svc1:8000', and use the tls secret "my-cert".
Command: ```bash kubectl create ingress api-gateway-ingress --rule="testing.com/bar=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": "", "...
Copy the local file /tmp/foo_dir to the remote pod velero/api-server-pod-3 in the /tmp/bar_dir directory.
Command: ```bash kubectl cp /tmp/foo_dir velero/api-server-pod-3:/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 ku...
Start a Jenkins pod with custom specifications using JSON overrides
Command: ```bash kubectl run nginx --image=jenkins --overrides='{ "apiVersion": "stable-2.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] -- ...
Create a copy of the "log-aggregator-pod" pod by adding a debug container and changing the container images.
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-memcached --image=debian --set-image=api=api:v2,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource a...
Scale the deployment named web to 1 replica, considering its current size is 3 replicas.
Command: ```bash kubectl scale --current-replicas=3 --replicas=1 deployment/web ``` 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 spec...
Forward traffic from local port 3000 to pod port 9090 using all available addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/cdn-service-pod 3000: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 w...
Display the modified deployment.yaml file for the notification-handler-deployment, setting the PORT environment variable to 8080, without making any changes to the deployment on the server.
Command: ```bash kubectl set env deployment/notification-handler-deployment PORT=8080 -o yaml ``` 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 ...
Forward traffic from port 5000 on all addresses to port 8088 in the pod named "mypod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/mypod 5000: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 sel...
Get output from running the 'wp' command in the auth-service-pod's first container
Command: ```bash kubectl exec auth-service-pod -- 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 kubectl.kuber...
Forward local port 8081 to port 8088 in the pod named "proxy-server-pod"
Command: ```bash kubectl port-forward pod/proxy-server-pod 8081: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 a...