#夏日挑战赛#使用MogDB Operator在Kubernetes上部署MogDB集群 原创
[本文正在参加星光计划3.0–夏日挑战赛] https://ost.51cto.com/posts/13641#comment
本文介绍了如何使用MogDB Operator在Kubernetes上部署MogDB集群自动运维系统,包含MogDB Operator部署,Kubernetes上的MogDB集群创建等。
Kubernetes的部署以及Kubernetes里的Operator不在此篇文章赘述,如感兴趣可参考我之前的文章:
1.kubeadm部署一主两从的kubernetes集群
2.Kubernetes里的Operator
一、部署MogDB Operator
1.获取Kustomize v3+
kustomize 是一种安装应用的方案, 是一个通用的工具,它的作用是对描述 Kubernetes 资源的 YAML 文件进行定制,产生新的 YAML 文件,并保持原始的 YAML 文件不变。和包管理工具 Helm不同的是,kustomize 不使用模板,而是直接工作在原始的 YAML 文件上。kustomize 的另外一个优势是集成在 kubectl 中,这就意味着不需要安装额外的工具就可以进行定制。但是,kubectl 自带的 kustomize 的版本比较低,目前仍然需要安装单独的 kustomize 工具。
安装Kustomize
curl -s "https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
2.安装 MogDB Operator
获取压缩包
wget https://cdn-mogdb.enmotech.com/mogdb-stack/v1.0.0/mogdb-operator-examples.tar --no-check-certificate
tar xf mogdb-operator-examples.tar
MogDB Operator安装项目在kustomize/install目录下
要安装的组件
mogdb-operator-controller-manager
mogdb-apiserver
mgo-client
mgo-client运行在物理机下,其余组件都运行在k8s下
kustomize build ./kustomize/install/default | kubectl apply -f -
查看namespace以及对应的pod
[root@pg01 MogDB-stack]# kubectl get ns
NAME STATUS AGE
default Active 62d
kube-node-lease Active 62d
kube-public Active 62d
kube-system Active 62d
kubernetes-dashboard Active 62d
mogdb-operator-system Active 2m41s
ns-test Active 62d
[root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
NAME READY STATUS RESTARTS AGE
mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 0 7m30s
mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 7m30s
二、安装MogDB集群
1.安装所需csi
(不安装的话会存在挂在不上pvc的问题,pod处于pending状态)
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.22/deploy/local-path-storage.yaml
2.安装集群
kubectl apply -f https://cdn-mogdb.enmotech.com/mogdb-stack/v1.0.0/mogdb-cluster.yaml
3.查看当前pod状态
[root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
NAME READY STATUS RESTARTS AGE
cluster1-lh2d4 0/3 Init:0/1 0 3m6s
mogdb-apiserver-74b8f54cc6-7qqrx 1/1 Running 0 4m24s
mogdb-operator-controller-manager-8586c668fd-c4wpr 1/1 Running 0 4m24s
[root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
NAME READY STATUS RESTARTS AGE
cluster1-cjtdm 0/3 Init:0/1 0 2m3s
cluster1-lh2d4 3/3 Running 0 7m12s
mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 0 7m30s
mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 7m30s
用describe 命令查看状态,进行到哪一步了,发现在拉取镜像
kubectl describe pod cluster1-lh2d4 -n mogdb-operator-system
4.最后正常的状态是这样的:
[root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
NAME READY STATUS RESTARTS AGE
cluster1-auto-2022-07-20t10-07-00-backup-cvdmh 1/1 Running 0 24s
cluster1-cjtdm 3/3 Running 0 6m52s
cluster1-lh2d4 3/3 Running 0 12m
mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 0 12m
mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 12m
三、查看MogDB服务端口
[root@pg01 MogDB-stack]# kubectl get svc -n mogdb-operator-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cluster1-svc-master NodePort 10.4.97.127 <none> 5432:30013/TCP 14m
cluster1-svc-replicas NodePort 10.11.13.40 <none> 5432:30012/TCP 14m
mogdb-apiserver NodePort 10.7.87.91 <none> 8444:32444/TCP 14m
k8s集群内部通过5432端口,集群外部通过30013端口访问实际的MogDB集群。
四、连接集群
1.修改默认用户的密码
可以通过kubectl命令连接到容器,修改密码
[root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
NAME READY STATUS RESTARTS AGE
cluster1-auto-2022-07-20t10-07-00-backup-cvdmh 1/1 Running 0 9m1s
cluster1-cjtdm 3/3 Running 0 15m
cluster1-lh2d4 3/3 Running 0 20m
mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 1 (<invalid> ago) 20m
mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 20m
[root@pg01 MogDB-stack]# kubectl exec -it cluster1-lh2d4 -n mogdb-operator-system ha-sidecar -- /bin/bash
Defaulted container "sidecar" out of: sidecar, mogdb-exporter, ha-sidecar, init-og (init)
omm@cluster1-lh2d4:/$ gsql -dpostgres
gsql ((MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
MogDB=# ALTER USER mogdb WITH PASSWORD 'Enmo@123';
NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
ALTER ROLE
MogDB=# \q
2.本地通过容器访问
[root@pg01 MogDB-stack]# kubectl exec -it cluster1-lh2d4 -n mogdb-operator-system ha-sidecar -- /bin/bash
Defaulted container "sidecar" out of: sidecar, mogdb-exporter, ha-sidecar, init-og (init)
omm@cluster1-lh2d4:/$ gsql -h 172.20.10.6 -d postgres -p 30013 -U mogdb -W Enmo@123
gsql ((MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
MogDB=> select version();
version
--------------------------------------------------------------------------------------------------------------------------------------------------
(MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)
3.不通过容器,通过终端访问暴露的端口
在另一个服务器,远程访问该节点的Kubernetes上的MogDB数据库,我这里当前节点为172.20.10.6。远程使用的节点为172.20.10.7
[omma@pg02 ~]$ ip a| grep global | grep ens33
inet 172.20.10.7/28 brd 172.20.10.15 scope global ens33
[omma@pg02 ~]$ gsql postgres -h 172.20.10.6 -p 30013 -U mogdb
Password for user mogdb:
gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
openGauss=> select version();
version
--------------------------------------------------------------------------------------------------------------------------------------------------
(MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 7.3.0, 64-bit
(1 row)
111111
三连111111
学到了 马一下
大哥好