A well designed application is likely to have configurations which vary between deployments. Kubernetes makes it easy to override the configurations specified in images.
Example Container Setup
Let's go through an example of configuring Redis. Our goal is to change the
maxmemory parameter. (Imagine that you need a larger amount of memory for production vs dev)
Create a new Application
Create a new Component
Set the image to "redis"
To understand why configuration should be setup outside the container itself, let's first try something that doesn't work: configuring the application right in the container.
Click the Shell icon to open a shell attached to our redis container. In the shell, enter:
Verify that the config has been correctly set
Everything seem to be working. However, let's try deleting the pod.
Go to Containers and click on the Delete icon
As soon as the pod is deleted, kubernetes will schedule a new one to be deployed, automatically maintaining the desired state of 1 pod running.
After the new pod is created, click on the Shell icon next to it.
maxmemory setting via
So what happened to our setting? It was lost when the pod was destroyed and recreated. Since pods and containers are ephemeral, we can't store configuration states within the pod.
Adding a Config File
The correct way to configure containers is via environment variables and configuration files. Redis happens to use config files.
Go to Components, click on Edit
In the Configuration Files section click Add
For Mount Path, type
Click on the Edit Icon
A modal editor will pop up, inside the editor, enter our desired config
We've just created a config file. Now we need to override the startup command to tell redis to use it.
In the Command input box, type
Click Update Component
After the update is complete, open the shell again and type
Our configuration is picked up, this time via the configuration pod.
Now if we delete the pod again(go ahead and try it), the configuration will still be there.
Other Applications may use environment variables instead of config files. To add an environment variable, click Add in the Environment Variables section of the Edit Component Form:
Click Update Component to apply this change
To verify that the Environment Variable has been set, open a shell and type
You should see the value set above(42) as the output