Home > Back-end >  Why does Kubernetes use a yaml file per "resource"
Why does Kubernetes use a yaml file per "resource"

Time:02-17

I am looking for a (more or less scientific) document/presentation that explains why the developers of the "Kubernbetes language" made the choice to fragment an application definition (for instance) in multiple yaml files instead of writing a single yaml file with all the details of the application deployment (all deployments, volumes, ...)?

I imagine that this has something to do with reusability, maintainability and readability but it would be nice to have a more strucutred argumentation (I think of a conference paper or presentation in a conference such as kubcon or dockercon)

Thanks,

Abdelghani

CodePudding user response:

First things first, Kubernetes does not have its own language, most used language is YAML, but you could work with JSON, or even XML if this were supported. YAML is more human readable and portable across several programming languages. Kubernetes is complex because we want to do complex things. It simply makes things more manageable if we split the deployment in several YAML files, as programmers use different files for different purposes. And, when a modification occurs you only kubectl apply a 'tiny' file. Why they actually chose YAML and separated files was influenced by Google's Borg system, which Kubernetes grabbed a lot of concepts from.

CodePudding user response:

why the developers of the "Kubernbetes language" made the choice to fragment an application definition (for instance) in multiple yaml files instead of writing a single yaml file with all the details of the application deployment (all deployments, volumes, ...)?

This allows us to modify the configuration of Kubernetes objects easier. Thus, you do not have to go through the entire cluster configuration yaml file to make a small change in the service backend, for example. And yes, it is easier to develop and maintain a bunch of files, each containing some object or a group of related objects.

Keep in mind that you can call kubectl apply command on a directory of config files:

kubectl apply -f <directory>

Group related k8s objects into a single file whenever it makes sense. So, it is easier to manage.

But you definitely can put the entire cluster configuration in one yaml file using this syntax (note ---).

apiVersion: v1
kind: Service
metadata:
# skip

---
apiVersion: apps/v1
kind: Deployment
metadata:
# skip

Kubernetes developers suggest write your configuration files using YAML rather than JSON. Though these formats can be used interchangeably in almost all scenarios, YAML tends to be more user-friendly.

There is a good Kubernetes page on Configuration Best Practices.

  • Related