prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Update the annotation 'app-version' of the pod named 'proxy' to '2.5.1', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods proxy 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 include ...
Get output from running the 'geth' command in the rocket-ranger container of the web-app-pod pod.
Command: ```bash kubectl exec web-app-pod -c rocket-ranger -- geth ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the...
Update the pod 'backend' with the label 'env' and the value 'development'
Command: ```bash kubectl label pods backend env=development ``` 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"...
Execute the 'mongod' command in the 'quantum-quark' container of the 'monitoring-pod' pod to get the output.
Command: ```bash kubectl exec monitoring-pod -c quantum-quark -- mongod ``` 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...
Taint nodes with the label 'customer=acme-corp' and add a taint called 'disktype' with the value 'node-1:PreferNoSchedule'
Command: ```bash kubectl taint node -l customer=acme-corp disktype=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": "", "usage": "...
Copy the local file "/tmp/foo_dir" to the remote pod named "ingress-controller-pod-8" in the "ingress-nginx" namespace as "/tmp/bar".
Command: ```bash kubectl cp /tmp/foo_dir ingress-nginx/ingress-controller-pod-8::/tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted...
Create a new ExternalName service named external-geolocation-service with the external name practice-online.site
Command: ```bash kubectl create service externalname external-geolocation-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 refer...
Create a cron job named "cleanup-task" that runs the command "go version" using the golang image every minute.
Command: ```bash kubectl create cronjob cleanup-task --image=golang --schedule="*/1 * * * *" -- go 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", "short": "-o",...
Create a cluster role named "foo" with the specified permissions for the resource "configmaps" and the resource names "backup-service" and "file-storage"
Command: ```bash kubectl create clusterrole foo --verb=get --resource=configmaps --resource-name=backup-service --resource-name=file-storage ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client|n...
Rename a context in your kubeconfig file
Command: ```bash kubectl config rename-context cloud-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 also...
Set the cluster field in the my-context context to cluster-gamma in the kubeconfig file.
Command: ```bash kubectl config set contexts.edge-context.cluster cluster-gamma ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Import the environment variables from the 'tls-certificate-secret' secret into the 'order-processing-deployment' deployment.
Command: ```bash kubectl set env --from=secret/tls-certificate-secret deployment/order-processing-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in o...
Copy a file named "foo" from the remote pod "auth-service-pod-11" to a local directory named "bar_dir"
Command: ```bash kubectl cp kubeapps/auth-service-pod-11::/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 ...
Create a ClusterIP service named monitoring-service-clusterip, exposing port 8443 on the service and forwarding traffic to port 6379 on the pods.
Command: ```bash kubectl create service clusterip monitoring-service-clusterip --tcp=8443:6379 ``` 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": "...
import the 'MAX_CONNECTIONS' key from the 'configmap/namespace-config' and set it as an environment variable in the 'frontend-deployment' deployment
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/namespace-config deployment/frontend-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 defi...
Create a role binding for user1, user2, and group1 using the custom_role cluster role
Command: ```bash kubectl create rolebinding custom_role --clusterrole=custom_role --user=user1 --user=user2 --group=group1 ``` 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] [--ser...
Enable auto scaling for the "api" deployment with a minimum of 7 pods and a maximum of 10 pods.
Command: ```bash kubectl autoscale deployment api --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 uses the...
remove all pods
Command: ```bash kubectl delete pods --all ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some resources, ...
Set the cluster field in a specific context to a new value.
Command: ```bash kubectl config set contexts.cluster-2-context.cluster star-cluster ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value yo...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l version=v1.0.0 datacenter=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": "", "usage":...
create an ingress called 'private-ingress' that directs requests to foo.com/module to a service with the name 'svc1' and port '5432', using a TLS secret named 'my-cert'
Command: ```bash kubectl create ingress private-ingress --rule="foo.com/module=svc1:5432,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Import environment variables from a config map with a specific prefix for a deployment.
Command: ```bash kubectl set env --from=configmap/api-config --prefix=MYSQL_ 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 specific keys from a config map for a deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-prod deployment/cache-cluster-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable...
Create a new config map named 'namespace-config' with the specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=properties=/path/to/options/file1.txt --from-file=key1=/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 creati...
Import specific keys from a config map to a deployment's environment variables.
Command: ```bash kubectl set env --keys=redis_host --from=configmap/app-secrets 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 in...
Create a new ExternalName service named external-git-service with the external name sandbox-site.co
Command: ```bash kubectl create service externalname external-git-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 reference services...
Import the specific key 'REDIS_HOST' from the 'global-config' config map into the 'monitoring-stack-deployment' deployment.
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/global-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 defi...
Import environment variables from a config map with a specific prefix for a deployment
Command: ```bash kubectl set env --from=configmap/global-config --prefix=MYSQL_ 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 definitio...
Create a copy of the mypod pod, with a new debug-image-app pod, replacing the command of the nano-bot container with `sh`
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-app --container=nano-bot -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by default if no ...
Remove the label 'release' from the 'proxy' pod if it exists
Command: ```bash kubectl label pods proxy release- ``` 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...
Set the custom TLS server name to "sun-cluster" for the "testing-cluster" cluster entry.
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=sun-cluster ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certifica...
Update the container image of the 'alpine' deployment
Command: ```bash kubectl set image deployment/alpine busybox=busybox alpine=alpine:3.14 ``` 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), replicase...
Forward traffic from port 8088 to port 5000 in the pod
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/e-commerce-pod 8088: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...
Expose a replica set as a service on port 9000, connecting to the containers on port 818100.
Command: ```bash kubectl expose rs node --port=9000 --target-port=818100 ``` 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...
Use Vim editor to modify the configuration of the web-service service.
Command: ```bash KUBE_EDITOR="vim" kubectl edit svc/web-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 variables, or ...
Add a taint to nodes with a specific label
Command: ```bash kubectl taint node -l feature=feature-xyz cpu-type=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": "", ...
Auto scale the replication controller "proxy" with a target CPU utilization of 40% and a minimum of 1 pod and a maximum of 5 pods.
Command: ```bash kubectl autoscale rc proxy --max=5 --cpu-percent=40 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that uses t...
Forward all traffic from port 5000 to port 8080 in the 'chat-app-pod' pod, listening on all addresses.
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/chat-app-pod 5000: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...
Create a copy of the auth-service-pod named debug-image-web, with an interactive shell in the time-machine container
Command: ```bash kubectl debug auth-service-pod -it --copy-to=debug-image-web --container=time-machine -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by...
Expose replica set as a service with specified target port and port
Command: ```bash kubectl expose rs alpine --port=5000 --target-port=300100 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Start a wordpress pod named 'nginx' with custom specifications specified in the JSON file using the given command.
Command: ```bash kubectl run nginx --image=wordpress --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] -- [COM...
Switch to raw terminal mode and attach to the astro-container in the log-aggregator-pod.
Command: ```bash kubectl attach log-aggregator-pod -c astro-container -i -t ``` What it does: Attach to a process that is already running inside an existing container. Syntax: `kubectl attach (POD | TYPE/NAME) -c CONTAINER` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name....
Start a pod named "hazelcast" using the Alpine image and expose port 9092.
Command: ```bash kubectl run hazelcast --image=alpine --port=9092 ``` 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...
Add a taint with key 'disktype' on nodes having label environment=production
Command: ```bash kubectl taint node -l environment=production 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": "",...
List the replication controller 'web', service 'auth-service-rc', and pod 'proxy-service-pod'
Command: ```bash kubectl get rc/web service/auth-service-rc pods/proxy-service-pod ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is nam...
Create a job with a specific command
Command: ```bash kubectl create job testing --image=amazonlinux -- /bin/bash -c "echo 'Hello ``` 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": "...
Set the server field of a specific cluster to a new URL
Command: ```bash kubectl config set clusters.dev-cluster.server https://1.2.3.4 ``` What it does: Set an individual value in a kubeconfig file. PROPERTY_NAME is a dot delimited name where each token represents either an attribute name or a map key. Map keys may not contain dots. PROPERTY_VALUE is the new value you wa...
Update the 'auth' pod with the annotation 'alert-email' and the value 'alerts@example.com'.
Command: ```bash kubectl annotate pods auth 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 include ar...
Forward traffic from port 9090 on localhost and IP address 10.19.21.23 to port 8081 in the pod named "cdn-service-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/cdn-service-pod 9090: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 cri...
Create a new config map named "api-config" with the specified keys instead of using the file basenames on disk
Command: ```bash kubectl create configmap api-config --from-file=conf=/path/to/preferences/file1.txt --from-file=data=/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 config...
Create a service for a replicated ubuntu using replica set named 'ubuntu', which serves on port 6379 and connects to the containers on port 500100
Command: ```bash kubectl expose rs ubuntu --port=6379 --target-port=500100 ``` 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....
Retrieve the logs of the previous terminated "rocket-ranger" container from the "database-pod" pod.
Command: ```bash kubectl logs -p -c rocket-ranger 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", "s...
Forward traffic from local port 8000 to the pod's port 9090
Command: ```bash kubectl port-forward pod/security-service-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 be select...
Create a pod disruption budget named `worker-pdb` that will select all pods with the `app=nginx` label and require at least 20% of the pods selected to be available at any point in time.
Command: ```bash kubectl create pdb worker-pdb --selector=app=nginx --min-available=20% ``` 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-run=server|clien...
Create a new config map named 'namespace-config' in the current namespace, using the files 'file1.txt' and 'file2.txt' from '/path/to/options/' and '/path/to/configurations/' respectively.
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/options/file1.txt --from-file=data=/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 creat...
Create a new secret named 'payment-gateway-secret' using the properties from the file located at 'path/to/properties.env'
Command: ```bash kubectl create secret generic payment-gateway-secret --from-env-file=path/to/properties.env ``` What it does: Create a secret based on a file, directory, or specified literal value. A single secret may package one or more key/value pairs. When creating a secret based on a file, the key will default to...
Create an ingress called 'app-gateway-ingress' that directs requests to foo.com/bar to the service 'svc1' on port 8181
Command: ```bash kubectl create ingress app-gateway-ingress --rule="foo.com/bar=svc1:8181,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usag...
Create a new ClusterIP service named database-service-clusterip that maps port 6379 of the service to port 5432 of the target pods
Command: ```bash kubectl create service clusterip database-service-clusterip --tcp=6379:5432 ``` 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...
Create an ingress resource with the name 'default-ingress' that routes requests from 'site.com/module' to 'svc1:5001' and uses the TLS secret "my-cert".
Command: ```bash kubectl create ingress default-ingress --rule="site.com/module=svc1:5001,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...
Show the resource usage metrics for all pods in the "external-monitoring-service" namespace
Command: ```bash kubectl top pod --namespace=external-monitoring-service ``` What it does: Display resource (CPU/memory) usage of pods. The 'top pod' command allows you to see the resource consumption of pods. Due to the metrics pipeline delay, they may be unavailable for a few minutes since pod creation. Syntax: `ku...
create a new ClusterIP service named 'payment-service-clusterip' that forwards TCP traffic from port 8089 to port 3306
Command: ```bash kubectl create service clusterip payment-service-clusterip --tcp=8089:3306 ``` 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"...
Copy the file located at /var/run/secrets/kubernetes.io/serviceaccount/ in your local machine to the /tmp/bar directory of the remote pod named task-processor-pod-17 in the namespace velero.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ velero/task-processor-pod-17:/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": "Con...
Remove the 'NoExecute' taint with the key 'datacenter' from the 'node-1' node
Command: ```bash kubectl taint nodes node-1 datacenter: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 of: jso...
Set the CPU limits of the MySQL container in the deployment to "2" and the memory limits to "4Gi"
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=2,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 requested, but may burst up to its ...
Execute the command 'java -jar /usr/share/jenkins/jenkins.war' within the pod 'database-pod' using the 'quantum-quark' container and retrieve the output.
Command: ```bash kubectl exec database-pod -c quantum-quark -- java -jar /usr/share/jenkins/jenkins.war ``` 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":...
Update the image of all containers in the DaemonSet named "staging" to "redis:6.2.5".
Command: ```bash kubectl set image daemonset staging *=redis:6.2.5 ``` 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: `kube...
Include the certificate authority data for the 'on-prem-cluster' cluster entry by running the command:
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/staging-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 conf...
Set the cpu limits of the mysql container in the deployment to "200m" and memory limits to "64Mi"
Command: ```bash kubectl set resources deployment mysql -c=nginx --limits=cpu=200m,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, but may burst up to ...
Import environment variables with a prefix 'MYSQL_' from the 'app-config-dev' config map and set them in the 'mydeployment' deployment.
Command: ```bash kubectl set env --from=configmap/app-config-dev --prefix=MYSQL_ 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 one o...
Import specific keys from a config map to a deployment's environment variables
Command: ```bash kubectl set env --keys=log_level --from=configmap/log-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 in o...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=database_url --from=configmap/app-config-dev deployment/payment-processor-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable ...
Create an ingress called 'www-ingress' with a rule that directs requests to "testing.com/module" to the 'svc1:8010' service, using the TLS secret "my-cert"
Command: ```bash kubectl create ingress www-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": "", "usage...
Copy the local file /tmp/foo to /tmp/bar inside the auth-service-pod-11 pod in the front-end-container container.
Command: ```bash kubectl cp /tmp/foo auth-service-pod-11:/tmp/bar -c front-end-container ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Forward local port 8888 to port 3000 in the backend-pod pod
Command: ```bash kubectl port-forward pod/backend-pod 8888:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected automa...
create a service for the php deployment, which serves on port 80 and connects to the containers on port 8000
Command: ```bash kubectl expose deployment php --port=8000 --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 ...
Import the 'EXTERNAL_API_URL' key from the 'global-config' config map to the 'api-server-deployment' deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/global-config deployment/api-server-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defi...
Create an ingress resource named 'public-ingress' that maps requests for 'website.com/bar' to the service 'svc1' on port 5001
Command: ```bash kubectl create ingress public-ingress --rule="website.com/bar=svc1:5001,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Create a copy of the proxy-service-pod and name it debug-image-1, with all container images changed to amazonlinux
Command: ```bash kubectl debug proxy-service-pod --copy-to=debug-image-1 --set-image=*=amazonlinux ``` 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 i...
Import the 'API_KEY' from the 'ui-config' config map and set it as an environment variable in the 'gateway-deployment' deployment.
Command: ```bash kubectl set env --keys=API_KEY --from=configmap/ui-config deployment/gateway-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one o...
Embed certificate authority data for the "on-prem-cluster" cluster entry.
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/galaxy-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl confi...
Add a taint with the key 'cpu-type' and value 'web-node-8:PreferNoSchedule' on all nodes having the label 'feature=feature-xyz'
Command: ```bash kubectl taint node -l feature=feature-xyz cpu-type=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": "", "usag...
Forward port 8088 on your local machine to port 5432 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward pod/proxy-server-pod 8088: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 a...
Change the service account of the deployment named "search-engine-deployment" to the default service account
Command: ```bash kubectl set serviceaccount deployment search-engine-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 local port 5432 to port 6379 in the pod named "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-pod 5432:6379 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected au...
Begin streaming the logs of the "ruby" container in the "proxy-service-pod" pod
Command: ```bash kubectl logs -f -c ruby 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...
Copy the "/var/run/secrets/kubernetes.io/serviceaccount/" directory from the remote pod "kubeapps/message-broker-pod-15" to the local directory "/tmp/bar"
Command: ```bash kubectl cp kubeapps/message-broker-pod-15:/var/run/secrets/kubernetes.io/serviceaccount/ /tmp/bar ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "C...
Create a service for the replication controller specified in the "hazelcast-controller.yaml" file with the following configuration:
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8181 --target-port=300000 ``` 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 ...
Scale the deployment named prod-app-rs to have 1 replica
Command: ```bash kubectl scale --current-replicas=7 --replicas=1 deployment/prod-app-rs ``` 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...
Create a new config map named db-config with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap db-config --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/configs/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Create a job named 'data-migration-job' using the 'postgres' image, with the command 'postgres'
Command: ```bash kubectl create job data-migration-job --image=postgres -- postgres ``` 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 fo...
Set the service account of the 'frontend-deployment' deployment to 'flux'
Command: ```bash kubectl set serviceaccount deployment frontend-deployment flux ``` What it does: Update the service account of pod template resources. Possible resources (case insensitive) can be: replicationcontroller (rc), deployment (deploy), daemonset (ds), job, replicaset (rs), statefulset Syntax: `kubectl set ...
Create a new ClusterIP service with the name `analytics-service-clusterip` and map port 8010 on the service to port 3306 on the backend
Command: ```bash kubectl create service clusterip analytics-service-clusterip --tcp=8010:3306 ``` 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": "-...
Add a taint to the node with label 'service=auth' and the key 'workload' set to 'PreferNoSchedule'
Command: ```bash kubectl taint node -l service=auth workload=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...
Give detailed information about all pods labeled with "role=database"
Command: ```bash kubectl describe po -l role=database ``` 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, provide...
Create an ingress with a rule that directs requests to a specific service and port, and specify a TLS secret for secure communication.
Command: ```bash kubectl create ingress app-loadbalancer-ingress --rule="testing.com/input=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"...
Forward local port 9090 to port 8080 in the 'backend-pod' pod
Command: ```bash kubectl port-forward pod/backend-pod 9090: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...
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/properties/file1.txt --from-file=key2=/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 creatin...
Create a new config map with specified keys instead of file basenames on disk.
Command: ```bash kubectl create configmap app-settings --from-file=conf=/path/to/settings/file1.txt --from-file=data=/path/to/parameters/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a c...
Execute the command 'jenkins-plugin-cli' in the astro-container of the vpn-service-pod and capture the output.
Command: ```bash kubectl exec vpn-service-pod -c astro-container -- 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....
Delete the pods and services named "log-aggregator" and "media-stream"
Command: ```bash kubectl delete pod,service log-aggregator media-stream ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and lab...