Kubernetes 部署配置中心 Apollo 1.4.0
文章目录
!版权声明:本博客内容均为原创,每篇博文作为知识积累,写博不易,转载请注明出处。
系统环境:
- Apollo 版本:1.4.0
- Kubernetes 版本:1.14.0
参考:
- Apollo Github 地址:https://github.com/ctripcorp/apollo
注意:部署比较复杂,极容易出错,请严格按步骤执行!
一、Apollo 简介
Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性,适用于微服务配置管理场景。
服务端基于 Spring Boot 和 Spring Cloud 开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。且 Java 客户端不依赖任何框架,能够运行于所有 Java 运行时环境,同时对 Spring/Spring Boot 环境也有较好的支持。
二、Apollo 特性
- 部署简单
- 灰度发布
- 版本发布管理
- 提供开放平台API
- 客户端配置信息监控
- 提供Java和.Net原生客户端
- 配置修改实时生效(热发布)
- 权限管理、发布审核、操作审计
- 统一管理不同环境、不同集群的配置
三、Apollo 环境描述
Apollo 提供了四套环境配置:
- DEV:开发环境
- FAT:功能验收测试环境,用于软件测试者测试使用
- UAT:用户验收测试环境,用于生产环境下的软件测试者测试使用
- PRO:生成环境
每个环境都需要安装相应组件,这里为了简单,只部署 DEV
与 PRO
环境。
四、获取 apollo 压缩包
从 https://github.com/ctripcorp/apollo/releases 下载预先打好的 zip 包:
- apollo-1.4.0.zip
- apollo-portal-1.4.0-github.zip
- apollo-adminservice-1.4.0-github.zip
- apollo-configservice-1.4.0-github.zip
1#下载 Apollo 源码
2$ wget https://github.com/ctripcorp/apollo/archive/v1.4.0.zip
3
4#下载 Apollo Admin Server
5$ wget https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-adminservice-1.4.0-github.zip
6
7#下载 Apollo Config Service
8$ wget https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-configservice-1.4.0-github.zip
9
10#下载 Apollo Portal
11$ wget https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-portal-1.4.0-github.zip
五、解压 apollo 压缩包
将源码包中部署文件复制到自定义目录:
1#解压源码包
2$ unzip v1.4.0.zip
3
4#创建用于部署的自定义文件夹
5$ mkdir ./deploy
6
7#将部署文件和脚本复制到自定义 deploy 目录
8$ cp -R ./apollo-1.4.0/scripts/apollo-on-kubernetes/* ./deploy
解压三个组件并放置在 deploy 目录下对应的文件夹下:
1#解压各个组件压缩包
2$ unzip -o apollo-configservice-1.4.0-github.zip -d ./deploy/apollo-config-server/
3$ unzip -o apollo-adminservice-1.4.0-github.zip -d ./deploy/apollo-admin-server/
4$ unzip -o apollo-portal-1.4.0-github.zip -d ./deploy/apollo-portal-server/
5
6#应用 Jar 重命名
7$ mv ./deploy/apollo-config-server/apollo-configservice-1.4.0.jar ./deploy/apollo-config-server/apollo-configservice.jar
8$ mv ./deploy/apollo-admin-server/apollo-adminservice-1.4.0.jar ./deploy/apollo-admin-server/apollo-adminservice.jar
9$ mv ./deploy/apollo-portal-server/apollo-portal-1.4.0.jar ./deploy/apollo-portal-server/apollo-portal.jar
六、构建 Docker 镜像
1#构建 alpine 镜像
2$ docker build -t alpine-bash:3.8 ./deploy/alpine-bash-3.8-image
3
4#构建 config-service 镜像
5$ docker build -t apollo-config-server:v1.4.0 ./deploy/apollo-config-server
6
7#构建 admin-server
8$ docker build -t apollo-admin-server:v1.4.0 ./deploy/apollo-admin-server
9
10#构建 portal 镜像
11$ docker build -t apollo-portal-server:v1.4.0 ./deploy/apollo-portal-server
七、推送镜像到镜像仓库
推送镜像到镜像仓库,方便在 Kubernetes 中部署应用。
1#打标签
2$ docker tag alpine-bash:3.8 mydlqclub/alpine-bash:3.8
3$ docker tag apollo-config-server:v1.4.0 mydlqclub/apollo-config-server:v1.4.0
4$ docker tag apollo-admin-server:v1.4.0 mydlqclub/apollo-admin-server:v1.4.0
5$ docker tag apollo-portal-server:v1.4.0 mydlqclub/apollo-portal-server:v1.4.0
6
7#推送镜像到镜像仓库
8$ docker push mydlqclub/alpine-bash:3.8
9$ docker push mydlqclub/apollo-config-server:v1.4.0
10$ docker push mydlqclub/apollo-admin-server:v1.4.0
11$ docker push mydlqclub/apollo-portal-server:v1.4.0
八、Kubernetes 中部署 Mysql
部署 Mysql 数据库
创建 Mysql 的 PV/PVC 存储资源,这里是通过静态方式创建 PV 与 PVC 绑定,用的是 NFS 存储,创建 PV 时需要指定 NFS Server 地址。
mysql-storage.yaml
1apiVersion: v1
2kind: PersistentVolume
3metadata:
4 name: mysql-pv
5 labels:
6 app: mysql-pv
7spec:
8 accessModes:
9 - ReadWriteOnce
10 capacity:
11 storage: 5Gi
12 mountOptions: #NFS挂在选项
13 - hard
14 - nfsvers=4
15 nfs: #NFS设置
16 server: 192.168.2.11 #替换nfs服务器地址
17 path: /nfs/data/mysql #替换nfs存储目录
18---
19kind: PersistentVolumeClaim
20apiVersion: v1
21metadata:
22 name: mysql-pvc
23spec:
24 accessModes:
25 - ReadWriteOnce
26 resources:
27 requests:
28 storage: 5Gi #设置大小为5G
29 selector:
30 matchLabels:
31 app: mysql-pv
创建 Mysql 的配置文件,注意,配置文件中一定要设置最大连接数参数,否则 Apollo 启动时连接池会创建大量与 Mysql 的连接,如果设置最大连接数太小,很可能导致 Apollo 重启。
1kind: ConfigMap
2apiVersion: v1
3metadata:
4 name: mysql-config
5 labels:
6 app: mysql
7data:
8 my.cnf: |-
9 [client]
10 default-character-set=utf8mb4
11 [mysqld]
12 max_connections = 2000
创建 Service 与 Deployment 部署文件
mysql-deploy.yaml
1apiVersion: v1
2kind: Service
3metadata:
4 name: mysql
5 labels:
6 app: mysql
7spec:
8 type: NodePort
9 ports:
10 - name: mysql
11 port: 3306
12 targetPort: 3306
13 nodePort: 30336
14 selector:
15 app: mysql
16---
17apiVersion: apps/v1
18kind: Deployment
19metadata:
20 name: mysql
21 labels:
22 app: mysql
23spec:
24 replicas: 1
25 selector:
26 matchLabels:
27 app: mysql
28 template:
29 metadata:
30 labels:
31 app: mysql
32 spec:
33 containers:
34 - name: mysql
35 image: "mysql:5.7.26"
36 imagePullPolicy: "IfNotPresent"
37 ports:
38 - name: mysql
39 containerPort: 3306
40 env:
41 - name: MYSQL_ROOT_PASSWORD #root用户密码
42 value: "123456"
43 resources:
44 limits:
45 cpu: 1000m
46 memory: 512Mi
47 requests:
48 cpu: 100m
49 memory: 256Mi
50 livenessProbe: #活性探针
51 initialDelaySeconds: 30
52 periodSeconds: 10
53 timeoutSeconds: 5
54 successThreshold: 1
55 failureThreshold: 3
56 exec:
57 command: ["mysqladmin", "-uroot", "-p${MYSQL_ROOT_PASSWORD}", "ping"]
58 readinessProbe: #就绪探针
59 initialDelaySeconds: 10
60 periodSeconds: 10
61 timeoutSeconds: 5
62 successThreshold: 1
63 failureThreshold: 3
64 exec:
65 command: ["mysqladmin", "-uroot", "-p${MYSQL_ROOT_PASSWORD}", "ping"]
66 volumeMounts:
67 - name: data
68 mountPath: /var/lib/mysql
69 - name: config
70 mountPath: /etc/mysql/my.cnf
71 subPath: my.cnf
72 volumes:
73 - name: data
74 persistentVolumeClaim:
75 claimName: mysql-pvc #绑定上面创建的 PVC
76 - name: config
77 configMap:
78 name: mysql-config #使用 ConfigMap 中的 Mysql 配置
kubernetes 集群部署 Mysql
- -n:指定应用在 Kubernetes 中部署的 Namespace
1# 部署存储
2$ kubectl apply -f mysql-storage.yaml -n mydlqclub
3
4# 部署 Mysql
5$ kubectl apply -f mysql-deploy.yaml -n mydlqclub
导入 SQL 文件
进入 sources/apollo-1.4.0/scripts/apollo-on-kubernetes/db 文件夹下,内容如下:
1.
2├── config-db-dev
3│ └── apolloconfigdb.sql
4├── config-db-prod
5│ └── apolloconfigdb.sql
6├── config-db-test-alpha
7│ └── apolloconfigdb.sql
8├── config-db-test-beta
9│ └── apolloconfigdb.sql
10└── portal-db
11 └── apolloportaldb.sql
将 config-db-dev、config-db-prod 与 portal-db 目录下的 sql 文件导入上面创建的数据库中。
九、Kubernetes 中部署 Apollo
注意:请把下面所有的
mydlqcloud
为本人部署Apollo
的Namespace
,所以这里要将全部的mydlqcloud
改成你做自己要部署Apollo
的Kubernetes
中Namespace
名称。另一个就是,部署前确保数据库中已经导入 SQL 文件,否则会就绪探针探活失败错误。
1、部署 Dev 环境 Apollo 组件
(1)、apollo-config-server-dev 部署文件
apollo-config-server-dev.yaml
1# Configmap 文件,注意修改数据库配置、用户名、密码参数
2kind: ConfigMap
3apiVersion: v1
4metadata:
5 name: configmap-apollo-config-server-dev
6data:
7 application-github.properties: |
8 spring.datasource.url = jdbc:mysql://mysql.mydlqcloud:3306/DevApolloConfigDB?characterEncoding=utf8
9 spring.datasource.username = root
10 spring.datasource.password = 123456
11 eureka.service.url = http://statefulset-apollo-config-server-dev-0.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-1.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-2.service-apollo-meta-server-dev:8080/eureka/
12---
13kind: Service
14apiVersion: v1
15metadata:
16 name: service-apollo-meta-server-dev
17 labels:
18 app: service-apollo-meta-server-dev
19spec:
20 type: ClusterIP
21 clusterIP: None
22 sessionAffinity: ClientIP
23 ports:
24 - port: 8080
25 targetPort: 8080
26 selector:
27 app: pod-apollo-config-server-dev
28---
29kind: Service
30apiVersion: v1
31metadata:
32 name: service-apollo-config-server-dev
33 labels:
34 app: service-apollo-config-server-dev
35spec:
36 type: NodePort
37 sessionAffinity: ClientIP
38 ports:
39 - port: 8080
40 targetPort: 8080
41 nodePort: 30002 #NodePort方式暴露配置服务端地址,用于Kubernetes集群外部访问、测试
42 selector:
43 app: pod-apollo-config-server-dev
44---
45kind: StatefulSet
46apiVersion: apps/v1
47metadata:
48 name: statefulset-apollo-config-server-dev
49 labels:
50 app: statefulset-apollo-config-server-dev
51spec:
52 serviceName: service-apollo-meta-server-dev
53 replicas: 3
54 selector:
55 matchLabels:
56 app: pod-apollo-config-server-dev
57 updateStrategy:
58 type: RollingUpdate
59 template:
60 metadata:
61 labels:
62 app: pod-apollo-config-server-dev
63 spec:
64 containers:
65 - image: mydlqclub/apollo-config-server:v1.4.0
66 name: container-apollo-config-server-dev
67 ports:
68 - containerPort: 8080
69 env:
70 - name: APOLLO_CONFIG_SERVICE_NAME
71 value: "service-apollo-config-server-dev.mydlqcloud" #修改namespace名称
72 resources:
73 limits:
74 cpu: 2000m
75 memory: 512Mi
76 requests:
77 cpu: 500m
78 memory: 256Mi
79 readinessProbe:
80 tcpSocket:
81 port: 8080
82 initialDelaySeconds: 10
83 periodSeconds: 5
84 livenessProbe:
85 tcpSocket:
86 port: 8080
87 initialDelaySeconds: 120
88 periodSeconds: 10
89 volumeMounts:
90 - name: volume-configmap-apollo-config-server-dev
91 mountPath: /apollo-config-server/config/application-github.properties
92 subPath: application-github.properties
93 volumes:
94 - name: volume-configmap-apollo-config-server-dev
95 configMap:
96 name: configmap-apollo-config-server-dev
97 items:
98 - key: application-github.properties
99 path: application-github.properties
(2)、appllp-admin-server-dev 部署文件
appllp-admin-server-dev.yaml
1kind: ConfigMap
2apiVersion: v1
3metadata:
4 name: configmap-apollo-admin-server-dev
5data:
6 application-github.properties: |
7 spring.datasource.url = jdbc:mysql://mysql.mydlqcloud:3306/DevApolloConfigDB?characterEncoding=utf8
8 spring.datasource.username = root
9 spring.datasource.password = 123456
10 eureka.service.url = http://statefulset-apollo-config-server-dev-0.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-1.service-apollo-meta-server-dev:8080/eureka/,http://statefulset-apollo-config-server-dev-2.service-apollo-meta-server-dev:8080/eureka/
11---
12kind: Service
13apiVersion: v1
14metadata:
15 name: service-apollo-admin-server-dev
16 labels:
17 app: service-apollo-admin-server-dev
18spec:
19 type: ClusterIP
20 sessionAffinity: ClientIP
21 ports:
22 - port: 8090
23 targetPort: 8090
24 selector:
25 app: pod-apollo-admin-server-dev
26---
27kind: Deployment
28apiVersion: apps/v1
29metadata:
30 name: deployment-apollo-admin-server-dev
31 labels:
32 app: deployment-apollo-admin-server-dev
33spec:
34 replicas: 3
35 selector:
36 matchLabels:
37 app: pod-apollo-admin-server-dev
38 strategy:
39 rollingUpdate:
40 maxSurge: 1
41 maxUnavailable: 1
42 template:
43 metadata:
44 labels:
45 app: pod-apollo-admin-server-dev
46 spec:
47 initContainers:
48 - image: mydlqclub/alpine-bash:3.8
49 name: check-service-apollo-config-server-dev
50 #注意修改namespace
51 command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-config-server-dev.mydlqcloud:8080"]
52 containers:
53 - image: mydlqclub/apollo-admin-server:v1.4.0
54 name: container-apollo-admin-server-dev
55 ports:
56 - containerPort: 8090
57 env:
58 - name: APOLLO_ADMIN_SERVICE_NAME
59 value: "service-apollo-admin-server-dev.mydlqcloud" # 注意修改 Namespace
60 resources:
61 limits:
62 cpu: 2000m
63 memory: 512Mi
64 requests:
65 cpu: 500m
66 memory: 256Mi
67 readinessProbe:
68 tcpSocket:
69 port: 8090
70 initialDelaySeconds: 10
71 periodSeconds: 5
72 livenessProbe:
73 tcpSocket:
74 port: 8090
75 initialDelaySeconds: 120
76 periodSeconds: 10
77 volumeMounts:
78 - name: volume-configmap-apollo-admin-server-dev
79 mountPath: /apollo-admin-server/config/application-github.properties
80 subPath: application-github.properties
81 volumes:
82 - name: volume-configmap-apollo-admin-server-dev
83 configMap:
84 name: configmap-apollo-admin-server-dev
85 items:
86 - key: application-github.properties
87 path: application-github.properties
(3)、kubernetes 部署 Dev 环境的 admin、config
- -n:指定应用在 Kubernetes 中部署的 Namespace
1# 部署 apollo-config-server-dev
2$ kubectl apply -f apollo-config-server-dev.yaml -n mydlqclub
3
4# 部署 appllp-admin-server-dev
5$ kubectl apply -f appllp-admin-server-dev.yaml -n mydlqclub
2、部署 Prod 环境 Apollo 组件
(1)、apollo-config-server-prod 部署文件
apollo-config-server-prod.yaml
1kind: ConfigMap
2apiVersion: v1
3metadata:
4 name: configmap-apollo-config-server-prod
5data:
6 application-github.properties: |
7 spring.datasource.url = jdbc:mysql://mysql.mydlqcloud:3306/ProdApolloConfigDB?characterEncoding=utf8
8 spring.datasource.username = root
9 spring.datasource.password = 123456
10 eureka.service.url = http://statefulset-apollo-config-server-prod-0.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-1.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-2.service-apollo-meta-server-prod:8080/eureka/
11---
12kind: Service
13apiVersion: v1
14metadata:
15 name: service-apollo-meta-server-prod
16 labels:
17 app: service-apollo-meta-server-prod
18spec:
19 type: ClusterIP
20 clusterIP: None
21 sessionAffinity: ClientIP
22 ports:
23 - protocol: TCP
24 port: 8080
25 targetPort: 8080
26 selector:
27 app: pod-apollo-config-server-prod
28---
29kind: Service
30apiVersion: v1
31metadata:
32 name: service-apollo-config-server-prod
33 labels:
34 app: service-apollo-config-server-prod
35spec:
36 type: NodePort
37 sessionAffinity: ClientIP
38 ports:
39 - port: 8080
40 targetPort: 8080
41 nodePort: 30005
42 selector:
43 app: pod-apollo-config-server-prod
44---
45kind: StatefulSet
46apiVersion: apps/v1
47metadata:
48 name: statefulset-apollo-config-server-prod
49 labels:
50 app: statefulset-apollo-config-server-prod
51spec:
52 serviceName: service-apollo-meta-server-prod
53 replicas: 3
54 selector:
55 matchLabels:
56 app: pod-apollo-config-server-prod
57 updateStrategy:
58 type: RollingUpdate
59 template:
60 metadata:
61 labels:
62 app: pod-apollo-config-server-prod
63 spec:
64 containers:
65 - image: mydlqclub/apollo-config-server:v1.4.0
66 name: container-apollo-config-server-prod
67 ports:
68 - containerPort: 8080
69 env:
70 - name: APOLLO_CONFIG_SERVICE_NAME
71 value: "service-apollo-config-server-prod.mydlqcloud" # 注意修改 Namespace
72 readinessProbe:
73 tcpSocket:
74 port: 8080
75 initialDelaySeconds: 10
76 periodSeconds: 5
77 livenessProbe:
78 tcpSocket:
79 port: 8080
80 initialDelaySeconds: 120
81 periodSeconds: 10
82 volumeMounts:
83 - name: volume-configmap-apollo-config-server-prod
84 mountPath: /apollo-config-server/config/application-github.properties
85 subPath: application-github.properties
86 volumes:
87 - name: volume-configmap-apollo-config-server-prod
88 configMap:
89 name: configmap-apollo-config-server-prod
90 items:
91 - key: application-github.properties
92 path: application-github.properties
(2)、appllp-admin-server-prod 部署文件
appllp-admin-server-prod.yaml
1kind: ConfigMap
2apiVersion: v1
3metadata:
4 name: configmap-apollo-admin-server-prod
5data:
6 application-github.properties: |
7 spring.datasource.url = jdbc:mysql://mysql.mydlqcloud:3306/ProdApolloConfigDB?characterEncoding=utf8
8 spring.datasource.username = root
9 spring.datasource.password = 123456
10 eureka.service.url = http://statefulset-apollo-config-server-prod-0.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-1.service-apollo-meta-server-prod:8080/eureka/,http://statefulset-apollo-config-server-prod-2.service-apollo-meta-server-prod:8080/eureka/
11---
12kind: Service
13apiVersion: v1
14metadata:
15 name: service-apollo-admin-server-prod
16 labels:
17 app: service-apollo-admin-server-prod
18spec:
19 ports:
20 - protocol: TCP
21 port: 8090
22 targetPort: 8090
23 selector:
24 app: pod-apollo-admin-server-prod
25 type: ClusterIP
26 sessionAffinity: ClientIP
27---
28kind: Deployment
29apiVersion: apps/v1
30metadata:
31 name: deployment-apollo-admin-server-prod
32 labels:
33 app: deployment-apollo-admin-server-prod
34spec:
35 replicas: 3
36 selector:
37 matchLabels:
38 app: pod-apollo-admin-server-prod
39 strategy:
40 rollingUpdate:
41 maxSurge: 1
42 maxUnavailable: 1
43 template:
44 metadata:
45 labels:
46 app: pod-apollo-admin-server-prod
47 spec:
48 initContainers:
49 - image: mydlqclub/alpine-bash:3.8
50 name: check-service-apollo-config-server-prod
51 # 注意修改 Namespace
52 command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 50 --retry-delay 1 --retry-max-time 120 service-apollo-config-server-prod.mydlqcloud:8080"]
53 containers:
54 - image: mydlqclub/apollo-admin-server:v1.4.0
55 name: container-apollo-admin-server-prod
56 ports:
57 - containerPort: 8090
58 env:
59 - name: APOLLO_ADMIN_SERVICE_NAME
60 value: "service-apollo-admin-server-prod.mydlqcloud" # 注意修改 Namespace
61 readinessProbe:
62 tcpSocket:
63 port: 8090
64 initialDelaySeconds: 10
65 periodSeconds: 5
66 livenessProbe:
67 tcpSocket:
68 port: 8090
69 initialDelaySeconds: 120
70 periodSeconds: 10
71 volumeMounts:
72 - name: volume-configmap-apollo-admin-server-prod
73 mountPath: /apollo-admin-server/config/application-github.properties
74 subPath: application-github.properties
75 volumes:
76 - name: volume-configmap-apollo-admin-server-prod
77 configMap:
78 name: configmap-apollo-admin-server-prod
79 items:
80 - key: application-github.properties
81 path: application-github.properties
(3)、kubernetes 部署 Dev 环境的 admin、config
- -n:指定应用在 Kubernetes 中部署的 Namespace
1# 部署 apollo-config-server-prod
2$ kubectl apply -f apollo-config-server-prod.yaml -n mydlqclub
3
4# 部署 appllp-admin-server-prod
5$ kubectl apply -f appllp-admin-server-prod.yaml -n mydlqclub
3、部署 Apollo Portal
(1)、service-apollo-portal-server 部署文件
下面是 Portal 的部署文件,里面有个初始化镜像,是用于进行检测 Config Server、Admin Server 是否正常启动。这里需要注意,如果你上面只部署了 DEV 环境,那么请看部署文件中的注释,删除 Pro 环境的检测配置,否则服务将不能正常启动。
service-apollo-portal-server.yaml
1# Configmap 中配置要使用的环境,这里只用 DEV 与 PRO 两个环境, 注意修改下面的参数中的 Namespace
2kind: ConfigMap
3apiVersion: v1
4metadata:
5 name: configmap-apollo-portal-server
6data:
7 application-github.properties: |
8 spring.datasource.url = jdbc:mysql://mysql.mydlqcloud:3306/ApolloPortalDB?characterEncoding=utf8
9 spring.datasource.username = root
10 spring.datasource.password = 123456
11 apollo-env.properties: |
12 dev.meta=http://service-apollo-config-server-dev.mydlqcloud:8080
13 pro.meta=http://service-apollo-config-server-prod.mydlqcloud:8080
14---
15kind: Service
16apiVersion: v1
17metadata:
18 name: service-apollo-portal-server
19 labels:
20 app: service-apollo-portal-server
21spec:
22 type: NodePort
23 sessionAffinity: ClientIP # portal session 保持
24 ports:
25 - protocol: TCP
26 port: 8070
27 targetPort: 8070
28 nodePort: 30011
29 selector:
30 app: pod-apollo-portal-server
31---
32kind: Deployment
33apiVersion: apps/v1
34metadata:
35 name: deployment-apollo-portal-server
36 labels:
37 app: deployment-apollo-portal-server
38spec:
39 replicas: 3
40 selector:
41 matchLabels:
42 app: pod-apollo-portal-server
43 strategy:
44 rollingUpdate:
45 maxSurge: 1
46 maxUnavailable: 1
47 template:
48 metadata:
49 labels:
50 app: pod-apollo-portal-server
51 spec:
52 initContainers:
53 # 测试 admin-service 服务是否能正常提供服务,如果执行失败,Portal 服务将不能正常启动,注意修改下面的 Namespace
54 #### ----- 测 Dev 环境的配置 -------
55 - image: mydlqclub/alpine-bash:3.8
56 name: check-service-apollo-admin-server-dev
57 command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-admin-server-dev.mydlqcloud:8090"]
58 #### ------- 检测 Prod 环境的配置,如果你没有创建 Prod 环境,请去掉下面这段配置 -------
59 - image: mydlqclub/alpine-bash:3.8
60 name: check-service-apollo-admin-server-prod
61 command: ['bash', '-c', "curl --connect-timeout 2 --max-time 5 --retry 60 --retry-delay 1 --retry-max-time 120 service-apollo-admin-server-prod.mydlqcloud:8090"]
62 ### -----------------------------------------------------------------------------
63 containers:
64 - image: mydlqclub/apollo-portal-server:v1.4.0
65 name: container-apollo-portal-server
66 ports:
67 - containerPort: 8070
68 env:
69 - name: APOLLO_PORTAL_SERVICE_NAME
70 value: "service-apollo-portal-server.mydlqcloud" # 注意修改 Namespace
71 readinessProbe:
72 tcpSocket:
73 port: 8070
74 initialDelaySeconds: 10
75 periodSeconds: 5
76 livenessProbe:
77 tcpSocket:
78 port: 8070
79 initialDelaySeconds: 120
80 periodSeconds: 15
81 volumeMounts:
82 - name: volume-configmap-apollo-portal-server
83 mountPath: /apollo-portal-server/config/application-github.properties
84 subPath: application-github.properties
85 - name: volume-configmap-apollo-portal-server
86 mountPath: /apollo-portal-server/config/apollo-env.properties
87 subPath: apollo-env.properties
88 volumes:
89 - name: volume-configmap-apollo-portal-server
90 configMap:
91 name: configmap-apollo-portal-server
92 items:
93 - key: application-github.properties
94 path: application-github.properties
95 - key: apollo-env.properties
96 path: apollo-env.properties
(2)、kubernetes 部署 Apollo Portal
- -n:指定应用在 Kubernetes 中部署的 Namespace
1$ kubectl apply -f service-apollo-portal-server.yaml -n mydlqclub
十、访问 Apollo Portal 界面
本人 Kubernetes 集群地址为 192.168.2.11,并且刚刚创建 Portal 时候配置的 Service 设置的 NodePort 端口为 30011,所以这里输入地址:http://192.168.2.11:30011 访问 Apollo Portal 界面,进入 Apollo 配置中心。
默认用户名密码:
- 用户名:apollo
- 密 码:admin
---END---
!版权声明:本博客内容均为原创,每篇博文作为知识积累,写博不易,转载请注明出处。