Write Config To Nacos

    Nacos is committed to help you discover, configure, and manage your microservices. It provides a set of simple and useful features enabling you to realize dynamic service discovery, service configuration, service metadata and traffic management.

    Nacos makes it easier and faster to construct, deliver and manage your microservices platform. It is the infrastructure that supports a service-centered modern application architecture with a microservices or cloud-native approach.

    By default, KubeVela saves the config as a Secret. We could define the template and write the config to the Nacos server. In this case, the role of KubeVela is to check the config content and generate the configuration in a certain format and synchronize it to Nacos. Then, you could write the config to Nacos in Workflow and Pipeline.

    Expected Outputs

    1. +---------+--------+--------------------------------+----------+---------+---------+
    2. | NAME | TYPE | DESCRIPTION | REQUIRED | OPTIONS | DEFAULT |
    3. +---------+--------+--------------------------------+----------+---------+---------+
    4. | client | object | Discover the Nacos servers by | false | | |
    5. | | | the client. | | | |
    6. | servers | array | Directly configure the Nacos | false | | |
    7. | | | server address | | | |
    8. +---------+--------+--------------------------------+----------+---------+---------+
    9. client
    10. +--------------------+---------+--------------------------------------------+----------+---------+---------+
    11. | NAME | TYPE | DESCRIPTION | REQUIRED | OPTIONS | DEFAULT |
    12. +--------------------+---------+--------------------------------------------+----------+---------+---------+
    13. | (client).password | string | the password for nacos auth | false | | |
    14. | (client).regionId | string | the regionId for kms | false | | |
    15. | (client).secretKey | string | the SecretKey for kms | false | | |
    16. | (client).username | string | the username for nacos auth | false | | |
    17. | (client).accessKey | string | the AccessKey for kms | false | | |
    18. | (client).endpoint | string | the endpoint for get Nacos | true | | |
    19. | | | server addresses | | | |
    20. | (client).openKMS | boolean | it's to open kms,default is false. | false | | |
    21. | | | https://help.aliyun.com/product/28933.html | | | |
    22. +--------------------+---------+--------------------------------------------+----------+---------+---------+

    Then create a config to connect the Nacos server:

    There is a default template to help you publish the config to the Nacos:

    1. vela config-template show nacos-config

    This template cue is like this:

    1. metadata: {
    2. alias: "Nacos Configuration"
    3. description: "Write the configuration to the nacos"
    4. sensitive: false
    5. scope: "system"
    6. template: {
    7. nacos: {
    8. // The endpoint can not references the parameter.
    9. endpoint: {
    10. // Users must create a config base the nacos-server template firstly.
    11. name: "nacos"
    12. }
    13. format: parameter.contentType
    14. // could references the parameter
    15. metadata: {
    16. dataId: parameter.dataId
    17. group: parameter.group
    18. if parameter.appName != _|_ {
    19. appName: parameter.appName
    20. }
    21. if parameter.namespaceId != _|_ {
    22. namespaceId: parameter.namespaceId
    23. }
    24. if parameter.tenant != _|_ {
    25. tenant: parameter.tenant
    26. }
    27. tag: parameter.tag
    28. }
    29. }
    30. content: parameter.content
    31. }
    32. // +usage=Configuration ID
    33. dataId: string
    34. // +usage=Configuration group
    35. group: *"DEFAULT_GROUP" | string
    36. // +usage=The configuration content.
    37. content: {
    38. ...
    39. }
    40. contentType: *"json" | "yaml" | "properties" | "toml"
    41. // +usage=The app name of the configuration
    42. appName?: string
    43. // +usage=The namespaceId of the configuration
    44. namespaceId?: string
    45. // +usage=The tenant, corresponding to the namespace ID field of Nacos
    46. tenant?: string
    47. // +usage=The tag of the configuration
    48. tag?: string
    49. }
    50. }

    The template includes the template.nacos section means the config created with this template should be written to the Nacos, There are some important sections:

    • template.nacos.endpoint KubeVela will read the Nacos server connector info from the provided config.
    • template.nacos.format KubeVela will generate the configuration content with the provided format. Supported options include json, yaml, properties, and toml.

    You could refer to this template to custom the scene template. Expose the required parameters.

    1. host = 127.0.0.1
    2. username = root

    After the command is executed successfully, let’s check the config in the Nacos Dashboard.