Helm簡介
此文章取自官網 https://helm.sh/,并加入了自己的理解
Kubernetes的包管理器,類似于CentOS的yum
和Ubuntu的apt
,每個包稱為一個Chart,一個Chart是一個目錄,一般情況下會將目錄進行打包壓縮,形成name-version.tgz
格式的單一文件,方便傳輸和存儲
對應用發布者而言,Helm可以打包應用,管理應用依賴關系,管理應用版本并發布到軟件倉庫。
對使用者而言,不再需要了解Kubernetes的Yaml語法并編寫應用部署文件,可以通過Helm下載并在kubernetes上安裝需要的應用。
Helm Charts可降低管理復雜性,可定義、安裝和升級應用程序,容易在公有云或私有云創建、版本、共享、發布、回滾
詞義:
Tiller:Tiller 是 Helm 的服務端,部署在 Kubernetes 集群中。用于接收 Helm 的請求
Chart:Helm 的軟件包,采用 TAR 格式。其包含一組k8s的YAML資源文件
Repoistory:Helm 的軟件倉庫,用來保存Chart的軟件包,Helm可管理多個Repoistory
Release:使用 helm install 命令在 Kubernetes 集群中部署的 Chart 稱為 Release。
先決條件
成功且正確安全地使用Helm需要滿足以下先決條件。
- Kubernetes集群
- 確定要應用于安裝的安全配置(如果有)
- 安裝和配置集群端服務Helm和Tiller。
注意1:作者此處是虛擬機內安裝了kubernetes單master節點,若是生產安裝請移步官方文檔:Helm安全安裝
注意2:默認情況下,安裝Tiller時,未啟用身份驗證。要了解有關為Tiller配置強TLS身份驗證的更多信息,請參閱 Tiller TLS指南。
作者Machine 為Ubuntu 18.04具體信息如下:
root@master:/home/hzz# lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
docker版本為18.06.3-ce,小版本沒有太大差別
Kubernetes版本為1.15.3:
root@master:/home/hzz# kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:13:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.3", GitCommit:"2d3c76f9091b6bec110a5e63777c332469e0cba2", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:50Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
打開可以查看版本,后面拼接系統對應版本就可以下載了,linux直接wget就可以
谷歌鏡像地址:https://storage.googleapis.com/kubernetes-helm/
微軟鏡像地址:https://mirror.azure.cn/kubernetes/helm/
如:
root@master:/home/hzz# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.9.1-linux-amd64.tar.gz
--2019-09-01 17:09:32-- https://storage.googleapis.com/kubernetes-helm/helm-v2.9.1-linux-amd64.tar.gz
Resolving storage.googleapis.com (storage.googleapis.com)... 172.217.160.80, 2404:6800:4008:802::2010
Connecting to storage.googleapis.com (storage.googleapis.com)|172.217.160.80|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9160761 (8.7M) [application/x-tar]
Saving to: ‘helm-v2.9.1-linux-amd64.tar.gz’
helm-v2.9.1-linux-amd64.tar.gz 100%[==============================================================================================>] 8.74M 9.03MB/s in 1.0s
2019-09-01 17:09:34 (9.03 MB/s) - ‘helm-v2.9.1-linux-amd64.tar.gz’ saved [9160761/9160761]
一、安裝
注:這里作者安裝的是穩定的2.14.0版本
1、解壓包,復制helm到/usr/local/bin/ 客戶端
我這里用的是root用戶,所以直接拷貝到了/usr/bin/目錄下
root@master:/home/hzz# tar -zxvf helm-v2.14.0-linux-amd64.tar.gz
linux-amd64/
linux-amd64/tiller
linux-amd64/README.md
linux-amd64/LICENSE
linux-amd64/helm
root@master:/home/hzz# cp linux-amd64/helm /usr/bin/
root@master:/home/hzz# helm
The Kubernetes package manager
To begin working with Helm, run the 'helm init' command:
$ helm init
This will install Tiller to your running Kubernetes cluster.
It will also set up any necessary local configuration.
此時運行helm version
已經可以看到helm客戶端的版本了,但是連接不到服務端
root@master:/home/hzz# helm version
Client: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
Error: could not find a ready tiller pod
2、初始化Helm 服務端
注:此處k8s會去倉庫拉鏡像,谷歌被墻所以這里需要指定--stable-repo-url
參數
helm init \
--history-max=3 \
--tiller-image=gcr.azk8s.cn/kubernetes-helm/tiller:v2.14.0 \
--stable-repo-url=https://mirror.azure.cn/kubernetes/charts/ \
--service-account=helm-tiller
2.1、創建account并賦權
注意3:1.6之前的Kubernetes版本對基于角色的訪問控制(RBAC)的支持有限或不支持。1.6之后的默認開啟
我這里k8s集群開啟了RBAC認證,所以需要多處理一步,沒開啟RBAC的可忽略
# 創建賬號、綁定角色
kubectl create serviceaccount --namespace kube-system helm-tiller
kubectl create clusterrolebinding helm-tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:helm-tiller
# 給tiller設置角色
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"helm-tiller"}}}}' deployment.extensions "tiller-deploy" patched
# 查看授權
kubectl get deploy --namespace kube-system tiller-deploy --output yaml|grep serviceAccount
serviceAccount: helm-tiller
serviceAccountName: helm-tiller
如果這里的權限問題沒有處理好,安裝完成后會發現命令沒有權限,
root@master:/home/hzz# helm ls
Error: configmaps is forbidden: User "system:serviceaccount:kube-system:default" cannot list resource "configmaps" in API group "" in the namespace "kube-system"
可以通過helm reset -f
或者helm reset --force
強制刪除tiller容器后,使用正確的參數重新進行helm init
操作
3、驗證安裝
出現helm client 和server之后helm便安裝完成
root@master:/home/hzz# kubectl -n kube-system get pods|grep tiller-deploy
tiller-deploy-7d49974877-w78nz 1/1 Running 0 4h46m
root@master:/home/hzz# helm version
Client: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.14.0", GitCommit:"05811b84a3f93603dd6c2fcfe57944dfa7ab7fd0", GitTreeState:"clean"}
可執行helm list
查看K8S中已安裝的charts 。
二、使用
1、更換倉庫
# 先移除原先的倉庫
root@master:/home/hzz# helm repo remove stable
"stable" has been removed from your repositories
# 添加新的倉庫地址
root@master:/home/hzz# helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"stable" has been added to your repositories
# 更新倉庫
root@master:/home/hzz# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete.
2、查看可獲取的Chart
root@master:/home/hzz# helm search
NAME CHART VERSION APP VERSION DESCRIPTION
stable/acs-engine-autoscaler 2.1.3 2.1.1 Scales worker nodes within agent pools
stable/aerospike 0.1.7 v3.14.1.2 A Helm chart for Aerospike in Kubernetes
stable/anchore-engine 0.1.3 0.1.6 Anchore container analysis and policy evaluation engine s...
stable/artifactory 7.0.3 5.8.4 Universal Repository Manager supporting all major packagi...
stable/artifactory-ha 0.1.0 5.8.4 Universal Repository Manager supporting all major packagi...
stable/aws-cluster-autoscaler 0.3.2 Scales worker nodes within autoscaling groups.
stable/bitcoind 0.1.0 0.15.1 Bitcoin is an innovative payment network and a new kind o...
..................
這里有一篇思路更清晰的文章
參考:https://blog.csdn.net/bbwangj/article/details/81087911