Helm使用

Helm 基本概念

Helm 可以理解爲 Kubernetes 的包管理工具,可以方便地發現、共享和使用爲Kubernetes構建的應用,它包含幾個基本概念

  • Chart:一個 Helm 包,其中包含了運行一個應用所需要的鏡像、依賴和資源定義等,還可能包含 Kubernetes 集羣中的服務定義,類似 Homebrew 中的 formula,APT 的 dpkg 或者 Yum 的 rpm 文件,
  • Release: 在 Kubernetes 集羣上運行的 Chart 的一個實例。在同一個集羣上,一個 Chart 可以安裝很多次。每次安裝都會創建一個新的 release。例如一個 MySQL Chart,如果想在服務器上運行兩個數據庫,就可以把這個 Chart 安裝兩次。每次安裝都會生成自己的 Release,會有自己的 Release 名稱。
  • Repository:用於發佈和存儲 Chart 的倉庫。

Helm 組件

Helm 採用客戶端/服務器架構,有如下組件組成:
Helm CLI 是 Helm 客戶端,可以在本地執行;
Tiller 是服務器端組件,在 Kubernetes 羣集上運行,並管理 Kubernetes 應用程序的生命週期 ;
Repository 是 Chart 倉庫,Helm客戶端通過HTTP協議來訪問倉庫中Chart的索引文件和壓縮包。

安裝helm 客戶端

參考
https://github.com/kubernetes/helm/blob/master/docs/install.md?spm=5176.100239.blogcont159601.25.ee1b35eCYPzhZ&file=install.md
下載安裝helm

tar -zxvf helm-v2.8.0-rc.1-linux-amd64.tgz
mv linux-amd64/helm /usr/local/bin/helm
helm help

安裝helm服務端

因爲網絡原因,指定helm的repo爲阿里雲的https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
預先下載好了gcr.io/kubernetes-helm/tiller:v2.7.0鏡像。
遇到錯誤failed to list: configmaps is forbidden: User “system:serviceaccount:kube-system:default” cannot list configmaps in the namespace “kube-system”
執行以下命令創建serviceaccount tiller並且給它集羣管理權限,使用tiller的安裝helm服務端。

kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
helm init --service-account tiller --upgrade -i gcr.io/kubernetes-helm/tiller:v2.7.0 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

helm使用

若要查看在存儲庫中可用的所有 Helm charts,請鍵入以下命令:

helm search

若遇到Unable to get an update from the “stable” chart repository (https://kubernetes-charts.storage.googleapis.com) 錯誤
手動更換stable 存儲庫爲阿里雲的存儲庫

helm repo remove stable
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update
helm search

卸載helm服務端

執行命令,加–force強制卸載

helm reset 或
helm reset --force

安裝chart 管理UI monocular

Monocular是一個開源軟件,用於管理kubernetes上以Helm Charts形式創建的服務,可以通過它的web頁面來安裝helm Charts。
安裝Nginx Ingress controller
安裝的k8s集羣啓用了RBAC,則一定要加rbac.create=true參數。

helm install stable/nginx-ingress --set controller.hostNetwork=true,rbac.create=true

安裝Monocular

$ helm repo add monocular https://kubernetes-helm.github.io/monocular
$ helm helm install monocular/monocular -f custom-repos.yaml

custom-repos.yaml爲自己定義的chart repo源

cat ../../monocular/custom-repos.yaml
api:
  config:
    repos:
      - name: stable
        url: https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts
        source: https://github.com/kubernetes/charts/tree/master/stable
      - name: incubator
        url: https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator
        source: https://github.com/kubernetes/charts/tree/master/incubator
      - name: monocular
        url: https://kubernetes-helm.github.io/monocular
        source: https://github.com/kubernetes-helm/monocular/tree/master/charts

安裝中遇到的問題是如和給monocular cahrt中mongodb的PVC持久化存儲,這個就要依賴實踐中kubernetes的環境了,我使用的k8s環境使用ceph rbd存儲。我首先就要創建一個default storageclass給所以未明顯指定storageclass的PVC使用,然後手動創建rbd image,創建k8s pv綁定到rbd image上。這樣chart中pvc纔會綁定到pv上,使用ceph存儲。刪除chart的release後,還要手動回收pv。此外,chart中鏡像的下載也費勁。
monocular

目前的monocular只能使用chart的默認配置來部署chart的release,無法自定義配置值。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章