prompt
stringlengths
13
282
response
stringlengths
128
3.11k
Create a service for the replicated PHP pods that serves on port 5000 and connects to the containers on port 8082, using the command `kubectl expose rc php --port=5000 --target-port=8082`.
Command: ```bash kubectl expose rc php --port=5000 --target-port=808200 ``` 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 ...
Rename a context in your kubeconfig file
Command: ```bash kubectl config rename-context local-context team-beta-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 a...
Get the output from running the 'irb' command inside the 'mypod' pod using the first container
Command: ```bash kubectl exec mypod -- irb ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted, use the kubectl.kubernetes.io/d...
Retrieve the details of the 'monitoring-pod' pod in JSON format.
Command: ```bash kubectl get -o json pod monitoring-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 namespaced you will only see r...
Create a ClusterIP service named ldap-service-clusterip that maps port 6379 to port 5001.
Command: ```bash kubectl create service clusterip ldap-service-clusterip --tcp=6379:5001 ``` 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 a new config map named global-config from an environment file
Command: ```bash kubectl create configmap global-config --from-env-file=path/to/profiles.env ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a config map based on a file, the key will default to the...
Add a taint with the key 'app' and value 'prod-node-5:PreferNoSchedule' on nodes that have the label 'environment=production'
Command: ```bash kubectl taint node -l environment=production app=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage...
Embed the certificate authority data for the my-k8s-cluster cluster entry
Command: ```bash kubectl config set-cluster my-k8s-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 confi...
Copy the `/var/run/secrets/kubernetes.io/serviceaccount/` file from the local machine to `/tmp/bar` directory in the remote pod named `task-processor-pod-17` in the `logging` namespace.
Command: ```bash kubectl cp /var/run/secrets/kubernetes.io/serviceaccount/ logging/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": "Co...
Import specific keys from a config map
Command: ```bash kubectl set env --keys=DEBUG_MODE --from=configmap/monitoring-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 definitio...
Create a new config map named "namespace-config" with specified keys instead of file basenames on disk
Command: ```bash kubectl create configmap namespace-config --from-file=conf=/path/to/parameters/file1.txt --from-file=data=/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 creati...
Create a new config map named 'ui-config' in the default namespace, using the 'properties' file located at '/path/to/profiles/file1.txt' and the 'key1' file located at '/path/to/parameters/file2.txt'
Command: ```bash kubectl create configmap ui-config --from-file=properties=/path/to/profiles/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 creating ...
Create a copy of the email-service-pod with a debug container and different container images
Command: ```bash kubectl debug email-service-pod -it --copy-to=dgb-img --image=debian --set-image=database=mysql:5.7,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 resource a...
Taint node 'node-1' with hardware:NoSchedule
Command: ```bash kubectl taint nodes node-1 hardware: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|...
Import the 'LOG_LEVEL' key from the 'kube-system-config' config map and set it as an environment variable in the 'analytics-platform-deployment' deployment.
Command: ```bash kubectl set env --keys=LOG_LEVEL --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 variabl...
Check to see if you have permission to list the job named "notification-sender-job" in the "kube-dns" namespace
Command: ```bash kubectl auth can-i list jobs.batch/notification-sender-job -n kube-dns ``` What it does: Check whether an action is allowed. VERB is a logical Kubernetes API verb like 'get', 'list', 'watch', 'delete', etc. TYPE is a Kubernetes resource. Shortcuts and groups will be resolved. NONRESOURCEURL is a parti...
Forward port 6379 on the pod named "api-service-pod" to port 3000 on all addresses
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/api-service-pod 6379:3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod w...
Set the custom TLS server name for a cluster entry named "testing-cluster" to "star-cluster".
Command: ```bash kubectl config set-cluster testing-cluster --tls-server-name=star-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] [--certific...
Execute the command "redis-server --version" inside the 'e-commerce-pod' pod and display the output.
Command: ```bash kubectl exec e-commerce-pod -- redis-server --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, use...
Create a new secret named 'oauth-secret' with keys for each file in the 'path/to/properties' folder
Command: ```bash kubectl create secret generic oauth-secret --from-file=path/to/properties ``` 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 basename of t...
Create a copy of the 'chat-app-pod' pod and change all container images to 'postgres'. Name the copy 'debug-image-1'.
Command: ```bash kubectl debug chat-app-pod --copy-to=debug-image-1 --set-image=*=postgres ``` 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 res...
Auto scale the replication controller "vpn" based on CPU utilization, ensuring there are between 1 and 5 pods, with a target CPU utilization of 60%.
Command: ```bash kubectl autoscale rc vpn --max=5 --cpu-percent=60 ``` 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...
Execute the 'postgres' command inside the 'time-machine' container of the 'proxy-server-pod' pod.
Command: ```bash kubectl exec proxy-server-pod -c time-machine -- postgres ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omitted,...
Create a new ClusterIP service named frontend-service-clusterip, mapping TCP port 3000 on the service to port 5000 on the backend
Command: ```bash kubectl create service clusterip frontend-service-clusterip --tcp=3000:5000 ``` 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...
Set the server field for the e2e cluster entry to "https://1.2.3.4" without modifying any other values.
Command: ```bash kubectl config set-cluster e2e --server=https://1.2.3.4 ``` 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] [--certificate-authority=path...
Copy the file named 'foo' located in the '/tmp' directory on your local machine to the '/etc/kubernetes' directory inside the 'auth-service-pod-11' pod in the 'metallb-system' namespace.
Command: ```bash kubectl cp :/tmp/foo metallb-system/auth-service-pod-11:/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,...
Expose the replica set "nginx" as a service, which listens on port 8181 and connects to the containers on port 808000.
Command: ```bash kubectl expose rs nginx --port=8181 --target-port=808000 ``` 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 the key 'workload' on nodes having the label 'app=web-app'
Command: ```bash kubectl taint node -l app=web-app 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 ...
Forward traffic from port 8080 on all addresses to port 8000 in the pod named "proxy-server-pod".
Command: ```bash kubectl port-forward --address 0.0.0.0 pod/proxy-server-pod 8080: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 ...
delete the pods and services named 'backend' and 'frontend'
Command: ```bash kubectl delete pod,service backend frontend ``` 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...
Update the pod specified in the "pod.json" file with the annotation "deployment-script" set to the URL "https://example.com/deploy.sh"
Command: ```bash kubectl annotate -f pod.json deployment-script='https://example.com/deploy.sh' ``` 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 ...
Autoscale the "api" replication controller with the number of pods ranging from 1 to 5, targeting a CPU utilization of 90%.
Command: ```bash kubectl autoscale rc api --max=5 --cpu-percent=90 ``` 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...
Forward local traffic on ports 8080 to port 3000 in the 'security-service-pod' pod
Command: ```bash kubectl port-forward pod/security-service-pod 8080 3000 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be select...
Create a LoadBalancer service named media-stream-lb for TCP traffic on port 9091, forwarding to port 8088
Command: ```bash kubectl create service loadbalancer media-stream-lb --tcp=9091:8088 ``` What it does: Create a LoadBalancer service with the specified name. Syntax: `kubectl create service loadbalancer NAME [--tcp=port:targetPort] [--dry-run=server|client|none]` Helpful flags: "flag": "--output", "short": "-o", "de...
Retrieve the documentation of the "template" field in the "spec" section of the pods resource.
Command: ```bash kubectl explain resource=pods.spec.template ``` What it does: List the fields for supported resources. This command describes the fields associated with each supported API resource. Fields are identified via a simple JSONPath identifier: <type>.<fieldName>[.<fieldName>] Add the --recursive flag to dis...
Generate a Kubernetes manifest from the configuration directory located at /usr/share/kubernetes/config/testing.
Command: ```bash kubectl kustomize /usr/share/kubernetes/config/testing ``` What it does: Build a set of KRM resources using a 'kustomization.yaml' file. The DIR argument must be a path to a directory containing 'kustomization.yaml', or a git repository URL with a path suffix specifying same with respect to the reposi...
Continuously stream the logs of the "lunar-launcher" container in the "vpn-service-pod" pod.
Command: ```bash kubectl logs -f -c lunar-launcher vpn-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"...
Set the custom TLS server name to "my-k8s-cluster" for the "sun-cluster" cluster entry in the Kubernetes configuration.
Command: ```bash kubectl config set-cluster sun-cluster --tls-server-name=my-k8s-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] [--certificat...
Create a service for the replication controller specified in the "ruby-controller.yaml" file, which serves on port 80 and connects to the containers on port 8000.
Command: ```bash kubectl expose -f ruby-controller.yaml --port=8000 --target-port=800000 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on the s...
Create a new config map named monitoring-config with specified keys and their corresponding data files
Command: ```bash kubectl create configmap monitoring-config --from-file=settings=/path/to/data/file1.txt --from-file=key2=/path/to/data/file2.txt ``` What it does: Create a config map based on a file, directory, or specified literal value. A single config map may package one or more key/value pairs. When creating a co...
Embed client certificate data for "deploy-bot" entry
Command: ```bash kubectl config set-credentials deploy-bot --client-certificate=~/.kube/admin.crt --embed-certs=true ``` 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 --clien...
Create a service for the hazelcast controller specified in the "hazelcast-controller.yaml" file
Command: ```bash kubectl expose -f hazelcast-controller.yaml --port=8088 --target-port=808300 ``` What it does: Expose a resource as a new Kubernetes service. Looks up a deployment, service, replica set, replication controller or pod by name and uses the selector for that resource as the selector for a new service on ...
Retrieve the logs from container payment-gateway-pod-1 in the deployment/backend-microservice-deployment
Command: ```bash kubectl logs deployment/backend-microservice-deployment -c payment-gateway-pod-1 ``` What it does: Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional. Syntax: `kubectl logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]` Helpf...
Auto scale the deployment "proxy" with a minimum of 6 pods and a maximum of 8 pods.
Command: ```bash kubectl autoscale deployment proxy --min=6 --max=8 ``` 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 th...
Configure the certificate authority data for the staging-cluster cluster entry.
Command: ```bash kubectl config set-cluster staging-cluster --embed-certs --certificate-authority=~/.kube/star-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config ...
Create an ingress called 'private-service-ingress' with a rule that directs requests to website.com/bar to svc1:8080
Command: ```bash kubectl create ingress private-service-ingress --rule="website.com/bar=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": "...
Retrieve the logs of the previous terminated "nebula-navigator" container from the "log-aggregator-pod", including a snapshot of the logs.
Command: ```bash kubectl logs -p -c nebula-navigator log-aggregator-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": "--conta...
Add the annotation 'criticality' with the value 'high' to the pod named 'foo'.
Command: ```bash kubectl annotate pods foo criticality=high ``` 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 arbitrary string ...
Add a 'PreferNoSchedule' taint with key 'app' on all nodes that have the label 'service=auth'
Command: ```bash kubectl taint node -l service=auth app=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 form...
Enable the OpenID Connect auth provider for the "security-user" entry with additional arguments
Command: ```bash kubectl config set-credentials security-user --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar ``` 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: ...
Set the 'criticality' annotation to 'high' for the 'backend' pod.
Command: ```bash kubectl annotate pods backend criticality=high ``` 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 arbitrary str...
Update the 'monitoring-stack-deployment' deployment with a new environment variable
Command: ```bash kubectl set env deployment/monitoring-stack-deployment QUEUE_NAME=task-queue ``` 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 ...
Create a pod disruption budget named auth-service-pdb that selects pods with the version=v2 label and requires at least 9 of them to be available at any point in time.
Command: ```bash kubectl create poddisruptionbudget auth-service-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 [-...
Add a taint with the key 'cpu-type' on nodes having the label namespace=mynamespace
Command: ```bash kubectl taint node -l namespace=mynamespace 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": ""...
Import specific keys from a config map to set environment variables for a deployment
Command: ```bash kubectl set env --keys=debug_mode --from=configmap/ui-config deployment/proxy-service-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...
roll back the deployment named prod to the previous version
Command: ```bash kubectl rollout undo deployment/prod ``` What it does: Roll back to a previous rollout. Syntax: `kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags]` Helpful flags: "flag": "--filename", "short": "-f", "default": "[]", "usage": "Filename, directory, or URL to files identifying the resource to get f...
Forward local port 8000 to pod port 8888
Command: ```bash kubectl port-forward pod/security-service-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 select...
Apply a taint with the key 'datacenter' and the value 'storage-node-13:PreferNoSchedule' on nodes that have the label 'customer=acme-corp'
Command: ```bash kubectl taint node -l customer=acme-corp datacenter=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": "",...
Remove a taint from a specified node
Command: ```bash kubectl taint nodes dev-node-4 environment: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...
Create a new config map named app-config-prod with the properties of the specified files
Command: ```bash kubectl create configmap app-config-prod --from-file=settings=/path/to/properties/file1.txt --from-file=key2=/path/to/settings/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 deployment named 'api' using the 'wordpress' image
Command: ```bash kubectl create deployment api --image=wordpress ``` 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|yaml|nam...
Get the output from running the 'docker run ubuntu echo "Hello, World"' command in the cosmic-container from the gateway-pod.
Command: ```bash kubectl exec gateway-pod -c cosmic-container -- docker run ubuntu echo "Hello, World" ``` What it does: Execute a command in a container. Syntax: `kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": ...
Create a new secret named docker-registry-secret using the configurations from the path/to/configurations.env file.
Command: ```bash kubectl create secret generic docker-registry-secret --from-env-file=path/to/configurations.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 defaul...
Scale the replica set 'staging-app-rs' to have 3 replicas
Command: ```bash kubectl scale --replicas=3 rs/staging-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 is specified, it is valid...
import the REDIS_HOST key from the config map named kube-system-config into the deployment named cache-cluster-deployment
Command: ```bash kubectl set env --keys=REDIS_HOST --from=configmap/kube-system-config 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 de...
Create a copy of the analytics-pod pod, changing the command of the cosmic-container container to run the sh shell
Command: ```bash kubectl debug analytics-pod -it --copy-to=debug-image-web --container=cosmic-container -- 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 b...
Update the pod named 'monitoring' by setting the annotation 'criticality' to 'high', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods monitoring criticality='high' ``` 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 incl...
Forward data between ports 8080 and 8080 on your local machine and the pod named 'log-aggregator-pod'
Command: ```bash kubectl port-forward pod/log-aggregator-pod 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 selected...
Copy the service account credentials from a remote pod to the local file system
Command: ```bash kubectl cp kube-server/image-resizer-pod-20:/var/run/secrets/kubernetes.io/serviceaccount/ /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": "", "u...
List the specified resources by their type and names
Command: ```bash kubectl get rc/web service/analytics-rc pods/e-commerce-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 namespace...
Create a new ClusterIP service named inventory-service-clusterip that maps port 8181 to port 8084
Command: ```bash kubectl create service clusterip inventory-service-clusterip --tcp=8181:8084 ``` 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 specific keys from a config map into the environment variables of a deployment
Command: ```bash kubectl set env --keys=my-example-key --from=configmap/log-config deployment/search-engine-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Create a new ingress resource named 'app1-ingress' with a rule that directs requests from 'website.com/module' to the service 'svc1' on port '9092', using the TLS secret named 'my-cert'.
Command: ```bash kubectl create ingress app1-ingress --rule="website.com/module=svc1:9092,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...
Forward port 8080 on localhost and selected IP to port 5432 in the pod named "log-aggregator-pod"
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/log-aggregator-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 ...
Create a deployment in the default namespace named monitoring, using the alpine image and exposing port 8088
Command: ```bash kubectl create deployment monitoring --image=alpine --port=8088 ``` 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 o...
Forward local port 8888 to port 8088 in the selected pod.
Command: ```bash kubectl port-forward deployment/api-server-deployment 8888 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 b...
Create an ingress rule called 'website-ingress' that directs requests to website.com/module to svc1:8080 with a tls secret called "my-cert"
Command: ```bash kubectl create ingress website-ingress --rule="website.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": "", "u...
Scale the replica set named 'bar' to 3 replicas
Command: ```bash kubectl scale --replicas=3 rs/bar ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated before...
Forward port 6379 on your local machine to port 8081 in the pod "api-service-pod"
Command: ```bash kubectl port-forward pod/api-service-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 criteria, a pod will be selected au...
Create an ingress called 'app2-ingress' to route requests from website.com/module to svc1:9092 with the tls secret "my-cert"
Command: ```bash kubectl create ingress app2-ingress --rule="website.com/module=svc1:9092,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...
Forward local port 6379 to port 5432 in the pod "chat-app-pod"
Command: ```bash kubectl port-forward pod/chat-app-pod 6379 5432 ``` What it does: Forward one or more local ports to a pod. Use resource type/name such as deployment/mydeployment to select a pod. Resource type defaults to 'pod' if omitted. If there are multiple pods matching the criteria, a pod will be selected autom...
Create a copy of the log-aggregator-pod pod, adding a debug container and changing the container images
Command: ```bash kubectl debug log-aggregator-pod -it --copy-to=my-debugger --image=debian --set-image=api=api:v2,api=api:v2 ``` 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...
Update the environment variable JWT_SECRET for the deployment 'mydeployment'.
Command: ```bash kubectl set env deployment/mydeployment JWT_SECRET=your-jwt-secret ``` 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 templates ...
Get the output from running the 'apk add curl' command in the 'lunar-launcher' container from the 'frontend-pod' pod.
Command: ```bash kubectl exec frontend-pod -c lunar-launcher -- apk add curl ``` 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 omitte...
Scale the deployment named "db-migration-replicaset" to a desired size of 5, considering that its current size is 3.
Command: ```bash kubectl scale --current-replicas=3 --replicas=5 deployment/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 --reso...
Set up autoscaling for the "frontend" deployment with a minimum of 4 pods and a maximum of 12 pods.
Command: ```bash kubectl autoscale deployment frontend --min=4 --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 use...
Set a custom TLS server name for the galaxy-cluster cluster
Command: ```bash kubectl config set-cluster galaxy-cluster --tls-server-name=app-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] [--certificat...
Copy the file ~/.config/kube to the /etc/kubernetes directory inside the file-server-pod-14 pod in the file-server container.
Command: ```bash kubectl cp ~/.config/kube file-server-pod-14:/etc/kubernetes -c file-server ``` What it does: Copy files and directories to and from containers. Syntax: `kubectl cp <file-spec-src> <file-spec-dest>` Helpful flags: "flag": "--container", "short": "-c", "default": "", "usage": "Container name. If omit...
Forward local port 8888 to pod port 8000 for a specific pod
Command: ```bash kubectl port-forward pod/security-service-pod 8888 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 select...
Taint nodes with the label 'role=database' with a taint key='datacenter' and value='prod-node-5' and effect='PreferNoSchedule'
Command: ```bash kubectl taint node -l role=database datacenter=prod-node-5:PreferNoSchedule ``` What it does: Update the taints on one or more nodes. Syntax: `kubectl taint NODE NAME KEY_1=VAL_1:TAINT_EFFECT_1 ... KEY_N=VAL_N:TAINT_EFFECT_N` Helpful flags: "flag": "--output", "short": "-o", "default": "", "usage":...
Import the environment variables with a prefix "MYSQL_" from the config map "monitoring-config" and apply it to the "proxy-service-deployment" deployment.
Command: ```bash kubectl set env --from=configmap/monitoring-config --prefix=MYSQL_ deployment/proxy-service-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 defin...
Import the environment variables from the 'app-config-dev' config map into the 'user-management-deployment' deployment, prefixing each variable with 'MYSQL_'
Command: ```bash kubectl set env --from=configmap/app-config-dev --prefix=MYSQL_ deployment/user-management-deployment ``` What it does: Update environment variables on a pod template. List environment variable definitions in one or more pods, pod templates. Add, update, or remove container environment variable defini...
Use the vi editor to edit the configuration of the loadbalancer service
Command: ```bash KUBE_EDITOR="vi" kubectl edit svc/loadbalancer-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 variab...
Update the annotation 'security-scan-status' of the pod 'proxy-server' to 'pass', overwriting any existing value
Command: ```bash kubectl annotate --overwrite pods proxy-server security-scan-status='pass' ``` What it does: Update the annotations on one or more resources. All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labe...
Delete pods and services named "frontend" and "analytics"
Command: ```bash kubectl delete pod,service frontend 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 select...
Scale the resource specified in the "conf.json" file to 1 replica.
Command: ```bash kubectl scale --replicas=1 -f conf.json ``` What it does: Set a new size for a deployment, replica set, replication controller, or stateful set. Scale also allows users to specify one or more preconditions for the scale action. If --current-replicas or --resource-version is specified, it is validated ...
Embed the certificate authority data for the 'on-prem-cluster' cluster entry using the provided certificate authority file "~/.kube/dev-cluster/kubernetes.ca.crt"
Command: ```bash kubectl config set-cluster on-prem-cluster --embed-certs --certificate-authority=~/.kube/dev-cluster/kubernetes.ca.crt ``` What it does: Set a cluster entry in kubeconfig. Specifying a name that already exists will merge new fields on top of existing values for those fields. Syntax: `kubectl config s...
Scale the deployment named staging-app-rs to have 7 replicas, assuming the current replicas count is 5.
Command: ```bash kubectl scale --current-replicas=5 --replicas=7 deployment/staging-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-vers...
Port forward the local machine and selected IP to a pod's port
Command: ```bash kubectl port-forward --address localhost,10.19.21.23 pod/api-service-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 cri...
Add a taint with the key 'cpu-type' and no value to the node 'k8s-node-1'
Command: ```bash kubectl taint nodes k8s-node-1 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 of: j...