前面我们在使用 wordpress+MySQL 部署博客应用的时候,需要做许多的工作,需要每个 pod
创建 pv 和 pvc,然后分别创建每个应用的 pod 及 svc,整个过程非常的麻烦。
如果搭建博客所有步骤作为一个整体,放在一个文件夹里(叫做 chart),以后我们直接使用
这个 chart 就可以把所有的操作一次性做完,这样很容易实现了一个博客应用(chart 的一
个实例,叫做 release),就非常的方便了。这个就类似于我们用虚拟机模板去克隆出来一台
台的虚拟机,这样就省的在一台台的去安装了,这个模板就是 chart,克隆出来的虚拟机就
是 release。
helm 实现的就是这样的功能,在互联网上存在 chart 仓库(也可以自己搭建)包括了各种
应用,我们需要什么应用直接拉取部署即可。
在 helm 2.X 版本的时候,helm 是一种 C/S 结构的应用,包括 helm 客户端和 tiller 服务器端,
用户通过 helm 客户端向 tiller 服务端发送部署请求,tiller 服务端和 kubernetes 的 apiserver
进行交互然后部署。
下载最新版的 helm,下载地址 https://github.com/helm/helm/releases
提前下载所需要的文件
https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz 及对应的 checksum 文件
[root@vms61 helm3]# helm repo list
Error: no repositories to show
[root@vms61 helm3]# helm repo add ali https://apphub.aliyuncs.com
"ali" has been added to your repositories
[root@vms61 helm3]# helm repo add azure http://mirror.azure.cn/kubernetes/charts/
"azure" has been added to your repositories
[root@vms61 helm3]# helm search repo mysql
NAME CHART VERSION APP VERSION DESCRIPTION
ali/mysql 6.8.0 8.0.19 Chart to create a Highly available MySQL cluster
ali/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi...
ali/mysqlha 1.0.0 5.7.13 MySQL cluster with a single master and zero or ...
ali/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with...
azure/mysql 1.6.7 5.7.30 Fast, reliable, scalable, and easy to use open-...
azure/mysqldump 2.6.1 2.4.1 A Helm chart to help backup MySQL databases usi...
azure/prometheus-mysql-exporter 0.7.1 v0.11.0 DEPRECATED A Helm chart for prometheus mysql ex...
ali/percona 1.2.0 5.7.17 free, fully compatible, enhanced, open source d...
ali/percona-xtradb-cluster 1.0.3 5.7.19 free, fully compatible, enhanced, open source d...
ali/phpmyadmin 4.2.12 5.0.1 phpMyAdmin is an mysql administration frontend
azure/percona 1.2.1 5.7.26 free, fully compatible, enhanced, open source d...
azure/percona-xtradb-cluster 1.0.5 5.7.19 free, fully compatible, enhanced, open source d...
azure/phpmyadmin 4.3.5 5.0.1 DEPRECATED phpMyAdmin is an mysql administratio...
ali/mariadb 7.3.9 10.3.22 Fast, reliable, scalable, and easy to use open-...
ali/mariadb-galera 0.8.1 10.4.12 MariaDB Galera is a multi-master database clust...
azure/gcloud-sqlproxy 0.6.1 1.11 DEPRECATED Google Cloud SQL Proxy
azure/mariadb 7.3.14 10.3.22 DEPRECATED Fast, reliable, scalable, and easy t...
[root@vms61 helm3]# helm install name azure/mysql^C
[root@vms61 helm3]# helm pull azure/mysql
[root@vms61 helm3]# ll
总用量 12656
-rwxr-xr-x 1 root root 6546 10月 15 10:46 get
-rw-r--r-- 1 root root 12927632 10月 14 12:36 helm-v3.2.1-linux-amd64.tar.gz
-rw-r--r-- 1 root root 833 10月 14 12:34 helm-v3.2.1-linux-amd64.tar.gz.sha256.asc
-rw-r--r-- 1 root root 97 10月 14 12:34 helm-v3.2.1-linux-amd64.tar.gz.sha256sum
-rw-r--r-- 1 root root 11424 10月 15 11:58 mysql-1.6.7.tgz
[root@vms61 helm3]# helm package mysql/
Successfully packaged chart and saved it to: /root/helm3/mysql-1.6.7.tgz
[root@vms61 helm3]# ll
总用量 12656
-rwxr-xr-x 1 root root 6546 10月 15 10:46 get
-rw-r--r-- 1 root root 12927632 10月 14 12:36 helm-v3.2.1-linux-amd64.tar.gz
-rw-r--r-- 1 root root 833 10月 14 12:34 helm-v3.2.1-linux-amd64.tar.gz.sha256.asc
-rw-r--r-- 1 root root 97 10月 14 12:34 helm-v3.2.1-linux-amd64.tar.gz.sha256sum
drwxr-xr-x 3 root root 96 10月 15 12:00 mysql
-rw-r--r-- 1 root root 11420 10月 15 12:01 mysql-1.6.7.tgz
[root@vms61 mysql]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
[root@vms61 mysql]# helm install db .
NAME: db
LAST DEPLOYED: Thu Oct 15 12:22:57 2020
NAMESPACE: chap11-helm
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
db-mysql.chap11-helm.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace chap11-helm db-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 db-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/db-mysql 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
[root@vms61 mysql]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
db chap11-helm 1 2020-10-15 12:22:57.709270172 +0800 CST deployed mysql-1.6.7 5.7.30
[root@vms61 mysql]# kubectl get pods
NAME READY STATUS RESTARTS AGE
db-mysql-8695f4987c-xsknk 0/1 Init:0/1 0 14s
[root@vms61 mysql]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
db-mysql ClusterIP 10.100.24.64 <none> 3306/TCP 2m27s
[root@vms61 mysql]# mysql -uroot -predhat -h10.100.24.64
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> exit
Bye
[root@vms61 mysql]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
db chap11-helm 1 2020-10-15 12:22:57.709270172 +0800 CST deployed mysql-1.6.7 5.7.30
[root@vms61 mysql]# helm delete db
release "db" uninstalled
[root@vms61 mysql]# kubectl get all
NAME READY STATUS RESTARTS AGE
pod/db-mysql-8695f4987c-xsknk 0/1 Terminating 0 3m14s
[root@vms61 mysql]# kubectl get all
No resources found in chap11-helm namespace.
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。