当前位置:   article > 正文

Helm-MySQL_helm 部署mysql

helm 部署mysql

1.创建NFS StorageClass

1.创建NFS服务端

选取 192.168.0.57 节点做为服务端

[root@master ~]# mkdir -p /data/nfs
[root@master ~]# chmod -R 777 /data/nfs/
[root@master ~]# yum install nfs-utils -y
[root@master ~]# vim /etc/exports
[root@master ~]# /data/nfs *(rw,sync,no_root_squash,no_all_squash)
[root@master ~]# systemctl start nfs
[root@master ~]# systemctl enable nfs
#检查nfs是否生效
[root@master ~]# showmount -e 192.168.0.57
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

2.创建NFS客户端

# 下载代码
yum install git -y git clone  https://github.com/rimusz/nfs-client-provisioner.git

# 创建集群角色,添加权限
[root@master ~]# cd /root/nfs-client-provisioner/
[root@master nfs-client-provisioner]# vim deploy/auth/clusterrolebinding.yaml
    # 将roleRef.name的值修改为:cluster-admin
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io

[root@master nfs-client-provisioner]# kubectl create -f deploy/auth/serviceaccount.yaml -f deploy/auth/clusterrole.yaml -f deploy/auth/clusterrolebinding.yaml

# 编辑文件/root/nfs-client-provisioner/deploy/deployment.yaml修改nfs服务器的地址及路径,apiVersion值修改为:apps/v1,并添加selector
[root@master nfs-client-provisioner]# vim deploy/deployment.yaml
kind: Deployment
# 第一处修改
apiVersion: apps/v1
metadata:
  name: nfs-client-provisioner
spec:
  replicas: 1
  strategy:
    type: Recreate
  # 第二处修改
  selector:
    matchLabels:
      app: nfs-client-provisioner
  template:
    metadata:
      labels:
        app: nfs-client-provisioner
    spec:
      serviceAccountName: nfs-client-provisioner
      containers:
        - name: nfs-client-provisioner
          image: quay.io/external_storage/nfs-client-provisioner:latest
          volumeMounts:
            - name: nfs-client-root
              mountPath: /persistentvolumes
          env:
            - name: PROVISIONER_NAME
              value: fuseim.pri/ifs
            - name: NFS_SERVER
            # 第三处修改
              value: 192.168.0.57
            - name: NFS_PATH
            # 第四处修改
              value: /data/nfs
      volumes:
        - name: nfs-client-root
          nfs:
           # 第五处修改
            server: 192.168.0.57
            # 第六处修改
            path: /data/nfs

[root@master nfs-client-provisioner]# kubectl apply -f deploy/class.yaml -f deploy/deployment.yaml


# 测试:创建一个pvc,创建一个pod
[root@master nfs-client-provisioner]# kubectl create -f deploy/test-claim.yaml -f deploy/test-pod.yaml
[root@master nfs-client-provisioner]# kubectl get po
NAME                                     READY   STATUS      RESTARTS   AGE
nfs-client-provisioner-67fdcd8c7-8ft5w   1/1     Running     0          2m30s
test-pod                                 0/1     Completed   0          39s
  • 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

2.安装Helm3

[root@master ~]# cd /usr/local/bin/
[root@master ~]# wget https://get.helm.sh/helm-v3.5.4-linux-amd64.tar.gz
[root@master ~]# tar -zxvf helm-v3.5.4-linux-amd64.tar.gz
[root@master ~]# cd linux-amd64
[root@master ~]# cp helm ../
# 验证helm安装是否成功
[root@master ~]# helm version
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
version.BuildInfo{Version:"v3.5.4", GitCommit:"1b5edb69df3d3a08df77c9902dc17af864ff05d1", GitTreeState:"clean", GoVersion:"go1.15.11"}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

3.添加Chart仓库

[root@master ~]# helm repo add mysql https://apphub.aliyuncs.com
# 更新仓库
[root@master ~]# helm repo update
  • 1
  • 2
  • 3

4.使用helm下载安装包

# 查看可以下载的版本
[root@master ~]# helm search repo mysqlha
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
NAME            CHART VERSION   APP VERSION     DESCRIPTION
mysql/mysqlha   1.0.0           5.7.13          MySQL cluster with a single master and zero or ...

# 下载至本地
[root@master ~]# helm pull mysql/mysqlha --version=1.0.0
[root@master ~]# ll
-rw-r--r-- 1 root root      6956 Dec 15 10:57 mysqlha-1.0.0.tgz

