K8S deploys N microservices, each of which has many configurations and requires a configuration center to centrally manage these configurations. Apollo was used as the configuration center. This article describes how to deploy the Apollo configuration center in a K8S cluster using ArgoCD.

A, environmental

  1. Multiple K8S clusters have been set up. One cluster corresponds to the other
  2. ArgoCD is installed in the cluster
  3. A mysql database (Apollo requires a mysql database, so you must have a mysql database)

Initialize the mysql database

To initialize the script, use the official script: github.com/apolloconfi…

Apolloconfigdb. SQL initializes the database of config — ApolloConfigdb

Apolloportaldb. SQL initializes the portal database – ApolloPortalDB

Apollo is deployed in the K8S cluster

Please refer to the official documentation: www.apolloconfig.com/#/zh/deploy…

Apollo 1.7.0 adds a deployment mode based on Kubernetes native service discovery, simplifies overall deployment by removing the built-in Eureka, and also provides Helm Charts for easy deployment. Support for Helm Charts, which is easy to deploy with argoCD.

Download the code, put it in your ArgoCD configuration bin, modify the mysql information, and define the ArgoCD Application.

Download the code

git clone https://github.com/apolloconfig/apollo-helm-chart
Copy the code

Modify mysql interconnection configuration

  • Apollo-portal Interconnects with mysql

  • Apollo-service Interconnects with mysql

The deployment of Apollo – portal

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: apollo-portal
  namespace: argocd
spec:
  destination:
    namespace: apollo
    server: https://kubernetes.default.svc
  project: ops-prod
  source:
    path: apollo-helm-chart/apollo-portal/
    repoURL: https://xxxxxxxxx.git
    targetRevision: HEAD
  syncPolicy:
    syncOptions:
    - CreateNamespace=true
    automated:
      selfHeal: false
      prune: false
Copy the code
  • Support for the namespace Apollo in Project: OPS-PROd
  • Install into namespace namespace: Apollo
  • Path: Apollo-helm-chart/Apollo-portal/is the code path you downloaded
  • RepoURL: xxxxxxxxx.git is the address of the configuration bin

Deploy the test environment Apollo-portal

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: apollo-service-dev
  namespace: argocd
spec:
  destination:
    namespace: apollo
    server: https://kubernetes.default.svc
  project: ops-prod
  source:
    helm:
      valueFiles:
      - values-dev.yaml
    path: apollo-helm-chart/apollo-service/
    repoURL: https://xxxxxx.git
    targetRevision: HEAD
  syncPolicy:
    syncOptions:
    - CreateNamespace=true
    automated:
      selfHeal: false
      prune: false
Copy the code
  • Path is changed to Apollo-service

  • To support multiple environments, I copied multiple values under Apollo-service, corresponding to the configuration of multiple environments.

This is specified by valueFiles in Application.

  source:
    helm:
      valueFiles:
      - values-dev.yaml
Copy the code

App specifies the helm to use different valueFiles. See the official example: github.com/argoproj/ar…

Deploy the production environment Apollo-Portal

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: apollo-service-prod
  namespace: argocd
spec:
  destination:
    namespace: apollo
    server: https://kubernetes.default.svc
  project: ops-prod
  source:
    helm:
      valueFiles:
      - values-prod.yaml
    path: apollo-helm-chart-main/apollo-service/
    repoURL: https://xxxxxx.git
    targetRevision: HEAD
  syncPolicy:
    syncOptions:
    - CreateNamespace=true
    automated:
      selfHeal: false
      prune: false
Copy the code

Docking with Apollo

Local docking Apollo

The official document states that the Config Service is deployed on the public cloud, and the address registered with the Meta Server is an Intranet address. The local development environment cannot be directly connected.

For local boot, we need to add -dapollo.configService = to the boot parameterhttp://xxxxxx

http://xxxxxxx is the LB address exposed by configService.

The cluster service container connects to Apollo

In the Deployment file of the business container

          command: ["/bin/sh"]
          args: ["-c", "set -e && java -Dapollo.configService=http://xxxxxx/ -jar app.jar"]
          
Copy the code

Five, Apollo use

TODO