1. 程式人生 > >kubernetes學習筆記之十四:helm入門

kubernetes學習筆記之十四:helm入門

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
[[email protected]01 ~]# wget https://storage.googleapis.com/kubernetes-helm/helm-v2.12.1-linux-amd64.tar.gz  #如何無法科學上網可以從我的網盤中下載 連結: (
https://pan.baidu.com/s/1XmVnCMmNVOf1puRqgoqdXw
提取碼: 44s1)
[[email protected]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 [[email protected]-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 [[email protected]-01 linux-amd64]# cp helm /usr/bin/ #下載解壓完成後,直接將helm執行檔案放入PATH環境變數中就可以使用了 [[email protected]-01 linux-amd64]# helm -h
2.安裝 tiller

由於tiller需要安裝、刪除等操作pod的許可權,所以要為tiller設定相應的許可權,許可權可以分為叢集級別或名稱空間級別

配置文件:https://github.com/helm/helm/blob/master/docs/rbac.md

[[email protected]01 ~]# mkdir manifests
[[email protected]-01 ~]# cd manifests/
[[email protected]-01 manifests]# ll
總用量 0
[[email protected]-01 manifests]# mkdir helm
[[email protected]-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
[[email protected]-01 manifests]# kubectl apply -f tiller-rbac.yaml 
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created
[[email protected]-01 manifests]# kubectl get sa -n kube-system |grep tiller  #確認是否建立成功
tiller                               1         57s
[[email protected]-01 manifests]# helm init --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!
[[email protected]-01 manifests]# kubectl get pod -n kube-system |grep tiller #檢視tiller的pod是否建立成功
tiller-deploy-7d898b45c4-knp4b      1/1     Running   0          2m
[[email protected]-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"}

檢視下載的包的資訊

[[email protected]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
[[email protected]-01 archive]# tar xf redis-1.1.15.tgz 
tar: redis/Chart.yaml:不可信的舊時間戳 1970-01-01 08:00:00  #時間戳告警可以忽略
.....
[[email protected]-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

專案地址:https://github.com/helm/helm

下載地址:https://github.com/helm/helm/releases/ 

helm官方網址:https://helm.sh/

helm chart官方網址:https://hub.kubeapps.com/  (chart分為stable和incubator兩類)