k8s deployment apollo configuration center

Convenient for online k8s to automatically obtain the latest configuration from apollo when deploying pod

Architecture diagram

flow chart

  1. Deploy database

1.1 four mysql deployments

MKDIR - P / data / Apollo / MySQL Apollo PRD / data / Apollo / MySQL Apollo test / data / Apollo / MySQL Apollo dev / data / Apollo / MySQL Apollo / MySQL Apollo portal / / NFS server creates folder

kubectl apply -f mysql-apollo-dev.yml #Develop db

apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: sre
  name: mysql-apollo-dev-pv
spec:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 150Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nas
  nfs:
    path: /data/apollo/mysql-apollo-dev
    server: 192.168.1.20

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  namespace: sre
  name: mysql-apollo-dev-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nas
  resources:
    requests:
      storage: 150Gi

---
apiVersion: v1
kind: Service
metadata:
  name: mysql-apollo-dev
  namespace: sre
spec:
  ports:
  - port: 3306
    nodePort: 30100
  type: NodePort
  selector:
    app: mysql-apollo-dev

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mysql-apollo-dev
  namespace: sre
spec:
  selector:
    matchLabels:
      app: mysql-apollo-dev
  template:
    metadata:
      labels:
        app: mysql-apollo-dev
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql-apollodev
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-apollo-dev-pvc

kubectl apply -f mysql-apollo-test.yml //Test db

apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: sre
  name: mysql-apollo-test-pv
spec:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 150Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nas
  nfs:
    path: /data/apollo/mysql-apollo-test
    server: 192.168.1.20

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  namespace: sre
  name: mysql-apollo-test-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nas
  resources:
    requests:
      storage: 150Gi

---
apiVersion: v1
kind: Service
metadata:
  name: mysql-apollo-test
  namespace: sre
spec:
  ports:
  - port: 3306
    nodePort: 30101
  type: NodePort
  selector:
    app: mysql-apollo-test

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mysql-apollo-test
  namespace: sre
spec:
  selector:
    matchLabels:
      app: mysql-apollo-test
  template:
    metadata:
      labels:
        app: mysql-apollo-test
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql-apollot
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-apollo-test-pvc

kubectl apply -f mysql-apollo-prd.yml //Production db

apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: sre
  name: mysql-apollo-prd-pv
spec:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 150Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nas
  nfs:
    path: /data/apollo/mysql-apollo-prd
    server: 192.168.1.20

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  namespace: sre
  name: mysql-apollo-prd-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nas
  resources:
    requests:
      storage: 150Gi

---
apiVersion: v1
kind: Service
metadata:
  name: mysql-apollo-prd
  namespace: sre
spec:
  ports:
  - port: 3306
    nodePort: 30102
  type: NodePort
  selector:
    app: mysql-apollo-prd

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mysql-apollo-prd
  namespace: sre
spec:
  selector:
    matchLabels:
      app: mysql-apollo-prd
  template:
    metadata:
      labels:
        app: mysql-apollo-prd
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql-apolloprd
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-apollo-prd-pvc

kubectl apply -f mysql-apollo-portal.yml //Entry db

apiVersion: v1
kind: PersistentVolume
metadata:
  namespace: sre
  name: mysql-apollo-portal-pv
spec:
  accessModes:
    - ReadWriteMany
  capacity:
    storage: 150Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nas
  nfs:
    path: /data/apollo/mysql-apollo-portal
    server: 192.168.1.20

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  namespace: sre
  name: mysql-apollo-portal-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nas
  resources:
    requests:
      storage: 150Gi

---
apiVersion: v1
kind: Service
metadata:
  name: mysql-apollo-portal
  namespace: sre
spec:
  ports:
  - port: 3306
    nodePort: 30104
  type: NodePort
  selector:
    app: mysql-apollo-portal

---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mysql-apollo-portal
  namespace: sre
