Structuring kubernetes configuration files

12/20/2018

Say that I have 5 apis that i want to deploy in a Kubernetes cluster, my question is simply what is the best practice to store the yaml files related to Kubernetes.

In projects I've seen online, Kubernetes yaml files are just added to the the api project itself. I wonder if it makes sense to decouple all files related to Kubernetes in an entirely separate "project", and which is managed by VCS as a completely separated entity from the api projects themselves.

This question arises since I'm currently reading a book about Kubernetes, on the topic namespaces, and considered it might be a good idea to have separate namespaces per environment (DEV / UAT / PROD), and it may make sense to have these files in a centralized "Kubernetes" project (unless it might be better to have a separate cluster per environment (?)).

-- Trace
kubernetes

2 Answers

12/20/2018

From Production k8s experience for CI/CD:

  • One cluster per environment such as dev , stage , prod ( optionally per data centre )
  • One namespace per project

  • One git deployment repo per project

  • One branch in git deployment repo per environment

  • Use configmaps for configuration aspects
  • Use secret management solution to store and use secrets
-- Ijaz Ahmad Khan
Source: StackOverflow

12/20/2018

Whether to put the yaml in the same repo as the app is a question that projects answer in different ways. You might want to put them together if you find that you often change both at the same time or you just find it clearer to see everything in one place. You might separate if you mostly work on the yaml separately or if you find it less clutttered or want different visibility for it (e.g. different teams to look at it). If things get more sophisticated then you'll actually want to generate the yaml from templates and inject environment-specific configuration into it at deploy time (whether those environments are namespaces or clusters) - see Best practices for storing kubernetes configuration in source control for more discussion on this.

-- Ryan Dawson
Source: StackOverflow