This is the 19th day of my participation in the Gwen Challenge in November. Check out the details: The last Gwen Challenge in 2021

Because the creator changed Apollo source code, so need to repackage, and then make a mirror.

1. The docker deployment of Apollo

Pack 1.

Refer to above.

2. Create an image

1. Obtain the ZIP package

Get the package in /apollo-portal/target/, apollo-adminService /target/, apollo-configService /target/.

2. Obtain dockerflie

Get the DockerFlie from apollo-portal, Apollo-adminService, and Apollo-ConfigService respectively.

3. Place the preceding two files in any folder and execute them respectively

docker build -t apollo-portal .
docker build -t apollo-adminservice .
docker build -t apollo-configservice .
Copy the code

3. Run the container

Run the following command on the VM.

adminconfig
docker run -d -p 8090:8090 --net=host -e SPRING_DATASOURCE_URL="jdbc:postgresql://ip:5432/apolloconfig? characterEncoding=utf8" -e SPRING_DATASOURCE_USERNAME=apolloconfig -e SPRING_DATASOURCE_PASSWORD=123  -d -v /tmp/logs:/opt/logs --name apollo-adminservice apollo-adminservice

SPRING_DATASOURCE_URL: Address of ApolloConfigDBSPRING_DATASOURCE_USERNAME: User name of ApolloConfigDBSPRING_DATASOURCE_PASSWORD: password of ApolloConfigDB --name apollo-adminService apollo-adminService: Apollo -configService docker run -p8080:8080 --net=host -e SPRING_DATASOURCE_URL="jdbc:postgresql://ip:5432/apolloconfig? characterEncoding=utf8"  -e SPRING_DATASOURCE_USERNAME=apolloconfig -e SPRING_DATASOURCE_PASSWORD=123  -d -v /tmp/logs:/opt/logs --name apollo-configservice apollo-configservice

SPRING_DATASOURCE_URL: Address of ApolloConfigDBSPRING_DATASOURCE_USERNAME: User name of ApolloConfigDBSPRING_DATASOURCE_PASSWORDApollo-portal docker run -p: password of ApolloConfigDB8070:8070 --net=host -e SPRING_DATASOURCE_URL="jdbc:postgresql://ip:5432/apolloportal"  -e SPRING_DATASOURCE_USERNAME=apolloportal -e SPRING_DATASOURCE_PASSWORD=123 -e APOLLO_PORTAL_ENVS=dev  -e DEV_META=http://localhost:8080 -d -v /tmp/logs:/opt/logs --name apollo-portal apollo-portalSPRING_DATASOURCE_URL: address of ApolloPortalDBSPRING_DATASOURCE_USERNAME: User name of the environment ApolloPortalDBSPRING_DATASOURCE_PASSWORD: Password of environment ApolloPortalDB APOLLO_PORTAL_ENVS(optional): DEV_META/PRO_META(optional) can be configured using this environment parameter corresponding to the ApolloPortalDB apollo.portal.envs configuration item if it is not configured in the database: Meta Service address configuration corresponding to the environment, in order to ${ENV} _META naming, it is important to note if the configuration of ApolloPortalDB Apollo. Portal. Meta. The configuration of the servers, With Apollo. Portal. Meta. The configuration of the serversCopy the code

If you do not have customized database requirements, refer to the official document github.com/ctripcorp/a…

2. Apollo k8s deployment

K8s is used to deploy the kubernetes-Dashboard with the yamL file and the dev environment.

For those unfamiliar with Kubernetes-Dashboard, check out the K8S column.

1. The deployment of Apollo – admin

---
apiVersion: v1
kind: ConfigMap
metadata: namespace: Apollo # Change your namespacename: configmap-apollo-admin-server
data:
  application-github.properties: |
    spring.datasource.url = jdbc:postgresql://ip:5432/apolloconfig? characterEncoding=utf8
    spring.datasource.username = apolloconfig
    spring.datasource.password = 123
    eureka.service.url = ip:5001/eureka
---
apiVersion: v1
kind: Service
metadata:
  namespace: apollo
  name: service-apollo-admin-server
  labels:
    app: service-apollo-admin-server