spec:
  selector:
    matchLabels:
      app: mysql-apollo-portal
  template:
    metadata:
      labels:
        app: mysql-apollo-portal
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 3306
          name: mysql-apolloptl
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-apollo-portal-pvc

2.1.1 import db related data

# cd apollo/scripts/apollo-on-kubernetes/db/
# mysql -h127.0.0.1 -uroot -ppassword -P30100 < config-db-dev/apolloconfigdb.sql
# mysql -h127.0.0.1 -uroot -ppassword -P30101 < config-db-test-beta/apolloconfigdb.sql 
# mysql -h127.0.0.1 -uroot -ppassword -P30102 < config-db-prod/apolloconfigdb.sql
# mysql -h127.0.0.1 -uroot -ppassword -P30103 < portal-db/apolloconfigdb.sql 

2. Build an image

https://github.com/ctripcorp/apollo/releases #3 packages found

# wget https://github.com/ctripcorp/apollo/releases/download/v1.3.0/apollo-adminservice-1.3.0-github.zip
# wget https://github.com/ctripcorp/apollo/releases/download/v1.3.0/apollo-configservice-1.3.0-github.zip
# wget https://github.com/ctripcorp/apollo/releases/download/v1.3.0/apollo-portal-1.3.0-github.zip

2.1 unzip the jar s related to the three packages and name them as
apollo-adminservice.jar
apollo-configservice.jar
apollo-portal.jar

jar package moves the corresponding directory Apollo admin server Apollo config server Apollo portal server

VIM Apollo admin server / Dockerfile / / note a line to avoid that configmap is read-only. All three dockerfiles need to be modified

vim apollo-config-server/Dockerfile

vim apollo-portal-server/Dockerfile

#ENTRYPOINT ["/apollo-admin-server/entrypoint.sh"]

2.2 build related images

# cd apollo/scripts/apollo-on-kubernetes/alpine-bash-3.8-image
# docker build -t apollo:alpine-bash-3.8 .
# docker push apollo:alpine-bash-3.8

# cd apollo/scripts/apollo-on-kubernetes/apollo-admin-server
# docker build -t apollo:apollo-admin-server-v1.3.0 .
# docker push apollo:apollo-admin-server-v1.3.0

# cd apollo/scripts/apollo-on-kubernetes/apollo-config-server
# docker build -t apollo:apollo-config-server-v1.3.0 .
# docker push  apollo:apollo-config-server-v1.3.0

# cd  apollo-portal-server
# docker build -t apollo:apollo-portal-server-v1.3.0 
# docker push apollo:apollo-portal-server-v1.3.0

3. Modify the configuration file

cd apollo/scripts/apollo-on-kubernetes/kubernetes

3.1 dev

kubectl apply -f apollo-env-dev/service-apollo-admin-server-dev.yaml

# configmap for apollo-admin-server-dev

kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-admin-server-dev
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-dev:3306/DevApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = password
    eureka.service.url = http://statefulset-apollo-config-server-dev-0.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-1.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-2.service-apollo-meta-server-dev:8080/eureka/

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-admin-server-dev
  labels:
    app: service-apollo-admin-server-dev
spec:
  ports:
    - protocol: TCP
      port: 8090
      targetPort: 8090
  selector:
    app: pod-apollo-admin-server-dev
  type: ClusterIP
  sessionAffinity: ClientIP

---
kind: Deployment
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: deployment-apollo-admin-server-dev
  labels:
    app: deployment-apollo-admin-server-dev
