DNS-based service discovery for multi-environment Apollo¶
DNS-based service discovery for multi-environment Apollo is a networking strategy used to isolate service discovery and configuration management within Kubernetes clusters. By configuring specific DNS records for different environments (e.g., Test and Production), this approach ensures that applications in a specific environment namespace connect only to the corresponding Apollo configuration service instance, preventing cross-contamination of configuration and traffic.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Architecture¶
This architecture relies on segregating the Apollo Config Service components into dedicated Kubernetes namespaces and using Ingress DNS names to route traffic.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Environment Segregation¶
To support multiple environments, dedicated Kubernetes namespaces are created (e.g., test and prod).^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md] Correspondingly, the backend databases are separated into ApolloConfigTestDB and ApolloConfigProdDB.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Each environment deploys its own instance of the Apollo Config Service, mapped via specific DNS entries:
- Test Environment:
config-test.od.com - Production Environment:
config-prod.od.com
These domains resolve to the same Ingress Controller IP (e.g., 10.4.7.10) but route traffic to different backend services based on the hostname.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Configuration¶
The core mechanism involves pointing the application's Apollo client (apollo.meta) to the environment-specific DNS address.
Intra-namespace Discovery¶
For workloads deployed within the same Kubernetes namespace as the Config Service (e.g., in the prod namespace), direct Kubernetes service discovery can be utilized.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md] In this scenario, the application is configured to connect to http://apollo-configservice:8080.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md] This leverages the internal cluster DNS, bypassing the external Ingress and simplifying network paths.
Inter-namespace Discovery¶
When using distinct DNS domains via Ingress, the environment variable for the application container is set to the specific domain.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Example Test Environment Configuration:
env:
- name: C_OPTS
value: "-Denv=fat -Dapollo.meta=http://config-test.od.com"
This ensures that the Test environment application queries the Test Config Service, while Production applications query their respective service.