1.Helm的簡介
Helm是Kubernetes的一個包管理工具,用來簡化Kubernetes應用的部署和管理。可以把Helm比作CentOS的yum工具。 Helm有如下幾個基本概念:
Chart: 是Helm管理的安裝包,里面包含需要部署的安裝包資源。可以把Chart比作CentOS yum使用的rpm文件。每個Chart包含下面兩部分:
1.包的基本描述文件Chart.yaml
2.放在templates目錄中的一個或多個Kubernetes manifest文件模板
Release:是chart的部署實例,一個chart在一個Kubernetes集群上可以有多個release,即這個chart可以被安裝多次
Repository:chart的倉庫,用於發布和存儲chart
使用Helm可以完成以下事情:
1.管理Kubernetes manifest files
2.管理Helm安裝包charts
3.基於chart的Kubernetes應用分發
二、Helm的組成
Helm由兩部分組成,客戶端helm和服務端tiller。 1.tiller運行在Kubernetes集群上,管理chart安裝的release 2.helm是一個命令行工具,可在本地運行,一般運行在CI/CD Server上。
三、安裝helm和tiller
1.下載helm
[root@master-01 ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.12.1-linux-amd64.tar.gz #如何無法科*學*上*網可以從我的網盤中下載 鏈接: (https://pan.baidu.com/s/1XmVnCMmNVOf1puRqgoqdXw 提取碼: 44s1)
[root@master-01 ~]# tar xf helm-v2.12.1-linux-amd64.tar.gz 總用量 32508
-rw-------. 1 root root 2002 2018-12-28 14:02 anaconda-ks.cfg -rw-r--r-- 1 root root 22719794 2019-01-03 21:55 helm-v2.12.1-linux-amd64.tar.gz drwxr-xr-x 2 root root 64 2018-12-20 07:11 linux-amd64 [root@master-01 linux-amd64]# ll 總用量 71644
-rwxr-xr-x 1 root root 36844864 2018-12-20 07:09 helm -rw-r--r-- 1 root root 11343 2018-12-20 07:11 LICENSE -rw-r--r-- 1 root root 3138 2018-12-20 07:11 README.md -rwxr-xr-x 1 root root 36495968 2018-12-20 07:11 tiller [root@master-01 linux-amd64]# cp helm /usr/bin/ #下載解壓完成后,直接將helm執行文件放入PATH環境變量中就可以使用了 [root@master-01 linux-amd64]# helm -h
2.安裝 tiller
由於tiller需要安裝、刪除等操作pod的權限,所以要為tiller設置相應的權限,權限可以分為集群級別或名稱空間級別
配置文檔:https://github.com/helm/helm/blob/master/docs/rbac.md
[root@master-01 ~]# mkdir manifests [root@master-01 ~]# cd manifests/ [root@master-01 manifests]# ll 總用量 0 [root@master-01 manifests]# mkdir helm [root@master-01 manifests]# cat tiller-rbac.yaml #創建tiller的rbac配置文件 apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: tiller namespace: kube-system [root@master-01 manifests]# kubectl apply -f tiller-rbac.yaml serviceaccount/tiller created clusterrolebinding.rbac.authorization.k8s.io/tiller created [root@master-01 manifests]# kubectl get sa -n kube-system |grep tiller #確認是否創建成功 tiller 1 57s [root@master-01 manifests]# helm init --service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.12.1 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts #由於牆的原因,所以我們使用阿里的chart倉庫,注意指定的tiller版本需要和helm版本一致
$HELM_HOME has been configured at /root/.helm.
Tiller (the Helm server-side component) has been upgraded to the current version.
Happy Helming!
[root@master-01 manifests]# kubectl get pod -n kube-system |grep tiller #查看tiller的pod是否創建成功
tiller-deploy-7d898b45c4-knp4b 1/1 Running 0 2m
[root@master-01 manifests]# helm version
Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
可能遇到的報錯:
E0224 14:13:16.077226 7416 portforward.go:331] an error occurred forwarding 37271 -> 44134: error forwarding port 44134 to pod 76a7312e49220a229e443546a4b32d3e0406f09fd9b3646b3d30f6833e121375, uid : unable to do port forwarding: socat not found. Error: cannot connect to Tiller
解決方法:
在所有節點和vip服務器上安裝socat
yum -y install socat
如果只安裝helm客戶端,執行以下操作:
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.12.1-linux-amd64.tar.gz #下載安裝包 helm init --client-only --stable-repo-url https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts/ #使用--client-only 參數
四、常用命令
查看下載的包的信息
[root@master-01 manifests]# ll ~/.helm/cache/archive/ #helm下載的包路徑 總用量 8
-rw-r--r-- 1 root root 6189 2019-01-03 23:16 redis-1.1.15.tgz [root@master-01 archive]# tar xf redis-1.1.15.tgz tar: redis/Chart.yaml:不可信的舊時間戳 1970-01-01 08:00:00 #時間戳告警可以忽略 ..... [root@master-01 archive]# tree redis redis ├── Chart.yaml #描述當前chart有哪些屬性信息 ├── README.md #自述文件 ├── templates #模板文件目錄 │ ├── deployment.yaml #模板文件,之所以叫做模板文件是因為文件中大量使用了go語言模板 │ ├── _helpers.tpl │ ├── networkpolicy.yaml │ ├── NOTES.txt │ ├── pvc.yaml │ ├── secrets.yaml │ └── svc.yaml └── values.yaml #定義默認值 1 directory, 10 files
其他:
[root@master-01 ~]# helm -h [root@k8s-master templates]# helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator #添加一個repo倉庫,名稱為incubator [root@k8s-master templates]# helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts [root@k8s-master templates]# helm repo remove stable #刪除一個倉庫,名稱為stable [root@k8s-master templates]# helm repo list #顯示所有的倉庫列表 [root@k8s-master templates]# helm repo update [root@k8s-master templates]# helm search elasticsearch #搜索一個chart [root@k8s-master templates]# helm fetch incubator/elasticsearch #下載一個chart並解壓到本地 [root@k8s-master archive]# cd /root/.helm/cache/archive [root@k8s-master archive]# ll
查看詳細命令幫助: https://docs.helm.sh/helm/#helm
項目地址:https://github.com/helm/helm
下載地址:https://github.com/helm/helm/releases/
官方文檔地址:https://docs.helm.sh/
helm官方網址:https://helm.sh/
helm chart官方網址:https://hub.kubeapps.com/