[轉帖]Kubernetes中安裝Helm及使用

Kubernetes中安裝Helm及使用

版權聲明:本文爲博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連接和本聲明。
本文連接: https://blog.csdn.net/qq_35959573/article/details/80885052

Helm 致力於成爲 Kubernetes 的包管理工具,能夠方便地發現、共享和使用爲 Kubernetes 構建的應用,它包含幾個基本概念:node

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

Helm 採用客戶端/服務器架構,有以下組件組成:nginx

  • Helm CLI 是 Helm 客戶端,能夠在本地執行;
  • Tiller 是服務器端組件,在 Kubernetes 羣集上運行,並管理 Kubernetes 應用程序的生命週期 ;
  • Repository 是 Chart 倉庫,Helm客戶端經過HTTP協議來訪問倉庫中Chart的索引文件和壓縮包

Helm工做原理:git

Helm把Kubernetes資源(好比deployments、services或 ingress等) 打包到一個chart中,而chart被保存到chart倉庫。經過chart倉庫可用來存儲和分享chart。Helm使發佈可配置,支持發佈應用配置的版本管理,簡化了Kubernetes部署應用的版本控制、打包、發佈、刪除、更新等操做github

Helm客戶端:web

Helm客戶端是一個命令行工具,負責管理charts、reprepository和release。它經過gPRC API(使用kubectl port-forward將tiller的端口映射到本地,而後再經過映射後的端口跟tiller通訊)向tiller發送請求,並由tiller來管理對應的Kubernetes資源數據庫

Tiller服務端:api

Tiller接收來自Helm客戶端的請求,並把相關資源的操做發送到Kubernetes,負責管理(安裝、查詢、升級或刪除等)和跟蹤Kubernetes資源。爲了方便管理,tiller把release的相關信息保存在kubernetes的ConfigMap中服務器

2、Helm 客戶端安裝

從官網下載最新版本的二進制安裝包到本地:https://github.com/kubernetes/helm/releasesmarkdown

解壓安裝:架構

# 解壓壓縮包
tar -zxvf helm-2.9.0.tar.gz
# 把 helm 指令放到bin目錄下
mv helm-2.9.0/helm /usr/local/bin/helm

# 驗證
helm help
3、Helm 服務端安裝

在 Kubernetes 中安裝 Tiller 服務,可選鏡像:registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1(阿里雲)

1)先在 K8S 集羣上每一個節點安裝 socat 軟件,否則會報以下錯誤:

E0522 22:22:15.492436   24409 portforward.go:331] an error occurred forwarding 38398 -> 44134: error forwarding port 44134 to pod dc6da4ab99ad9c497c0cef1776b9dd18e0a612d507e2746ed63d36ef40f30174, uid : unable to do port forwarding: socat not found.
Error: cannot connect to Tiller
# YUM 安裝(每一個節點都要安裝)
yum install -y socat 

 

2)安裝服務端(Tiller)

注意 這裏面的 helm version 要與 tiller 後面的tag 已知起來
注意 init 以後能夠先查看一下deployment 有沒有 pod的建立 時間可能會挺長的 還須要pull images

# 建立服務端 helm init
--service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts # 建立TLS認證服務端,參考地址:https://github.com/gjmzj/kubeasz/blob/master/docs/guide/helm.md helm init --service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1 --tiller-tls-cert /etc/kubernetes/ssl/tiller001.pem --tiller-tls-key /etc/kubernetes/ssl/tiller001-key.pem --tls-ca-cert /etc/kubernetes/ssl/ca.pem --tiller-namespace kube-system --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

 

遇到錯誤 failed to list: configmaps is forbidden: User 「system:serviceaccount:kube-system:default」 cannot list configmaps in the namespace 「kube-system」

執行如下命令建立 serviceaccount tiller 而且給它集羣管理權限

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 版本信息
helm version

Client: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}

# 查看 pod 運行狀況
kubectl get pod -o wide --all-namespaces

NAMESPACE     NAME                             READY     STATUS    RESTARTS   AGE       IP            NODE
kube-system   tiller-deploy-59c7578f9b-28kb9   1/1       Running   0          16s       172.20.0.41   192.168.80.231

 

4、Helm 使用

1)更換倉庫:

若遇到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

 

2)查看在存儲庫中可用的全部 Helm charts:

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 evaluatio...
stable/artifactory              7.0.3           5.8.4           Universal Repository Manager supporting all maj...
stable/artifactory-ha           0.1.0           5.8.4           Universal Repository Manager supporting all maj...
stable/aws-cluster-autoscaler   0.3.2                           Scales worker nodes within autoscaling groups.
... ...

 

3)更新charts列表:

helm repo update

 

4)安裝charts:

Monocular是一個開源軟件,用於管理kubernetes上以Helm Charts形式建立的服務,能夠經過它的web頁面來安裝helm Charts

安裝Nginx Ingress controller,安裝的k8s集羣啓用了RBAC,則必定要加rbac.create=true參數

 
  

安裝Monocular:

# 添加新的源
helm repo add monocular https://kubernetes-helm.github.io/monocular
# 安裝
helm install monocular/monocular -f custom-repos.yaml

# custom-repos.yaml 內容
cat 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

 

5)查看K8S中已安裝的charts:

helm list

NAME                REVISION    UPDATED                     STATUS      CHART               NAMESPACE
amber-seal          1           Mon Jul  2 17:29:25 2018    DEPLOYED    nginx-ingress-0.9.5 default  
my-release          1           Mon Jul  2 15:19:44 2018    DEPLOYED    spark-0.1.10        default  
nonplussed-panther  1           Mon Jul  2 17:27:41 2018    FAILED      nginx-ingress-0.9.5 default  
turbulent-tuatara   1           Mon Jul  2 17:31:33 2018    DEPLOYED    monocular-0.6.2     default

 

6)刪除安裝的charts:

# 刪除:helm delete xxx
helm delete amber-seal

 

5、卸載 Helm 服務端

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

helm reset 或
helm reset --force

參考地址:https://github.com/gjmzj/kubeasz/blob/master/docs/guide/helm.md 
     http://www.javashuo.com/article/p-vhazzjbn-ce.html 
     https://blog.csdn.net/luanpeng825485697/article/details/80873236

相關文章
相關標籤/搜索