简体   繁体   中英

kubectl instead of yaml files in production?

I am trying to find the simpliest method to use kubernetes in production. YAML templates look like an overhead to me. Eg all I want is expose simple backend service. I can do it with kubectl with 2 lean commands:

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment hello-server --type LoadBalancer --port 80 --target-port 8080

But is it fine to use this in production? I would like to use Infrastructure-as-a-Code approach.

Is there a way to avoid working with kubernetes template files directly and still follow best practices? Eg generating Yaml files from docker-compose files or similar?

What is the expected kubectl usage in production? Just

kubectl apply -f <folder> 

while it is developers job to maintain template files in <folder> ? Is there a Declarative Management with kubectl without writing kubernetes templates myself? Eg some files that contain the minimal info needed to templates to be generated.

Really want to use Kubernetes, please advice the simplest way to do this!

I am quoting the original question here:

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0 kubectl expose deployment hello-server --type LoadBalancer --port 80 --target-port 8080

But is it fine to use this in production? I would like to use Infrastructure-as-a-Code approach.

Your first approach is a list of commands, that must be executed in a certain order. In addition, all these commands are not idempotent , so you cannot run the commands multiple times.

Also from the original question:

Is there a way to avoid working with kubernetes template files directly and still follow best practices? Eg generating Yaml files from docker-compose files or similar?

What is the expected kubectl usage in production? Just

kubectl apply -f <folder>

The second approach is declarative, you only describe what you want, and the command is idempotent, so it can be run many times without problems. Your desired state is written in text files, so any change can be managed with a version control system, eg Git and the process can be done with validation in a CI/CD pipeline.

For production environments, it is best practice to use version control system like git for what your cluster contain. This make it easy to recover or recreate your system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM