prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Get output from running the 'go' command in the warp-drive container of the frontend-pod
Command: ```bash kubectl exec frontend-pod -c warp-drive -- 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 kub...
Edit the 'data-migration-job' job using the v1 API format in JSON.
Command: ```bash kubectl edit job.v1.batch/data-migration-job -o json ``` 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 variable...
Get the output from running the 'mysql' command in the 'astro-container' from the 'proxy-service-pod'
Command: ```bash kubectl exec proxy-service-pod -c astro-container -- 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...
Forward data between local ports 5000 and 6000 and ports 6379 and 6000 in the log-aggregator-pod pod.
Command: ```bash kubectl port-forward pod/log-aggregator-pod 5000 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...
Create a cluster role named "view" with the following permissions:
Command: ```bash kubectl create clusterrole view --verb=delete --resource=services --resource-name=image-processor --resource-name=cache-redis ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Create a copy of the 'database-pod' pod and name it 'my-custom-dbg', changing all container images to 'node'
Command: ```bash kubectl debug database-pod --copy-to=my-custom-dbg --set-image=*=node ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no resourc...
Delete the prod-cluster cluster configuration
Command: ```bash kubectl config delete-cluster prod-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Execute the 'go run hello.go' command inside the gateway-pod and get the output.
Command: ```bash kubectl exec gateway-pod -- 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 kubec...
Copy the local file /tmp/foo_dir to the remote pod metrics-exporter-pod-10 in the kube-server namespace, and place it in the directory /etc/kubernetes.
Command: ```bash kubectl cp /tmp/foo_dir kube-server/metrics-exporter-pod-10:/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 omit...
Update the 'media-stream' pod with the annotation 'description' and the value 'Web server for marketing site', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods media-stream description='Web server for marketing site' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be ...
Copy the ~/.config/kube file from the database-pod-2 pod to the /tmp/bar directory on your local machine
Command: ```bash kubectl cp kube-proxy/database-pod-2:~/.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 ku...
Create a single ingress called 'default-ingress' with a rule that directs requests from site.com/bar to svc1:27017, using the tls secret "my-cert"
Command: ```bash kubectl create ingress default-ingress --rule="site.com/bar=svc1:27017,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"...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=DEBUG_MODE --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 ...
Import the `database_url` key from the `namespace-config` config map into the `email-server-deployment` deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/namespace-config 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 def...
Create a pod disruption budget named logging-pdb that selects pods with the version=v2 label and requires at least one of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget logging-pdb --selector=version=v2 --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [--dry-...
Update the label of a pod with a specific value
Command: ```bash kubectl label pods analytics tier=frontend ``` 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"...
Update the node specified in the "node-config.toml" file by partially merging the strategic patch provided in the command
Command: ```bash kubectl patch -f node-config.toml -p '{"spec":{"type":"LoadBalancer"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FILE]` He...
Forward local port 8080 to port 8088 in the cdn-service-pod, allowing data to flow between the two ports.
Command: ```bash kubectl port-forward pod/cdn-service-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 au...
Copy the contents of the /var/run/secrets/kubernetes.io/serviceaccount/ directory from the monitoring-agent-pod-6 pod in the kubeapps namespace to a local directory named /tmp/bar.
Command: ```bash kubectl cp kubeapps/monitoring-agent-pod-6:/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": "...
Create a new ClusterIP service named api-service-clusterip that maps port 8088 to port 27017.
Command: ```bash kubectl create service clusterip api-service-clusterip --tcp=8088:27017 ``` 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", "...
Taint node 'node-2' with the key 'cpu-type', value 'x86' and effect 'NoSchedule'
Command: ```bash kubectl taint nodes node-2 cpu-type=x86: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: j...
Create a job with a specific command
Command: ```bash kubectl create job database-seeding-job --image=nginx -- nginx -t ``` 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 for...
Set a custom TLS server name for validation for the star-cluster cluster entry.
Command: ```bash kubectl config set-cluster star-cluster --tls-server-name=kube-cluster-2 ``` 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...
Set the service account of the deployment named "scheduler-app-deployment" to "kube-scheduler"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment kube-scheduler ``` 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 8088 to port 8000 in the pod named "analytics-pod" to enable data forwarding
Command: ```bash kubectl port-forward pod/analytics-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 be selected auto...
Execute the command 'apache2ctl -D FOREGROUND' in the pod 'proxy-service-pod' using the container 'warp-drive' and retrieve the output.
Command: ```bash kubectl exec proxy-service-pod -c warp-drive -- apache2ctl -D FOREGROUND ``` 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 na...
Create a new config map named app-config from an env file
Command: ```bash kubectl create configmap app-config --from-env-file=path/to/settings.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...
Create a service for a replicated node using replica set, which serves on port 8010 and connects to the containers on port 8084
Command: ```bash kubectl expose rs node --port=8010 --target-port=808400 ``` 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...
Obtain the output of the 'jenkins-plugin-cli' command in the lunar-launcher from the security-service-pod.
Command: ```bash kubectl exec security-service-pod -c lunar-launcher -- jenkins-plugin-cli ``` 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 n...
Update the 'proxy' pod by adding the annotation 'security-scan-status' with the value 'pass'.
Command: ```bash kubectl annotate pods proxy security-scan-status=pass ``` 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 arbitr...
Create a deployment named 'jenkins-x' using the 'amazonlinux' image
Command: ```bash kubectl create deployment jenkins-x --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 config map named kube-system-config in the current namespace using the specified files for the key-value pairs
Command: ```bash kubectl create configmap kube-system-config --from-file=settings=/path/to/settings/file1.txt --from-file=key2=/path/to/data/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...
Add the label 'component' with the value 'api' to the 'web' pod.
Command: ```bash kubectl label pods web component=api ``` 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 ...
Execute the command 'apache2ctl -D FOREGROUND' in the nano-bot container of the pod 'proxy-service-pod', and display the output.
Command: ```bash kubectl exec proxy-service-pod -c nano-bot -- apache2ctl -D FOREGROUND ``` 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...
Get output from running the 'mysqld' command in the 'astro-container' from the 'api-service-pod'
Command: ```bash kubectl exec api-service-pod -c astro-container -- mysqld ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Edit the "notification-service" service using the "emacs" editor.
Command: ```bash KUBE_EDITOR="emacs" kubectl edit svc/notification-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 var...
Remove the label 'app' from the pod 'media-stream'
Command: ```bash kubectl label pods media-stream app- ``` 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 ...
Create a new NodePort service named web-app-nodeport, mapping port 8084 on the host to port 8000 on the targeted pods
Command: ```bash kubectl create service nodeport web-app-nodeport --tcp=8084:8000 ``` 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": "",...
Embed the certificate authority data for the "prod-cluster" cluster entry by running the command:
Command: ```bash kubectl config set-cluster prod-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 set-...
Create an ingress that directs requests from testing.com/example to svc1:8081 with TLS encryption using the secret "my-cert"
Command: ```bash kubectl create ingress service-ingress --rule="testing.com/example=svc1:8081,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": "", "...
Taint nodes with label 'stack=tech-stack' with the taint key 'dedicated' and value 'prod-node-5:PreferNoSchedule'
Command: ```bash kubectl taint node -l stack=tech-stack dedicated=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Expose a ReplicaSet named "centos" as a Service, where the Service listens on port 5001 and connects to the containers in the ReplicaSet on port 700000
Command: ```bash kubectl expose rs centos --port=5001 --target-port=700000 ``` 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....
Apply a taint with the key 'cpu-type' on nodes that have the label app=web-app and set the value to 'gpu-node-12:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app cpu-type=gpu-node-12: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": "Ou...
Retrieve the output from running the 'docker run ubuntu echo "Hello, World"' command in the code-explorer container of the auth-service-pod
Command: ```bash kubectl exec auth-service-pod -c code-explorer -- docker run ubuntu echo "Hello, World" ``` 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"...
Get kafka topics list from the analytics-service
Command: ```bash kubectl exec svc/analytics-service -- kafka-topics --list ``` 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,...
Add a taint with key 'hardware' on nodes having label 'myLabel'
Command: ```bash kubectl taint node -l myLabel hardware=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": "Output f...
Wait for the pod named "api-service-pod" to be in the "Ready" state
Command: ```bash kubectl wait --for=condition=Ready pod/api-service-pod ``` 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 resource. Alternatively, the command ca...
Check if you have permission to list the job named "cleanup-job" in the namespace "cert-manager"
Command: ```bash kubectl auth can-i list jobs.batch/cleanup-job -n cert-manager ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a partial URL t...
Remove a specific label from a pod
Command: ```bash kubectl label pods frontend role- ``` What it does: Update the labels on a resource. Syntax: `kubectl label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]` Helpful flags: "flag": "--all-namespaces", "short": "-A", "default": "false", "usage": "If tru...
Create a service for the replicated wordpress workload
Command: ```bash kubectl expose rc wordpress --port=7000 --target-port=909100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified po...
Get the output of the 'php --version' command from the first pod of the log-aggregator-deployment.
Command: ```bash kubectl exec deploy/log-aggregator-deployment -- php --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...
Create a new ClusterIP service named frontend-service-clusterip on port 7000, forwarding traffic to port 8080.
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=7000: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...
Switch to raw terminal mode and attach to a specific pod/container to interact with 'bash' in the time-machine container.
Command: ```bash kubectl attach cdn-service-pod -c time-machine -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 om...
Create a pod disruption budget named 'messaging-pdb' that selects all pods with the 'release=1.0.0' label and requires at least four of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=release=1.0.0 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=N [-...
Add a taint with key 'disktype' and value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'cluster=my-cluster'
Command: ```bash kubectl taint node -l cluster=my-cluster disktype=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
run the 'ash' command inside the payment-gateway-pod and display the output
Command: ```bash kubectl exec payment-gateway-pod -- ash ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.k...
Create an ingress resource named 'public-ingress' that routes requests from 'testing.com/module' to the service 'svc1:8010', using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress public-ingress --rule="testing.com/module=svc1:8010,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...
Rename the context 'cluster-2-context' to 'user-a-context' in your kubeconfig file
Command: ```bash kubectl config rename-context cluster-2-context user-a-context ``` What it does: Renames a context from the kubeconfig file. CONTEXT_NAME is the context name that you want to change. NEW_NAME is the new name you want to set. Note: If the context being renamed is the 'current-context', this field will ...
Create a copy of the database-pod and add a debug container to it
Command: ```bash kubectl debug database-pod -it --copy-to=debug-image-memcached --image=debian --set-image=cache=redis:alpine,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...
Listen on port 8888 locally, forwarding data between port 8080 in the pod 'backend-pod'
Command: ```bash kubectl port-forward pod/backend-pod 8888 8080 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
Configure auto-scaling for the replication controller "vpn" with a target CPU utilization of 20% and a minimum of 1 pod and a maximum of 5 pods.
Command: ```bash kubectl autoscale rc vpn --max=5 --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 uses the...
Create an ingress called 'public-service-ingress' with a rule that directs requests from testing.com/module to svc1:9000
Command: ```bash kubectl create ingress public-service-ingress --rule="testing.com/module=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":...
Create a service for the replication controller specified in "nginx-controller.yaml"
Command: ```bash kubectl expose -f nginx-controller.yaml --port=5000 --target-port=330600 ``` 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 an ingress called 'external-ingress' with a rule that directs requests to website.com/input to svc1:8088 and uses the tls secret "my-cert"
Command: ```bash kubectl create ingress external-ingress --rule="website.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...
Forward traffic from localhost on port 6379 to the targetPort of the service's port named "https" in a pod selected by the analytics-service service.
Command: ```bash kubectl port-forward service/analytics-service 6379: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...
Import the smtp_server key from the global-config config map into the scheduler-app-deployment deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/global-config deployment/scheduler-app-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Set the service account of the 'load-balancer-deployment' deployment to 'default'
Command: ```bash kubectl set serviceaccount deployment load-balancer-deployment default ``` 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: `kube...
Forward port 6379 on localhost and IP 10.19.21.23 to port 3000 in the pod named "backend-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 6379:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Forward the localhost and IP address to listen on port 8000 and forward it to port 8088 in the pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 8000: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 ...
Retrieve snapshot logs from container frontend-deployment-1 in the deployment named gateway-pod
Command: ```bash kubectl logs deployment/frontend-deployment -c gateway-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: "flag": "-...
Create a service for the 'alpine' deployment, which serves on port 9091 and connects to the containers on port 801000
Command: ```bash kubectl expose deployment alpine --port=9091 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
update the environment variables of a deployment to use specific keys from a config map.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/global-config deployment/log-aggregator-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definit...
Scale the deployment named foo to 5 replicas, if the current size is 1
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/foo ``` 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...
Create a cron job named "database-maintenance" that runs the command "npm --version" every minute using the image "node"
Command: ```bash kubectl create cronjob database-maintenance --image=node --schedule="*/1 * * * *" -- npm --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", "shor...
Start a redis pod with custom specifications using JSON overrides
Command: ```bash kubectl run nginx --image=redis --overrides='{ "apiVersion": "v2.1.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...
Copy a local directory to a directory in a remote pod.
Command: ```bash kubectl cp /tmp/foo_dir_dir task-processor-pod-17:/tmp/bar_dir_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 ...
Retrieve the snapshot logs from a container named api-server-deployment-1 in a deployment called database-pod
Command: ```bash kubectl logs deployment/api-server-deployment -c database-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: "flag":...
Copy the local file /tmp/foo to the remote pod kube-proxy/payment-gateway-pod-19 in the namespace, and place it in the /tmp/bar directory
Command: ```bash kubectl cp /tmp/foo kube-proxy/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, use the...
Display information about the control plane and cluster services.
Command: ```bash kubectl cluster-info ``` What it does: Display addresses of the control plane and services with label kubernetes.io/cluster-service=true. To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. Syntax: `kubectl cluster-info`
Expose the replication controller specified in the "ruby-controller.yaml" file as a service, serving on port 8082 and connecting to the containers on port 801000.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8082 --target-port=801000 ``` 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...
Run the 'nginx -t' command in the cosmic-container of the chat-app-pod and display the output.
Command: ```bash kubectl exec chat-app-pod -c cosmic-container -- 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,...
Create a cluster role named "view" with the ability to watch services and specify the resource names "mail-server" and "database-master"
Command: ```bash kubectl create clusterrole view --verb=watch --resource=services --resource-name=mail-server --resource-name=database-master ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|...
Edit the 'notification-service' service using the Sublime editor
Command: ```bash KUBE_EDITOR="sublime" kubectl edit svc/notification-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 v...
Expose the replicated python service on port 8081, connecting to the containers on port 8000
Command: ```bash kubectl expose rc python --port=8081 --target-port=8000 ``` 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...
Copy the file ~/.config/kube from the remote pod 'argocd/cache-pod-5' to the local directory '/tmp/bar'
Command: ```bash kubectl cp argocd/cache-pod-5:~/.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 kubectl....
Get output from running the 'mongo' command in rocket-ranger from the web-app-pod
Command: ```bash kubectl exec web-app-pod -c rocket-ranger -- mongo ``` 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 th...
import specific keys from a config map to a deployment
Command: ```bash kubectl set env --keys=api_key --from=configmap/ui-config deployment/analytics-platform-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitio...
create a service for the 'centos' deployment, serving on port 9000 and forwarding connections to the containers on port 909200
Command: ```bash kubectl expose deployment centos --port=9000 --target-port=909200 ``` 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...
Get the output from running the 'psql' command in the first container of the first pod of the 'email-service' service
Command: ```bash kubectl exec svc/email-service -- psql ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.ku...
Set up autoscaling for the deployment "chat-app"
Command: ```bash kubectl autoscale deployment chat-app --min=7 --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...
Forcefully drain node "edge-node-10" even if there are unmanaged pods on it
Command: ```bash kubectl drain edge-node-10 --force ``` What it does: Drain node in preparation for maintenance. The given node will be marked unschedulable to prevent new pods from arriving. 'drain' evicts the pods if the API server supports https://kubernetes.io/docs/concepts/workloads/pods/disruptions/ . Otherwise,...
List deployments in the YAML output format of the "v1.0.0" version of the "external-apps" API group.
Command: ```bash kubectl get deployments.v1.0.0.external-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 w...
Create a new service named external-database-service that maps to an external DNS name (practice-online.site)
Command: ```bash kubectl create service externalname external-database-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 referenc...
Create a new config map named app-config-dev with specific keys and corresponding files
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/configs/file1.txt --from-file=key2=/path/to/data/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 co...
Get the output from running "ruby --version" command in the first pod of the deployment "gateway-deployment".
Command: ```bash kubectl exec deploy/gateway-deployment -- 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 omitted, ...
Import specific keys from a config map to a deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --from=configmap/db-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 definitio...
Set the service account for the deployment named 'cache-cluster-deployment' to 'kube-scheduler'
Command: ```bash kubectl set serviceaccount deployment cache-cluster-deployment kube-scheduler ``` 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...
Create a job for batch processing using a specific image and command
Command: ```bash kubectl create job batch-processing --image=redis -- redis-server --version ``` What it does: Create a job with the specified name. Syntax: `kubectl create job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "...
Configure autoscaling for the replication controller "analytics" with a maximum of 5 pods and a target CPU utilization of 81%.
Command: ```bash kubectl autoscale rc analytics --max=5 --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 that us...
Add a taint with key 'disktype' on nodes having label region=eu-west-2
Command: ```bash kubectl taint node -l region=eu-west-2 disktype=testing-node-11: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": "", "us...