使用helm 3.0安装mysql+nfs+动态Pv provisioner

1、前言

Helm是kubernetes上的包管理工具,通过helm可以方便地进行容器应用布署,helm3.0 beta版是最新的helm,这个版本不再依赖triller,通过kubernetes api进行配置管理。

2、下载helm最新版

mkdir -p ~/helm3
cd ~/helm3
wget https://get.helm.sh/helm-v3.0.0-beta.2-linux-amd64.tar.gz
tar -zxvf helm-v3.0.0-beta.2-linux-amd64.tar.gz
cp helm /usr/local/bin
helm init

3、添加charts的加速仓库

添加微软的chart仓库,这个仓库与官网的charts仓库更新比较同步

helm repo add azure http://mirror.azure.cn/kubernetes/charts/
helm repo update
helm search repo mysql  //测试helm charts repo是否正常访问

4、安装nfs服务器

为了简化测试,我们在Master上部署nfs服务器,为kuernetes提供PV provisioner

(1)通过yum安装nfs服务器

yum -y install nfs-utils

(2)配置nfs服务器

创建nfs存储目录

mkdir /nfs
chmod  -R 777 /nfs

(3)修改exports配置文件

echo "/nfs *(rw,no_root_squash,sync)" > /etc/exports

(4)启用配置

#查看是否export生效
exportfs -r

(5)配置rpcbind和Nfs服务

rpcbind是用于Nfs服务跨机器访问

#启动rpcbind、nfs服务,配置为自动启动
systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs && systemctl enable nfs

(6)查看nfs服务器工作情况

[root@centos75 nfs]# showmount -e 10.0.135.30
Export list for 10.0.135.30:
/nfs *

(7)通过helm安装nfs client provisioner

使用默认设置安装helm,会自动创建一个storageClass:nfs-client
helm install my-nfsclient azure/nfs-client-provisioner --set nfs.server=10.0.135.30 --set nfs.path=/nfs/k8s

5、安装MySQL

helm install my-sql azure/mysql --set persistence.storageClass=nfs-client --set mysqlRootPassword=test123

#输出结果如下
[root@centos75 ~]# helm install my-sql azure/mysql --set persistence.storageClass=nfs-client --set mysqlRootPassword=test123

NAME: my-sql
LAST DEPLOYED: 2019-09-06 15:04:12.216593381 +0800 CST m=+1.320154309
NAMESPACE: default
STATUS: deployed
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
my-sql-mysql.default.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default my-sql-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

To connect to your database:

1. Run an Ubuntu pod that you can use as a client:

    kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il

2. Install the mysql client:

    $ apt-get update && apt-get install mysql-client -y

3. Connect using the mysql cli, then provide your password:
    $ mysql -h my-sql-mysql -p

To connect to your database directly from outside the K8s cluster:
    MYSQL_HOST=127.0.0.1
    MYSQL_PORT=3306

    # Execute the following command to route the connection:
    kubectl port-forward svc/my-sql-mysql 3306

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
[root@centos75 ~]#

5、测试Mysql的连通性

为了测试Mysql连通性,我们安装一个ubuntu的pod,在pod里测试,避免在Node节点系统上安装,保持环境的纯粹性

检查pod是否创建完成,因为helm需要拉取mysql的image,需要等待一段时间
[root@centos75 mysql]# kubectl get po
NAME                                                   READY   STATUS    RESTARTS   AGE
my-nfsclient-nfs-client-provisioner-6554f6dc9f-h9n6x   1/1     Running   0          18m
my-sql-mysql-85d466996f-t8znp                          1/1     Running   0          11m
[root@centos75 mysql]#

#登录mysql pod 
kubectl exec -it my-sql-mysql-85d466996f-t8znp bash

#测试数据库是否可以连通

[root@centos75 mysql]# kd exec -it my-sql-mysql-85d466996f-t8znp bash
root@my-sql-mysql-85d466996f-t8znp:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 85
Server version: 5.7.14 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>

6、总结

通过helm可以方便的安装kubernetes应用,并且提供丰富的配置能力,可以通过helm show 查看安装包的使用说明。

helm3.0是helm一个比较大的升级,去除了对triller的依赖,非常轻量级,使用方面也有细节不太一样

你可能感兴趣的:(使用helm 3.0安装mysql+nfs+动态Pv provisioner)