K8s deploy the Apollo configuration center

Time:2021-12-30

Deployment environment

1、mysql 10.10.10.26
Account root password 123
Apollo config internal address 10.43 twenty-two point two two

1、 Create data

The Apollo server requires two databases: Apollo PORTALDB and Apollo configdb. We have prepared SQL files for the creation of databases, tables and sample data respectively. We only need to import the database.
1. Create Apollo PORTALDB
Import through various MySQL clientsapolloportaldb.sqlJust.
2. Create Apollo configdb
Import through various MySQL clientsapolloconfigdb.sqlJust.

2、 Create Secrets

Apollo config environment variable (DEV)

apiVersion: v1
kind: Secret
metadata:
  name: apollo-config-secret
  namespace: default
type: Opaque
data:
  #SPRING_DATASOURCE_PASSWORD: 123
  SPRING_DATASOURCE_PASSWORD: MTIz
  #SPRING_DATASOURCE_URL: jdbc:mysql://10.10.10.26:30001/ApolloConfigDB?characterEncoding=utf8
  SPRING_DATASOURCE_URL: >-
    amRiYzpteXNxbDovLzEwLjEwLjEwLjI2OjMwMDAxL0Fwb2xsb0NvbmZpZ0RCP2NoYXJhY3RlckVuY29kaW5nPXV0Zjg=
  #SPRING_DATASOURCE_USERNAME: root
  SPRING_DATASOURCE_USERNAME: cm9vdA==

Apollo portal environment variable (DEV)

apiVersion: v1
kind: Secret
metadata:
  name: apollo-portal-secret
  namespace: default
type: Opaque
data:
  #APOLLO_PORTAL_ENVS = dev
  APOLLO_PORTAL_ENVS: ZGV2
  #PRO_META = http://localhost:8080
  PRO_META: aHR0cDovL2xvY2FsaG9zdDo4MDgw
  #SPRING_DATASOURCE_PASSWORD = 123
  SPRING_DATASOURCE_PASSWORD: MTIz
  #SPRING_DATASOURCE_URL = jdbc:mysql://10.10.10.26:30001/ApolloPortalDB? characterEncoding=utf8
  SPRING_DATASOURCE_URL: >-
    amRiYzpteXNxbDovLzEwLjEwLjEwLjI2OjMwMDAxL0Fwb2xsb1BvcnRhbERCPyBjaGFyYWN0ZXJFbmNvZGluZz11dGY4
   #SPRING_DATASOURCE_USERNAME = root
  SPRING_DATASOURCE_USERNAME: cm9vdA==

3、 Create configuration file configmap

1. Create ciphertext for environment variables

apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    name: apollo-portal-cfg-dev
  name: apollo-portal-cfg
  namespace: default
data:
  key-apollo-env.properties: |-
    local.meta=http://localhost:8080
    dev.meta=http://10.43.22.22:8080
    fat.meta=http://fill-in-fat-meta-server:8080
    uat.meta=http://fill-in-uat-meta-server:8080
    lpt.meta=${lpt_meta}
    pro.meta=http://fill-in-pro-meta-server:8080
  key-app.properties: |-
    appId=100003173
    jdkVersion=1.8
  key-application-github.properties: |-
    local.meta=http://localhost:8080
    dev.meta=http://fill-in-dev-meta-server:8080
    fat.meta=http://fill-in-fat-meta-server:8080
    uat.meta=http://fill-in-uat-meta-server:8080
    lpt.meta=${lpt_meta}
    pro.meta=http://fill-in-pro-meta-server:8080

4、 Deploy Apollo config

1. Create internal access service

apiVersion: v1
kind: Service
metadata:
  name: apollo-config-service-inner
  namespace: default
spec:
  selector:
    name: apollo-config-dev
  type: ClusterIP
  clusterIP: 10.43. 22.22 # write the value to the Apollo configdb database Eureka service. url
  ports:
    - name: 
      port: 8080
      protocol: TCP
      targetPort: 8080
  sessionAffinity: None

2. Deployment Services

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-config
  namespace: default
