Like most applications we have three distinct running environments:
These are all basically configured through ENV variables.
How is it best to run all the services/pods/containers in our environments? Through labels? or namespaces?
I am not sure if there is an official best practice, but I have always preferred to separate environments using namespaces for the following reasons:
It allows you to use the exact same YAML files for your deployments, services, etc in all three environments. To switch environments, all you have to do is add --namespace=${YOUR_NS}
to your kubectl commands or even just specify one context for every namespace in your kubectl configuration, so you can say something like kubectl config use-context production
. Check out the docs!
You can use Resource Quotas to put limits on the amount of compute resources that should be available to each environment.
You could use RBAC to control access to your environments. For example you could allow only a small group of people to make changes to the production environment, but have all developers do whatever they want in your development environment.
Inside of every namespace you could then use labels to structure your app into different tiers, for example. This configuration would then be the same in every environment.