prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Scale the deployment named backend-service-replicaset to 7 replicas if its current size is 5
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/backend-service-replicaset ``` 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 --r...
Update the pod named 'api' by setting the annotation 'team' to the value 'frontend-team', overwriting any existing value.
Command: ```bash kubectl annotate --overwrite pods api team='frontend-team' ``` 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 a...
Switch to raw terminal mode and attach to the 'nebula-navigator' container inside the 'mypod' pod.
Command: ```bash kubectl attach mypod -c nebula-navigator -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,...
create a new LoadBalancer service named 'gateway-lb' that maps TCP port 7000 on the cluster to port 8181 on the service
Command: ```bash kubectl create service loadbalancer gateway-lb --tcp=7000:8181 ``` 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", "default...
Run the 'redis-server' command in the quantum-quark container of the media-stream-pod pod and get the output.
Command: ```bash kubectl exec media-stream-pod -c quantum-quark -- 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 omi...
Create a copy of the email-service-pod, changing all container images to python and name it debug-image-web
Command: ```bash kubectl debug email-service-pod --copy-to=debug-image-web --set-image=*=python ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if n...
Execute the 'jenkins-plugin-cli' command on the first pod of the 'proxy-service-deployment' deployment to retrieve the output
Command: ```bash kubectl exec deploy/proxy-service-deployment -- 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...
Add a taint with the key 'app' and value 'backup-node-14:PreferNoSchedule' on nodes having the label tier=frontend.
Command: ```bash kubectl taint node -l tier=frontend app=backup-node-14: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...
Forward traffic from port 8081 on all addresses to port 8081 in the pod named api-service-pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 8081: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 w...
Apply a taint to a specific node with a given key, value, and effect.
Command: ```bash kubectl taint nodes app-node-6 datacenter=dc-1:NoExecute ``` 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...
Wait until the pod named "cdn-service-pod" has the status condition of type "Ready"
Command: ```bash kubectl wait --for=condition=Ready pod/cdn-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...
Create a new config map named app-config using the specified keys and corresponding files.
Command: ```bash kubectl create configmap app-config --from-file=conf=/path/to/configs/file1.txt --from-file=data=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config ...
Run the 'node' command in rocket-ranger from the frontend-pod and get the output.
Command: ```bash kubectl exec frontend-pod -c rocket-ranger -- 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 th...
import the LOG_LEVEL key from the monitoring-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/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 d...
Start port forwarding from local port 8080 to port 8088 in the frontend-pod. Make it accessible from all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/frontend-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...
Execute the 'python --version' command in the nebula-navigator container of the log-aggregator-pod and retrieve the output.
Command: ```bash kubectl exec log-aggregator-pod -c nebula-navigator -- python --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 nam...
Return the snapshot logs of all containers in the 'chat-app-pod' pod
Command: ```bash kubectl logs chat-app-pod --all-containers=true ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", ...
Create a copy of the 'log-aggregator-pod' pod with a debug container and change the container images to 'debian'
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=my-custom-dbg --image=debian --set-image=api=api:v2,scheduler=my-scheduler:1.0 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resou...
Forward local port 8000 to pod port 8888
Command: ```bash kubectl port-forward pod/log-aggregator-pod 8000 8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected...
Import the REDIS_HOST key from the namespace-config ConfigMap and set it as an environment variable in the user-management-deployment deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/namespace-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 de...
Add a taint with the key 'zone' on nodes that have the label 'region=eu-west-2'
Command: ```bash kubectl taint node -l region=eu-west-2 zone=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": "O...
Create a priority class named high-priority with a value of 1000 and a description of "Top priority, critical workloads"
Command: ```bash kubectl create priorityclass high-priority --value=1000 --description="Top priority, critical workloads" ``` What it does: Create a priority class with the specified name, value, globalDefault and description. Syntax: `kubectl create priorityclass NAME --value=VALUE --global-default=BOOL [--dry-run=s...
Create a copy of the 'cdn-service-pod' pod and change all container images to 'redis'
Command: ```bash kubectl debug cdn-service-pod --copy-to=dgb-img --set-image=*=redis ``` 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 resource ...
Create a cluster role named "custom_role" with the API Group "tokenreviews.authentication.k8s.io" specified
Command: ```bash kubectl create clusterrole custom_role --verb=exec,list,delete --resource=tokenreviews.authentication.k8s.io ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful ...
Forward traffic from local port 8000 to the pod's port 8000
Command: ```bash kubectl port-forward pod/proxy-server-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 criteria, a pod will be selected a...
Create a pod disruption budget named 'load-balancer-pdb' that will select all pods with the 'version=v2' label and require at least 9 of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget load-balancer-pdb --selector=version=v2 --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 [...
Start streaming the logs of the 'mycontainer' container in the 'proxy-server-pod' pod
Command: ```bash kubectl logs -f -c mycontainer proxy-server-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 the 'gpu-node-12' node by applying a strategic merge patch with the following JSON:
Command: ```bash kubectl patch node gpu-node-12 -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...
Forward local port 8081 to port 9090 in the frontend-pod pod
Command: ```bash kubectl port-forward pod/frontend-pod 8081 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...
Copy the file '/tmp/foo' from the remote pod 'logging-agent-pod-7' to the local directory '/tmp/bar_dir'
Command: ```bash kubectl cp kubeapps/logging-agent-pod-7:/tmp/foo /tmp/bar_dir ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the k...
Forward local port 3000 to port 8088 in the chat-app-pod pod
Command: ```bash kubectl port-forward pod/chat-app-pod 3000:8088 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Import the specified keys from a config map into the environment variables of a deployment.
Command: ```bash kubectl set env --keys=database_url --from=configmap/log-config deployment/backend-microservice-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...
import the REDIS_HOST key from the config map named namespace-config and set it as an environment variable in the deployment named notification-handler-deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/namespace-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 variab...
Create a copy of the e-commerce pod with a debug container and changed container images.
Command: ```bash kubectl debug e-commerce-pod -it --copy-to=debug-image-app --image=debian --set-image=mailer=mailer:latest,proxy=nginx:1.21 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resourc...
Display the most recent 3 lines of output for the 'proxy-service-pod' pod.
Command: ```bash kubectl logs --tail=3 proxy-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": "--container", "short":...
Listen on local port 8888 and forward data to/from port 5000 in the 'chat-app-pod' pod.
Command: ```bash kubectl port-forward pod/chat-app-pod 8888 5000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
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=200m,memory=4Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource request...
delete a cluster named "testing-cluster"
Command: ```bash kubectl config delete-cluster testing-cluster ``` What it does: Delete the specified cluster from the kubeconfig. Syntax: `kubectl config delete-cluster NAME`
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-name-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 ...
Set up autoscaling for the replication controller "payment"
Command: ```bash kubectl autoscale rc payment --max=2 --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 uses...
Apply a taint to nodes with the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production app=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": "", "u...
Get the output from running the 'elasticsearch-plugin --list' command in the nebula-navigator container from the database-pod pod.
Command: ```bash kubectl exec database-pod -c nebula-navigator -- elasticsearch-plugin --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": "Containe...
Create a new ExternalName service named external-payment-gateway-service with the external name "test-site.org"
Command: ```bash kubectl create service externalname external-payment-gateway-service --external-name test-site.org ``` 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...
Forward the local port 6379 to the 'log-aggregator-pod' pod's port 8888
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-pod 6379:8888 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the ...
Create a new config map named 'kube-system-config' using the data from the 'path/to/data.env' environment file.
Command: ```bash kubectl create configmap kube-system-config --from-env-file=path/to/data.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 th...
Set the certificate authority data for the cluster-alpha cluster.
Command: ```bash kubectl config set clusters.cluster-alpha.certificate-authority-data $(echo "cert_data_here" | base64 -i -) ``` 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...
Create a new ExternalName service named external-third-party-api-service with the external name "sandbox-site.co"
Command: ```bash kubectl create service externalname external-third-party-api-service --external-name sandbox-site.co ``` 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 refere...
Execute the 'geth version' command in the quantum-quark container from the email-service-pod pod.
Command: ```bash kubectl exec email-service-pod -c quantum-quark -- geth 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 om...
Apply a taint to a node with specific key, value, and effect
Command: ```bash kubectl taint nodes edge-node-10 app=backend: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 format...
Execute the command "composer --version" inside the "payment-gateway-pod" pod using the "rocket-ranger" container and retrieve the output.
Command: ```bash kubectl exec payment-gateway-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 nam...
Set the custom TLS server name to 'cluster-beta' for the 'staging-cluster' cluster entry
Command: ```bash kubectl config set-cluster staging-cluster --tls-server-name=cluster-beta ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Forward local port 3000 to port 9090 in the analytics-platform-deployment pod.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 3000 9090 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a po...
Set the service account of the deployment "scheduler-app-deployment" to "kube-controller-manager"
Command: ```bash kubectl set serviceaccount deployment scheduler-app-deployment kube-controller-manager ``` 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), statefulse...
Create a single ingress called 'api-v2-ingress' that directs requests to foo.com/input to svc1:9091 with a tls secret "my-cert"
Command: ```bash kubectl create ingress api-v2-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":...
import the API_KEY key from the app-config-dev config map and set it as an environment variable in the load-balancer-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/app-config-dev 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 definitio...
Expose the replica set named "hazelcast" as a service on port 8089, with the service forwarding traffic to containers on port 637900.
Command: ```bash kubectl expose rs hazelcast --port=8089 --target-port=637900 ``` 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...
Update the environment variables of a deployment by adding a new variable.
Command: ```bash kubectl set env deployment/user-management-deployment S3_BUCKET=my-s3-bucket ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one or more pod ...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to the /etc/kubernetes directory in the 'logging' namespace, for the 'database-pod-2' pod
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ logging/database-pod-2:/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": "Co...
Add a taint to the nodes labeled with feature=feature-xyz, with the key 'environment' and value 'k8s-node-1:PreferNoSchedule'.
Command: ```bash kubectl taint node -l feature=feature-xyz environment=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...
Update the annotation 'app-version' of the pod 'media-stream' with the value '2.5.1', replacing any existing value
Command: ```bash kubectl annotate --overwrite pods media-stream app-version='2.5.1' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and i...
Import specific keys from a config map into a deployment.
Command: ```bash kubectl set env --keys=DATABASE_URL --from=configmap/app-config-prod 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 d...
Forward port 8888 on localhost and 10.19.21.23 to port 8888 in the e-commerce pod
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/e-commerce-pod 8888: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 crit...
Create a new config map named 'global-config' with the 'settings' key from the '/path/to/properties/file1.txt' file and the 'key2' key from the '/path/to/options/file2.txt' file.
Command: ```bash kubectl create configmap global-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/options/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=web' to the pod 'proxy-server'
Command: ```bash kubectl label pods proxy-server component=web ``` 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", "usa...
import the API_KEY key from the monitoring-config config map and set it as an environment variable for the database-deployment deployment
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/monitoring-config 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...
Create a cluster role named "reader" that allows user to perform "create", "get" and "proxy" on configmaps
Command: ```bash kubectl create clusterrole reader --verb=create,get,proxy --resource=configmaps ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "s...
Configure the "developer" entry with additional exec auth plugin arguments
Command: ```bash kubectl config set-credentials developer --exec-arg=arg1 --exec-arg=arg2 ``` 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 ...
Create a service for the replicated ubuntu pods, serving on port 80 and connecting to the containers on port 8888
Command: ```bash kubectl expose rc ubuntu --port=80 --target-port=888800 ``` 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...
Create a new pod named "hazelcast" using the golang image and expose port 8010 on the container.
Command: ```bash kubectl run hazelcast --image=golang --port=8010 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--f...
Execute the 'psql' command in the code-explorer container of the monitoring-pod and retrieve the output.
Command: ```bash kubectl exec monitoring-pod -c code-explorer -- 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 ...
Create a new secret named ldap-credentials-secret using the files in the folder "path/to/profiles" as keys.
Command: ```bash kubectl create secret generic ldap-credentials-secret --from-file=path/to/profiles ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the base...
Get output from running the 'mysql --version' command in stardust-shuttle from pod payment-gateway-pod
Command: ```bash kubectl exec payment-gateway-pod -c stardust-shuttle -- mysql --version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container nam...
Create an ingress named 'app-ingress' that directs requests to testing.com/example to svc1:3001
Command: ```bash kubectl create ingress app-ingress --rule="testing.com/example=svc1:3001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create an ingress called 'frontend-ingress' that directs requests from foo.com/example to svc1:8089 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="foo.com/example=svc1:8089,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Set the resource request and limits for all containers in the alpine deployment
Command: ```bash kubectl set resources deployment alpine --limits=cpu=200m,memory=512Mi --requests=cpu=5,memory=1Gi ``` What it does: Specify compute resource requirements (CPU, memory) for any resource that defines a pod template. If a pod is successfully scheduled, it is guaranteed the amount of resource requested,...
Update the "container-name" container's CPU resource limit to "200m" on the node specified in the "node-settings.json" file using a strategic merge patch.
Command: ```bash kubectl patch -f node-settings.json -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...
Create a service for the replicated centos using the replica set 'centos', which serves on port 8000 and connects to the containers on port 8000.
Command: ```bash kubectl expose rs centos --port=8000 --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 ~/.config/kube file from the pod named logging/admin-dashboard-pod-16 to /etc/kubernetes on your local machine.
Command: ```bash kubectl cp logging/admin-dashboard-pod-16:~/.config/kube /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...
Execute the command "pip --version" in the "stardust-shuttle" container of the "vpn-service-pod" pod.
Command: ```bash kubectl exec vpn-service-pod -c stardust-shuttle -- pip --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 ...
Retrieve the snapshot logs from container order-processing-deployment-1 of the deployment named proxy-server-pod
Command: ```bash kubectl logs deployment/order-processing-deployment -c proxy-server-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 flag...
Add a taint with key 'zone' and no value to the 'monitoring-node-15' node
Command: ```bash kubectl taint nodes monitoring-node-15 zone:NoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One o...
Use the context for a specific cluster
Command: ```bash kubectl config use-context web-cluster ``` What it does: Set the current-context in a kubeconfig file. Syntax: `kubectl config use-context CONTEXT_NAME`
Import specific keys from a config map to a deployment environment variable.
Command: ```bash kubectl set env --keys=smtp_server --from=configmap/kube-system-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 varia...
Add a taint with key 'dedicated' on nodes having label version=v1.0.0, and value 'backup-node-14:PreferNoSchedule'
Command: ```bash kubectl taint node -l version=v1.0.0 dedicated=backup-node-14: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...
Port forward from port 8081 on all addresses to port 8000 in the pod "proxy-server-pod"
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8081: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 ...
Add a taint with the key 'dedicated' on nodes that have the label 'zone=us-east-1'
Command: ```bash kubectl taint node -l zone=us-east-1 dedicated=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": ...
Create a job with a specific command to be executed
Command: ```bash kubectl create job certificate-renewal --image=redis -- redis-cli ``` 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...
Remove all taints with key 'cpu-type' from node 'edge-node-10'
Command: ```bash kubectl taint nodes edge-node-10 cpu-type- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json|yaml...
Retrieve the version of PHP running in the cosmic-container from the pod auth-service-pod
Command: ```bash kubectl exec auth-service-pod -c cosmic-container -- 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...
create a job named "testing" using the image "docker.elastic.co/elasticsearch/elasticsearch" and run the command "elasticsearch-plugin --list" within the job
Command: ```bash kubectl create job testing --image=docker.elastic.co/elasticsearch/elasticsearch -- elasticsearch-plugin --list ``` 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", "sho...
Create a new secret named aws-credentials-secret with keys for each file in the 'path/to/settings' folder
Command: ```bash kubectl create secret generic aws-credentials-secret --from-file=path/to/settings ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to the basen...
Forward traffic from port 8000 on all addresses to port 5000 in the pod e-commerce-pod.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8000: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 wi...
Set the user field of the user-a-context context entry to "cluster-admin" without modifying any other values
Command: ```bash kubectl config set-context user-a-context --user=cluster-admin ``` What it does: Set a context 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-context [NAME | --current] [--cluster=cluster_nicknam...
Create a cluster role named "default_role" with the API Group specified as "tokenreviews.authentication.k8s.io" and the verbs "update", "get", and "patch" allowed
Command: ```bash kubectl create clusterrole default_role --verb=update,get,patch --resource=tokenreviews.authentication.k8s.io ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|none]` Helpful...
Import the 'api-secret-key' environment variable from a secret into the 'web-app-deployment' deployment.
Command: ```bash kubectl set env --from=secret/api-secret-key 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 more pod te...
Create a copy of the 'log-aggregator-pod' with the container image changed to 'alpine', and name it 'debug-image-api'.
Command: ```bash kubectl debug log-aggregator-pod --copy-to=debug-image-api --set-image=*=alpine ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if ...
View the detailed configuration of a specific pod named "payment-gateway-pod".
Command: ```bash kubectl describe pods/payment-gateway-pod ``` What it does: Show details of a specific resource or group of resources. Print a detailed description of the selected resources, including related resources such as events or controllers. You may select a single object by name, all objects of that type, pr...
Execute the 'redis-cli' command in the 'warp-drive' container of the 'chat-app-pod' pod and get the output.
Command: ```bash kubectl exec chat-app-pod -c warp-drive -- redis-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, use ...
Display the 23 most recent lines of logs for the pod named "analytics-pod"
Command: ```bash kubectl logs --tail=23 analytics-pod ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "flag": "--container", "short": "-...
Create a new config map named kube-system-config in the current namespace, using the values of the specified files as key-value pairs
Command: ```bash kubectl create configmap kube-system-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 ...