本章将主要介绍如何在Kubernets集群中部署Apollo配置中心分布式集群。
专栏目录:
携程 Apollo 配置中心 | 学习笔记 序章
欢迎关注个人公众号: Coder编程
欢迎关注个人网站:www.52melrin.com
注:这篇文章主要在上一篇文章携程 Apollo 配置中心 | 学习笔记(十五)| 如何在Linux中部署Apollo配置中心集群(分布式)?的基础上,对Kubernetes的文件作出整理。
Kubernetes集群已搭建完毕:Master :192.168.220.83 其他的Slave:192.168.220.85,192.168.220.86,192.168.220.87
Harbor镜像仓库已搭建完毕:192.168.220.84
docker环境已搭建完毕:192.168.220.83
docker-compose环境已搭建完毕:192.168.220.83
其他的基础环境不做过多说明。
注:依然在上一篇文章的基础进行Kubernetes的环境部署,如果没有看上一篇文章的,请自动忽视本文!
192.168.220.83 使用的端口分别是30070、30080、30090
192.168.220.85 使用的端口分别是30071、30081、30091
这个可以参考上一篇文章进行修改,并重新打包。
这里为了在Kubernetes中保持高可用,我同时保证了不同的Ip与端口
个人理解:Ip 对“外”暴露入口,端口对“内”暴露入口。这里的内外看个人理解了,这里我就不做过多详细解释说明。(要解释说明,估计又得扯一堆!)
说明:因为Kubernetes 只能在Master主节点上进行发布,所以在83机子上新建两个目录。分别是apollo11,apollo22
文中多处的两个文件。apollo.yaml 与docker-compose.yml 将在下面作出简要说明。
apollo-adminservice、apollo-configservice、apollo-portal 分别将打包好的 apollo-xxx-0.11.0-github.zip 与 apollo-xxx.jar
放入到对应的文件夹中。
192.168.220.83,的机子
version: "3"
services:
apollo-configservice: ##容器服务名
container_name: apollo-configservice ##容器名
build: apollo-configservice/ ##Dockerfile路径
image: 192.168.220.84/third_party/apollo-configservice:1.11.2 ##镜像名
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:31101/ApolloConfigDB?characterEncoding=utf8
- spring_datasource_username=root
- spring_datasource_password=xxxx
apollo-adminservice:
container_name: apollo-adminservice
build: apollo-adminservice/
image: 192.168.220.84/third_party/apollo-adminservice:1.11.2
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:31101/ApolloConfigDB?characterEncoding=utf8
- spring_datasource_username=root
- spring_datasource_password=123456
apollo-portal:
container_name: apollo-portal
build: apollo-portal/
image: 192.168.220.84/third_party/apollo-portal:1.11.2
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:31101/ApolloPortalDB?characterEncoding=utf8
- spring_datasource_username=root
- spring_datasource_password=123456
- dev_meta=http://xxxx:30080
以上脱敏,个人根据自己信息进行修改!
运行:docker-compose up -d
再次运行 docker-compose down 可以停掉docker-compose
分别运行:
docker push 192.168.220.84/third_party/apollo-portal:1.11.2
docker push 192.168.220.84/third_party/apollo-adminservice:1.11.2
docker push 192.168.220.84/third_party/apollo-configservice:1.11.2
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:31101/apolloconfigdb?useUnicode=true&characterEncoding=utf8
- name: spring_datasource_username
value: root
image: 192.168.220.84/third_party/apollo-configservice:1.11.2
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://xxxx:31101/apolloconfigdb?useUnicode=true&characterEncoding=utf8
- name: spring_datasource_username
value: root
image: 192.168.220.84/third_party/apollo-adminservice:1.11.2
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://xxxx:30080
- name: spring_datasource_password
value: "123456"
- name: spring_datasource_url
value: jdbc:mysql://xxxx:31101/apolloportaldb?useUnicode=true&characterEncoding=utf8
- name: spring_datasource_username
value: root
image: 192.168.220.84/third_party/apollo-portal:1.11.2
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: {}
运行命令:
kubectl apply -f apollo.yaml
运行后可以看到已经成功的界面。
其他不做过多说明。
注:
另外一台192.168.220.85 需求做相关修改,注意kubernetes中的标签labels、name 要作出修改。这里就不做赘述了。有其他问题可以留言!
到此,Kubernetes 集群部署 Apollo 分布式集群到此结束。