alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.97k stars 8.34k forks source link

Kubernetes native configuration managenment #3114

Open DanielLiu1123 opened 1 year ago

DanielLiu1123 commented 1 year ago

Background

Kubernetes has become synonymous with cloud-native, and building applications based on Kubernetes can help us reduce maintenance costs and software complexity, so imagine if Kubernetes could be integrated into the Spring ecosystem, which I'm sure could solve any problem you're facing.

Kubernetes provides Configmap and Secret to manage configuration, Spring Cloud provides the ability to dynamically refresh at runtime, and the combination of the two makes for a "cloud-native configuration center" with native-supported RBAC, so you don't need Nacos (config) / Apollo anymore.

Goals

steverao commented 1 year ago

It looks good! But we need to discuss which main branch of 2.2.x/2021.x/2022.x that will support the ability.

DanielLiu1123 commented 1 year ago

I think it is possible to support both 2021.x and 2022.x branches.

DanielLiu1123 commented 1 year ago

This module has the same purpose as Spring Cloud Kubernetes Config, to provide Kubernetes ConfigMap/Secret as a remote configuration with the ability to be dynamically refreshed.

But one major difference is that Spring Cloud Kubernetes Config relies on the spring-cloud-starter-bootstrap implementation for its configurations. So the configurations need to be placed in bootstrap.yml or by using import: spring.config.import=kubernetes:config.

Both of these approaches have some limitations.

For way one:

For way two:

What problems are solved by Spring Cloud Alibaba Kubernetes Config module?

  1. Unified configuration, unlike Spring Cloud Kubernetes has two sets of configuration, reducing the cost of use.
  2. The implementation does not depend on spring-cloud-starter-bootstrap, all configurations are placed in application.yml, there is no parent-child context, which is more convenient for debugging and understanding.
  3. More flexible and simple configuration, you can specify different namesapce, configuration priority, refreshable for different configurations.
  4. Better refresh performance, in the refresh phase will not pull any configuration, but only the latest configuration will be resolved as PropertySource and added to the environment, so this approach should have theoretical best performance for the refresh phase.

Configurations when using Spring Cloud Kubernetes Config and Spring Cloud Alibaba Kubernetes Config:

ruansheng8 commented 1 year ago

@DanielLiu1123
Why Spring Cloud Alibaba Kubernetes Config using spring.cloud.k8s.config instead of using spring.cloud.kubernetes.config, it may be a better choice to keep the configuration properties of similar functional modules consistent.

DanielLiu1123 commented 1 year ago

Why Spring Cloud Alibaba Kubernetes Config using spring.cloud.k8s.config instead of using spring.cloud.kubernetes.config.

This is tricky one, it conflicts with Spring Cloud Kubernetes if we use spring.cloud.kubernetes.config.

spring.cloud.alibaba-kubernetes.config might also be an option?

DanielLiu1123 commented 1 year ago

I think spring.cloud.alibaba.kubernetes.config is a good choice

All of the modules don't have alibaba in the prefix, such as spring.cloud.nacos, spring.cloud.sentinel, if the prefix contains alibaba from the beginning, it's a good choice.

I think both spring.cloud.alibaba-kubernetes and spring.cloud.alibaba.kubernetes are acceptable.

steverao commented 1 year ago

I think spring.cloud.alibaba.kubernetes.config is a good choice

All of the modules don't have alibaba in the prefix, such as spring.cloud.nacos, spring.cloud.sentinel, if the prefix contains alibaba from the beginning, it's a good choice.

I think both spring.cloud.alibaba-kubernetes and spring.cloud.alibaba.kubernetes are acceptable.

I suggest using spring.cloud.alibaba-kubernetes, alibaba-kubernetes is component name. It will be same as before.