博主vx: haitangyijiusu 。很高兴认识你!偶尔带huo,都是精挑细选信得过的产品,欢迎来支持,期待和您相遇!
一、环境介绍
- helm3.5.2
- centos7
- kubernetes1.20.4
二、安装
1、下载helm最新版并解压
tar -zxvf helm-v3.5.2-linux-amd64.tar.gz
cp -a linux-amd64/helm /usr/local/bin/
确认版本:
helm version:
version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}
2、账号与角色绑定
创建名为tiller的ServiceAccount:
kubectl create serviceaccount --namespace kube-system tiller
3、把tiller与角色tiller-cluster-rule进行绑定:
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
4、helm初始化
当您已经安装好了Helm之后,您可以添加一个chart 仓库。从 Artifact Hub中查找有效的Helm chart仓库。
helm repo add stable https://charts.helm.sh/stable
当添加完成,您将可以看到可以被您安装的charts列表:
helm search repo stable
helm repo update # 确定我们可以拿到最新的charts列表
5、尝试安装
[root@k8s-master vali]# helm install stable/mysql --generate-name
WARNING: This chart is deprecated
NAME: mysql-1615133119
LAST DEPLOYED: Mon Mar 8 00:05:25 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysql-1615133119.default.svc.cluster.localTo get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysql-1615133119 -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-1615133119 -pTo 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-1615133119 3306mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
在上面的例子中,stable/mysql这个chart被发布,名字是 mysql-1615134814
通过执行 helm show chart stable/mysql 命令简单的了解到这个chart的基本信息。 或者您可以执行 helm show all stable/mysql 获取关于该chart的所有信息。
helm show all stable/mysql
每执行 helm install 的时候,都会创建一个新的发布版本。 所以一个chart在同一个集群里面可以被安装多次,每一个都可以被独立的管理和升级。
可以很容易看到哪些chart被发布
[root@k8s-master home]# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mysql-1615133119 default 1 2021-03-08 00:05:25.321585283 +0800 CST deployed mysql-1.6.9 5.7.30
helm list 命令会列出所有可被部署的版本。
6、卸载一个版本
[root@k8s-master home]# helm uninstall mysql-1615133119
release "mysql-1615133119" uninstalled
该命令会从Kubernetes卸载 smiling-penguin, 它将删除和该版本相关的所有相关资源(service、deployment、 pod等等)甚至版本历史。
helm status smiling-penguin
通过Helm命令查看更多的有用的信息,请使用 helm help 命令,或者在任意命令后添加 -h 选项:
部分参考自:https://helm.sh/docs/intro/install/