spec:
  replicas: 3
  selector:
    matchLabels:
      app: pod-apollo-admin-server-dev
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-admin-server-dev
    spec:

      volumes:
        - name: volume-configmap-apollo-admin-server-dev
          configMap:
            name: configmap-apollo-admin-server-dev
            items:
              - key: application-github.properties
                path: application-github.properties

      initContainers:
        #- image: alpine-bash:3.8
        - image: apollo:alpine-bash-3.8
          name: check-service-apollo-config-server-dev
          command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-config-server-dev.sre:8080"]

      containers:
        #- image: apollo-admin-server:v1.0.0
        - image: apollo:apollo-admin-server-v1.3.0
          securityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-admin-server-dev
          ports:
            - protocol: TCP
              containerPort: 8090

          volumeMounts:
            - name: volume-configmap-apollo-admin-server-dev
              mountPath: /apollo-admin-server/config/application-github.properties
              subPath: application-github.properties

          env:
            - name: APOLLO_ADMIN_SERVICE_NAME
              value: "service-apollo-admin-server-dev.sre"

          readinessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 120
            periodSeconds: 10

      dnsPolicy: ClusterFirst
      restartPolicy: Always

kubectl apply -f apollo-env-dev/service-apollo-config-server-dev.yaml

# configmap for apollo-config-server-dev

kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-config-server-dev
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-dev:3306/DevApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = password
    eureka.service.url = http://statefulset-apollo-config-server-dev-0.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-1.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-2.service-apollo-meta-server-dev:8080/eureka/

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-meta-server-dev
  labels:
    app: service-apollo-meta-server-dev
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    app: pod-apollo-config-server-dev
  type: ClusterIP
  clusterIP: None
  sessionAffinity: ClientIP

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-config-server-dev
  labels:
    app: service-apollo-config-server-dev
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30002
  selector:
    app: pod-apollo-config-server-dev 
  type: NodePort
  sessionAffinity: ClientIP

---
kind: StatefulSet
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: statefulset-apollo-config-server-dev
  labels:
    app: statefulset-apollo-config-server-dev
spec:
  serviceName: service-apollo-meta-server-dev
  replicas: 3
  selector:
    matchLabels:
      app: pod-apollo-config-server-dev
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-config-server-dev
    spec:

      volumes:
        - name: volume-configmap-apollo-config-server-dev
          configMap:
            name: configmap-apollo-config-server-dev
            items:
              - key: application-github.properties
                path: application-github.properties

      containers:
        #- image: apollo-config-server:v1.0.0
        - image: apollo:apollo-config-server-v1.3.0
          securityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-config-server-dev
          ports:
            - protocol: TCP
              containerPort: 8080

          volumeMounts:
            - name: volume-configmap-apollo-config-server-dev
              mountPath: /apollo-config-server/config/application-github.properties
              subPath: application-github.properties

          env:
            - name: APOLLO_CONFIG_SERVICE_NAME
              value: "service-apollo-config-server-dev.sre"

          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds:  120
            periodSeconds: 10

      dnsPolicy: ClusterFirst
      restartPolicy: Always

3.2 test

kubectl apply -f apollo-env-test-beta/service-apollo-admin-server-test-beta.yaml

# configmap for apollo-admin-server-test-beta

kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-admin-server-test-beta
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-test.sre:3306/TestBetaApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = password
    eureka.service.url = http://statefulset-apollo-config-server-test-beta-0.service-apollo-meta-server-test-beta:8080/eureka/,http://statefulset-apollo-config-server-test-beta-1.service-apollo-meta-server-test-beta:8080/eureka/,http://statefulset-apollo-config-server-test-beta-2.service-apollo-meta-server-test-beta:8080/eureka/

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-admin-server-test-beta
  labels:
    app: service-apollo-admin-server-test-beta
spec:
  ports:
    - protocol: TCP
      port: 8090
      targetPort: 8090
  selector:
    app: pod-apollo-admin-server-test-beta
  type: ClusterIP
  sessionAffinity: ClientIP

---
kind: Deployment
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: deployment-apollo-admin-server-test-beta
  labels:
    app: deployment-apollo-admin-server-test-beta
