• [使用MogDB Operator在Kubernetes上部署MogDB集群(MogDB Stack)]


    本文介绍了如何使用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

    1. curl -s "https://raw.githubusercontent.com/\
    2. 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

    1. [root@pg01 MogDB-stack]# kubectl get ns
    2. NAME STATUS AGE
    3. default Active 62d
    4. kube-node-lease Active 62d
    5. kube-public Active 62d
    6. kube-system Active 62d
    7. kubernetes-dashboard Active 62d
    8. mogdb-operator-system Active 2m41s
    9. ns-test Active 62d
    10. [root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
    11. NAME READY STATUS RESTARTS AGE
    12. mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 0 7m30s
    13. 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状态

    1. [root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
    2. NAME READY STATUS RESTARTS AGE
    3. cluster1-lh2d4 0/3 Init:0/1 0 3m6s
    4. mogdb-apiserver-74b8f54cc6-7qqrx 1/1 Running 0 4m24s
    5. mogdb-operator-controller-manager-8586c668fd-c4wpr 1/1 Running 0 4m24s
    6. [root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
    7. NAME READY STATUS RESTARTS AGE
    8. cluster1-cjtdm 0/3 Init:0/1 0 2m3s
    9. cluster1-lh2d4 3/3 Running 0 7m12s
    10. mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 0 7m30s
    11. mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 7m30s

    用describe 命令查看状态,进行到哪一步了,发现在拉取镜像

    kubectl describe pod cluster1-lh2d4 -n mogdb-operator-system
    

    4.最后正常的状态是这样的:

    1. [root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
    2. NAME READY STATUS RESTARTS AGE
    3. cluster1-auto-2022-07-20t10-07-00-backup-cvdmh 1/1 Running 0 24s
    4. cluster1-cjtdm 3/3 Running 0 6m52s
    5. cluster1-lh2d4 3/3 Running 0 12m
    6. mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 0 12m
    7. mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 12m

    三、查看MogDB服务端口

    1. [root@pg01 MogDB-stack]# kubectl get svc -n mogdb-operator-system
    2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
    3. cluster1-svc-master NodePort 10.4.97.127 <none> 5432:30013/TCP 14m
    4. cluster1-svc-replicas NodePort 10.11.13.40 <none> 5432:30012/TCP 14m
    5. mogdb-apiserver NodePort 10.7.87.91 <none> 8444:32444/TCP 14m

    k8s集群内部通过5432端口,集群外部通过30013端口访问实际的MogDB集群。

    四、连接集群

    1.修改默认用户的密码

    可以通过kubectl命令连接到容器,修改密码

    1. [root@pg01 MogDB-stack]# kubectl get pods -n mogdb-operator-system
    2. NAME READY STATUS RESTARTS AGE
    3. cluster1-auto-2022-07-20t10-07-00-backup-cvdmh 1/1 Running 0 9m1s
    4. cluster1-cjtdm 3/3 Running 0 15m
    5. cluster1-lh2d4 3/3 Running 0 20m
    6. mogdb-apiserver-74b8f54cc6-wmkdq 1/1 Running 1 (<invalid> ago) 20m
    7. mogdb-operator-controller-manager-8586c668fd-ghjrn 1/1 Running 0 20m
    8. [root@pg01 MogDB-stack]# kubectl exec -it cluster1-lh2d4 -n mogdb-operator-system ha-sidecar -- /bin/bash
    9. Defaulted container "sidecar" out of: sidecar, mogdb-exporter, ha-sidecar, init-og (init)
    10. omm@cluster1-lh2d4:/$ gsql -dpostgres
    11. gsql ((MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr )
    12. Non-SSL connection (SSL connection is recommended when requiring high-security)
    13. Type "help" for help.
    14. MogDB=# ALTER USER mogdb WITH PASSWORD 'Enmo@123';
    15. NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.
    16. ALTER ROLE
    17. MogDB=# \q

    2.本地通过容器访问

    1. [root@pg01 MogDB-stack]# kubectl exec -it cluster1-lh2d4 -n mogdb-operator-system ha-sidecar -- /bin/bash
    2. Defaulted container "sidecar" out of: sidecar, mogdb-exporter, ha-sidecar, init-og (init)
    3. omm@cluster1-lh2d4:/$ gsql -h 172.20.10.6 -d postgres -p 30013 -U mogdb -W Enmo@123
    4. gsql ((MogDB 3.0.0 build 62408a0f) compiled at 2022-06-30 14:21:11 commit 0 last mr )
    5. Non-SSL connection (SSL connection is recommended when requiring high-security)
    6. Type "help" for help.
    7. MogDB=> select version();
    8. version
    9. --------------------------------------------------------------------------------------------------------------------------------------------------
    10. (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
    11. (1 row)

    3.不通过容器,通过终端访问暴露的端口

    在另一个服务器,远程访问该节点的Kubernetes上的MogDB数据库,我这里当前节点为172.20.10.6。远程使用的节点为172.20.10.7

    1. [omma@pg02 ~]$ ip a| grep global | grep ens33
    2. inet 172.20.10.7/28 brd 172.20.10.15 scope global ens33
    3. [omma@pg02 ~]$ gsql postgres -h 172.20.10.6 -p 30013 -U mogdb
    4. Password for user mogdb:
    5. gsql ((openGauss 3.0.0 build 02c14696) compiled at 2022-04-01 18:12:34 commit 0 last mr )
    6. Non-SSL connection (SSL connection is recommended when requiring high-security)
    7. Type "help" for help.
    8. openGauss=> select version();
    9. version
    10. --------------------------------------------------------------------------------------------------------------------------------------------------
    11. (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
    12. (1 row)

  • 相关阅读:
    《元宇宙2086》亮相金鸡奖中国首部元宇宙概念院线电影启动
    【HMS core】【FAQ】Account Kit、push Kit典型问题合集1
    FISCO BCOS(十七)利用脚本进行区块链系统监控
    c++基础题 想不明白的逻辑
    单调栈理论基础 及 力扣:739. 每日温度
    【FFH】从0到提交PR至OpenHarmony源仓库详细教程
    【Redis】Redis入门教程(介绍 下载安装 Jedis 图形化界面)
    【OpenEVSE 】汽车充电桩控制项目解析
    webpack5从零开始,到打包一个项目的基本配置
    python cookbook 学习笔记(持续更新)
  • 原文地址:https://blog.csdn.net/weixin_47308871/article/details/125902937