Reputation: 203
Is there any way to update a container (or more accurately all running containers of a specific application) configuration file while it's running?
Lets say that I have a configuration file that my application reads each time it needs to access some configuration value, and I have decided to change that value while the application is running so that the next time that it reads the value it will be the updated value.
From looking at the kubernetes documentation It feels like that there should be some kubectl command that will allow it, but I couldn't find it.
Also I guess that I can achieve similar result by doing a rolling update to those containers, right?
Upvotes: 0
Views: 1269
Reputation: 39507
You need to take a look at confmaps
and secrets
.
Many applications require configuration via some combination of config files, command line arguments, and environment variables. These configuration artifacts should be decoupled from image content in order to keep containerized applications portable.
You can use confmap
to store lets say nginx config, then edit the confmap, and the edits will be live on the running containers. (in nginx case you need to reload the nginx service so the new configuration takes effect.)
Example Yaml:
kind: ConfigMap
apiVersion: v1
metadata:
creationTimestamp: 2016-02-18T19:14:38Z
name: example-config
namespace: default
data:
example.property.1: hello
example.property.2: world
example.property.file: |-
property.1=value-1
property.2=value-2
property.3=value-3
To create configmap
from exitsting config file:
kubectl create configmap <confmap name> --from-file=path/to/config.conf
To edit configmap
:
kubectl edit configmap <confmap name>
Secrets
are similar to configmaps, they are just used for secure data, like private keys, password and etc.
Upvotes: 1