apollo部署
# 前言
apollo架构图:
主要对图中以下组件做容器化,使用helm安装:
- Portal
- PortalDB+ConfigDB = Mysql
- Config Service
- Admin Service
# 1.准备工作
# 1.1 准备源文件
拉取apollo仓库
git clone https://github.com/apolloconfig/apollo.git
1
# 1.2 准备sql脚本
cd apollo-1.8.2/scripts
ls -l sql/
total 44
-rw-r--r-- 1 root root 21291 May 29 2021 apolloconfigdb.sql
-rw-r--r-- 1 root root 16278 May 29 2021 apolloportaldb.sql
drwxr-xr-x 7 root root 4096 May 29 2021 delta
mkdir -p /mnt/apollo
cp -r sql /mnt/apollo/
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 1.3 准备helm文件
ls -l helm/
total 28
drwxr-xr-x 3 root root 4096 May 29 2021 apollo-portal
drwxr-xr-x 3 root root 4096 May 29 2021 apollo-service
-rw-r--r-- 1 root root 17648 May 29 2021 README.md
cp -r helm /mnt/apollo/
1
2
3
4
5
6
7
2
3
4
5
6
7
# 2. 部署Mysql数据库
# 1.1 创建挂载目录
mkdir -p /data/mysql
1
# 1.2 准备yaml文件
cat mysql.yaml
apiVersion: v1
data:
mysqld.cnf: |-
[client]
default-character-set=utf8
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
skip_external_locking
skip-symbolic-links
memlock=true
max_connect_errors = 20000
max_connections = 3000
skip-name-resolve
default-time-zone = system
default-storage-engine = InnoDB
explicit_defaults_for_timestamp = 1
lower_case_table_names = 1
key_buffer_size = 4096M
table_open_cache = 1024
sort_buffer_size = 4M
read_buffer_size = 4M
thread_cache_size = 128
query_cache_size = 512M
character-set-server = utf8
collation-server = utf8_general_ci
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
# innoDB
innodb_page_size = 16K
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_io_capacity = 200
innodb_io_capacity_max = 2000
kind: ConfigMap
metadata:
name: mysql-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7.32
env:
- name: MYSQL_ROOT_PASSWORD
value: "1234qwer"
ports:
- containerPort: 3306
protocol: TCP
name: 3306tcp01
volumeMounts:
- name: mysql-data
mountPath: "/var/lib/mysql"
- name: mysql-conf
mountPath: "/etc/mysql/mysql.conf.d/"
volumes:
- name: mysql-data
hostPath:
path: /data/mysql
type: Directory
- name: mysql-conf
configMap:
name: mysql-config
---
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
labels:
name: mysql-svc
spec:
type: NodePort
ports:
- port: 3306
protocol: TCP
targetPort: 3306
name: http
nodePort: 30306
selector:
app: mysql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 1.3 执行命令创建
kubectl apply -f mysql.yaml
1
# 1.4 初始化数据库
查看mysql pod
kubectl get pods -nops
NAME READY STATUS RESTARTS AGE
mysql-6b87687cd9-vlplk 1/1 Running 0 23d
1
2
3
2
3
cp 初始化脚本到pod
cd /mnt/apollo/sql
kubectl cp apolloportaldb.sql mysql-6b87687cd9-vlplk:/tmp -nops
kubectl cp apolloconfigdb.sql mysql-6b87687cd9-vlplk:/tmp -nops
1
2
3
2
3
进入容器,登陆mysql进行导入
kubectl exec -it mysql-6b87687cd9-vlplk -nops bash
mysql -uroot -p1234qwer
// 导入config库
mysql> create database apolloconfigdb; // 创建库
mysql> use apolloconfigdb;
mysql> source /tmp/apolloconfigdb.sql; // 导入sql脚本
mysql> show tables;
// 导入portal库
mysql> create database apolloportaldb;
mysql> use apolloportaldb;
mysql> source /tmp/apolloportaldb.sql;
mysql> show tables;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
# 3. 部署Config 和 Admin
# 3.1 准备yaml文件
cd /mnt/helm/apollo-service
ls -l
total 12
-rw-r--r-- 1 root root 426 May 29 2021 Chart.yaml
drwxr-xr-x 2 root root 4096 May 29 2021 templates
-rw-r--r-- 1 root root 2361 May 29 2021 values.yaml
1
2
3
4
5
6
2
3
4
5
6
修改values.yaml如下:
configdb:
name: apollo-configdb
# apolloconfigdb host
host: "mysql-svc"
port: 3306
dbName: apolloconfigdb
# apolloconfigdb user name
userName: "root"
# apolloconfigdb password
password: "1234qwer"
connectionStringProperties: characterEncoding=utf8
service:
# whether to create a Service for this host or not
enabled: false
fullNameOverride: ""
port: 3306
type: ClusterIP
configService:
name: apollo-configservice
fullNameOverride: "apollo-configservice"
replicaCount: 1
containerPort: 8080
image:
repository: apolloconfig/apollo-configservice
tag: "1.8.2"
pullPolicy: IfNotPresent
imagePullSecrets: []
service:
fullNameOverride: ""
port: 8080
targetPort: 8080
type: ClusterIP
ingress:
enabled: false
annotations: { }
hosts:
- host: ""
paths: [ ]
tls: [ ]
liveness:
initialDelaySeconds: 100
periodSeconds: 10
readiness:
initialDelaySeconds: 30
periodSeconds: 5
config:
# spring profiles to activate
profiles: "github,kubernetes"
# override apollo.config-service.url: config service url to be accessed by apollo-client
configServiceUrlOverride: "http://apollo-configservice.ops"
# override apollo.admin-service.url: admin service url to be accessed by apollo-portal
adminServiceUrlOverride: "http://apollo-adminservice.ops:8090"
# specify the context path, e.g. /apollo
contextPath: ""
# environment variables passed to the container, e.g. JAVA_OPTS
env: {}
strategy: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
adminService:
name: apollo-adminservice
fullNameOverride: "apollo-adminservice"
replicaCount: 1
containerPort: 8090
image:
repository: apolloconfig/apollo-adminservice
tag: "1.8.2"
pullPolicy: IfNotPresent
imagePullSecrets: []
service:
fullNameOverride: ""
port: 8090
targetPort: 8090
type: ClusterIP
ingress:
enabled: false
annotations: { }
hosts:
- host: ""
paths: [ ]
tls: [ ]
liveness:
initialDelaySeconds: 100
periodSeconds: 10
readiness:
initialDelaySeconds: 30
periodSeconds: 5
config:
# spring profiles to activate
profiles: "github,kubernetes"
# specify the context path, e.g. /apollo
contextPath: ""
# environment variables passed to the container, e.g. JAVA_OPTS
env: {}
strategy: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 3.2 使用helm创建
# 3.2.1 安装helm命令
wget https://get.helm.sh/helm-v3.8.2-linux-amd64.tar.gz
tar xf helm-v3.8.2-linux-amd64.tar.gz
mv linux-amd64 /usr/bin/helm
helm version
1
2
3
4
2
3
4
# 3.2.2 helm安装Config 和 Admin
cd /mnt/helm/apollo-service
helm install apollo-service -f values.yaml -nops ./
kubectl get pods -nops
NAME READY STATUS RESTARTS AGE
apollo-adminservice-6b6cf8ccc4-qr9zt 1/1 Running 0 23d
apollo-configservice-6cc547cdbb-2jmj2 1/1 Running 0 23d
mysql-6b87687cd9-vlplk 1/1 Running 0 23d
1
2
3
4
5
6
7
2
3
4
5
6
7
# 3.3 创建ingress
创建config-ingress.yaml文件
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: config
namespace: ops
spec:
rules:
- host: apl-config.se.local
http:
paths:
- backend:
serviceName: apollo-configservice-ecox
servicePort: 8080
path: /
pathType: ImplementationSpecific
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
执行创建:
kubectl apply -f config-ingress.yaml
1
- host: apl-config.se.local
http:
paths:
- backend:
serviceName: apollo-configservice-ecox
servicePort: 8080
path: /
pathType: ImplementationSpecific
# 4.部署portal
# 4.1 准备yaml文件
cd /mnt/helm/apollo-portal
ls -l
total 12
-rw-r--r-- 1 root root 392 May 29 2021 Chart.yaml
drwxr-xr-x 2 root root 4096 May 29 2021 templates
-rw-r--r-- 1 root root 1433 May 29 2021 values.yaml
1
2
3
4
5
6
2
3
4
5
6
修改values.yaml如下:
name: apollo-portal
fullNameOverride: ""
replicaCount: 1
containerPort: 8070
image:
repository: apolloconfig/apollo-portal
tag: "1.8.2"
pullPolicy: IfNotPresent
imagePullSecrets: []
service:
fullNameOverride: ""
port: 8070
targetPort: 8070
nodePort: 30020
type: NodePort
sessionAffinity: ClientIP
ingress:
enabled: false
annotations: {}
hosts:
- host: ""
paths: []
tls: []
liveness:
initialDelaySeconds: 100
periodSeconds: 10
readiness:
initialDelaySeconds: 30
periodSeconds: 5
# environment variables passed to the container, e.g. JAVA_OPTS
env: {}
strategy: {}
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
config:
# spring profiles to activate
profiles: "github,auth"
# specify the env names, e.g. dev,pro
envs: "test"
# specify the meta servers, e.g.
# dev: http://apollo-configservice-dev:8080
# pro: http://apollo-configservice-pro:8080
metaServers:
test: http://apollo-configservice.ops:8080
# specify the context path, e.g. /apollo
contextPath: ""
# extra config files for apollo-portal, e.g. application-ldap.yml
files: {}
portaldb:
name: apollo-portaldb
# apolloportaldb host
host: mysql-svc
port: 3306
dbName: apolloportaldb
# apolloportaldb user name
userName: root
# apolloportaldb password
password: 1234qwer
connectionStringProperties: characterEncoding=utf8
service:
# whether to create a Service for this host or not
enabled: false
fullNameOverride: ""
port: 3306
type: ExternalName
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 4.2 helm安装portal
cd /mnt/helm/apollo-portal
helm install apollo-portal -f values.yaml -nops ./
kubectl get pods -nops
NAME READY STATUS RESTARTS AGE
apollo-adminservice-ecox-6b6cf8ccc4-qr9zt 1/1 Running 0 23d
apollo-configservice-ecox-6cc547cdbb-2jmj2 1/1 Running 0 23d
apollo-portal-687dd5b489-5vc6w 1/1 Running 0 23d
mysql-6b87687cd9-vlplk 1/1 Running 0 23d
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 4.3 创建ingress
创建portal-ingress.yaml文件
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: portal
namespace: ops
spec:
rules:
- host: apl.se.local
http:
paths:
- backend:
serviceName: apollo-portal
servicePort: 8070
path: /
pathType: ImplementationSpecific
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
执行创建:
kubectl apply -f portal-ingress.yaml
1
# 4.4 访问portal
# 4.4.1 使用ingress域名
浏览器访问:http://apl.se.local
# 4.4.2 使用svc nodeport方式访问
kubectl get svc -nops
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
apollo-adminservice-ecox ClusterIP 172.30.128.41 <none> 8090/TCP 23d
apollo-configservice-ecox ClusterIP 172.30.128.131 <none> 8080/TCP 23d
apollo-portal NodePort 172.30.128.132 <none> 8070:30129/TCP 23d
mysql-svc NodePort 172.30.128.46 <none> 3306:30306/TCP 23d
1
2
3
4
5
6
2
3
4
5
6
看到apollo-portal Nodeport为30129
浏览器访问:http://IP:30129
上次更新: 2022/06/12, 15:48:09