专栏目录:
欢迎关注个人公众号: Coder编程
欢迎关注个人网站:www.52melrin.com
以上为之前写的携程Apollo配置中心相关文章,有需要,请自行查阅
接下来将介绍携程Apollo配置中心部署至Kubernetes集群中
注意:这里需要有一定的Kubernetes相关知识,和搭建好的环境。
一、环境准备
这里就不过多介绍环境相关内容了,跟之前的类似。这里需要准备好Kubernetes的相关环境,如何搭建的,可以参考Kubernetes 1.9.0离线安装
一、修改配置文件
接上一篇文章,修改部分文件docker-compose.yml
version: "3" services: apollo-configservice: ##容器服务名 container_name: apollo-configservice ##容器名 build: apollo-configservice/ ##Dockerfile路径 image: xx/third_party/apollo-configservice:0.10.8 ##镜像名 network_mode: host ##网络设置 ports: - "30080:30080" volumes: - "/Users/mobin/opt/logs/100003171:/opt/logs/100003171" ##将/opt/logs/100003171目录挂载到宿主机的/Users/mobin/opt/logs/100003171方便在宿主机上查看日志 environment: - spring_datasource_url=jdbc:mysql://xxxx:xx/ApolloConfigDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=123456 apollo-adminservice: container_name: apollo-adminservice build: apollo-adminservice/ image: xxx/third_party/apollo-adminservice:0.10.8 network_mode: host #net: "host" ports: - "30090:30090" depends_on: - apollo-configservice volumes: - "/Users/mobin/opt/logs/100003172:/opt/logs/100003172" environment: - spring_datasource_url=jdbc:mysql://xxxx:xx/ApolloConfigDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=123456 apollo-portal: container_name: apollo-portal build: apollo-portal/ image: xxxx/third_party/apollo-portal:0.10.8 network_mode: host #net: "host" ports: - "30070:30070" depends_on: - apollo-adminservice #links: # - apollo-adminservice # - apollo-configservice volumes: - "/Users/mobin/opt/logs/100003173:/opt/logs/100003173" environment: - spring_datasource_url=jdbc:mysql://xxxx:xx/ApolloPortalDB?characterEncoding=utf8 - spring_datasource_username=root - spring_datasource_password=123456 - dev_meta=http://xxxx:30080上述内容就不做过多介绍了。
之后使用Kompose将docker-compose文件转换成kubernetes相关文件。这里就不一一列举了。直接放文件!
kubernetes.yml
apiVersion: extensions/v1beta1 kind: Deployment metadata: annotations: kompose.cmd: kompose convert kompose.version: 1.11.0 (39ad614) creationTimestamp: null labels: io.kompose.service: apollo-configservice name: apollo-configservice spec: replicas: 1 strategy: type: Recreate template: metadata: creationTimestamp: null labels: io.kompose.service: apollo-configservice spec: #hostNetwork: true containers: - env: - name: spring_datasource_password value: "123456" - name: spring_datasource_url value: jdbc:mysql://xxxx:xx/apolloconfigdb?useUnicode=true&characterEncoding=utf8 - name: spring_datasource_username value: root image: x.x.x.x/third_party/apollo-configservice:0.10.1 name: apollo-configservice ports: - containerPort: 30080 resources: {} volumeMounts: - mountPath: /opt/logs/100003171 name: apollo-configservice volumes: - name: apollo-configservice hostPath: path: /u03/apollo/logs/100003171 status: {} --- apiVersion: v1 kind: Service metadata: annotations: kompose.cmd: kompose convert kompose.version: 1.11.0 (39ad614) creationTimestamp: null labels: io.kompose.service: apollo-configservice name: apollo-configservice spec: type: NodePort ports: - name: "http" port: 30080 targetPort: 30080 nodePort: 30080 selector: io.kompose.service: apollo-configservice status: loadBalancer: {} --- apiVersion: extensions/v1beta1 kind: Deployment metadata: annotations: kompose.cmd: kompose convert kompose.version: 1.11.0 (39ad614) creationTimestamp: null labels: io.kompose.service: apollo-adminservice name: apollo-adminservice spec: replicas: 1 strategy: type: Recreate template: metadata: creationTimestamp: null labels: io.kompose.service: apollo-adminservice spec: #hostNetwork: true containers: - env: - name: spring_datasource_password value: "123456" - name: spring_datasource_url value: jdbc:mysql://x.x.x.x:xx/apolloconfigdb?useUnicode=true&characterEncoding=utf8 - name: spring_datasource_username value: root image: x.x.x.x:xx/third_party/apollo-adminservice:0.10.8 name: apollo-adminservice ports: - containerPort: 30090 resources: {} volumeMounts: - mountPath: /opt/logs/100003172 name: apollo-adminservice volumes: - name: apollo-adminservice hostPath: path: /u03/apollo/logs/100003172 status: {} --- apiVersion: v1 kind: Service metadata: annotations: kompose.cmd: kompose convert kompose.version: 1.11.0 (39ad614) creationTimestamp: null labels: io.kompose.service: apollo-adminservice name: apollo-adminservice spec: type: NodePort ports: - name: "http" port: 30090 targetPort: 30090 nodePort: 30090 selector: io.kompose.service: apollo-adminservice status: loadBalancer: {} --- apiVersion: extensions/v1beta1 kind: Deployment metadata: annotations: kompose.cmd: kompose convert kompose.version: 1.11.0 (39ad614) creationTimestamp: null labels: io.kompose.service: apollo-portal name: apollo-portal spec: replicas: 1 strategy: type: Recreate template: metadata: creationTimestamp: null labels: io.kompose.service: apollo-portal spec: #hostNetwork: true containers: - env: - name: dev_meta value: http://x.x.x.x:30080 - name: spring_datasource_password value: "123456" - name: spring_datasource_url value: jdbc:mysql://x.x.x.x:xx/apolloportaldb?useUnicode=true&characterEncoding=utf8 - name: spring_datasource_username value: root image: x.x.x.x/third_party/apollo-portal:0.10.8 name: apollo-portal ports: - containerPort: 30070 resources: {} volumeMounts: - mountPath: /opt/logs/100003173 name: apollo-portal volumes: - name: apollo-portal hostPath: path: /u03/apollo/logs/100003173 status: {} --- apiVersion: v1 kind: Service metadata: annotations: kompose.cmd: kompose convert kompose.version: 1.11.0 (39ad614) creationTimestamp: null labels: io.kompose.service: apollo-portal name: apollo-portal spec: type: NodePort ports: - name: "http" port: 30070 targetPort: 30070 nodePort: 30070 selector: io.kompose.service: apollo-portal status: loadBalancer: {}
以上为kubernetes启动文件。根据个人需要作出相应修改!
启动文件后,会发现客户端报一个错误:client端连接的是Kubernetes内网ip 10.x.x.x 导致apollo port端无法找到admin和config。
这时候需要修改apollo-adminservice 、apollo-configservice 中的 bootstrap.yml文件。
apollo-adminservice 中的bootstrap.yml文件修改同apollo-configservice
这里添加某一个kubernetes的外网ip地址,以及暴露的端口号。之后重新打包成镜像,上传至harbor 镜像库。重新运行上面的kubernetes.yaml文件。
即可看到成功部署,这里就不放图了。。。