spec:
  selector:
    matchLabels:
      name: apollo-config-dev
  template:
    metadata:
      labels:
        name: apollo-config-dev
    spec:
      containers:
        - imagePullPolicy: IfNotPresent
          image: 'apolloconfig/apollo-configservice:latest'
          envFrom:
            - prefix: ''
              secretRef:
                name: apollo-config-secret
          ports:
            - name: 8080tcp
              expose: true
              protocol: TCP
              containerPort: 8080
          name: apollo-config

5、 Deploy Apollo admin

1. Configuration database
Change configuration apolloconfigdb > serverconfig > Eureka service. url =http://10.43.22.22:8080/eureka/

K8s deploy the Apollo configuration center

image.png

2. Deployment Services

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-admin
  namespace: default
spec:
  selector:
    matchLabels:
      name: apollo-admin-dev
  template:
    metadata:
      labels:
        name: apollo-admin-dev
    spec:
      containers:
        - imagePullPolicy: IfNotPresent
          image: 'apolloconfig/apollo-adminservice:latest'
          envFrom:
            - prefix: ''
              secretRef:
                name: apollo-config-secret
          ports:
            - name: 8090tcp
              expose: true
              protocol: TCP
              containerPort: 8090
          name: apollo-admin
      restartPolicy: Always
  replicas: 1

6、 Deploy Apollo portal

1. Deployment Services

apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-portal
  namespace: default
spec:
  selector:
    matchLabels:
      name: apollo-portal-dev
  template:
    metadata:
      labels:
        name: apollo-portal-dev
    spec:
      containers:
        - imagePullPolicy: IfNotPresent
          image: 'apolloconfig/apollo-portal:latest'
          envFrom:
            - prefix: ''
              secretRef:
                name: apollo-portal-secret
          ports:
            - name: 8070tcp
              expose: true
              protocol: TCP
              containerPort: 8070
          name: apollo-portal
          volumeMounts:
          - name: apollo-portal-cfg-volume
            mountPath: /apollo-portal/config/
      restartPolicy: Always
      volumes:
      - name: apollo-portal-cfg-volume
        configMap:
         name: apollo-portal-cfg
         items:
         - key: key-application-github.properties
           path: application-github.properties
         - key: key-apollo-env.properties
           path: apollo-env.properties
         - key: key-app.properties
           path: app.properties
  replicas: 1

2. Exposure services

apiVersion: v1
kind: Service
metadata:
  name: apollo-portal-front
  namespace: default
spec:
  selector:
    name: apollo-portal-dev
  type: NodePort
  ports:
    - name: ''
      port: 8070
      protocol: TCP
      targetPort: 8070
      nodePort: 30004
  sessionAffinity: None
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apollo-dev
  namespace: default
spec:
  selector:
    matchLabels:
      app: apollo-dev
  template:
    metadata:
      labels:
        app: apollo-dev
    spec:
      containers:
        - imagePullPolicy: IfNotPresent
          image: 'apolloconfig/apollo-configservice:latest'
          envFrom:
            - prefix: ''
              secretRef:
                name: apollo-config-dev
          ports:
            - name: 8080tcp
              expose: true
              protocol: TCP
              containerPort: 8080
          name: apollo-config
        - imagePullPolicy: IfNotPresent
          image: 'apolloconfig/apollo-adminservice:latest'
          envFrom:
            - prefix: ''
              secretRef:
                name: apollo-config-dev
          ports:
            - name: 8090tcp
              expose: true
              protocol: TCP
              containerPort: 8090
          name: apollo-admin
        - imagePullPolicy: IfNotPresent
          image: 'apolloconfig/apollo-portal:latest'
          envFrom:
            - prefix: ''
              secretRef:
                name: apollo-portal-dev
          ports:
            - name: 8070tcp
              expose: true
              protocol: TCP
              containerPort: 8070
          name: apollo-portal
          volumeMounts:
          - name: apollo-portal-cfg-volume
            mountPath: /apollo-portal/config/
      restartPolicy: Always
      volumes:
      - name: apollo-portal-cfg-volume
        configMap:
         name: apollo-cfg
         items:
         - key: key-application-github.properties
           path: application-github.properties
         - key: key-apollo-env.properties
           path: apollo-env.properties
         - key: key-app.properties
           path: app.properties
  replicas: 1

View the status in the container: kubectl exec – it Apollo portal dev-6779cb4fcf-g7r7r — container Apollo Portal — sh