|
1 | 1 | # Configuration |
2 | 2 |
|
| 3 | +## Environments variables of PyMS: |
| 4 | + |
| 5 | +**CONFIGMAP_FILE**: The path to the configuration file. By default, PyMS search the configuration file in your |
| 6 | +actual folder with the name "config.yml" |
| 7 | +**CONFIGMAP_SERVICE**: the name of the keyword that define the block of key-value of [Flask Configuration Handling](http://flask.pocoo.org/docs/1.0/config/) |
| 8 | +and your own configuration (see the next section to more info) |
| 9 | + |
3 | 10 | ## Create configuration |
4 | 11 | Each microservice needs a config file in yaml or json format to work with it. This configuration contains |
5 | 12 | the Flask settings of your project and the [Services](services.md). With this way to create configuration files, we |
@@ -44,7 +51,6 @@ or in a config.json: |
44 | 51 |
|
45 | 52 | This file could contains this keywords: |
46 | 53 |
|
47 | | - |
48 | 54 | ## pyms block |
49 | 55 |
|
50 | 56 | ```pyms```: all subsets inside this keyword are the settings of this library. Each keyword will be a service of our |
@@ -96,6 +102,8 @@ ms1-api: |
96 | 102 | TESTING: false |
97 | 103 | ``` |
98 | 104 |
|
| 105 | +You can set this keyword with the environment var **CONFIGMAP_SERVICE**. |
| 106 | + |
99 | 107 | ## Import Configuration |
100 | 108 | With pyms, all configuration is stored as flask configuration and it can be acceded from: |
101 | 109 |
|
@@ -142,4 +150,37 @@ API = Api( |
142 | 150 | ``` |
143 | 151 |
|
144 | 152 | **IMPORTANT:** If you use this method to get configuration out of context, you must set the `CONFIGMAP_SERVICE` or set |
145 | | -the default key `ms` for your configuration block in your config.yml |
| 153 | +the default key `ms` for your configuration block in your config.yml |
| 154 | + |
| 155 | + |
| 156 | +## Looking for Configuration file with Kubernetes Configmaps |
| 157 | +By default, Microservice class search a config.yml in the same path. You can set a different route or set a json file. |
| 158 | +To change this path, define a environment variable `CONFIGMAP_FILE`. |
| 159 | + |
| 160 | +This way of looking for the configuration is useful when you work with Docker and Kubernetes. For example, you can integrate |
| 161 | +a configmap of Kubernetes, with this microservice and a deployment with: |
| 162 | + |
| 163 | +```yaml |
| 164 | +apiVersion: extensions/v1beta1 |
| 165 | +kind: Deployment |
| 166 | +metadata: |
| 167 | + name: my-microservice |
| 168 | +spec: |
| 169 | + replicas: 1 |
| 170 | + template: |
| 171 | + spec: |
| 172 | + containers: |
| 173 | + - name: my-microservice |
| 174 | + image: ... |
| 175 | + env: |
| 176 | + - name: CONFIGMAP_FILE |
| 177 | + value: "/usr/share/microservice/config.yaml" |
| 178 | +
|
| 179 | + volumeMounts: |
| 180 | + - mountPath: /usr/share/microservice |
| 181 | + name: ms-config-volume |
| 182 | + volumes: |
| 183 | + - name: ms-config-volume |
| 184 | + configMap: |
| 185 | + name: my-microservice-configmap |
| 186 | +``` |
0 commit comments