spec:
  replicas: 3
  selector:
    matchLabels:
      app: pod-apollo-admin-server-test-beta
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-admin-server-test-beta
    spec:
      nodeSelector:
        node: "apollo"

      volumes:
        - name: volume-configmap-apollo-admin-server-test-beta
          configMap:
            name: configmap-apollo-admin-server-test-beta
            items:
              - key: application-github.properties
                path: application-github.properties

      initContainers:
        - image: apollo:alpine-bash-3.8
        #- image: alpine-bash:3.8
          name: check-service-apollo-config-server-test-beta
          command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-config-server-test-beta.sre:8080"]

      containers:
        #- image: apollo-admin-server:v1.0.0
        - image: apollo:apollo-admin-server-v1.3.0
          imagePullPolicy: IfNotPresent
          name: container-apollo-admin-server-test-beta
          ports:
            - protocol: TCP
              containerPort: 8090

          volumeMounts:
            - name: volume-configmap-apollo-admin-server-test-beta
              mountPath: /apollo-admin-server/config/application-github.properties
              subPath: application-github.properties

          env:
            - name: APOLLO_ADMIN_SERVICE_NAME
              value: "service-apollo-admin-server-test-beta.sre"

          readinessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 120
            periodSeconds: 10

      dnsPolicy: ClusterFirst
      restartPolicy: Always

# kubectl apply -f apollo-env-test-beta/service-apollo-config-server-test-beta.yaml 
---
# configmap for apollo-config-server-test-beta
kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-config-server-test-beta
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-test.sre:3306/TestBetaApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = password
    eureka.service.url = http://statefulset-apollo-config-server-test-beta-0.service-apollo-meta-server-test-beta:8080/eureka/,http://statefulset-apollo-config-server-test-beta-1.service-apollo-meta-server-test-beta:8080/eureka/,http://statefulset-apollo-config-server-test-beta-2.service-apollo-meta-server-test-beta:8080/eureka/

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-meta-server-test-beta
  labels:
    app: service-apollo-meta-server-test-beta
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    app: pod-apollo-config-server-test-beta
  type: ClusterIP
  clusterIP: None
  sessionAffinity: ClientIP

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-config-server-test-beta
  labels:
    app: service-apollo-config-server-test-beta
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30111
  selector:
    app: pod-apollo-config-server-test-beta
  type: NodePort
  sessionAffinity: ClientIP

---
kind: StatefulSet
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: statefulset-apollo-config-server-test-beta
  labels:
    app: statefulset-apollo-config-server-test-beta
spec:
  serviceName: service-apollo-meta-server-test-beta
  replicas: 3
  selector:
    matchLabels:
      app: pod-apollo-config-server-test-beta
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-config-server-test-beta
    spec:

      volumes:
        - name: volume-configmap-apollo-config-server-test-beta
          configMap:
            name: configmap-apollo-config-server-test-beta
            items:
              - key: application-github.properties
                path: application-github.properties

      containers:
        #- image: apollo-config-server:v1.0.0
        - image: apollo:apollo-config-server-v1.3.0
          securityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-config-server-test-beta
          ports:
            - protocol: TCP
              containerPort: 8080

          volumeMounts:
            - name: volume-configmap-apollo-config-server-test-beta
              mountPath: /apollo-config-server/config/application-github.properties
              subPath: application-github.properties
          env:
            - name: APOLLO_CONFIG_SERVICE_NAME
              value: "service-apollo-config-server-test-beta.sre"

          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 120
            periodSeconds: 15

      dnsPolicy: ClusterFirst
      restartPolicy: Always

3.3 prd

kubectl apply -f apollo-env-prod/service-apollo-admin-server-prod.yaml

# configmap for apollo-admin-server-prod

kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-admin-server-prod
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-prd.sre:3306/ProdApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = password
    eureka.service.url = http://statefulset-apollo-config-server-prod-0.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-1.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-2.service-apollo-meta-server-prod:8080/eureka/

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-admin-server-prod
  labels:
    app: service-apollo-admin-server-prod
