prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Forward traffic from port 8000 on localhost and IP 10.19.21.23 to port 9090 in the web-app-pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/web-app-pod 8000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteri...
Execute the 'composer --version' command in the pod 'frontend-pod' using the 'rocket-ranger' container, and retrieve the output.
Command: ```bash kubectl exec frontend-pod -c rocket-ranger -- composer --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If o...
Add a taint with the key 'disktype' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 disktype=worker-node-3:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage"...
Set environment variables for a deployment by importing them from a config map with a specified prefix.
Command: ```bash kubectl set env --from=configmap/app-config-dev --prefix=MYSQL_ deployment/notification-handler-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable d...
Apply the configuration in the manifest.yaml file that matches the label app=nginx and delete any other resources that are not specified in the file and also match the label app=nginx.
Command: ```bash kubectl apply --prune -f manifest.yaml -l app=nginx ``` 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 'crea...
Forward traffic from port 8000 on all addresses to port 9090 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 8000:9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will...
Create a role named "reader" with ResourceName specified
Command: ```bash kubectl create role reader --verb=watch --resource=pods --resource-name=cdn-proxy --resource-name=message-queue ``` 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...
Attach to the pod "cdn-service-pod" and get the output from the container "stardust-shuttle"
Command: ```bash kubectl attach cdn-service-pod -c stardust-shuttle ``` 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 job named "log-collection" using the golang image and execute the command "go"
Command: ```bash kubectl create job log-collection --image=golang -- go ``` 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...
Get output from running 'wp' command in code-explorer container in pod 'frontend-pod'
Command: ```bash kubectl exec frontend-pod -c code-explorer -- 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 ...
Remove the label named 'bar' from the 'auth' pod
Command: ```bash kubectl label pods auth tier- ``` 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 true, c...
Create a new LoadBalancer service named security-service-lb, and map TCP traffic from port 9092 of the service to port 8000 of the pods.
Command: ```bash kubectl create service loadbalancer security-service-lb --tcp=9092:8000 ``` 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",...
Open the service called authentication-service for editing using the vi editor.
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/authentication-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...
set the environment variable "log_level" in the deployment "user-management-deployment" by importing it from the "global-config" config map, only importing the keys specified.
Command: ```bash kubectl set env --keys=log_level --from=configmap/global-config deployment/user-management-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...
Create a deployment named "db" that runs the "ruby" image with 3 replicas.
Command: ```bash kubectl create deployment db --image=ruby --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": "", "usage": "Output format. One of: json|y...
Set the resource request and limits for all containers in the python deployment
Command: ```bash kubectl set resources deployment python --limits=cpu=200m,memory=512Mi --requests=cpu=2,memory=64Mi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested...
Begin streaming the logs of the "stardust-shuttle" container in the "database-pod" pod.
Command: ```bash kubectl logs -f -c stardust-shuttle 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",...
Partially update a node using a strategic merge patch, providing the patch as a JSON object
Command: ```bash kubectl patch node storage-node-13 -p '{"spec":{"containers":[{"name":"container-name", "resources":{"limits":{"cpu":"200m"}}}]}' ``` 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 ...
Execute the 'go run hello.go' command in the stardust-shuttle container of the analytics-pod and retrieve the output.
Command: ```bash kubectl exec analytics-pod -c stardust-shuttle -- 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 ...
Create a cluster role named "reader" with ResourceName specified
Command: ```bash kubectl create clusterrole reader --verb=create --resource=configmaps --resource-name=database-master --resource-name=api-server ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cli...
Remove the label 'unhealthy-' from the 'monitoring' pod if it exists
Command: ```bash kubectl label pods monitoring unhealthy- ``` 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": ...
Taint nodes with label owner=john-doe for zone=node-2
Command: ```bash kubectl taint node -l owner=john-doe zone=node-2: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...
List the replication controller web, service media-stream-rc, and pod payment-gateway-pod
Command: ```bash kubectl get rc/web service/media-stream-rc pods/payment-gateway-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 n...
Add a taint with key 'disktype=dev-node-4:PreferNoSchedule' on nodes having label stack=tech-stack.
Command: ```bash kubectl taint node -l stack=tech-stack disktype=dev-node-4: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":...
Set the environment variable "config_file_path" in the "search-engine-deployment" deployment by importing the value from the "app-settings" config map.
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/app-settings 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 de...
import the log_level key from the ui-config config map and set it as an environment variable in the monitoring-stack-deployment deployment.
Command: ```bash kubectl set env --keys=log_level --from=configmap/ui-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 of the 'web-app-deployment' deployment to 'prometheus'
Command: ```bash kubectl set serviceaccount deployment web-app-deployment prometheus ``` 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...
Forward local traffic from port 3000 to port 6379 inside a pod selected by the 'database-deployment' deployment.
Command: ```bash kubectl port-forward deployment/database-deployment 3000 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 ...
Update the annotation 'last-deployment' of the 'monitoring' pod to '2023-03-15', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods monitoring last-deployment='2023-03-15' ``` 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 label...
Copy the local file "/tmp/foo_dir" to the remote pod "monitoring/metrics-exporter-pod-10" in the "/etc/kubernetes" directory.
Command: ```bash kubectl cp /tmp/foo_dir monitoring/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 omitt...
Create a job named "indexing" using the specified image and run the "dotnet" command inside the job.
Command: ```bash kubectl create job indexing --image=mcr.microsoft.com/dotnet/core/runtime -- dotnet ``` 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": "", "u...
Create a role binding named admin that assigns the admin cluster role to developer3, k8s-admin, and qa-engineers users and groups.
Command: ```bash kubectl create rolebinding admin --clusterrole=admin --user=developer3 --user=k8s-admin --group=qa-engineers ``` What it does: Create a role binding for a particular role or cluster role. Syntax: `kubectl create rolebinding NAME --clusterrole=NAME|--role=NAME [--user=username] [--group=groupname] [--...
Create a new ClusterIP service named inventory-service-clusterip with the port mapping TCP 8181 to port 9000.
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=8181:9000 ``` 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": "-...
Apply a taint to the node 'prod-node-5' with the key 'dedicated' and no value.
Command: ```bash kubectl taint nodes prod-node-5 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:...
Retrieve the list of deployments in the "custom-deployments" API group with version "v1.1.0" in YAML format.
Command: ```bash kubectl get deployments.v1.1.0.custom-deployments -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 ...
Create a single ingress called 'private-api-ingress' that directs requests to testing.com/example to the service 'svc1' on port '3306', and use the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress private-api-ingress --rule="testing.com/example=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": "...
Get the output from running the 'jenkins-plugin-cli' command in the first container of the first pod of the 'payment-service' service.
Command: ```bash kubectl exec svc/payment-service -- 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 name. If omitted, us...
Forward local port 8080 to port 3000 in the pod selected by the deployment "authentication-service-deployment".
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 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, ...
Add a taint with the key 'app' on nodes having the label app=web-app using the command 'kubectl taint node -l app=web-app app=web-node-8:PreferNoSchedule'
Command: ```bash kubectl taint node -l app=web-app app=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": "Output f...
Create a new config map named app-config-prod and populate it with the specified files and keys
Command: ```bash kubectl create configmap app-config-prod --from-file=properties=/path/to/preferences/file1.txt --from-file=key1=/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 creati...
Forward local port 8080 to the pod port 5000 for the pod named cdn-service-pod
Command: ```bash kubectl port-forward pod/cdn-service-pod 8080 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...
Execute the 'dotnet' command inside the 'security-service-pod' pod.
Command: ```bash kubectl exec security-service-pod -- dotnet ``` 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 environment variables from the email-credentials-secret into the web-app-deployment
Command: ```bash kubectl set env --from=secret/email-credentials-secret deployment/web-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 definitions in one or m...
Create a cluster role named "reader" with ResourceName specified for "dev-database" and "prod-api-gateway"
Command: ```bash kubectl create clusterrole reader --verb=exec --resource=configmaps --resource-name=dev-database --resource-name=prod-api-gateway ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|cl...
Listen on port 5432 on all addresses and forward the traffic to port 5000 in the security-service-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/security-service-pod 5432: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 ...
Copy a file from a remote pod to a local location
Command: ```bash kubectl cp kubeapps/web-app-pod-1::/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 kubectl.ku...
Copy the local file /tmp/foo to the remote pod rook-ceph/api-server-pod-3 in the /tmp/bar directory
Command: ```bash kubectl cp /tmp/foo rook-ceph/api-server-pod-3:/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...
Rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context dev-context new-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 also be u...
Forward incoming traffic on port 8000 of localhost and IP address 10.19.21.23 to port 8000 of the 'backend-pod' pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 8000: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 criteri...
Forward traffic from local port 9090 to port 3000 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 9090: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 au...
Create a new ClusterIP service named database-service-clusterip with the TCP port mapping of 8010 to 8082
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=8010:8082 ``` 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 the 'lunar-launcher' container in the 'cdn-service-pod' pod
Command: ```bash kubectl attach cdn-service-pod -c lunar-launcher -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 ...
Import the environment variables from the 'monitoring-credentials-secret' secret into the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret 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 one...
list the deployments in the "hotfix-1.1.2" version of the "api-v1" API group and display the output in JSON format
Command: ```bash kubectl get deployments.hotfix-1.1.2.api-v1 -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wi...
Create a new LoadBalancer service named 'api-service-lb' and map incoming traffic from port 8081 to port 8088.
Command: ```bash kubectl create service loadbalancer api-service-lb --tcp=8081:8088 ``` 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 deployment named logging with the node image and expose port 8083.
Command: ```bash kubectl create deployment logging --image=node --port=8083 ``` What it does: Create a deployment with the specified name. Syntax: `kubectl create deployment NAME --image=image -- [COMMAND] [args...]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: js...
Copy the file '/tmp/foo' from the 'message-broker-pod-15' pod to the local machine's '/tmp/bar' directory.
Command: ```bash kubectl cp kube-flannel/message-broker-pod-15::/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 t...
Update the annotation 'git-repo' with the value 'https://github.com/example/my-app' for the pod 'web', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods web 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 larger t...
Forward local port 8088 to pod port 8000
Command: ```bash kubectl port-forward pod/frontend-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 autom...
Create a new config map named "namespace-config" with specified keys and file paths.
Command: ```bash kubectl create configmap namespace-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/properties/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When cr...
Start a pod called 'nginx' using the 'amazonlinux' image, but override some of the specifications with values provided in the JSON object.
Command: ```bash kubectl run nginx --image=amazonlinux --overrides='{ "apiVersion": "beta-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] -- ...
Create a copy of the auth-service-pod by adding a debug container and changing container images for the proxy and worker containers.
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-web --image=debian --set-image=proxy=nginx:1.21,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...
Forward traffic from local port 8888 to port 5432 in the 'frontend-pod' pod
Command: ```bash kubectl port-forward pod/frontend-pod 8888:5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Import specific keys from a config map into a deployment's environment variables
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-secrets 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 definit...
Partially update the node specified in "machine-configuration.yaml" by setting the "unschedulable" field to true.
Command: ```bash kubectl patch -f machine-configuration.yaml -p '{"spec":{"unschedulable":true}}' ``` 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 ...
Update the image of the 'mysql' deployment, setting the 'busybox' container image to 'busybox' and the 'mysql' container image to 'mysql:5.7.35'
Command: ```bash kubectl set image deployment/mysql busybox=busybox mysql=mysql:5.7.35 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset...
Create a new ClusterIP service named backend-service-clusterip listening on port 8084 and forwarding traffic to port 8083
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=8084:8083 ``` 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"...
Auto scale the "web" replication controller with the number of pods between 1 and 8, and the target CPU utilization set at 81%.
Command: ```bash kubectl autoscale rc web --max=8 --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 uses the...
Get the output from running the 'python' command in the lunar-launcher container of the email-service-pod pod
Command: ```bash kubectl exec email-service-pod -c lunar-launcher -- python ``` 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 new secret named 'gcp-service-account-secret' with the specified keys instead of names on disk
Command: ```bash kubectl create secret generic gcp-service-account-secret --from-file=ssh-privatekey=path/to/id_rsa --from-file=ssh-publickey=path/to/id_rsa.pub ``` 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 creati...
Update the image of all containers in the 'prod' daemonset to 'php:7.4.22'
Command: ```bash kubectl set image daemonset prod *=php:7.4.22 ``` What it does: Update existing container image(s) of resources. Possible resources include (case insensitive): pod (po), replicationcontroller (rc), deployment (deploy), daemonset (ds), statefulset (sts), cronjob (cj), replicaset (rs) Syntax: `kubectl ...
Create a new config map named app-config-dev with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-config-dev --from-file=settings=/path/to/parameters/file1.txt --from-file=key2=/path/to/configurations/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 ...
Create a service for the 'centos' deployment, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose deployment centos --port=8088 --target-port=808300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specifi...
Create an ingress called 'private-service-ingress' that directs requests from 'testing.com/input' to service 'svc1' on port 27017 with the TLS secret 'my-cert'
Command: ```bash kubectl create ingress private-service-ingress --rule="testing.com/input=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"...
Create a new secret with key-value pairs
Command: ```bash kubectl create secret generic app-config-secret --from-literal=key1=supersecret --from-literal=key2=topsecret ``` 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 k...
Listen on local ports 8888 and 6000, forwarding data to/from ports 6379 and 6000 in a pod selected by the deployment
Command: ```bash kubectl port-forward deployment/authentication-service-deployment 8888 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, ...
Set the service account of the 'log-aggregator-deployment' deployment to 'my-service-account'
Command: ```bash kubectl set serviceaccount deployment log-aggregator-deployment my-service-account ``` 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...
import the 'API_KEY' key from the 'app-config-dev' config map and set it as an environment variable in the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-dev deployment/web-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 definitions in ...
Create a job to build an image using the nginx image
Command: ```bash kubectl create job image-build-job --image=nginx -- nginx ``` 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...
Embed the certificate authority data for the "edge-cluster" cluster entry by running the command "kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster edge-cluster --embed-certs --certificate-authority=~/.kube/kube-cluster-2/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...
Delete the context for the staging-context cluster
Command: ```bash kubectl config delete-context staging-context ``` What it does: Delete the specified context from the kubeconfig. Syntax: `kubectl config delete-context NAME`
Create a new ClusterIP service named backend-service-clusterip for the TCP port mapping from local port 9091 to target port 8083.
Command: ```bash kubectl create service clusterip backend-service-clusterip --tcp=9091:8083 ``` What it does: Create a ClusterIP service with the specified name. Syntax: `kubectl create service clusterip NAME [--tcp=<port>:<targetPort>] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o"...
Get the output from running the 'python' command in the 'nebula-navigator' container of the 'database-pod' pod.
Command: ```bash kubectl exec database-pod -c nebula-navigator -- python ``` 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, u...
Rename the context 'staging-context' to 'edge-context'
Command: ```bash kubectl config rename-context staging-context edge-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 also...
Forward local port 8080 to port 8088 in the pod "log-aggregator-pod"
Command: ```bash kubectl port-forward pod/log-aggregator-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...
Forward traffic from port 8080 on localhost and IP address 10.19.21.23 to port 5000 in the pod named mypod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8080: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 p...
List the deployments in the JSON output format for the "sandbox-apps" API group, using the version "v3.0.0"
Command: ```bash kubectl get deployments.v3.0.0.sandbox-apps -o json ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wi...
configure resource requests and limits for all containers in a deployment named centos for CPU and memory usage
Command: ```bash kubectl set resources deployment centos --limits=cpu=200m,memory=512Mi --requests=cpu=1,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...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=config_file_path --from=configmap/env-vars deployment/database-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions...
Increase the number of replicas in the 'mysql' replica set to 3
Command: ```bash kubectl scale --replicas=3 rs/mysql ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated befo...
Get the output from running the 'node' command in the container named 'mycontainer' in the pod named 'backend-pod'
Command: ```bash kubectl exec backend-pod -c mycontainer -- node ``` 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 k...
Start a pod using the Ethereum client-go image and expose port 5000
Command: ```bash kubectl run hazelcast --image=ethereum/client-go --port=5000 ``` 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: ...
Create a MySQL pod with the container exposing port 8084
Command: ```bash kubectl run hazelcast --image=mysql --port=8084 ``` 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...
Update the pod with the name 'api' by adding the label 'env' with the value 'staging'
Command: ```bash kubectl label pods api env=staging ``` 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 tr...
Create an ingress named 'private-ingress' that routes requests for website.com/bar to svc1:8088 and uses the TLS secret named "my-cert"
Command: ```bash kubectl create ingress private-ingress --rule="website.com/bar=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": "", "usag...
Update the pod named 'security' with the annotation 'alert-email' and set its value to 'alerts@example.com'
Command: ```bash kubectl annotate pods security alert-email=alerts@example.com ``` 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 includ...
Rename the context 'testing-context' to 'edge-context' in your kubeconfig file
Command: ```bash kubectl config rename-context testing-context edge-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 also...
Import the 'smtp_server' key from the 'db-config' ConfigMap into the 'search-engine-deployment' Deployment.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/db-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...
Add a taint with key 'workload' on nodes having label component=proxy
Command: ```bash kubectl taint node -l component=proxy workload=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":...
Create a pod disruption budget named messaging-pdb that will select all pods with the release=1.0.0 label and require at least 9 of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget messaging-pdb --selector=release=1.0.0 --min-available=9 ``` 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 [-...