docker,k8s部署Apollo

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: docker,k8s部署Apollo


image.png

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

1.docker部署Apollo

1. 打包

可以参考上文。

2.制作镜像

1.获取zip包

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

image.png

2.获取dockerflie

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

image.png

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

docker build -t apollo-portal .
docker build -t apollo-adminservice .
docker build -t apollo-configservice .

image.png

3.运行容器

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

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: 对应环境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-portal
docker 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: v1
kind: ConfigMap
metadata:
  namespace: apollo   #更改自己的namespace
  name: 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: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: ConfigMap
apiVersion: v1
metadata:
  namespace: apollo  #更改自己的namespace
  name: 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 #私人仓库
          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: 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 #上文的apollo-config 切记不用写localhost
---
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 #私人仓库
          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)

image.png

image.png


相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
4天前
|
测试技术 Linux 网络安全
【Docker项目实战】使用Docker部署Tasks.md任务管理白板
【6月更文挑战第1天】使用Docker部署Tasks.md任务管理白板
25 4
|
6天前
|
Kubernetes 开发者 Docker
构建高效微服务架构:Docker与Kubernetes的协同应用
【5月更文挑战第30天】 在当今软件开发领域,微服务架构已成为实现系统模块化、提升可维护性及扩展性的关键策略。本文深入探讨了如何通过Docker容器化技术和Kubernetes集群管理,共同构建一个既高效又可靠的后端微服务环境。我们将剖析Docker和Kubernetes的核心功能,以及它们如何相辅相成,支撑起现代化的云原生应用程序部署和管理。文章还将提供具体实践案例,帮助开发者理解将理论应用于实际开发过程中的步骤和考虑因素。
|
23小时前
|
Web App开发 测试技术 项目管理
【Docker项目实战】使用Docker部署Servas自托管书签管理工具
【6月更文挑战第5天】使用Docker部署Servas自托管书签管理工具
18 0
【Docker项目实战】使用Docker部署Servas自托管书签管理工具
|
23小时前
|
Docker 容器
docker 部署gitlab
docker 部署gitlab
|
1天前
|
IDE 前端开发 时序数据库
【Docker项目实战】使用Docker部署speedtest-tracker速度测试追踪器
【6月更文挑战第4天】使用Docker部署speedtest-tracker速度测试追踪器
4 0
|
2天前
|
Kubernetes 容器 Perl
k8s部署seata 报错 没有提供足够的身份验证信息 [ http-nio-7091-exec-2] [ty.JwtAuthenticationEntryPoint] [ commence] [] : Responding with unauthorized error. Message - Full authentication is required to access this resource
Kubernetes pod 在16:12时出现两次错误,错误信息显示需要完整认证才能访问资源。尽管有此错误,但页面可正常访问。附有yaml配置文件的图片。
12 2
|
3天前
|
容器 Docker JavaScript
使用 Docker 和 Docker Compose 部署 Vue
使用 Docker 和 Docker Compose 部署 Vue 项目有两种方式:直接使用 Docker 和使用 Docker Compose。
29 0
|
4天前
|
容器 Docker 项目管理
【Docker项目实战】使用Docker部署tududi个人任务管理工具
【6月更文挑战第2天】使用Docker部署tududi个人任务管理工具
26 4
|
5天前
|
JavaScript 应用服务中间件 nginx
Docker 部署 Vue
在 Docker 中使用 Node 和 Nginx 基础镜像来部署一个 Vue 项目,通常可以按照以下步骤进行。这些步骤涵盖了从构建 Vue 项目到配置 Dockerfile 和 Nginx 的过程。
16 1
|
5天前
|
Kubernetes 负载均衡 应用服务中间件
k8s 二进制安装 优化架构之 部署负载均衡,加入master02
k8s 二进制安装 优化架构之 部署负载均衡,加入master02