Skip to content

Commit a90f1ea

Browse files
committed
add containerization
1 parent 2d9b1d9 commit a90f1ea

File tree

6 files changed

+895
-0
lines changed

6 files changed

+895
-0
lines changed

CN/modules/ROOT/nav.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
* IvorySQL高级
99
** xref:v4.6/6.adoc[安装指南]
1010
** xref:v4.6/7.adoc[集群搭建]
11+
** 容器化指南
12+
*** xref:v4.6/37.adoc[K8S部署]
13+
*** xref:v4.6/38.adoc[Docker Swarm & Docker Compose部署]
1114
** xref:v4.6/8.adoc[开发者指南]
1215
** xref:v4.6/9.adoc[运维管理指南]
1316
** xref:v4.6/10.adoc[迁移指南]

CN/modules/ROOT/pages/v4.6/37.adoc

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
2+
:sectnums:
3+
:sectnumlevels: 5
4+
5+
= k8s部署单机容器和高可用集群
6+
7+
== 单机容器
8+
进入k8s集群的master节点上,创建名为ivorysql的namespace
9+
```
10+
[root@k8s-master ~]# kubectl create ns ivorysql
11+
```
12+
13+
下载最新docker_library代码
14+
```
15+
[root@k8s-master ~]# git clone https://github.com/IvorySQL/docker_library.git
16+
```
17+
18+
进入单机目录
19+
```
20+
[root@k8s-master ~]# cd docker_library/k8s-cluster/single
21+
[root@k8s-master single]# vim statefulset.yaml #根据个人环境自行修改statefulset中的pvc信息及数据库密码
22+
```
23+
24+
使用statefulset.yaml创建一个单机pod
25+
```
26+
[root@k8s-master single]# kubectl apply -f statefulset.yaml
27+
service/ivorysql-svc created
28+
statefulset.apps/ivorysql created
29+
```
30+
31+
等待pod创建成功
32+
```
33+
[root@k8s-master single]# kubectl get all -n ivorysql
34+
NAME READY STATUS RESTARTS AGE
35+
pod/ivorysql-0 0/1 ContainerCreating 0 47s
36+
37+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
38+
service/ivorysql-svc NodePort 10.108.178.236 <none> 5432:32106/TCP,1521:31887/TCP 47s
39+
40+
NAME READY AGE
41+
statefulset.apps/ivorysql 0/1 47s
42+
[root@k8s-master single]# kubectl get all -n ivorysql
43+
NAME READY STATUS RESTARTS AGE
44+
pod/ivorysql-0 1/1 Running 0 2m39s
45+
46+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
47+
service/ivorysql-svc NodePort 10.108.178.236 <none> 5432:32106/TCP,1521:31887/TCP 2m39s
48+
49+
NAME READY AGE
50+
statefulset.apps/ivorysql 1/1 2m39s
51+
```
52+
53+
psql连接IvorySQL的PG端口
54+
```
55+
[root@k8s-master single]# psql -U ivorysql -p 32106 -h 127.0.0.1 -d ivorysql
56+
Password for user ivorysql:
57+
58+
ivorysql=# select version();
59+
version
60+
------------------------------------------------------------------------------------------------------------------------
61+
PostgreSQL 17.6 (IvorySQL 4.6) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-28), 64-bit
62+
(1 row)
63+
64+
ivorysql=# show ivorysql.compatible_mode;
65+
ivorysql.compatible_mode
66+
--------------------------
67+
pg
68+
(1 row)
69+
70+
ivorysql=# exit
71+
```
72+
73+
psql连接IvorySQL的Oracle端口
74+
```
75+
[root@k8s-master single]# psql -U ivorysql -p 31887 -h 127.0.0.1 -d ivorysql
76+
Password for user ivorysql:
77+
78+
ivorysql=# select version();
79+
version
80+
------------------------------------------------------------------------------------------------------------------------
81+
PostgreSQL 17.6 (IvorySQL 4.6) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-28), 64-bit
82+
(1 row)
83+
84+
ivorysql=# show ivorysql.compatible_mode;
85+
ivorysql.compatible_mode
86+
--------------------------
87+
oracle
88+
(1 row)
89+
```
90+
91+
卸载单机容器
92+
```
93+
[root@k8s-master single]# kubectl delete-f statefulset.yaml
94+
```
95+
96+
== 高可用集群
97+
98+
进入k8s集群的master节点上,创建名为ivorysql的namespace
99+
```
100+
[root@k8s-master ~]# kubectl create ns ivorysql
101+
```
102+
103+
下载最新docker_library代码
104+
```
105+
[root@k8s-master ~]# git clone https://github.com/IvorySQL/docker_library.git
106+
```
107+
108+
进入高可用集群目录
109+
```
110+
[root@k8s-master ~]# cd docker_library/k8s-cluster/ha-cluster/helm_charts
111+
[root@k8s-master single]# vim values.yaml #根据个人环境自行values.yaml中的pvc信息及集群规模等信息,数据库密码查看templates/secret.yaml并自行修改。
112+
```
113+
114+
使用Helm(https://helm.sh/docs/intro/install/)命令部署高可用集群
115+
```
116+
[root@k8s-master helm_charts]# helm install ivorysql-ha-cluster -n ivorysql .
117+
NAME: ivorysql-ha-cluster
118+
LAST DEPLOYED: Wed Sep 10 09:45:36 2025
119+
NAMESPACE: ivorysql
120+
STATUS: deployed
121+
REVISION: 1
122+
TEST SUITE: None
123+
[root@k8s-master helm_charts]# kubectl get all -n ivorysql
124+
NAME READY STATUS RESTARTS AGE
125+
pod/ivorysql-patroni-hac-0 1/1 Running 0 42s
126+
pod/ivorysql-patroni-hac-1 0/1 Running 0 18s
127+
128+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
129+
service/ivorysql-patroni-hac NodePort 10.96.119.203 <none> 5432:32391/TCP,1521:32477/TCP 42s
130+
service/ivorysql-patroni-hac-config ClusterIP None <none> <none> 42s
131+
service/ivorysql-patroni-hac-pods ClusterIP None <none> <none> 42s
132+
service/ivorysql-patroni-hac-repl NodePort 10.100.122.0 <none> 5432:30111/TCP,1521:32654/TCP 42s
133+
134+
NAME READY AGE
135+
statefulset.apps/ivorysql-patroni-hac 1/3 42s
136+
```
137+
138+
等待所有pod均运行成功,集群部署成功
139+
```
140+
[root@k8s-master helm_charts]# kubectl get all -n ivorysql
141+
NAME READY STATUS RESTARTS AGE
142+
pod/ivorysql-patroni-hac-0 1/1 Running 0 88s
143+
pod/ivorysql-patroni-hac-1 1/1 Running 0 64s
144+
pod/ivorysql-patroni-hac-2 1/1 Running 0 41s
145+
146+
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
147+
service/ivorysql-patroni-hac NodePort 10.96.119.203 <none> 5432:32391/TCP,1521:32477/TCP 88s
148+
service/ivorysql-patroni-hac-config ClusterIP None <none> <none> 88s
149+
service/ivorysql-patroni-hac-pods ClusterIP None <none> <none> 88s
150+
service/ivorysql-patroni-hac-repl NodePort 10.100.122.0 <none> 5432:30111/TCP,1521:32654/TCP 88s
151+
NAME READY AGE
152+
statefulset.apps/ivorysql-patroni-hac 3/3 88s
153+
```
154+
155+
使用psql连接集群主节点的PG、Oracle端口
156+
```
157+
[root@k8s-master helm_charts]# psql -U ivorysql -p 32391 -h 127.0.0.1 -d ivorysql
158+
Password for user ivorysql:
159+
160+
ivorysql=# show ivorysql.compatible_mode;
161+
ivorysql.compatible_mode
162+
--------------------------
163+
pg
164+
(1 row)
165+
166+
ivorysql=# SELECT pg_is_in_recovery();
167+
pg_is_in_recovery
168+
-------------------
169+
f
170+
(1 row)
171+
172+
ivorysql=# exit
173+
[root@k8s-master helm_charts]# psql -U ivorysql -p 32477 -h 127.0.0.1 -d ivorysql
174+
Password for user ivorysql:
175+
176+
ivorysql=# show ivorysql.compatible_mode;
177+
ivorysql.compatible_mode
178+
--------------------------
179+
oracle
180+
(1 row)
181+
182+
ivorysql=# SELECT pg_is_in_recovery();
183+
pg_is_in_recovery
184+
-------------------
185+
f
186+
(1 row)
187+
188+
ivorysql=#
189+
```
190+
191+
使用psql连接集群备节点的PG、Oracle端口
192+
```
193+
[root@k8s-master helm_charts]# psql -U ivorysql -p 30111 -h 127.0.0.1 -d ivorysql
194+
Password for user ivorysql:
195+
196+
ivorysql=# show ivorysql.compatible_mode;
197+
ivorysql.compatible_mode
198+
--------------------------
199+
pg
200+
(1 row)
201+
202+
ivorysql=# SELECT pg_is_in_recovery();
203+
pg_is_in_recovery
204+
-------------------
205+
t
206+
(1 row)
207+
208+
ivorysql=# exit
209+
210+
[root@k8s-master helm_charts]# psql -U ivorysql -p 32654 -h 127.0.0.1 -d ivorysql
211+
Password for user ivorysql:
212+
213+
ivorysql=# show ivorysql.compatible_mode;
214+
ivorysql.compatible_mode
215+
--------------------------
216+
oracle
217+
(1 row)
218+
219+
ivorysql=# SELECT pg_is_in_recovery();
220+
pg_is_in_recovery
221+
-------------------
222+
t
223+
(1 row)
224+
225+
ivorysql=#
226+
```
227+
228+
卸载高可用集群
229+
```
230+
[root@k8s-master helm_charts]# helm uninstall ivorysql-ha-cluster -n ivorysql
231+
```
232+
删除PVC
233+
```
234+
[root@k8s-master helm_charts]# kubectl delete pvc ivyhac-config-ivorysql-patroni-hac-0 -n ivorysql
235+
[root@k8s-master helm_charts]# kubectl delete pvc ivyhac-config-ivorysql-patroni-hac-1 -n ivorysql
236+
[root@k8s-master helm_charts]# kubectl delete pvc ivyhac-config-ivorysql-patroni-hac-2 -n ivorysql
237+
[root@k8s-master helm_charts]# kubectl delete pvc pgdata-ivorysql-patroni-hac-0 -n ivorysql
238+
[root@k8s-master helm_charts]# kubectl delete pvc pgdata-ivorysql-patroni-hac-1 -n ivorysql
239+
[root@k8s-master helm_charts]# kubectl delete pvc pgdata-ivorysql-patroni-hac-2 -n ivorysql
240+
```

0 commit comments

Comments
 (0)