spec:
  ports:
    - protocol: TCP
      port: 8090
      nodePort: 8090
  selector:
    app: pod-apollo-admin-server
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: apollo
  name: deployment-apollo-admin-server
  labels:
    app: deployment-apollo-admin-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pod-apollo-admin-server
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-admin-server
    spec:
      volumes:
        - name: volume-configmap-apollo-admin-server
          configMap:
            name: configmap-apollo-admin-server
            items:
              - key: application-github.properties
                path: application-github.properties
      containers:
        - image: ip:9000/ Apollo/apollo-adminService :latestsecurityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-admin-server
          ports:
            - protocol: TCP
              containerPort: 8090
          volumeMounts:
            - name: volume-configmap-apollo-admin-server
              mountPath: /apollo-admin-server/config/application-github.properties
              subPath: application-github.properties
          env:
            - name: APOLLO_ADMIN_SERVICE_NAME
              value: "service-apollo-admin-server.sre"
          readinessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 10
            periodSeconds: 5
          livenessProbe:
            tcpSocket:
              port: 8090
            initialDelaySeconds: 120
            periodSeconds: 10
          
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      nodeName: Apollo # Specifies the nodesCopy the code

2. The deployment of Apollo – config

---
kind: ConfigMap
apiVersion: v1
metadata: namespace: Apollo # Change your namespacename: configmap-apollo-config-server
data:
  application-github.properties: |
    spring.datasource.url = jdbc:postgresql://ip:5432/apolloconfig? characterEncoding=utf8
    spring.datasource.username = apolloconfig
    spring.datasource.password = 123
    eureka.service.url = ip:5001/eureka
---
kind: Service
apiVersion: v1
metadata:
  namespace: apollo
  name: service-apollo-meta-server
  labels:
    app: service-apollo-meta-server
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  selector:
    app: pod-apollo-config-server
  type: ClusterIP
  clusterIP: None
  sessionAffinity: ClientIP
---
kind: Service
apiVersion: v1
metadata:
  namespace: apollo
  name: service-apollo-config-server
  labels:
    app: service-apollo-config-server
spec:
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 8080
  selector:
    app: pod-apollo-config-server
  type: NodePort
  sessionAffinity: ClientIP
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
  namespace: apollo
  name: statefulset-apollo-config-server
  labels:
    app: statefulset-apollo-config-server
spec:
  serviceName: service-apollo-meta-server
  replicas: 1
  selector:
    matchLabels:
      app: pod-apollo-config-server
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: pod-apollo-config-server
    spec:
      volumes:
        - name: volume-configmap-apollo-config-server
          configMap:
            name: configmap-apollo-config-server
            items:
              - key: application-github.properties
                path: application-github.properties
      containers:
        - image: ip:9000/ Apollo/Apollo - ConfigService: Latest # Private repositorysecurityContext:
            privileged: true
          imagePullPolicy: IfNotPresent
          name: container-apollo-config-server
          ports:
            - protocol: TCP
              containerPort: 8080
          volumeMounts:
            - name: volume-configmap-apollo-config-server
              mountPath: /apollo-config-server/config/application-github.properties
              subPath: application-github.properties
          env:
            - name: APOLLO_CONFIG_SERVICE_NAME
              value: "service-apollo-config-server.sre"
          readinessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5
          livenessProbe:
            tcpSocket:
              port: 8080
            initialDelaySeconds:  120
            periodSeconds: 10
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      nodeName: Apollo # Nodes Node nameCopy the code

3.apollo-portal

---
kind: ConfigMap
apiVersion: v1
metadata:
  namespace: apollo
  name: configmap-apollo-portal-server
data:
  application-github.properties: |
    spring.datasource.url = jdbc:postgresql://ip:5432/apolloportal
    spring.datasource.username = apolloportal
    spring.datasource.password = 123
  apollo-env.properties: |
    dev.meta=http:// IP :8080
---
kind: Service
apiVersion: v1
metadata:
  namespace: apollo
  name: service-apollo-portal-server
  labels:
    app: service-apollo-portal-server
spec:
  ports:
    - protocol: TCP
      port: 8070
      targetPort: 8070
      nodePort: 8070
  selector:
    app: pod-apollo-portal-server
  type: NodePort
  sessionAffinity: ClientIP
---
kind: Deployment
apiVersion: apps/v1
metadata:
  namespace: apollo
  name: deployment-apollo-portal-server
  labels:
    app: deployment-apollo-portal-server
spec:
  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
      containers:
        - image: ip:9000/ Apollo/Apollo - Portal: Latest # Private warehousesecurityContext:
            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
            initialDelaySeconds: 120
            periodSeconds: 15
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      nodeName: Apollo # Nodes addressCopy the code

Note: the above yamL must pay attention to the format, such as blank lines, Spaces, comments, can be removed must be removed, otherwise it will report various errors.

Note that the following configuration in Apollo-portal.zip also needs to be modified (otherwise localhost will always be accessed)