prompt
stringlengths
13
282
response
stringlengths
128
3.11k
import the MAX_CONNECTIONS key from the app-config-dev config map and set it as an environment variable in the notification-handler-deployment deployment.
Command: ```bash kubectl set env --keys=MAX_CONNECTIONS --from=configmap/app-config-dev 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 var...
Forward traffic from port 6379 on localhost and IP address 10.19.21.23 to port 8081 in the backend-pod.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/backend-pod 6379: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 criteri...
Create a pod disruption budget named auth-service-pdb that will select all pods with the region=us-east label and require at least one of them being available at any point in time
Command: ```bash kubectl create poddisruptionbudget auth-service-pdb --selector=region=us-east --min-available=1 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=...
Create a deployment named 'nats' that uses the 'php' image and exposes port 8080
Command: ```bash kubectl create deployment nats --image=php --port=8080 ``` 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...
Create a copy of the "chat-app-pod" pod by adding a debug container and changing the container images.
Command: ```bash kubectl debug chat-app-pod -it --copy-to=my-debugger --image=debian --set-image=web=nginx:latest,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. P...
Update the pod named 'analytics' by adding the label 'role' with the value 'backend'
Command: ```bash kubectl label pods analytics role=backend ``` 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":...
Create a single ingress called 'rontend-ingress' that directs requests to foo.com/module to svc1:8080 with a tls secret named "my-cert"
Command: ```bash kubectl create ingress rontend-ingress --rule="foo.com/module=svc1:8080,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Forward local port 8000 to port 5000 in the pod e-commerce-pod. Make sure to listen on localhost and IP 10.19.21.23.
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 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 crit...
Rename a context in the kubeconfig file
Command: ```bash kubectl config rename-context cluster-2-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 als...
Retrieve the previous terminated logs of the "rocket-ranger" container from the "proxy-server-pod" pod.
Command: ```bash kubectl logs -p -c rocket-ranger 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"...
Add a taint with key 'hardware' on nodes with the label 'owner=john-doe'
Command: ```bash kubectl taint node -l owner=john-doe hardware=kube-master-9: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 new pod named 'hazelcast' using the 'hazelcast/hazelcast' image and expose port 7000.
Command: ```bash kubectl run hazelcast --image=hazelcast/hazelcast --port=7000 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags:...
Forward traffic from local port 3000 to port 8000 in the pod selected by the 'notification-handler-deployment' deployment
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 3000 8000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a ...
Copy the kube config file from the local machine to the /tmp/bar_dir directory of the remote pod "api-server-pod-3" in the "openfaas" namespace.
Command: ```bash kubectl cp ~/.config/kube openfaas/api-server-pod-3:/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 th...
Remove the environment variable 'ENV' from the 'lunar-launcher' container in all deployment configs
Command: ```bash kubectl set env deployments --all --containers="lunar-launcher" ENV- ``` 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 template...
Listen on port 5000 locally and forward data to/from port 8888 in the frontend-pod
Command: ```bash kubectl port-forward pod/frontend-pod 5000 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 autom...
Create a deployment named wordpress with the wordpress image running and expose port 8888
Command: ```bash kubectl create deployment wordpress --image=wordpress --port=8888 ``` 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...
Start a php pod and expose port 9091
Command: ```bash kubectl run hazelcast --image=php --port=9091 ``` What it does: Create and run a particular image in a pod. Syntax: `kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]` Helpful flags: "flag": "--file...
Get the output from running the 'mongo' command in the 'code-explorer' container of the 'vpn-service-pod' pod
Command: ```bash kubectl exec vpn-service-pod -c code-explorer -- mongo ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Scale the deployment named prod-app-rs from its current size of 3 replicas to 7 replicas for the mysql service.
Command: ```bash kubectl scale --current-replicas=3 --replicas=7 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...
Remove the environment variable ENV from the container 'nebula-navigator' in all deployment configurations.
Command: ```bash kubectl set env deployments --all --containers="nebula-navigator" ENV- ``` 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 templa...
Run the 'kafka-console-producer --broker-list localhost:9092 --topic test' command in the astro-container of the analytics-pod and get the output
Command: ```bash kubectl exec analytics-pod -c astro-container -- kafka-console-producer --broker-list localhost:9092 --topic test ``` 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": "-...
Scale the replica set named 'db-migration-replicaset' to 5 replicas
Command: ```bash kubectl scale --replicas=5 rs/db-migration-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 --resource-version is specified, it...
Set the cluster field in a specific context to a specific cluster
Command: ```bash kubectl config set contexts.user-b-context.cluster testing-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...
Copy the /var/run/secrets/kubernetes.io/serviceaccount/ local file to the /etc/kubernetes directory in the remote pod named 'velero/cache-pod-5' in the current namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ velero/cache-pod-5:/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": "Contai...
Create a config map with key-value pairs
Command: ```bash kubectl create configmap app-name-config --from-literal=settings=config1 --from-literal=key2=config2 ``` 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, th...
Forward local traffic on port 3000 to the selected pod's port 8888.
Command: ```bash kubectl port-forward deployment/notification-handler-deployment 3000 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 ...
Listen on port 8000 on your local machine and forward the traffic to port 3000 in the 'mypod' pod.
Command: ```bash kubectl port-forward pod/mypod 8000: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 automaticall...
Retrieve the output of the 'psql' command from the first container of the payment-processor-deployment deployment.
Command: ```bash kubectl exec deploy/payment-processor-deployment -- 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, ...
Import the environment variables from the secret called 'monitoring-credentials-secret' and apply them to the 'load-balancer-deployment' deployment.
Command: ```bash kubectl set env --from=secret/monitoring-credentials-secret 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 definitions ...
Add a taint with the key 'zone' and value 'gpu-node-12:PreferNoSchedule' on the nodes that have the label 'project=project-alpha'.
Command: ```bash kubectl taint node -l project=project-alpha 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...
Run the 'go' command inside the nebula-navigator container in the api-service-pod and print the output
Command: ```bash kubectl exec api-service-pod -c nebula-navigator -- go ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, us...
Create a new ClusterIP service named git-service-clusterip and map port 3000 on the service to port 8888 on the target
Command: ```bash kubectl create service clusterip git-service-clusterip --tcp=3000:8888 ``` 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", "d...
Scale the deployment named payment-service-rs to have 5 replicas if it currently has 1 replica.
Command: ```bash kubectl scale --current-replicas=1 --replicas=5 deployment/payment-service-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-...
Output the modified deployment configuration in YAML format without making any changes to the deployment on the server
Command: ```bash kubectl set env deployment/user-management-deployment SMTP_HOST=smtp.example.com -o yaml ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable definitions in one ...
Set a taint with the key 'disktype' and value 'app-node-6:PreferNoSchedule' on nodes labeled with 'version=v1.0.0'
Command: ```bash kubectl taint node -l version=v1.0.0 disktype=app-node-6: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 copy of the 'vpn-service-pod' pod and add a debug container with the debian image
Command: ```bash kubectl debug vpn-service-pod -it --copy-to=debug-image-api --image=debian --set-image=mailer=mailer:latest,mailer=mailer:latest ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by re...
Remove a specific taint from a node
Command: ```bash kubectl taint nodes node-1 disktype:NoSchedule- ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "Output format. One of: json...
Create a debug instance of the web-app-pod pod by copying its configuration and adding a debug container
Command: ```bash kubectl debug web-app-pod -it --copy-to=debug-image-1 --image=debian --set-image=database=mysql:5.7,database=mysql:5.7 ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and...
Create an ExternalName service named my-ns that is associated with the external domain document-company.com.
Command: ```bash kubectl create service externalname my-ns --external-name document-company.com ``` 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 that exis...
set the resource request and limits for all containers in the elasticsearch deployment to cpu=200m and memory=512Mi for limits, and cpu=1 and memory=1Gi for requests.
Command: ```bash kubectl set resources deployment elasticsearch --limits=cpu=200m,memory=512Mi --requests=cpu=1,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 req...
Set up autoscaling for the "analytics" replication controller with a minimum of 1 pod, a maximum of 6 pods, and a target CPU utilization of 81%.
Command: ```bash kubectl autoscale rc analytics --max=6 --cpu-percent=81 ``` What it does: Creates an autoscaler that automatically chooses and sets the number of pods that run in a Kubernetes cluster. Looks up a deployment, replica set, stateful set, or replication controller by name and creates an autoscaler that us...
Forward data between local ports 8080 and 6000 and the corresponding ports in a pod selected by the deployment "web-app-deployment"
Command: ```bash kubectl port-forward deployment/web-app-deployment 8080 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 s...
Create an ingress named 'web-ingress' that routes requests from foo.com/input to svc1:8082 and use the 'my-cert' secret for TLS encryption.
Command: ```bash kubectl create ingress web-ingress --rule="foo.com/input=svc1:8082,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage": "O...
Display the snapshot logs from the container 'analytics-pod-1' in the deployment 'log-aggregator-deployment-1'
Command: ```bash kubectl logs deployment/log-aggregator-deployment -c analytics-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpful flags: "f...
Create a deployment named "auth" with the image "ubuntu" using Command: "docker run -it ubuntu"
Command: ```bash kubectl create deployment auth --image=ubuntu -- docker run -it ubuntu ``` 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...
Create a single ingress called 'public-api-ingress' that directs requests to testing.com/input to svc1:9000 with a tls secret "my-cert"
Command: ```bash kubectl create ingress public-api-ingress --rule="testing.com/input=svc1:9000,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", ...
Import specific keys from a config map into the environment variables of a deployment named "monitoring-stack-deployment"
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-prod 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 varia...
Switch to raw terminal mode and attach to the 'api-service-pod' pod, running the 'quantum-quark' container
Command: ```bash kubectl attach api-service-pod -c quantum-quark -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 o...
Create a pod disruption budget named 'elastic-search-pdb' that will select all pods with the 'owner=team-1' label and require at least four of them being available at any point in time.
Command: ```bash kubectl create poddisruptionbudget elastic-search-pdb --selector=owner=team-1 --min-available=4 ``` What it does: Create a pod disruption budget with the specified name, selector, and desired minimum available pods. Syntax: `kubectl create poddisruptionbudget NAME --selector=SELECTOR --min-available=...
Update the image of the first container in the pod named `cdn-service-pod` with the value "new image" using a JSON patch
Command: ```bash kubectl patch pod cdn-service-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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 ...
compare the current state of resources with a desired state defined in a params.json file
Command: ```bash kubectl diff -f params.json ``` What it does: Diff configurations specified by file name or stdin between the current online configuration, and the configuration as it would be if applied. The output is always YAML. KUBECTL_EXTERNAL_DIFF environment variable can be used to select your own diff command...
Set the CPU and memory limits to 200m and 512Mi respectively, and the CPU and memory requests to 50m and 64Mi respectively, for all containers in the mysql deployment.
Command: ```bash kubectl set resources deployment mysql --limits=cpu=200m,memory=512Mi --requests=cpu=50m,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 requeste...
Set the service account of the deployment "email-server-deployment" to "kube-controller-manager"
Command: ```bash kubectl set serviceaccount deployment email-server-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), statefulset...
Add a taint with the key 'zone' and value 'storage-node-13:PreferNoSchedule' on nodes that have the label 'release=beta'
Command: ```bash kubectl taint node -l release=beta zone=storage-node-13: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...
Delete pods and services with names "log-aggregator" and "analytics"
Command: ```bash kubectl delete pod,service log-aggregator analytics ``` What it does: Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label ...
Retrieve the output of the 'go version' command running in the lunar-launcher container of the gateway-pod pod.
Command: ```bash kubectl exec gateway-pod -c lunar-launcher -- go version ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, ...
Forward all data between local port 9090 and pod port 3000 for the analytics-platform-deployment deployment.
Command: ```bash kubectl port-forward deployment/analytics-platform-deployment 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 po...
Create a copy of a pod with a debug container and different container images
Command: ```bash kubectl debug mypod -it --copy-to=debug-image-web --image=debian --set-image=scheduler=my-scheduler:1.0,app=app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and ...
Create an ingress named 'app-ingress' that directs requests from 'site.com/bar' to the service 'svc1' on port '8010', using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress app-ingress --rule="site.com/bar=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": "Ou...
Create a cron job named 'alerts-cleanup' with the image 'alpine', running the command 'apk add curl' at every minute in the schedule.
Command: ```bash kubectl create cronjob alerts-cleanup --image=alpine --schedule="*/1 * * * *" -- apk add curl ``` 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": "...
Create an ingress resource named 'ingsecret' with TLS enabled, using the 'secret1' secret for SSL certificates
Command: ```bash kubectl create ingress ingsecret --class=default \ --rule="testing.com/*=svc:8081,tls=secret1" ``` 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 config map named db-config with specified keys from file paths
Command: ```bash kubectl create configmap db-config --from-file=properties=/path/to/properties/file1.txt --from-file=key1=/path/to/preferences/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creati...
Copy log-aggregator-pod and add a debug container and change container images
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=debug-image-api --image=debian --set-image=worker=my-custom-worker:1.2.3,logger=logging-app:debug ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects ...
Set the basic authentication credentials for the "dev-user" entry
Command: ```bash kubectl config set-credentials dev-user --username=admin --password=uXFGweU9l35qcif ``` 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 Be...
Import the key "EXTERNAL_API_URL" from the "app-config-dev" config map and set it as an environment variable in the "monitoring-stack-deployment" deployment.
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/app-config-dev 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 variab...
Add a taint with the key 'zone' and the value 'web-node-8:PreferNoSchedule' on nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend zone=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": "Outpu...
Partially update a node using a strategic merge patch, specifying the patch as JSON.
Command: ```bash kubectl patch node backup-node-14 -p '{"stringData":{"password":"new-password"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file ...
Partially update the gpu-node-12 node by providing a strategic merge patch as a JSON. Set the password to "new-password".
Command: ```bash kubectl patch node gpu-node-12 -p '{"stringData":{"password":"new-password"}' ``` What it does: Update fields of a resource using strategic merge patch, a JSON merge patch, or a JSON patch. JSON and YAML formats are accepted. Syntax: `kubectl patch (-f FILENAME | TYPE NAME) [-p PATCH|--patch-file FIL...
Forward traffic from your local machine's port 8080 to the pod's port 5432
Command: ```bash kubectl port-forward pod/analytics-pod 8080 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 auto...
Set the custom TLS server name for the cluster-gamma cluster entry.
Command: ```bash kubectl config set-cluster cluster-gamma --tls-server-name=kube-cluster-2 ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config set-cluster NAME [--server=server] [--certific...
Create an ingress with a rule that directs requests from testing.com/bar to svc1:7000 with a TLS secret named "my-cert"
Command: ```bash kubectl create ingress internal-ingress --rule="testing.com/bar=svc1:7000,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": "", "usa...
expose a replication controller as a service on port 3000, connecting to containers on port 801000
Command: ```bash kubectl expose rc alpine --port=3000 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port....
Add a taint with key 'environment' on nodes having label version=v1.0.0 with the taint value of 'testing-node-11:PreferNoSchedule'
Command: ```bash kubectl taint node -l version=v1.0.0 environment=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...
Set the cluster field to "cluster-beta" in the "prod-context" context.
Command: ```bash kubectl config set contexts.prod-context.cluster cluster-beta ``` 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 wan...
Display only the most recent 43 lines of output in the backend-pod pod
Command: ```bash kubectl logs --tail=43 backend-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": "-c"...
Update the pod 'foo' with the annotation 'backup-strategy' and the value 'daily-backups', replacing any existing value.
Command: ```bash kubectl annotate --overwrite pods foo backup-strategy='daily-backups' ``` 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 an...
Create a service for a replicated node using replica set, which serves on port 3000 and connects to the containers on port 801000
Command: ```bash kubectl expose rs node --port=3000 --target-port=801000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the specified port. A...
Create a new ExternalName service named external-ldap-service and map it to the external DNS name "mockup-cloud.cloud"
Command: ```bash kubectl create service externalname external-ldap-service --external-name mockup-cloud.cloud ``` 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 serv...
Add a taint to a node called 'testing-node-11' with the key 'cpu-type' and no value specified
Command: ```bash kubectl taint nodes testing-node-11 cpu-type: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 ...
partially update the gpu-node-12 node by setting the "unschedulable" field to true using a strategic merge patch specified in YAML format.
Command: ```bash kubectl patch node gpu-node-12 -p $'spec:\n 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 FILE]` Helpful ...
Create a cluster role named "foo" with a NonResourceURL specified for the "get" verb
Command: ```bash kubectl create clusterrole "foo" --verb=get --non-resource-url=/healthz ``` 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", "short": "...
Add a taint to 'node-2' with the key 'special' and no value
Command: ```bash kubectl taint nodes node-2 special: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: json|y...
Set up auto scaling for the "gateway" deployment with a minimum of 7 pods and a maximum of 12 pods
Command: ```bash kubectl autoscale deployment gateway --min=7 --max=12 ``` 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...
Create a copy of the analytics-pod and launch an interactive shell in the debug-image-api container with the command "sh", specifically targeting the time-machine container.
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-api --container=time-machine -- sh ``` What it does: Debug cluster resources using interactive debugging containers. 'debug' provides automation for common debugging tasks for cluster objects identified by resource and name. Pods will be used by de...
Copy the file named "foo" from the remote pod "auth-service-pod-11" to the local directory "/etc/kubernetes"
Command: ```bash kubectl cp velero/auth-service-pod-11::/tmp/foo /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, use the...
Copy the local file /tmp/foo_dir to the remote pod "file-server-pod-14" in the "kube-proxy" namespace at the location /etc/kubernetes.
Command: ```bash kubectl cp /tmp/foo_dir kube-proxy/file-server-pod-14:/etc/kubernetes ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, u...
Create a single ingress called 'app1-ingress' that directs requests to testing.com/input to the svc1:8181 service with a tls secret named "my-cert"
Command: ```bash kubectl create ingress app1-ingress --rule="testing.com/input=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": "", "usage...
Create an ingress called "private-api-ingress" with a rule that directs requests to "site.com/bar" to the service "svc1" with port "9091"
Command: ```bash kubectl create ingress private-api-ingress --rule="site.com/bar=svc1:9091,tls=my-cert" ``` What it does: Create an ingress with the specified name. Syntax: `kubectl create ingress NAME --rule=host/path=service:port[,tls[=secret]]` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usa...
Taint nodes with label "myLabel" using "cpu-type" key
Command: ```bash kubectl taint node -l myLabel 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": "", "usage": "Ou...
Copy the file /tmp/foo from the pod named message-broker-pod-15 in the istio-system namespace to the local directory /etc/kubernetes
Command: ```bash kubectl cp istio-system/message-broker-pod-15:/tmp/foo /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, ...
Create a new config map named app-settings by specifying the keys instead of using file basenames on disk
Command: ```bash kubectl create configmap app-settings --from-file=properties=/path/to/configurations/file1.txt --from-file=key1=/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 ...
Update the image of the first container in the proxy-service-pod by sending a JSON patch request, with the new image as the value to be replaced.
Command: ```bash kubectl patch pod proxy-service-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]' ``` 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 patc...
Retrieve and display deployments in YAML format using the "v3.0.0" version of the "legacy-apps" API group
Command: ```bash kubectl get deployments.v3.0.0.legacy-apps -o yaml ``` What it does: Display one or many resources. Prints a table of the most important information about the specified resources. You can filter the list using a label selector and the --selector flag. If the desired resource type is namespaced you wil...
import the EXTERNAL_API_URL key from the config map db-config into the payment-processor-deployment deployment
Command: ```bash kubectl set env --keys=EXTERNAL_API_URL --from=configmap/db-config 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 d...
Create a cluster role named "bar" with the following permissions:
Command: ```bash kubectl create clusterrole bar --verb=proxy --resource=services --resource-name=audit-logger --resource-name=machine-learning ``` What it does: Create a cluster role. Syntax: `kubectl create clusterrole NAME --verb=verb --resource=resource.group [--resource-name=resourcename] [--dry-run=server|client...
Begin streaming the logs of the code-explorer container in the cdn-service-pod pod
Command: ```bash kubectl logs -f -c code-explorer cdn-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",...
Forward data between local port 8081 and the pod's port 6379 in the frontend-pod.
Command: ```bash kubectl port-forward pod/frontend-pod 8081 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 autom...
Create an ingress resource called 'app1-ingress' that routes requests from 'website.com/input' to the service 'svc1' on port 8000, using the TLS secret 'my-cert'.
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/input=svc1:8000,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...
Add a taint with the key 'app' and the value 'storage-node-13:PreferNoSchedule' on all nodes that have the label 'tier=frontend'
Command: ```bash kubectl taint node -l tier=frontend app=storage-node-13: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...