spec:
  ports:
    - protocol: TCP
      port: 8090
      targetPort: 8090
  selector:
    app: pod-apollo-admin-server-prod  
  type: ClusterIP
  sessionAffinity: ClientIP

---
kind: Deployment
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: deployment-apollo-admin-server-prod
  labels:
    app: deployment-apollo-admin-server-prod
spec:
  replicas: 3
  selector:
    matchLabels:
      app: pod-apollo-admin-server-prod
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-admin-server-prod
    spec:

      volumes:
        - name: volume-configmap-apollo-admin-server-prod
          configMap:
            name: configmap-apollo-admin-server-prod
            items:
              - key: application-github.properties
                path: application-github.properties

      initContainers:
        #- image: alpine-bash:3.8
        - image: apollo:alpine-bash-3.8
          name: check-service-apollo-config-server-prod
          command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 50 --retry-delay 1 --retry-max-time 120 service-apollo-config-server-prod.sre:8080"]

      containers:
        #- image: apollo-admin-server:v1.0.0
        - image: apollo:apollo-admin-server-v1.3.0
          securityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-admin-server-prod
          ports:
            - protocol: TCP
              containerPort: 8090

          volumeMounts:
            - name: volume-configmap-apollo-admin-server-prod
              mountPath: /apollo-admin-server/config/application-github.properties
              subPath: application-github.properties

          env:
            - name: APOLLO_ADMIN_SERVICE_NAME
              value: "service-apollo-admin-server-prod.sre"

          readinessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 120
            periodSeconds: 10

      dnsPolicy: ClusterFirst
      restartPolicy: Always

apollo-env-prod/service-apollo-config-server-prod.yaml
---
# configmap for apollo-config-server-prod
kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-config-server-prod
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-prd.sre:3306/ProdApolloConfigDB?characterEncoding=utf8
    spring.datasource.username = root
    spring.datasource.password = password
    eureka.service.url = http://statefulset-apollo-config-server-prod-0.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-1.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-2.service-apollo-meta-server-prod:8080/eureka/

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-meta-server-prod
  labels:
    app: service-apollo-meta-server-prod
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    app: pod-apollo-config-server-prod
  type: ClusterIP
  clusterIP: None
  sessionAffinity: ClientIP

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-config-server-prod
  labels:
    app: service-apollo-config-server-prod
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30112
  selector:
    app: pod-apollo-config-server-prod
  type: NodePort
  sessionAffinity: ClientIP

---
kind: StatefulSet
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: statefulset-apollo-config-server-prod
  labels:
    app: statefulset-apollo-config-server-prod
spec:
  serviceName: service-apollo-meta-server-prod
  replicas: 3
  selector:
    matchLabels:
      app: pod-apollo-config-server-prod
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-config-server-prod
    spec:

      volumes:
        - name: volume-configmap-apollo-config-server-prod
          configMap:
            name: configmap-apollo-config-server-prod
            items:
              - key: application-github.properties
                path: application-github.properties

      containers:
        #- image: apollo-config-server:v1.0.0
        - image: apollo:apollo-config-server-v1.3.0
          securityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-config-server-prod
          ports:
            - protocol: TCP
              containerPort: 8080

          volumeMounts:
            - name: volume-configmap-apollo-config-server-prod
              mountPath: /apollo-config-server/config/application-github.properties
              subPath: application-github.properties
          env:
            - name: APOLLO_CONFIG_SERVICE_NAME
              value: "service-apollo-config-server-prod.sre"

          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 120
            periodSeconds: 10

      dnsPolicy: ClusterFirst
      restartPolicy: Always

3.4 portal

kubectl apply -f service-apollo-portal-server.yaml

# configmap for apollo-portal-server

kind: ConfigMap
apiVersion: v1
metadata:
  namespace: sre
  name: configmap-apollo-portal-server
