Helm安裝和使用

1、 Helm簡介

Helm是Kubernetes首選的包管理工具,在K8S中一個應用可能多個YAML清單文件,當應用不少時這些清單文件就會顯得很亂。Helm便能很好解決這種問題,Helm charts能夠爲K8S YAML清單文件提供模板語法,並且能夠實現應用的一鍵部署、更新、回滾、刪除等等。
Helm只是客戶端,服務端是Tiller,具體架構以下:
Helm安裝和使用
相關術語:node

Helm 命令行客戶端。
Tiller 服務端,部署在K8S集羣中,負責監聽Helm的請求、與K8S apiserver交互,實現應用的應用部署、更新等一系列操做。
Repository  chart倉庫,是一個http/https服務器。
Chart 安裝包,由一系列的清單文件組成。
Release chart部署到K8S後的實例。

2、 軟件環境

OS版本:Centos7.5
K8S版本:v1.14.0
Docker版本:18.09.5-ce
Helm版本:v2.13.1mysql

3、 安裝配置Helm

1. 二進制方式部署

倉庫地址:
https://github.com/helm/helm/releases
#根據須要下載對應版本
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.13.1-linux-amd64.tar.gz
tar zxf helm-v2.13.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/
#helm使用方法
helm help

2. 爲Tiller配置受權賬號

#當前Kubernetes集羣啓用了RBAC,爲tiller配置指定受權賬號:linux

cat <<EOF> tiller.yaml
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
EOF

apply後查看建立結果git

[root@k8s-master03]# kubectl get serviceaccount tiller -n kube-system -o wide
NAME     SECRETS   AGE
tiller   1         100s
[root@k8s-master03]# kubectl get clusterrolebinding tiller -o wide
NAME     AGE   ROLE                        USERS   GROUPS   SERVICEACCOUNTS
tiller   37s   ClusterRole/cluster-admin                    kube-system/tiller

3. 安裝服務端Tiller

#helm initgithub

[root@k8s-master03]# helm init --service-account tiller -i registry.aliyuncs.com/google_containers/tiller:v2.13.1 --skip-refresh
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.

helm初始化默認使用gcr.io源,因爲國內正常沒法訪問,因此這裏使了用阿里源。
注意tiller版本要和helm版本相同。
#helm init參數說明sql

--service-account 指定受權賬號
-i 指定倉庫鏡像
--skip-refresh 禁止Tiller更新索引,通常用於離線安裝
--node-selectors 選擇節點標籤,將Tiller pod部署在指定節點上
--override 更改Tiller deployment屬性值
--output 跳過安裝,並輸出到json或yaml格式的清單文件中,能夠用於kubectl手工安裝,該選項相似於kubectl的—dry-run

#查看建立podjson

[root@k8s-master03 ~]# kubectl get pods -n kube-system -l name=tiller                    
NAME                            READY   STATUS    RESTARTS   AGE
tiller-deploy-96f5d9ff4-ctswl   1/1     Running   0          45m

4、 使用Helm

#建立本地chart,會在本地生成一個文件夾,裏面包含chart所需的全部文件
helm create chart名稱 選項 
#helm倉庫增刪改查
helm repo add
helm repo list
helm repo lremove
helm repo update
#從倉庫中查找可用的chart,若是不指定將列出全部的chart
helm search
helm search mysql
#查看chart的詳細信息
helm inspect chart名稱
#將倉庫中的chart下載到本地保存爲tar包
helm fetch chart名稱
#從chart安裝應用
helm install chart名稱 選項
#查看當前集羣中部署的release
helm list
#查看release的狀態
helm status release名稱
#查看release歷史版本
helm history release名稱
#升級release
helm upgrade release名稱 chart名稱 選項
#回滾release
helm rollback release名稱 版本號 選項
#刪除release
helm delete release名稱 選項

參考:
helm安裝
https://helm.sh/docs/using_helm/#installing-helm
https://www.cnrancher.com/docs/rancher/v2.x/cn/installation/ha-install/helm-rancher/tcp-l4/helm-install/
helm命令詳解
https://helm.sh/docs/helm/api

相關文章
相關標籤/搜索