Skip to content

Kubernetes ConfigMap integration with Apollo

Kubernetes ConfigMap integration with Apollo involves using Kubernetes ConfigMaps to decouple application container images from configuration files, facilitating the management and delivery of the Apollo configuration center platform^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

This approach allows for the dynamic updating of configuration parameters—such as registry addresses or protocol ports—without rebuilding application images^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. By integrating Apollo, a distributed configuration center, with Kubernetes resources, operations teams can achieve centralized configuration management for microservices running across different environments^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Core Concepts

ConfigMap Fundamentals

A ConfigMap is an API object used to store non-confidential data in key-value pairs^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

The primary purpose of using ConfigMaps in this context is decoupling. It ensures that container images remain portable and reusable regardless of the specific runtime environment configuration^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Apollo Architecture

Apollo is a distributed configuration center typically composed of several microservices: * ConfigService: Provides configuration reading and push-pull mechanisms for clients^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. * AdminService: Manages configuration modifications and synchronization to the database^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. * Portal: The management interface for creating projects and modifying configurations^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

In a Kubernetes integration, these components are deployed as Pods/Deployments, and their specific settings (like database connection strings) are injected via ConfigMaps^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Implementation Strategy

Volume Mounting

The standard method for integrating ConfigMaps with applications (such as Apollo services or Dubbo monitors) is to mount the ConfigMap as a volume within the Pod specification^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

  1. Define the ConfigMap: Create a YAML file defining the configuration data (e.g., dubbo.properties or application-github.properties)^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].
  2. Configure Volumes: In the Deployment resource, define a volume that references the ConfigMap name^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].
  3. Mount Volume: In the container specification, mount this volume to a specific directory (e.g., /apollo-configservice/config or /dubbo-monitor-simple/conf), overriding the default configuration files packaged in the image^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Dynamic Configuration

Applications like Dubbo services connect to Apollo by passing environment variables (e.g., C_OPTS) via the Kubernetes Deployment definition^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

  • Example: -Dapollo.meta=http://config.od.com

Once connected, configuration changes (e.g., changing a Dubbo port from 20880 to 20881 or switching Zookeeper addresses) can be made in the Apollo Portal^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]. Although the application may require a restart to pick up specific changes, the need to rebuild the Docker image is eliminated^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Multi-Environment Management

Kubernetes and Apollo can be integrated to support multiple environments (e.g., FAT/Test, PROD) using a single application image^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Isolation Strategy

  1. Namespaces: Separate Kubernetes Namespaces (e.g., test, prod) are created to isolate resources^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].
  2. Dedicated Deployments: Separate instances of Apollo ConfigService and AdminService are deployed into each namespace^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].
  3. Domain Routing: Ingress rules are configured to route traffic to the specific environment's service (e.g., config-test.od.com vs. config-prod.od.com)^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].
  4. Database Separation: Separate databases (e.g., ApolloConfigTestDB, ApolloConfigProdDB) are used to ensure configuration data isolation^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Environment Variable Switching

The application image remains constant, but the Deployment manifests for each environment differ in their environment variables^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

  • Test: -Denv=fat -Dapollo.meta=http://config-test.od.com
  • Production: -Denv=pro -Dapollo.meta=http://config-prod.od.com (or internal service URL)^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

This ensures that a service in the test namespace only fetches configuration from the Test Apollo cluster, while the prod service fetches from Production^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md].

Sources