写点什么

部署 Apollo

作者:小黄鸡1992
  • 2021 年 11 月 19 日
  • 本文字数:5399 字

    阅读完需:约 18 分钟

部署Apollo

​因为楼主更改了 apollo 源码,所以需要重新打包,然后在制作镜像。

1.docker 部署 Apollo

1. 打包

可以参考上文。

2.制作镜像

1.获取 zip 包

分别获取打包之后 zip 包,在/apollo-portal/target/,apollo-adminservice/target/,apollo-configservice/target/中。


2.获取 dockerflie

分别在 apollo-portal,apollo-adminservice,apollo-configservice 中获取 dockerflie。


3.将以上两个文件分别放于任意文件夹中并分别执行

docker build -t apollo-portal .docker build -t apollo-adminservice .docker build -t apollo-configservice .
复制代码


3.运行容器

在虚拟机中执行以下命令即可。


adminconfigdocker 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: 对应环境ApolloConfigDB的地址SPRING_DATASOURCE_USERNAME: 对应环境ApolloConfigDB的用户名SPRING_DATASOURCE_PASSWORD: 对应环境ApolloConfigDB的密码--name apollo-adminservice apollo-adminservice:为镜像同名 下面同理
apollo-configservice docker run -p 8080: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: 对应环境ApolloConfigDB的地址SPRING_DATASOURCE_USERNAME: 对应环境ApolloConfigDB的用户名SPRING_DATASOURCE_PASSWORD: 对应环境ApolloConfigDB的密码
apollo-portaldocker run -p 8070: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-portal
SPRING_DATASOURCE_URL: 对应环境ApolloPortalDB的地址SPRING_DATASOURCE_USERNAME: 对应环境ApolloPortalDB的用户名SPRING_DATASOURCE_PASSWORD: 对应环境ApolloPortalDB的密码APOLLO_PORTAL_ENVS(可选): 对应ApolloPortalDB中的apollo.portal.envs配置项,如果没有在数据库中配置的话,可以通过此环境参数配置DEV_META/PRO_META(可选): 配置对应环境的Meta Service地址,以${ENV}_META命名,需要注意的是如果配置了ApolloPortalDB中的apollo.portal.meta.servers配置,则以apollo.portal.meta.servers中的配置为准
复制代码


如没有定制数据库需求,可以参考官方文档 https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97#2-apolloportalmetaservers---%E5%90%84%E7%8E%AF%E5%A2%83meta-service%E5%88%97%E8%A1%A8

2.k8s 部署 Apollo

​书接上文 楼主定制了 oracle 版本的 apollo,那么怎么使用 k8s 部署呢,本文只部署 dev 环境,使用 yaml 文件在 Kubernetes-dashboard 部署。


如果有对 Kubernetes-dashboard 不熟悉的,可以参考 k8s 专栏 。

1.部署 apollo-admin

---apiVersion: v1kind: ConfigMapmetadata:  namespace: apollo   #更改自己的namespace  name: configmap-apollo-admin-serverdata:  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: v1kind: Servicemetadata:  namespace: apollo  name: service-apollo-admin-server  labels:    app: service-apollo-admin-serverspec:  ports:    - protocol: TCP      port: 8090      nodePort: 8090  selector:    app: pod-apollo-admin-server  type: NodePort---apiVersion: apps/v1kind: Deploymentmetadata:  namespace: apollo  name: deployment-apollo-admin-server  labels:    app: deployment-apollo-admin-serverspec:  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:latest #镜像地址 楼主这里使用了私人仓库          securityContext:            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  #指定的nodes节点
复制代码

2.部署 apollo-config

---kind: ConfigMapapiVersion: v1metadata:  namespace: apollo  #更改自己的namespace  name: configmap-apollo-config-serverdata:  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: ServiceapiVersion: v1metadata:  namespace: apollo  name: service-apollo-meta-server  labels:    app: service-apollo-meta-serverspec:  ports:    - protocol: TCP      port: 8080      targetPort: 8080  selector:    app: pod-apollo-config-server  type: ClusterIP  clusterIP: None  sessionAffinity: ClientIP---kind: ServiceapiVersion: v1metadata:  namespace: apollo  name: service-apollo-config-server  labels:    app: service-apollo-config-serverspec:  ports:    - protocol: TCP      port: 8080      targetPort: 8080      nodePort: 8080  selector:    app: pod-apollo-config-server  type: NodePort  sessionAffinity: ClientIP---kind: StatefulSetapiVersion: apps/v1metadata:  namespace: apollo  name: statefulset-apollo-config-server  labels:    app: statefulset-apollo-config-serverspec:  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 #私人仓库          securityContext:            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节点名称
复制代码

3.apollo-portal

---kind: ConfigMapapiVersion: v1metadata:  namespace: apollo  name: configmap-apollo-portal-serverdata:  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 #上文的apollo-config 切记不用写localhost---kind: ServiceapiVersion: v1metadata:  namespace: apollo  name: service-apollo-portal-server  labels:    app: service-apollo-portal-serverspec:  ports:    - protocol: TCP      port: 8070      targetPort: 8070      nodePort: 8070  selector:    app: pod-apollo-portal-server  type: NodePort  sessionAffinity: ClientIP---kind: DeploymentapiVersion: apps/v1metadata:  namespace: apollo  name: deployment-apollo-portal-server  labels:    app: deployment-apollo-portal-serverspec:  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 #私人仓库          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            initialDelaySeconds: 120            periodSeconds: 15      dnsPolicy: ClusterFirst      restartPolicy: Always      nodeName: apollo #nodes地址
复制代码


注意:以上 yaml 一定注意格式,比如空行,空格,注释,能去掉一定去掉,否则会报各种错误。


注意 ,以下 apollo-portal.zip 中的配置也需要修改(否则一直会访问 localhost)





用户头像

小黄鸡1992

关注

小黄鸡加油 2021.07.13 加入

一位技术落地与应用的博主,带你从入门,了解和使用各项顶流开源项目。

评论

发布
暂无评论
部署Apollo