data:
  application-github.properties: |
    spring.datasource.url = jdbc:mysql://mysql-apollo-portal.sre:3306/ApolloPortalDB?characterEncoding=utf8
    # mysql username
    spring.datasource.username = root
    # mysql password
    spring.datasource.password = password
  apollo-env.properties: |
    dev.meta=http://service-apollo-config-server-dev.sre:8080
    #fat.meta=http://service-apollo-config-server-test-alpha.sre:8080
    uat.meta=http://service-apollo-config-server-test-beta.sre:8080
    pro.meta=http://service-apollo-config-server-prod.sre:8080

---
kind: Service
apiVersion: v1
metadata:
  namespace: sre
  name: service-apollo-portal-server
  labels:
    app: service-apollo-portal-server
spec:
  ports:
    - protocol: TCP
      port: 8070
      targetPort: 8070
      nodePort: 30110
  selector:
    app: pod-apollo-portal-server
  type: NodePort
  # portal session hold
  sessionAffinity: ClientIP

---
kind: Deployment
apiVersion: apps/v1beta2
metadata:
  namespace: sre
  name: deployment-apollo-portal-server
  labels:
    app: deployment-apollo-portal-server
spec:
  # 3 examples
  replicas: 1
  selector:
    matchLabels:
      app: pod-apollo-portal-server
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-portal-server
    spec:

      volumes:
        - name: volume-configmap-apollo-portal-server
          configMap:
            name: configmap-apollo-portal-server
            items:
              - key: application-github.properties
                path: application-github.properties
              - key: apollo-env.properties
                path: apollo-env.properties

      initContainers:
        # Ensure that admin service provides services normally
        #- image: alpine-bash:3.8
        - image: apollo:alpine-bash-3.8
          name: check-service-apollo-admin-server-dev
          command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-admin-server-dev.sre:8090"]
        #- image: alpine-bash:3.8
        #  name: check-service-apollo-admin-server-alpha
        #  command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-admin-server-test-alpha.sre:8090"]
        #- image: alpine-bash:3.8
        - image: apollo:alpine-bash-3.8
          name: check-service-apollo-admin-server-beta
          command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-admin-server-test-beta.sre:8090"]
        #- image: alpine-bash:3.8
        - image: apollo:alpine-bash-3.8
          name: check-service-apollo-admin-server-prod
          command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-admin-server-prod.sre:8090"]    

      containers:
        #- image: apollo-portal-server:v1.0.0    # Change to image under your docker registry
        - image: apollo:apollo-portal-server-v1.3.0    # Change to image under your docker registry
          securityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-portal-server
          ports:
            - protocol: TCP
              containerPort: 8070

          volumeMounts:
            - name: volume-configmap-apollo-portal-server
              mountPath: /apollo-portal-server/config/application-github.properties
              subPath: application-github.properties
            - name: volume-configmap-apollo-portal-server
              mountPath: /apollo-portal-server/config/apollo-env.properties
              subPath: apollo-env.properties

          env:
            - name: APOLLO_PORTAL_SERVICE_NAME
              value: "service-apollo-portal-server.sre"

          readinessProbe:
            tcpSocket:
              port: 8070
            initialDelaySeconds: 10
            periodSeconds: 5

          livenessProbe:
            tcpSocket:
              port: 8070
            # Within 120s, restart the container if the server is not started
            initialDelaySeconds: 120
            periodSeconds: 15

      dnsPolicy: ClusterFirst
      restartPolicy: Always

Open portal
http://127.0.0.1:30110/ #Check whether it is normal
Default account password: apollo admin

If you need external access, you need to add the configuration of external service

Both admin and config need to configure startup parameters

        - name: JAVA_OPTS
          value: "-Dapollo.configService=http://127.0.0.1:30002 -Deureka.instance.homePageUrl=http://127.0.0.1:30002"

Take away partners can join the group

Tags: Operation & Maintenance MySQL github Spring Docker

Posted on Tue, 26 May 2020 10:28:01 -0400 by alwaysinit