kubernetes Overriding environment variables

10/19/2018

I would like to be able to test my docker application on local before sending it to the cluster. I want to use mini Kube for this. Meanwhile, instead of having multiple kube config files which would define env variables for the cloud environment and for my local machine, I would like to override some of the env variables when running in local. I can see that you can do something like that with docker compose:

docker-compose up -f docker-compose.yml -f docker-compose.e2e.yml.

The second file would only have the overriding values. Yes, there are two files but I find it clean.

Is there a way to do something similar with Kube/minikube? Or even something better ???

-- MaatDeamon
docker
kubernetes

1 Answer

10/19/2018

I think you are asking how to pass different environment values into your Pods depending upon which environment they are deployed to. One pattern to achieve this is to deploy with helm. Then you use templated versions of your kubernetes descriptors for deployment. You also have a values.yaml file that contains values to be injected into the descriptors. You can switch and overlay values.yaml files at the time of install to control which values are injected for a given installation.

If you are asking how to switch whether a kubectl command runs against local or cloud without having to keep switching your kubeconfig file then you can add both contexts to your kubeconfig and use kubectl context to switch between them, as @Ijaz Khan suggests

-- Ryan Dawson
Source: StackOverflow