# 解压缩
[root@master ~]# tar -zxvf mysqlha-1.0.0.tgz
[root@master ~]# ll
drwxr-xr-x 3 root root      4096 Dec 15 11:14 mysqlha
-rw-r--r-- 1 root root      6956 Dec 15 10:57 mysqlha-1.0.0.tgz
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

5.自定义配置

1.更改service类型为nodePort

[root@master ~]# vim mysqlha/templates/svc.yaml
# Headless service for stable DNS entries of StatefulSet members.
apiVersion: v1
kind: Service
metadata:
  name: {{ template "fullname" . }}
  labels:
    app: {{ template "fullname" . }}
    chart: "{{ template "mysqlha.chart" . }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  ports:
  - name: {{ template "fullname" . }}
    port: 3306
    # 添加第一处
    targetPort: 3306
    # 添加第二处
    nodePort: 30036
  # 添加第三处
  type: NodePort
  # 注释下面一行
  #ClusterIP: None
  selector:
    app: {{ template "fullname" . }}
  • 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

2.编辑statefulset.yaml

[root@master ~]# vim mysqlha/templates/statefulset.yaml
# 第一处修改:修改api版本为如下
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ template "fullname" . }}
  labels:
    app: {{ template "fullname" . }}
    chart: "{{ template "mysqlha.chart" . }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  serviceName: {{ template "fullname" . }}
  replicas: {{ .Values.mysqlha.replicaCount }}
  # 第二处修改:增加selector属性
  selector:
    matchLabels:
      app: {{ template "fullname" . }}
  template:
    metadata:
      labels:
        app: {{ template "fullname" . }}
      {{- if .Values.mysqlha.podAnnotations }}
...
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

3.编辑values.yaml

[root@master ~]# vim mysqlha/values.yaml
mysqlha:
  # 编辑副本数
  replicaCount: 3
  # 取消注释,设置root密码
  mysqlRootPassword: CloudEasy2020
  mysqlReplicationUser: repl
  # 取消注释,设置同步用户repl的密码
  mysqlReplicationPassword: CloudEasy2021
  ...
persistence:
  enabled: true
  # 取消注释,填写前面创建的sc名称
  storageClass: "managed-nfs-storage"
  accessModes:
  - ReadWriteOnce
  size: 10Gi
  annotations: {}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

6.部署

# 创建namespace
[root@master ~]# kubectl create ns mysql
# 部署
[root@master ~]# helm install mysql mysqlha/ -n mysql
  • 1
  • 2
  • 3
  • 4

7.验证

方式三部署:Helm 安装

1.添加Chart仓库

[root@master ~]# helm repo add bitnami https://charts.bitnami.com/bitnami
[root@master ~]# helm repo update
[root@master ~]# helm search repo bitnami/mysql -l
  • 1
  • 2
  • 3

2.下载安装包

[root@master ~]# helm pull bitnami/mysql
# 默认下载最新版本,也可以指定版本号,如: --version 9.0.6
[root@master ~]# tar -zxvf mysql-9.6.0.tgz
[root@master ~]# cd mysql/
  • 1
  • 2
  • 3
  • 4

3.自定义配置

[root@master mysql]# vim values.yaml

1.全局配置:存储

global:
...
  storageClass: "nfs-stroage"
  • 1
  • 2
  • 3

2.版本【可选】

更改镜像就是更改版本,如示例为8.0.2版本,可以修改为5.7.38(5.7.38-debian-10-r32)

镜像地址:点击跳转

image:
  registry: docker.io
  repository: bitnami/mysql
  tag: 8.0.32-debian-11-r14
  digest: ""
  • 1
  • 2
  • 3
  • 4
  • 5

修改提示信息

appVersion: 5.7.38
  • 1

结果展示
image.png

3.类型

## @param architecture MySQL architecture (`standalone` or `replication`)
# 默认standalone
architecture: standalone
  • 1
  • 2
  • 3

4.root密码

auth:
  rootPassword: "CloudEasy2020"
  • 1
  • 2

暴露服务

新建 IngressRouteTCP 资源

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
  name: mysql
  namespace: mysql
spec:
  entryPoints:
  - mysql
  routes:
  - match: HostSNI(`*`)
    services:
    - name: mysql
      port: 3306
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

在traefik中添加路由

$ kubectl edit deployments.apps -n kube-system traefik

spec:
  template:
	spec:
      containers:
      - args:
				- --entrypoints.mysql.address=:13306			# 此处指定暴露至外网的端口
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/523653
推荐阅读
相关标签
  

闽ICP备14008679号