helm安装mysql

一.版本信息

[root@node-16 ~]# kubectl get nodes

NAME      STATUS   ROLES    AGE     VERSION

node-16   Ready    master   6d18h   v1.16.0

node-17   Ready    worker   6d18h   v1.16.0

node-18   Ready    worker   6d18h   v1.16.0

[root@node-16 ~]# docker version

Client: Docker Engine - Community

 Version:           18.09.6

 API version:       1.39

 Go version:        go1.10.8

 Git commit:        481bc77

 Built:             Sat May  4 02:33:34 2019

 OS/Arch:           linux/amd64

 Experimental:      false

 

Server: Docker Engine - Community

 Engine:

  Version:          18.09.6

  API version:      1.39 (minimum version 1.12)

  Go version:       go1.10.8

  Git commit:       481bc77

  Built:            Sat May  4 02:41:08 2019

  OS/Arch:          linux/amd64

  Experimental:     false

[root@node-16 ~]# helm version

version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}

[root@node-16 ~]#

 

2: 查看集群状态

 

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]# kubectl get nodes

NAME      STATUS   ROLES    AGE     VERSION

node-16   Ready    master   6d18h   v1.16.0

node-17   Ready    worker   6d18h   v1.16.0

node-18   Ready    worker   6d18h   v1.16.0

[root@node-16 ~]#

 

二、安装部署helm

使用helm的v3版本,v3版本不用配置服务端组件 Tiller。

2.1 下载软件包

#git clone  https://github.com/doitroot/helm.git

2.2.安装helm

将二进制文件复制到$PATH路径下即可使用。

2.3:添加存储库:

helm repo add stable http://mirror.azure.cn/kubernetes/charts

[root@node-16 ~]# helm repo update

[root@node-16 ~]#

三、使用helm安装mysql

3.1 下载镜像

使用helm安装有状态应用mysql,使用到的docker镜像有:

准备docker image

在安装mysql的helm包时需要mysql与xtrabackup的docker镜像。

[root@node-16 script]# docker pull docker.io/mysql:latest

[root@node-17 ~]# docker pull docker.io/mysql:latest

[root@node-18 ~]# docker pull docker.io/mysql:latest

[root@node-16 script]#

[root@node-16 script]# docker images|grep mysql

mysql                                             latest              0c27e8e5fcfa        4 days ago          546MB

mysql                                             5.7.28              db39680b63ac        4 months ago        437MB

 

[root@node-17 ~]#

[root@node-17 ~]# docker images|grep mysql

mysql                                             latest              0c27e8e5fcfa        4 days ago          546MB

mysql                                             5.7.28              db39680b63ac        4 months ago        437MB

[root@node-18 ~]# docker images|grep mysql

mysql                                             latest              0c27e8e5fcfa        4 days ago          546MB

mysql                                             5.7.28              db39680b63ac        4 months ago        437MB

[root@node-18 ~]#

#######################################################################################

3.2 搜索mysql的helm包

 

[root@node-16 script]# helm search repo mysql

NAME                                    CHART VERSION   APP VERSION     DESCRIPTION                                      

aliyun01/mysql                          6.8.0           8.0.19          Chart to create a Highly available MySQL cluster 

aliyun01/mysqldump                      2.6.0           2.4.1           A Helm chart to help backup MySQL databases usi...

aliyun01/mysqlha                        1.0.0           5.7.13          MySQL cluster with a single master and zero or ...

aliyun01/prometheus-mysql-exporter      0.5.2           v0.11.0         A Helm chart for prometheus mysql exporter with...

aliyun02/mysql                          0.3.5                           Fast, reliable, scalable, and easy to use open-...

stable/mysql                            1.6.3           5.7.28          Fast, reliable, scalable, and easy to use open-...

stable/mysqldump                        2.6.0           2.4.1           A Helm chart to help backup MySQL databases usi...

stable/prometheus-mysql-exporter        0.5.2           v0.11.0         A Helm chart for prometheus mysql exporter with...

aliyun01/percona                        1.2.0           5.7.17          free, fully compatible, enhanced, open source d...

aliyun01/percona-xtradb-cluster         1.0.3           5.7.19          free, fully compatible, enhanced, open source d...

aliyun01/phpmyadmin                     4.2.12          5.0.1           phpMyAdmin is an mysql administration frontend   

aliyun02/percona                        0.3.0                           free, fully compatible, enhanced, open source d...

aliyun02/percona-xtradb-cluster         0.0.2           5.7.19          free, fully compatible, enhanced, open source d...

stable/percona                          1.2.1           5.7.26          free, fully compatible, enhanced, open source d...

stable/percona-xtradb-cluster           1.0.3           5.7.19          free, fully compatible, enhanced, open source d...

stable/phpmyadmin                       4.3.5           5.0.1           DEPRECATED phpMyAdmin is an mysql administratio...

aliyun01/mariadb                        7.3.9           10.3.22         Fast, reliable, scalable, and easy to use open-...

