prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a job called 'image-build-job' using the 'alpine' image, and execute the command 'sleep 3600'
Command: ```bash kubectl create job image-build-job --image=alpine -- sleep 3600 ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output forma...
Retrieve the details of the 'web' replication controller, 'gateway-rc' service, and 'web-app-pod' pod.
Command: ```bash kubectl get rc/web service/gateway-rc pods/web-app-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you...
Create a new config map named env-vars using the parameters from the env file located at path/to/parameters.env.
Command: ```bash kubectl create configmap env-vars --from-env-file=path/to/parameters.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 default to the ba...
Scale the resource specified in the "params.json" file to 3 replicas.
Command: ```bash kubectl scale --replicas=3 -f params.json ``` 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 specified, it is validate...
Open the 'scheduler-service' service for editing using the 'sublime' editor.
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/scheduler-service ``` What it does: Edit a resource from the default editor. The edit command allows you to directly edit any API resource you can retrieve via the command-line tools. It will open the editor defined by your KUBE_EDITOR, or EDITOR environment vari...
Create an ingress named 'app-gateway-ingress' that routes requests from 'testing.com/bar' to 'svc1:9091' with a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.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": "", "...
Create a debug container in media-stream-pod, copying the container images and changing them to "debian" for logger and "my-custom-worker:1.2.3" for worker
Command: ```bash kubectl debug media-stream-pod -it --copy-to=dgb-img --image=debian --set-image=logger=logging-app:debug,worker=my-custom-worker:1.2.3 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified...
Output the modified configuration of the "gateway-deployment" deployment with the environment variable "JWT_SECRET" set to "your-jwt-secret" in YAML format, without making any changes to the deployment object on the server.
Command: ```bash kubectl set env deployment/gateway-deployment JWT_SECRET=your-jwt-secret -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 ...
Configure auto scaling for the "log-aggregator" replication controller with a minimum of 1 and a maximum of 6 pods and a target CPU utilization of 81%.
Command: ```bash kubectl autoscale rc log-aggregator --max=6 --cpu-percent=81 ``` 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 th...
Forward traffic from your local machine's port 8088 to port 8081 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Wait for the pod "api-service-pod" to be deleted, with a timeout of 60s, after executing the "kubectl delete pod/api-service-pod" command
Command: ```bash kubectl delete pod/api-service-pod kubectl wait --for=delete pod/busybox1 --timeout=60s ``` What it does: Experimental: Wait for a specific condition on one or many resources. The command takes multiple resources and waits until the specified condition is seen in the Status field of every given resour...
Check if you have permission to list the job named "image-processing-job" in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/image-processing-job -n kube-dns ``` 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 ...
Start a pod named 'hazelcast' using the 'ubuntu' image, and configure the container to expose port 3306.
Command: ```bash kubectl run hazelcast --image=ubuntu --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...
Attach to a pod and interact with the terminal
Command: ```bash kubectl attach backend-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...
Start listening on port 6379 locally and forward the traffic to port 9090 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 6379: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 autom...
Update the annotation 'git-repo' of the pod 'security' with the value 'https://github.com/example/my-app', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods security git-repo='https://github.com/example/my-app' ``` 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 copy of the "e-commerce-pod" pod, changing the command of the "time-machine" container to a shell session.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-api --container=time-machine -- 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 d...
Delete the context for the client-1-context cluster.
Command: ```bash kubectl config delete-context client-1-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Apply all the resources specified in the kustomization.yaml file located in the params directory.
Command: ```bash kubectl apply -k params/ ``` What it does: Apply a configuration to a resource by file name or stdin. The resource name must be specified. This resource will be created if it doesn't exist yet. To use 'apply', always create the resource initially with either 'apply' or 'create --save-config'. JSON and...
Create a new config map named api-config using the files file1.txt and file2.txt as the keys conf and data respectively
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a ...
Create a cluster role named "default_role" with the following ResourceName values: "identity-provider" and "nginx-proxy"
Command: ```bash kubectl create clusterrole default_role --verb=proxy --resource=pods --resource-name=identity-provider --resource-name=nginx-proxy ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|c...
Copy the "~/.config/kube" file to the remote pod "payment-gateway-pod-19" in the "metallb-system" namespace, and place it in the "/tmp/bar" directory.
Command: ```bash kubectl cp ~/.config/kube metallb-system/payment-gateway-pod-19:/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...
Set the service account of the deployment called email-server-deployment to tiller
Command: ```bash kubectl set serviceaccount deployment email-server-deployment tiller ``` 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: `kubect...
create a cron job called "alerts-cleanup" with a schedule to run every minute and execute the "pg_dump --version" command
Command: ```bash kubectl create cronjob alerts-cleanup --image=postgres --schedule="*/1 * * * *" -- pg_dump --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", "sh...
Delete both pods and services with the names "cdn" and "analytics"
Command: ```bash kubectl delete pod,service cdn analytics ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. S...
Set the custom TLS server name to 'dev-cluster' for the 'data-cluster' cluster entry.
Command: ```bash kubectl config set-cluster data-cluster --tls-server-name=dev-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 copy of the media-stream-pod and add a debug container with debian image
Command: ```bash kubectl debug media-stream-pod -it --copy-to=debug-image-api --image=debian --set-image=logger=logging-app:debug,web=nginx:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by r...
Apply a partial update to the 'prod-node-5' node by specifying the patch as a JSON object
Command: ```bash kubectl patch node prod-node-5 -p '{"spec":{"type":"LoadBalancer"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` Helpf...
Add certificate authority data for the kube-cluster-2 cluster entry.
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/edge-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 s...
Create a new pod named "hazelcast" using the Alpine image, and configure it to expose port 6379
Command: ```bash kubectl run hazelcast --image=alpine --port=6379 ``` 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...
Create a new ExternalName service named external-identity-provider-service that maps to the external DNS name "practice-online.site"
Command: ```bash kubectl create service externalname external-identity-provider-service --external-name practice-online.site ``` 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...
Create a service for a replicated php using replica set, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose rs php --port=8089 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A ...
Import the 'config_file_path' key from the 'api-config' config map and set it as an environment variable in the 'mydeployment' deployment.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/api-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 o...
Add a taint with key 'disktype' on nodes having label version=v1.0.0
Command: ```bash kubectl taint node -l version=v1.0.0 disktype=web-node-8: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": "...
Get the output of the 'nginx -t' command from the log-aggregator-pod.
Command: ```bash kubectl exec log-aggregator-pod -- nginx -t ``` 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 kubec...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/kube-system-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 de...
Update the node 'k8s-node-1' by changing the password to 'new-password'
Command: ```bash kubectl patch node k8s-node-1 -p $'stringData:\n password: new-password' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` ...
Import specific keys from a config map into a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/kube-system-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 ...
Forward traffic from port 8088 on all addresses to port 8000 in the web-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/web-app-pod 8088: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 a service for the centos replica set, which serves on port 9091 and connects to the containers on port 543200.
Command: ```bash kubectl expose rs centos --port=9091 --target-port=543200 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Forward data between local port 5432 and pod port 6379 in the backend-pod pod.
Command: ```bash kubectl port-forward pod/backend-pod 5432 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Remove all the taints with key 'special' from the node 'prod-node-5'
Command: ```bash kubectl taint nodes prod-node-5 special- ``` 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...
Execute the 'go' command in the first container of the web-app-deployment deployment.
Command: ```bash kubectl exec deploy/web-app-deployment -- 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 kube...
Create an ingress called 'public-ingress' with a rule that directs requests from site.com/input to svc1:3306, using the tls secret "my-cert"
Command: ```bash kubectl create ingress public-ingress --rule="site.com/input=svc1:3306,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"...
Enable the Google Compute Platform auth provider for the "app-operator" entry
Command: ```bash kubectl config set-credentials app-operator --auth-provider=gcp ``` What it does: Set a user entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values. Client-certificate flags: --client-certificate=certfile --client-key=keyfile Bearer token flags: ...
Copy the local file '/tmp/foo' to the '/etc/kubernetes' directory in the remote pod 'monitoring-agent-pod-6' in the 'kube-proxy' namespace.
Command: ```bash kubectl cp /tmp/foo kube-proxy/monitoring-agent-pod-6:/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, u...
Retrieve the output from running the 'redis-server' command in the first container of the 'security-service-pod'
Command: ```bash kubectl exec security-service-pod -- redis-server ``` 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...
Create a service for the replication controller defined in the "node-controller.yaml" file, serving on port 8084 and connecting to the containers on port 909100.
Command: ```bash kubectl expose -f node-controller.yaml --port=8084 --target-port=909100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Import specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/app-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 definition...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/email-service-rc pods/auth-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is nam...
Start a pod named "hazelcast" with the nginx image and expose port 7000.
Command: ```bash kubectl run hazelcast --image=nginx --port=7000 ``` 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...
Set the service account of the deployment 'authentication-service-deployment' to 'kube-proxy'
Command: ```bash kubectl set serviceaccount deployment authentication-service-deployment kube-proxy ``` 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 S...
Create an ingress called 'service-ingress' that directs requests to foo.com/input to a service named svc1 on port 9091
Command: ```bash kubectl create ingress service-ingress --rule="foo.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 debug copy of the monitoring pod, specifying the container name as lunar-launcher and opening an interactive shell.
Command: ```bash kubectl debug monitoring-pod -it --copy-to=dgb-img --container=lunar-launcher -- 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 default...
Copy the contents of "/var/run/secrets/kubernetes.io/serviceaccount/" directory from a remote pod named "message-broker-pod-15" in the "kube-system" namespace to the "/tmp/bar" directory locally.
Command: ```bash kubectl cp kube-system/message-broker-pod-15:/var/run/secrets/kubernetes.io/serviceaccount/ :/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"...
Set the resource request and limits for all containers in the alpine deployment to cpu=500m, memory=128Mi for requests and cpu=200m, memory=512Mi for limits.
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=500m,memory=128Mi ``` 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 reque...
Forward traffic from port 5432 on all addresses to port 8888 in the 'security-service-pod' pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5432: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 ...
Auto scale the replication controller "media-stream" with the number of pods between 1 and 6, targeting a CPU utilization of 50%.
Command: ```bash kubectl autoscale rc media-stream --max=6 --cpu-percent=50 ``` 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...
Create a new NodePort service named web-app-nodeport with a mapping from port 8089 to port 9092.
Command: ```bash kubectl create service nodeport web-app-nodeport --tcp=8089:9092 ``` 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": "",...
Stream the logs of the "time-machine" container in the "security-service-pod" pod
Command: ```bash kubectl logs -f -c time-machine security-service-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--contain...
Copy local file "/tmp/foo" to remote pod "worker-pod-4" in namespace "logging" as "/tmp/bar"
Command: ```bash kubectl cp /tmp/foo logging/worker-pod-4::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kube...
Set the client-key-data field in the prod-user user using the provided cert_data_here value, and ensure it is treated as raw bytes.
Command: ```bash kubectl config set users.prod-user.client-key-data cert_data_here --set-raw-bytes=true ``` 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...
Create a job to build an image using the PHP image
Command: ```bash kubectl create job image-build-job --image=php -- ``` 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...
Copy the local file /tmp/foo_dir to the remote pod worker-pod-4, specifically to the container worker-container, at the destination path /tmp/bar_dir.
Command: ```bash kubectl cp /tmp/foo_dir worker-pod-4:/tmp/bar_dir -c worker-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Copy the local file /tmp/foo to the remote pod web-app-pod-1 in the /tmp/bar directory, specifically in the logging-agent container.
Command: ```bash kubectl cp /tmp/foo web-app-pod-1:/tmp/bar -c logging-agent ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/app-secrets 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 definition...
Remove a taint from a node if it exists
Command: ```bash kubectl taint nodes kube-master-9 disktype: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...
Retrieve the output of the 'nginx -g "daemon off;"' command executed in the Nebula Navigator container of the 'mypod' pod.
Command: ```bash kubectl exec mypod -c nebula-navigator -- nginx -g "daemon off;" ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Forward traffic from port 3000 on localhost and IP address 10.19.21.23 to port 8000 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/chat-app-pod 3000: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 criter...
Approve the CSR 'csr-webserver-1'.
Command: ```bash kubectl certificate approve csr-webserver-1 ``` What it does: Approve a certificate signing request. kubectl certificate approve allows a cluster admin to approve a certificate signing request (CSR). This action tells a certificate signing controller to issue a certificate to the requestor with the at...
Forward local port 5432 to port 5432 in the selected pod
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 5432 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 po...
Set up autoscaling for the deployment "chat-app" with a minimum of 1 pod and a maximum of 10 pods
Command: ```bash kubectl autoscale deployment chat-app --min=1 --max=10 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that use...
Create an ingress called 'app-gateway-ingress' with a rule that directs requests to testing.com/module to svc1:8082
Command: ```bash kubectl create ingress app-gateway-ingress --rule="testing.com/module=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": ""...
Forward local connections from port 8080 to port 6379 in the e-commerce-pod
Command: ```bash kubectl port-forward pod/e-commerce-pod 8080 6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected aut...
Delete the pods and services with the names "analytics" and "media-stream"
Command: ```bash kubectl delete pod,service analytics media-stream ``` 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 se...
Create a deployment named "proxy" with the specified image and number of replicas
Command: ```bash kubectl create deployment proxy --image=docker.elastic.co/elasticsearch/elasticsearch --replicas=3 ``` 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":...
Generate a Kubernetes manifest from the current working directory
Command: ```bash kubectl kustomize ``` 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. If DIR is omitted, '.' is ...
Retrieve the password for the "moon-cluster" user
Command: ```bash kubectl config view -o jsonpath='{.users[?(@.name == "moon-cluster")].user.password}' ``` What it does: Display merged kubeconfig settings or a specified kubeconfig file. You can use --output jsonpath={...} to extract specific values using a jsonpath expression. Syntax: `kubectl config view` Helpful...
Create a pod disruption budget named cache-cluster-pdb that will select all pods with the component=web label and require a minimum of four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget cache-cluster-pdb --selector=component=web --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=...
Embed the certificate authority data for the "dev-cluster" cluster entry.
Command: ```bash kubectl config set-cluster dev-cluster --embed-certs --certificate-authority=~/.kube/moon-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-...
List deployments in YAML output format using the v3.0.0 version of the experimental-apps API group.
Command: ```bash kubectl get deployments.v3.0.0.experimental-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 new config map named app-secrets with the specified keys and their corresponding files as values
Command: ```bash kubectl create configmap app-secrets --from-file=settings=/path/to/options/file1.txt --from-file=key2=/path/to/preferences/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 ...
Start a PHP pod with a container that exposes port 9090.
Command: ```bash kubectl run hazelcast --image=php --port=9090 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--file...
Forward port 8081 on all addresses to port 8080 in the chat-app-pod pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-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...
Check if the current user has permission to list the job named "cache-warming-job" in the "kube-ingress" namespace.
Command: ```bash kubectl auth can-i list jobs.batch/cache-warming-job -n kube-ingress ``` 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...
List the deployments in YAML output format, specifically in the "v1.1.1" version of the "third-party-apps" API group.
Command: ```bash kubectl get deployments.v1.1.1.third-party-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...
Embed the certificate authority data for the testing-cluster cluster entry by running the command: "kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/galaxy-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster testing-cluster --embed-certs --certificate-authority=~/.kube/galaxy-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 confi...
Get the output of the 'node --version' command from the 'astro-container' in the 'media-stream-pod' pod.
Command: ```bash kubectl exec media-stream-pod -c astro-container -- node --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...
update the environment variables of the email-server-deployment deployment with the smtp_server key from the app-config-dev config map
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/app-config-dev deployment/email-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 defini...
Add a taint with the key 'workload' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production workload=k8s-node-1:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "u...
Embed the certificate authority data for the kube-cluster-2 cluster entry by running the command:
Command: ```bash kubectl config set-cluster kube-cluster-2 --embed-certs --certificate-authority=~/.kube/on-prem-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 confi...
Create a single ingress called 'www-ingress' that directs requests to foo.com/example to the 'svc1' service on port 9000, and use the 'my-cert' TLS secret.
Command: ```bash kubectl create ingress www-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": ...
Forward the local ports 5432 and 6000 to the corresponding ports 8088 and 6000 in the 'web-app-pod' pod
Command: ```bash kubectl port-forward pod/web-app-pod 5432 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...
Start a hazelcast pod with the name 'nginx' and the image 'hazelcast/hazelcast', while overloading the spec with a partial set of values parsed from the provided JSON
Command: ```bash kubectl run nginx --image=hazelcast/hazelcast --overrides='{ "apiVersion": "hotfix-1.1.2", "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] [--...
List all resources specified in the 'kustomization.yaml' file located in the 'options/' directory
Command: ```bash kubectl get -k options/ ``` 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 results in your ...
Forward ports 5432 and 8080 to/from ports 8080 and 6000 respectively for the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5432 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Create a NodePort service named security-service-nodeport
Command: ```bash kubectl create service nodeport security-service-nodeport --tcp=8082:3000 ``` 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", "defa...
Copy the file ~/.config/kube to the /tmp/bar directory of the 'worker-pod-4' pod in the 'kube-public' namespace.
Command: ```bash kubectl cp ~/.config/kube kube-public/worker-pod-4:/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kub...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=SMTP_SERVER --from=configmap/db-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Delete the pods and services with the names "frontend" and "proxy-server"
Command: ```bash kubectl delete pod,service frontend proxy-server ``` 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 sel...