• 利用Helm在K8S上部署 PolarDB-X 集群(详细步骤--亲测!!!)


    1、Helm简介

    Helm 是 Kubernetes 上的包管理器,用来管理 Kubernetes 应用程序,Helm Charts 可帮助您定义,安装和升级复杂的 Kubernetes 应用程序。Helm 把 Kubernetes 资源(比如deployments、services或ingress等) 打包到一个chart 中,而 chart 被保存到 chart 仓库。通过 chart 仓库可用来存储和分享 chart。 Helm 使发布可配置,支持发布应用配置的版本管理,简化了 Kubernetes 部署应用的版本控制、打包、发布、删除、更新等操作。

    Helm 之于 Kubernetes 好比 yum 之于 RHEL,或者 apt-get 之于 Ubuntu。Helm 使用 Chart 帮助我们管理应用,Chart 就好像 RPM 一样,里面描述了应用及其依赖关系

    helm v3 版本了移除 Tiller、让 Helm 成为一个纯客户端工具。

    Helm 可以理解为 Kubernetes 的包管理工具,可以方便地发现、共享和使用为 Kubernetes 构建的应用。

    • Chart:Helm 应用(package),包括该应用的所有 Kubernetes manifest 模版,类似于 [YUM] RPM 或 Apt
      dpkg 文件。

    • Repository:Helm package 存储仓库。

    • Release:chart 的部署实例,每个 chart 可以部署一个或多个 release。

    2、Helm 和 kubernetes 对应版本

    Helm版本支持的Kubernetes版本
    3.8.x1.23.x - 1.20.x
    3.7.x1.22.x - 1.19.x
    3.6.x1.21.x - 1.18.x
    3.5.x1.20.x - 1.17.x
    3.4.x1.19.x - 1.16.x
    3.3.x1.18.x - 1.15.x
    3.2.x1.18.x - 1.15.x
    3.1.x1.17.x - 1.14.x
    3.0.x1.16.x - 1.13.x
    2.16.x1.16.x - 1.15.x
    2.15.x1.15.x - 1.14.x
    2.14.x1.14.x - 1.13.x
    2.13.x1.13.x - 1.12.x
    2.12.x1.12.x - 1.11.x
    2.11.x1.11.x - 1.10.x
    2.10.x1.10.x - 1.9.x
    2.9.x1.10.x - 1.9.x
    2.8.x1.9.x - 1.8.x
    2.7.x1.8.x - 1.7.x
    2.6.x1.7.x - 1.6.x
    2.5.x1.6.x - 1.5.x
    2.4.x1.6.x - 1.5.x
    2.3.x1.5.x - 1.4.x
    2.2.x1.5.x - 1.4.x
    2.1.x1.5.x - 1.4.x
    2.0.x1.4.x - 1.3.x

    3、Helm chart 仓库

    3.1 添加仓库

    ##阿里云
    $ helm repo add ali-stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
    
    ##bitnami
    $ helm repo add bitnami https://charts.bitnami.com/bitnami
    
    ##kube-charts-mirror
    $ helm repo add stable https://burdenbear.github.io/kube-charts-mirror
    
    ##chart repository
    $ helm repo add gf-stable https://charts.helm.sh/stable
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    3.2 查看仓库

    helm repo list
    
    • 1

    在这里插入图片描述

    3.3 更新chart仓库

    helm repo update
    
    • 1

    3.4 移除chart仓库

    helm repo remove gf-stable
    
    • 1

    3.5 查看可安装的charts

    # 展现仓库的charts
    helm search repo
    
    • 1
    • 2

    在这里插入图片描述

    3.6 搜索charts

    # helm search repo可以在已添加的存储库中找到chart的名称
    # 搜索nginx
    helm search repo nginx
    
    • 1
    • 2
    • 3

    在这里插入图片描述

    3.7 展示charts的详细信息

    # 展示charts的详细信息
    helm show all bitnami/nginx
    
    • 1
    • 2

    3.8 查看charts上可配置的选项

    helm show values bitnami/nginx
    
    • 1

    3.9 安装charts

    # 安装
    # 在最简单的情况下,它需要两个参数:您选择的版本名称和您要安装的charts的名称
    # helm install happy-panda bitnami/wordpress
    # 如果您希望Helm为您生成名称,请省略发布名称并使用--generate-name
    # helm install --generate-name bitnami/wordpress
    # 更多安装方式
    # 1、一个charts存储库(正如我们在上面看到的)
    # 2、本地charts存档(helm install foo foo-0.1.1.tgz)
    # 3、解压后的charts目录(helm install foo path/to/foo)
    # 4、完整网址(helm install foo https://example.com/charts/foo-1.2.3.tgz)
    # 安装bitnami/wordpress: helm install --generate-name bitnami/wordpress
    # 下面部署nginx应用,直接覆盖参数部署为NodePort类型
    helm install my-nginx-app --set service.type=NodePort bitnami/nginx
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    3.9 查看安装列表

    # helm ls 
    # 或者
    # helm list
    [root@master ~]# helm  ls
    NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION
    my-nginx-app    default         1               2023-07-11 20:41:00.409971233 +0800 CST deployed        
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    3.10 查看状态

    helm status my-nginx-app
    
    # 当然我们也可以通过kubectl命令查看相关的pod是否创建成功
    kubectl get svc,pod -o wide
    
    
    NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE     SELECTOR
    service/kubernetes     ClusterIP   10.96.0.1       <none>        443/TCP        24h     <none>
    service/my-nginx-app   NodePort    10.100.84.209   <none>        80:30585/TCP   4m36s   app.kubernetes.io/instance=my-nginx-app,app.kubernetes.io/name=nginx
    
    NAME                                READY   STATUS    RESTARTS   AGE     IP              NODE     NOMINATED NODE   READINESS GATES
    pod/my-nginx-app-5f4f995dfd-wk49k   1/1     Running   0          4m36s   10.244.140.85   slave2   
    
    
    # 浏览器访问
    # http://:ndoeport
    curl 192.168.226.200:30585
    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
    html { color-scheme: light dark; }
    body { width: 35em; margin: 0 auto;
    font-family: Tahoma, Verdana, Arial, sans-serif; }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    
    
    
    • 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

    3.11 卸载

    # 卸载
    helm uninstall my-nginx-app
    
    release "my-nginx-app" uninstalled
    
    • 1
    • 2
    • 3
    • 4

    4、helm3的安装

    4.1 通过二进制方式安装helm3

    首先,前提是搭建了一套k8s集群,检查集群状态:

    kubectl get node
    
    • 1

    在这里插入图片描述

    #下载helm压缩包
    wget https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz
    #解压
    tar -zxf helm-v3.5.2-linux-amd64.tar.gz
    #移动helm到bin目录下
    mv linux-amd64/helm /usr/local/bin/
    #查看helm版本
    helm version
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    在这里插入图片描述

    #helm版本信息
    version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}
    
    • 1
    • 2

    4.2 chart的目录结构

    #创建一个chart, 指定chart名:mychart 
    helm create my chart  
    
    • 1
    • 2
    tree mychart/
    
    • 1
    mychart/                           #chart包的名称
    ├── charts                         #存放子chart的目录, 目录里存放这个chart依赖的所有子chart Chart.yaml
    ├── Chart.yaml                     #保存chart的基本信息, 包括名字、描述信息及版本等, 这个变量文件都可以被templates目录下文件所引用
    ├── templates                      #模板文件目录, 目录里面存放所有yaml模板文件, 包含了所有部署应用的yaml文件
    │   ├── deployment.yaml            #创建deployment对象的模板文件 
    │   ├── _helpers.tpl               #放置模板助手的文件, 可以在整个chart中重复使用, 是放一些templates目录下这些yaml都有可能会用的一些模板
    │   ├── hpa.yaml
    │   ├── ingress.yaml
    │   ├── NOTES.txt                  #存放提示信息的文件, 介绍chart帮助信息, helm install部署后展示给用户.如何使用chart等, 是部署chart后给用户的提示信息 
    │   ├── serviceaccount.yaml
    │   ├── service.yaml
    │   └── tests     #用于测试的文件, 测试完部署完chart后, 如web, 做一个链接, 看看你是否部署正常
    │       └── test-connection.yaml   
    └── values.yaml    #用于渲染模板的文件(变量文件,定义变量的值)定义templates目录下的yaml文件可能引用到的变量   #values.yaml用于存储templates目录中模板文件中用到变量的值, 这些变量定义都是为了让templates目录下yaml引用
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    在这里插入图片描述

    Chart.yaml文件字段说明

    cat Chart.yaml 
    
    • 1
    apiVersion: v2
    name: mychart
    description: A Helm chart for Kubernetes
    
    # A chart can be either an 'application' or a 'library' chart.
    #
    # Application charts are a collection of templates that can be packaged into versioned archives
    # to be deployed.
    #
    # Library charts provide useful utilities or functions for the chart developer. They're included as
    # a dependency of application charts to inject those utilities and functions into the rendering
    # pipeline. Library charts do not define any templates and therefore cannot be deployed.
    type: application
    
    # This is the chart version. This version number should be incremented each time you make changes
    # to the chart and its templates, including the app version.
    # Versions are expected to follow Semantic Versioning (https://semver.org/)
    version: 0.1.0
    
    # This is the version number of the application being deployed. This version number should be
    # incremented each time you make changes to the application. Versions are not expected to
    # follow Semantic Versioning. They should reflect the version the application is using.
    # It is recommended to use it with quotes.
    appVersion: "1.16.0"
    
    
    • 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

    5、部署 PolarDB-X Operator

    5.1 前置条件

    开始之前,请确保满足以下前置要求:

    已经准备了一个运行中的 Kubernetes 集群,并确保

    • 集群版本 >= 1.18.0
    • 至少有 2 个可分配的 CPU
    • 至少有 4GB 的可分配内存
    • 至少有 30GB 以上的磁盘空间
    • 已经安装了 kubectl 可以访问 Kubernetes 集群
    • 已经安装了 Helm 3

    5.2 开始安装

    首先创建一个叫 polardbx-operator-system 的命名空间,

     kubectl create namespace polardbx-operator-system
    
    • 1

    执行以下命令安装 PolarDB-X Operator。

    helm install --namespace polardbx-operator-system polardbx-operator polardbx/polardbx-operator
    
    • 1

    期望看到如下输出:

    apiVersion: polardbx.aliyun.com/v1
    kind: PolarDBXCluster
    metadata:
      name: quick-start
      annotations:
        polardbx/topology-mode-guide: quick-start
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    查看 PolarDB-X Operator 组件的运行情况,等待它们都进入 Running 状态:

    kubectl get pods --namespace polardbx-operator-system
    
    • 1

    在这里插入图片描述
    恭喜!PolarDB-X Operator 已经安装完成,现在可以开始部署 PolarDB-X 集群了!

    5.3 开始部署 PolarDB-X 集群

    PolarDB-X目前包含企业版和标准版两个系列,您可以根据实际的需求创建对应的集群。(二选一)

    1. 部署 PolarDB-X 企业版集群
      PolarDB-X 企业版是分布式架构集群,支持更大数据量,面向具备企业级超高并发、大规模数据复杂查询、加速分析的业务场景。 现在我们来快速部署一个 PolarDB-X 企业版集群,它包含 1 个 GMS 节点、1 个 CN 节点、1 个 DN 节点和 1 个 CDC 节点。

    执行以下命令创建一个这样的集群:

    echo "apiVersion: polardbx.aliyun.com/v1
    kind: PolarDBXCluster
    metadata:
      name: quick-start
      annotations:
        polardbx/topology-mode-guide: quick-start" | kubectl apply -f -
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    你将看到以下输出:
    在这里插入图片描述

    使用如下命令查看创建状态:

    kubectl get polardbxcluster -w
    
    • 1
    NAME          GMS   CN    DN    CDC   PHASE      DISK   AGE
    quick-start   0/1   0/1   0/1   0/1   Creating          35s
    quick-start   1/1   0/1   1/1   0/1   Creating          93s
    quick-start   1/1   0/1   1/1   1/1   Creating          4m43s
    quick-start   1/1   1/1   1/1   1/1   Running    2.4 GiB   4m44s
    
    • 1
    • 2
    • 3
    • 4
    • 5

    此刻,请耐心等待!!!
    此刻,请耐心等待!!!
    此刻,请耐心等待!!!

    在这里插入图片描述

    当 PHASE 显示为 Running 时,PolarDB-X 集群已经部署完成!

    恭喜你,现在可以开始连接并体验 PolarDB-X 分布式数据库了!

    1. 部署 PolarDB-X 标准版集群
      PolarDB-X 标准版采用一主一备一日志的三节点架构,性价比高,通过多副本同步复制,确保数据的强一致性。面向具备超高并发、复杂查询及轻量分析的在线业务场景。 现在我们来快速部署一个 PolarDB-X 标准版集群,它仅包含 1 个由三副本组成的DN节点。

    执行以下命令创建一个这样的集群:

    echo "apiVersion: polardbx.aliyun.com/v1
    kind: XStore
    metadata:
      name: quick-start
    spec:
      config:
        controller:
          RPCProtocolVersion: 1
      topology:
        nodeSets:
        - name: cand
          replicas: 2
          role: Candidate
          template:
            spec:
              image: polardbx/polardbx-engine-2.0:latest
              resources:
                limits:
                  cpu: "2"
                  memory: 4Gi
        - name: log
          replicas: 1
          role: Voter
          template:
            spec:
              image: polardbx/polardbx-engine-2.0:latest
              resources:
                limits:
                  cpu: "1"
                  memory: 2Gi" | kubectl apply -f -
    
    • 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

    你将看到以下输出:

    xstore.polardbx.aliyun.com/quick-start created
    
    • 1

    使用如下命令查看创建状态:

    kubectl get xstore -w
    
    • 1
    NAME          LEADER                    READY   PHASE     DISK      VERSION   AGE
    quick-start   quick-start-4dbh-cand-0   3/3     Running   3.6 GiB   8.0.18    11m
    
    • 1
    • 2

    此刻,请耐心等待!!!
    此刻,请耐心等待!!!
    此刻,请耐心等待!!!

    当 PHASE 显示为 Running 时,PolarDB-X 标准版集群已经部署完成!

    恭喜你,现在可以开始连接并体验 PolarDB-X 数据库了!

    5.4 连接 PolarDB-X 集群

    创建 PolarDB-X 集群时,PolarDB-X Operator 同时会为集群创建用于访问的服务,默认是 ClusterIP 类型。使用下面的命令查看用于访问的服务:

    kubectl get svc quick-start
    
    • 1

    期望输出:

    NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)             AGE
    quick-start   ClusterIP   10.96.215.132   <none>        3306/TCP,8081/TCP   25m
    
    
    • 1
    • 2
    • 3

    在这里插入图片描述
    这里也可以开一个nodeport对外访问的服务来暴露对外端口进行外网访问。

    也可以使用 kubectl 提供的 port-forward 命名将服务的 3306 端口转发到本地,并且保持转发进程存活。

    kubectl port-forward svc/quick-start 3306
    
    • 1

    Operator 将为 PolarDB-X 集群默认创建一个账号,并将密码存放在 secret 中。

    使用以下命令查看默认的账号与密码

    eval pxc=quick-start;eval user=$(kubectl get secret $pxc -o jsonpath={.data} | jq 'keys[0]'); echo "User: $user"; kubectl get secret $pxc -o jsonpath="{.data['$user']}" | base64 -d - | xargs echo "Password:"
    
    
    User: polardbx_root
    Password: 5486xjjg
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    此时出现-bash: jq: command not found
    解决:

    #下载并安装EPEL
    wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
     
    rpm -ivh epel-release-latest-7.noarch.rpm
     
    yum repolist      ##检查是否已添加至源列表
    
    yum -y install jq
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    保持 port-forward 的运行,重新打开一个终端,执行如下命令连接集群:

    mysql -h127.0.0.1 -P3306 -upolardbx_root -p5486xjjg
    
    • 1

    期望输出:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 6
    Server version: 5.6.29 Tddl Server (ALIBABA)
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    恭喜!你已经成功地部署并连接到了一个 PolarDB-X,现在你可以开始体验分布式数据库的能力了!

    6、销毁 PolarDB-X 集群

    完成测试后,你可以通过以下命令销毁 PolarDB-X 集群。

    kubectl delete polardbxcluster quick-start
    
    • 1

    再次查看以确保删除完成

    kubectl get polardbxcluster quick-start
    
    • 1

    7、卸载 PolarDB-X Operator

    使用如下命令卸载 PolarDB-X Operator。

    helm uninstall --namespace polardbx-operator-system polardbx-operator
    
    • 1

    Helm 卸载并不会删除对应的定制资源 CRD,使用下面的命令查看并删除 PolarDB-X 对应的定制资源:

    kubectl get crds | grep polardbx.aliyun.com
    
    
    polardbxclusters.polardbx.aliyun.com   2021-10-17T07:17:27Z
    xstores.polardbx.aliyun.com            2021-10-17T07:17:27Z
    
    • 1
    • 2
    • 3
    • 4
    • 5
    kubectl delete crds polardbxclusters.polardbx.aliyun.com xstores.polardbx.aliyun.com
    
    • 1

    在这里插入图片描述


    坚持到底,就是胜利,只有坚持到最后的人,才能享受到成功的喜悦。


  • 相关阅读:
    个人练习-PAT甲级-1143 Lowest Common Ancestor
    刷题记录:牛客NC50940Running Median
    hadoop2-hive
    selenium自动化测试+OCR-获取图片页面小说
    Layui 主窗口调用 iframe 弹出框模块,获取控件的相应值
    建设数字经济引领型城市 CDEC2022中国数字智能生态大会广州举行
    Elasticsearch8.2 使用snapshot备份能力
    彻底删除Ubuntu双系统(联想小新2022)
    弱口令(Weak Password)总结和爆破工具
    iOS代码混淆-从入门到放弃
  • 原文地址:https://blog.csdn.net/weixin_43025151/article/details/136659218