aliyun01/mariadb-galera                 0.8.1           10.4.12         MariaDB Galera is a multi-master database clust...

aliyun02/gcloud-sqlproxy                0.2.3                           Google Cloud SQL Proxy                           

aliyun02/mariadb                        2.1.6           10.1.31         Fast, reliable, scalable, and easy to use open-...

stable/gcloud-sqlproxy                  0.6.1           1.11            DEPRECATED Google Cloud SQL Proxy                

stable/mariadb                          7.3.14          10.3.22         DEPRECATED Fast, reliable, scalable, and easy t...

[root@node-16 script]#

 

3.4 安装mysql的helm包

 

[root@node-16 ~]# cat values.yaml

#mysqlRootPassword:

#mysqlUser:

#mysqlPassword:

#mysqlDatabase:

persistence:

  enabled: true

  storageClass: "managed-nfs-storage"

  accessMode: ReadWriteOnce

  size: 3Gi

 

 

[root@node-16 ~]#

[root@node-16 ~]#  helm install mysql  -f values.yaml stable/mysql

NAME: mysql

LAST DEPLOYED: Tue Apr 28 12:36:30 2020

NAMESPACE: default

STATUS: deployed

REVISION: 1

NOTES:

MySQL can be accessed via port 3306 on the following DNS name from within your cluster:

mysql.default.svc.cluster.local

 

To get your root password run:

 

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default 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 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/mysql 3306

 

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}

[root@node-16 ~]#

 

 

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]# helm list

NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART           APP VERSION

db01    default         1               2020-04-26 13:56:58.07831662 +0800 CST  deployed        mysql-1.6.3     5.7.28    

db02    default         1               2020-04-27 18:03:05.493881703 +0800 CST deployed        mysql-1.6.3     5.7.28    

mysql   default         1               2020-04-28 12:36:30.893187638 +0800 CST deployed        mysql-1.6.3     5.7.28    

[root@node-16 ~]#

 

 

3.5.查看mysql的有状态应用、pod、svc、pvc等k8s资源

 

[root@node-16 ~]# kubectl get pv

NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                      STORAGECLASS          REASON   AGE

pvc-d5623ae6-d4d5-4993-b00f-6b3bed4994ee   3Gi        RWO            Delete           Bound       default/mysql                              managed-nfs-storage            11s

 

[root@node-16 ~]#

[root@node-16 ~]# kubectl get pvc

NAME           STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS          AGE

mysql          Bound    pvc-d5623ae6-d4d5-4993-b00f-6b3bed4994ee   3Gi        RWO            managed-nfs-storage   46s

 

 

[root@node-16 ~]#

[root@node-16 ~]# kubectl get deployment

NAME                     READY   UP-TO-DATE   AVAILABLE   AGE

mysql                    1/1     1            1           83s

 

 

root@node-16 ~]# kubectl get service|grep mysql

db01-mysql            ClusterIP   10.0.0.206   <none>        3306/TCP       46h

db02-mysql            ClusterIP   10.0.0.141   <none>        3306/TCP       18h

mysql                 ClusterIP   10.0.0.66    <none>        3306/TCP       107s

[root@node-16 ~]#

 

 

 

 

四.客户端验证

 

[root@node-16 ~]# kubectl get secret --namespace default mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo

F43URG4Fln

[root@node-16 ~]#

[root@node-16 ~]#

[root@node-16 ~]#

 

 

 

[root@node-16 ~]# kubectl get pod|grep mysql

db01-mysql-6ff46d6ccb-6whjz               1/1     Running   0          46h

db02-mysql-59976896d-fj28z                1/1     Running   0          18h

mysql-5b59c4cd99-7dmk6                    1/1     Running   0          3m6s

[root@node-16 ~]#

[root@node-16 ~]#

 

[root@node-16 ~]# kubectl exec mysql-5b59c4cd99-7dmk6 -it /bin/bash

root@mysql-5b59c4cd99-7dmk6:/#

root@mysql-5b59c4cd99-7dmk6:/#

 

 

root@mysql-5b59c4cd99-7dmk6:/#

root@mysql-5b59c4cd99-7dmk6:/#

root@mysql-5b59c4cd99-7dmk6:/# mysql -uroot -p  

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 67

Server version: 5.7.28 MySQL Community Server (GPL)

 

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

mysql> CREATE TABLE test.messages (message VARCHAR(1024));

Query OK, 0 rows affected (0.01 sec)

 

mysql>

 

 

mysql> INSERT INTO test.messages VALUES ('hello');

Query OK, 1 row affected (0.00 sec)

 

mysql>

mysql>

mysql>

 

mysql>

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

| test               |

+--------------------+

5 rows in set (0.00 sec)

 

mysql>

mysql>

mysql> use test;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

mysql> select * from messages;

+---------+

| message |

+---------+

| hello   |

+---------+

1 row in set (0.00 sec)

 

mysql> exit

Bye

root@mysql-5b59c4cd99-7dmk6:/#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值