这篇文章将一步步教你如何在Kubernetes集群安装和配置helm,并用其部署和管理应用程序。
前置条件
开始使用helm之前,应具备以下条件。
-
正在运行的kubernetes集群
-
kubernetes集群API Endpoint应该可以从运行Helm的机器上访问。
-
使用kubectl对集群进行身份验证,它应该具有集群管理员权限。
Helm架构
在这里插入图片描述安装Helm[客户端]
在命令行执行以下命令。
curl -L https:///get_helm.sh | bash
由于国内网络原因,下载helm包时会失败。我已经将get_helm.sh脚本和helm的安装包打包:提取码:jrko
helm-v2.16.1-linux-amd64.tar.gz
[root@master helm]# bash get_helm.sh
Preparing to install helm and tiller into /usr/local/bin
helm installed into /usr/local/bin/helm
tiller installed into /usr/local/bin/tiller
Run 'helm init' to configure helm.
为Tiller 创建具有集群管理员权限的Service Account
Tiller是Helm的服务端组件。Tiller将被安装在kubernetes集群中,Helm客户端会与其交互,从而使用Helm charts部署应用程序。
Helm将管理k8s集群资源。因此,我们需要向安装在集群kube-system命令空间中的tiller组件添加必要的权限。
所以需要做以下操作:
-
创建名称为tiller的Service Account
-
创建tiller对Service Account具有集群管理员权限的ClusterRoleBinding。
我们将在一个yaml文件中添加Service Account和clusterRoleBinding。
创建一个名为helm-rbac.yaml的文件,并将以下内容复制到该文件中。
apiVersion: v1
kind: ServiceAccount
metadata:
name: tiller
namespace: kube-system
---
apiVersion: /v1
kind: ClusterRoleBinding
metadata:
name: tiller
roleRef:
apiGroup:
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: tiller
namespace: kube-system
使用kubectl创建:
kubectl apply -f helm-rbac.yam
初始化Helm:部署Tiller
下一步是初始化Helm。当初始化Helm时,将在kube-system名称空间中部署一个名为tiller-deploy的deploy。
使用以下命令初始化Helm。
helm init --service-account=tiller --history-max 300
如果要安装指定的tiller版本,则可以在init命令中使用--tiller-image参数指定tillerimage地址。可以在公共Google GCR注册中心找到所有tillerdocker映像。由于国内网络原因,可以从阿里镜像仓库拉取。即把/kubernetes-helm/tiller:v2.14.1替换为/google_containers/tiller:v2.14.1
helm init --service-account=tiller --tiller-image=/google_containers/tiller:v2.14.1 --history-max 300
执行后如下:
[root@master helm]# helm init --service-account=tiller --tiller-image=/google_containers/tiller:v2.14.1 --history-max 300
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
如果不加“ --service-account = tiller”参数,则会出现以下错误。
Error: no available release name found
可以使用kubectl在kube-system名称空间中查看tiller部署。
kubectl get deployment tiller-deploy -n kube-system
使用Helm部署应用
现在,让我们使用Helm部署Nginx应用。
执行以下helm install命令,在kubernetes集群中部署ingress nginx。它将从github仓库中下载nginx-ingress helm chart。
helm install stable/nginx-ingress --name nginx-ingress
可以使用以下命令检查helm chart是否安装。
helm ls
可以使用delete命令删除刚才的部署。例如:
helm delete nginx-ingress
从kubernetes集群中删除Helm(Tiller)
如果要从kubernetes集群中删除Tiller,请使用以下命令:
helm reset
由于某种原因,如果引发错误,请使用以下命令强制将其删除。
helm reset --force
也可以使用kubectl命令将其删除。
kubectl delete deployment tiller-deploy --namespace kube-system

















