github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/docs/design/global-config.md (about)

     1  # Global configuration
     2  
     3  The feature of global configuration is to expose the parameters of distributed applications in the entire cluster mirror.
     4  It is highly recommended exposing only a few parameters that users need to care about.
     5  
     6  If too many parameters need to be exposed, for example, the entire helm's values ​​want to be exposed,
     7  then it is recommended to build a new image and put the configuration in to overwrite it.
     8  
     9  Using dashboard as an example, we made a cluster mirror of dashboard,
    10  but different users want to use different port numbers while installing.
    11  In this scenario, sealer provides a way to expose this port number parameter to the environment
    12  variable of Clusterfile.
    13  
    14  Use global configuration capabilities
    15  For the image builder, this parameter needs to be extracted when making the image.
    16  Take the yaml of the dashboard as an example:
    17  
    18  dashboard.yaml.tmpl:
    19  
    20  ```yaml
    21  ...
    22  kind: Service
    23  apiVersion: v1
    24  metadata:
    25    labels:
    26      k8s-app: kubernetes-dashboard
    27    name: kubernetes-dashboard
    28    namespace: kubernetes-dashboard
    29  spec:
    30    ports:
    31      - port: 443
    32        targetPort: {{ .DashBoardPort }}
    33    selector:
    34      k8s-app: kubernetes-dashboard
    35  ...
    36  ```
    37  
    38  To write kubefile, you need to copy yaml to the "manifests" directory at this time,
    39  sealer only renders the files in this directory:
    40  
    41  sealer will render the .tmpl file and create a new file named `dashboard.yaml`
    42  
    43  ```yaml
    44  FROM kubernetes:1.16.9
    45  COPY dashobard.yaml.tmpl manifests/ # only support render template files in `manifests etc charts` dirs
    46  CMD kubectl apply -f manifests/dashobard.yaml
    47  ```
    48  
    49  For users, they only need to specify the cluster environment variables:
    50  
    51  ```shell script
    52  sealer run -e DashBoardPort=8443 mydashboard:latest -m xxx -n xxx -p xxx
    53  ```
    54  
    55  Or specify in Clusterfile:
    56  
    57  ```yaml
    58  apiVersion: sealer.io/v1
    59  kind: Cluster
    60  metadata:
    61    name: my-cluster
    62  spec:
    63    image: mydashobard:latest
    64    env:
    65      DashBoardPort=6443 # Specify a custom port here, which will be rendered into the mirrored yaml
    66  ...
    67  ```
    68  
    69  ## Using Env in shell plugin or other scripts
    70  
    71  [Using env in scripts](https://github.com/sealerio/sealer/blob/main/docs/design/clusterfile-v2.md#using-env-in-configs-and-script)
    72  
    73  ## Application config
    74  
    75  Application config file:
    76  
    77  Clusterfile:
    78  
    79  ```
    80  apiVersion: sealer.io/v1
    81  kind: Cluster
    82  metadata:
    83    name: my-cluster
    84  spec:
    85    image: registry.cn-qingdao.aliyuncs.com/sealer-app/my-SAAS-all-inone:latest
    86    provider: BAREMETAL
    87  ---
    88  apiVersion: sealer.io/v1
    89  kind: Config
    90  metadata:
    91    name: mysql-config
    92  spec:
    93    path: etc/mysql.yaml
    94    data: |
    95         mysql-user: root
    96         mysql-passwd: xxx
    97  ...
    98  ---
    99  apiVersion: sealer.io/v1
   100  kind: Config
   101  metadata:
   102    name: redis-config
   103  spec:
   104    path: etc/redis.yaml
   105    data: |
   106         redis-user: root
   107         redis-passwd: xxx
   108  ...
   109  ```
   110  
   111  When apply this Clusterfile, sealer will generate some values file for application config. Named etc/mysql-config.yaml  etc/redis-config.yaml.
   112  
   113  So if you want to use this config, Kubefile is like this:
   114  
   115  ```
   116  FROM kuberentes:v1.19.9
   117  ...
   118  CMD helm install mysql -f etc/mysql-config.yaml
   119  CMD helm install mysql -f etc/redis-config.yaml
   120  ```
   121  
   122  ## Development Document
   123  
   124  Before mounting Rootfs, templates need to be rendered for the files in etc, charts, and manifest directories,
   125  and render environment variables and annotations to the [configuration file].
   126  Generate the global.yaml file to the etc directory