HELM的安装与使用
说明:
- HELM的官方网站:https://helm.sh/,文档可以切换为中文
- 在Helm2中Tiller 主要用于在 Kubernetes 集群中管理各种应用发布的版本,在 Helm 3 中移除了 Tiller, 版本相关的数据直接存储在了 Kubernetes 中。所以在Helm中没有helm init的命令
以下为正文:
根据官网网站,ubuntu下安装的方式为:
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add - sudo apt-get install apt-transport-https --yes echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list sudo apt-get update sudo apt-get install helm
可以通过helm和helm version查看命令
再执行下面脚本让helm支持命令补全功能(输入完命令后按Tab键就会自动补全)
echo "source <(helm completion bash)" >> ~/.bash_profile
#先添加常用的chart源 helm repo add stable https://kubernetes-charts.storage.googleapis.com helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com helm repo add bitnami https://charts.bitnami.com/bitnami helm repo add aliyuncs https://apphub.aliyuncs.com #查看chart列表 [root@master nginx]# helm repo list NAME URL stable https://kubernetes-charts.storage.googleapis.com incubator https://kubernetes-charts-incubator.storage.googleapis.com bitnami https://charts.bitnami.com/bitnami aliyuncs https://apphub.aliyuncs.com
查找mysql的chart
helm search repo mysql NAME CHART VERSION APP VERSION DESCRIPTION aliyuncs/mysql 6.8.0 8.0.19 Chart to create a Highly available MySQL cluster aliyuncs/mysqldump 2.6.0 2.4.1 A Helm chart to help backup MySQL databases usi... aliyuncs/mysqlha 1.0.0 5.7.13 MySQL cluster with a single master and zero or ... aliyuncs/prometheus-mysql-exporter 0.5.2 v0.11.0 A Helm chart for prometheus mysql exporter with... bitnami/mysql 8.8.12 8.0.27 Chart to create a Highly available MySQL cluster aliyuncs/percona 1.2.0 5.7.17 free, fully compatible, enhanced, open source d... aliyuncs/percona-xtradb-cluster 1.0.3 5.7.19 free, fully compatible, enhanced, open source d... aliyuncs/phpmyadmin 4.2.12 5.0.1 phpMyAdmin is an mysql administration frontend bitnami/phpmyadmin 8.2.18 5.1.1 phpMyAdmin is an mysql administration frontend aliyuncs/mariadb 7.3.9 10.3.22 Fast, reliable, scalable, and easy to use open-... aliyuncs/mariadb-galera 0.8.1 10.4.12 MariaDB Galera is a multi-master database clust... bitnami/mariadb 9.7.0 10.5.12 Fast, reliable, scalable, and easy to use open-... bitnami/mariadb-cluster 1.0.2 10.2.14 DEPRECATED Chart to create a Highly available M... bitnami/mariadb-galera 6.0.3 10.6.4 MariaDB Galera is a multi-master database clust...
下载mysql的chart到本地看看
$ helm pull aliyuncs/mysql --untar $ tree mysql locales-launch: Data of en_US locale not found, generating, please wait... mysql ├── Chart.yaml ├── ci │ └── values-production.yaml ├── files │ └── docker-entrypoint-initdb.d │ └── README.md ├── README.md ├── templates │ ├── _helpers.tpl │ ├── initialization-configmap.yaml │ ├── master-configmap.yaml │ ├── master-statefulset.yaml │ ├── master-svc.yaml │ ├── NOTES.txt │ ├── secrets.yaml │ ├── servicemonitor.yaml │ ├── slave-configmap.yaml │ ├── slave-statefulset.yaml │ └── slave-svc.yaml ├── values-production.yaml └── values.yaml
安装mysql
$ helm install aliyuncs/mysql --generate-name NAME: mysql-1635754710 # release的名字 LAST DEPLOYED: Mon Nov 1 08:18:30 2021 NAMESPACE: default # namespace默认为default STATUS: deployed # 已经将chart部署到集群 REVISION: 1 TEST SUITE: None NOTES: # NOTES显示的是release的使用方法 Please be patient while the chart is being deployed Tip: Watch the deployment status using the command: kubectl get pods -w --namespace default Services: echo Master: mysql-1635754710.default.svc.cluster.local:3306 echo Slave: mysql-1635754710-slave.default.svc.cluster.local:3306 Administrator credentials: # 这里告诉你如何获取mysql的用户名和密码 echo Username: root echo Password : $(kubectl get secret --namespace default mysql-1635754710 -o jsonpath="{.data.mysql-root-password}" | base64 --decode) To connect to your database: # 这里告诉你如何连接数据库 1. Run a pod that you can use as a client: kubectl run mysql-1635754710-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mysql:8.0.19-debian-10-r0 --namespace default --command -- bash 2. To connect to master service (read/write): mysql -h mysql-1635754710.default.svc.cluster.local -uroot -p my_database 3. To connect to slave service (read-only): mysql -h mysql-1635754710-slave.default.svc.cluster.local -uroot -p my_database To upgrade this helm chart: # 这里告诉你如何修改chart的默认配置 1. Obtain the password as described on the 'Administrator credentials' section and set the 'root.password' parameter as shown below: ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1635754710 -o jsonpath="{.data.mysql-root-password}" | base64 --decode) helm upgrade mysql-1635754710 bitnami/mysql --set root.password=$ROOT_PASSWORD
在 Helm 3 中,则必须主动指定名称,或者增加 --generate-name 的参数
查看执行结果
kubectl get pods NAME READY STATUS RESTARTS AGE mysql-1635754710-master-0 0/1 Pending 0 3m15s mysql-1635754710-slave-0 0/1 Pending 0 3m15s
Pod是Pending状态,通过:kubectl describe pod mysql-1635754710-master-0这个命令可以看到是PersistentVolumeClaim相关的问题
查看刚才安装的release
$ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION mysql-1635840856 default 1 2021-11-02 08:14:17.004198481 +0000 UTC deployed mysql-6.8.0 8.0.19
再卸载
$ helm uninstall mysql-1635840856 release "mysql-1635840856" uninstalled
helm基本操作
helm create xx 创建一个chart helm install chartxx 安装 helm uninstall chartxx 卸载 helm upgrade chartxx 更新 helm template 渲染 helm list 列出已经deploy的应用 helm reset 卸载helm
参考资料:
作者 :秋时
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。