Skip to main content

Mount Configuration File

In Kubernetes deployment mode, mounting a configuration file is done by default through variables, where the configuration file is base64-encoded into variable values, and mounted into the container.

If you want to mount the following to the /usr/local/MDPrivateDeployment/integrate/appextensions.json in the container.

{
"WebhookUrl": "https://api.domain.com/hooks/NjA0NzdjMDNjMGFjMTE3ZGUwMjRjN2Nl",
"WebhookHeaders": {}
}

First, you need to encode the mounting path and the configuration file separately in Base64, either through the command (the steps in the example below) or an online encoding tool.

[root@localhost ~]# echo -n '/usr/local/MDPrivateDeployment/integrate/appextensions.json' | base64 -w0
L3Vzci9sb2NhbC9NRFByaXZhdGVEZXBsb3ltZW50L2ludGVncmF0ZS9hcHBleHRlbnNpb25zLmpzb24=
[root@localhost ~]# echo -n '{
"WebhookUrl": "https://api.domain.com/hooks/NjA0NzdjMDNjMGFjMTE3ZGUwMjRjN2Nl",
"WebhookHeaders": {}
}' | base64 -w0
ewogICJXZWJob29rVXJsIjogImh0dHBzOi8vYXBpLmRvbWFpbi5jb20vaG9va3MvTmpBME56ZGpNRE5qTUdGak1URTNaR1V3TWpSak4yTmwiLAogICJXZWJob29rSGVhZGVycyI6IHt9Cn0=

After finishing the encoding mentioned above, splice the encoded content with a colon. The left side of the colon is the encoded path and the right side is the encoded configuration file.

L3Vzci9sb2NhbC9NRFByaXZhdGVEZXBsb3ltZW50L2ludGVncmF0ZS9hcHBleHRlbnNpb25zLmpzb24=:ewogICJXZWJob29rVXJsIjogImh0dHBzOi8vYXBpLmRvbWFpbi5jb20vaG9va3MvTmpBME56ZGpNRE5qTUdGak1URTNaR1V3TWpSak4yTmwiLAogICJXZWJob29rSGVhZGVycyI6IHt9Cn0=
  • What you get now is the variable value that needs to be mounted

Next, set custom variable names such as ENV_SERVICE_CONFIG_INTEGRATEENV_SERVICE_CONFIG_SSO_JSON are possible. But the name of the environment variable must start with ENV_SERVICE_CONFIG.

Configure the defined variable names and encoded variable values in the config.yaml file of the microservice (variable values must be enclosed in double quotes).

ENV_SERVICE_CONFIG_INTEGRATE: "L3Vzci9sb2NhbC9NRFByaXZhdGVEZXBsb3ltZW50L2ludGVncmF0ZS9hcHBleHRlbnNpb25zLmpzb24=:ewogICJXZWJob29rVXJsIjogImh0dHBzOi8vYXBpLmRvbWFpbi5jb20vaG9va3MvTmpBME56ZGpNRE5qTUdGak1URTNaR1V3TWpSak4yTmwiLAogICJXZWJob29rSGVhZGVycyI6IHt9Cn0="

After the configuration, restart the microservice. After this,you can enter any microservice container to check whether the mounting path and configuration file are correct.


The above is the way to mount a configuration file into a container in Kubernetes deployment mode, you can take this as a model to mount multiple configuration files as long as the custom variable names are not duplicated.