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

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

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"}

3.添加Chart仓库

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

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

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" . }}

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 }}
...

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: {}

6.部署

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

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

2.下载安装包

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

3.自定义配置

[root@master mysql]# vim values.yaml

1.全局配置:存储

global:
...
  storageClass: "nfs-stroage"

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: ""

修改提示信息

appVersion: 5.7.38

结果展示
image.png

3.类型

## @param architecture MySQL architecture (`standalone` or `replication`)
# 默认standalone
architecture: standalone

4.root密码

auth:
  rootPassword: "CloudEasy2020"

暴露服务

新建 IngressRouteTCP 资源

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRouteTCP
metadata:
  name: mysql
  namespace: mysql
spec:
  entryPoints:
  - mysql
  routes:
  - match: HostSNI(`*`)
    services:
    - name: mysql
      port: 3306

在traefik中添加路由

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

spec:
  template:
	spec:
      containers:
      - args:
				- --entrypoints.mysql.address=:13306			# 此处指定暴露至外网的端口
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值