Kubernetes實戰總結 - Helm部署(v3.1.1)


什么是Helm?

Helm 是 Kubernetes 的軟件包管理器,用來簡化 Kubernetes 應用的部署和管理。

Helm 和 Kubernetes 的關系,就好比 yum 和 CentOS,apt-get 和 Ubuntu 的關系。

Helm2 主要分為客戶端 helm 和服務端 tiller,但最新發行 Helm3 已經移除了 tiller。

Helm
Helm 是一個命令行下的客戶端工具。主要用於 Kubernetes 應用程序 Chart 的創建、打包、發布以及創建和管理本地和遠程的 Chart 倉庫。

Tiller
Tiller 是 Helm 的服務端,部署在 Kubernetes 集群中。Tiller 用於接收 Helm 的請求,並根據 Chart 生成 Kubernetes 的部署文件( Helm 稱為 Release ),然后提交給 Kubernetes 創建應用。Tiller 還提供了 Release 的升級、刪除、回滾等一系列功能。

Chart
包含了創建Kubernetes的一個應用實例的必要信息,Helm 的軟件包,采用 TAR 格式。類似於 APT 的 DEB 包或者 YUM 的 RPM 包,其包含了一組定義 Kubernetes 資源相關的 YAML 文件。

Repoistory
Helm 的軟件倉庫,Repository 本質上是一個 Web 服務器,該服務器保存了一系列的 Chart 軟件包以供用戶下載,並且提供了一個該 Repository 的 Chart 包的清單文件以供查詢。Helm 可以同時管理多個不同的 Repository。

Release
是一個 chart 及其配置的一個運行實例,使用 helm install 命令在 Kubernetes 集群中部署的 Chart 稱為 Release。
Helm主要概念說明

注意:雖然helm比較好用,但新手不建議使用,因為快捷的部署管理不利於你對應用結構的理解。當然,如果你只是短期使用,不追求深層的掌握,helm是個不錯的選擇。

 


怎么安裝Helm2?

官方地址:https://helm.sh/docs/intro/install/,其中介紹了很多種部署方式,最常用的就是二進制方式。

 

首先下載二進制文件 helm-v2.16.3,執行以下命令。

tar -zxvf helm-v2.16.3-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm chmod a+x /usr/local/bin/helm 

 

最后我們還需要安裝服務端tiller,首先創建rbac訪問控制yaml文件。

# tiller-rbac.yaml

apiVersion: v1 kind: ServiceAccount metadata: name: tiller namespace: kube
-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: tiller namespace: kube-system

 

然后執行命令部署,初始化。

kubectl apply -f tiller-rbac.yaml
helm init --service-account tiller --skip-refresh

 

因為默認使用的grc.io庫,如果網絡不好,可以更改鏡像源(這是我的阿里雲鏡像地址,版本有限,部署其他版本請自行搜索更換)。

kubectl -n kube-system set image deployment/tiller-deploy tiller=registry.cn-shanghai.aliyuncs.com/leozhanggg/helm/tiller:v2.16.3

 

最后驗證是否部署成功。 

helm version
Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}

 

如果你還是覺得有點麻煩,我們可以編寫shell腳本,把整個流程串起來:

#!/bin/sh
# creator: zhangfan
# up-date: 2020/04/10
# description: one key deploy.

tag="v2.16.3"
helm_path="/usr/local/bin"
tiller_image="registry.cn-shanghai.aliyuncs.com/leozhanggg/helm/tiller:${tag}"

echo "Intall helm to ${helm_path}"
cp helm ${helm_path}
chmod a+x ${helm_path}/helm
echo

echo "helm init..."
kubectl apply -f tiller-rbac.yaml
helm init --service-account tiller --skip-refresh
sleep 3
echo

echo "set image to ${tiller_image}"
kubectl -n kube-system set image deployment/tiller-deploy tiller=${tiller_image}
until helm version 2>/dev/null ; do 
  echo "Warning: Waiting for completion or termination."
  echo
  sleep 5
done

echo "Successfully deployed!!!"

 

 這樣我們只需要創建文件install.sh和rbac.yaml,然后放到Helm-2.16.3版本內執行腳本就可以了。

[root@k8s-32 helm-2.16.3]# ls
install.sh helm LICENSE README.md tiller tiller-rbac.yaml
[root@k8s-32 helm-2.16.3]# sh install.sh
Intall helm to /usr/local/bin

helm init...
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created
$HELM_HOME has been configured at /root/.helm.
Warning: Tiller is already installed in the cluster.
(Use --client-only to suppress this message, or --upgrade to upgrade Tiller to the current version.)

set image to registry.cn-shanghai.aliyuncs.com/leozhanggg/helm/tiller:v2.16.3
deployment.apps/tiller-deploy image updated
Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Warning: Waiting for completion or termination.

Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Warning: Waiting for completion or termination.

Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Warning: Waiting for completion or termination.

Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Successfully deployed!!!

 

 


怎么安裝Helm3?

由於helm3移除了tiller,所以安裝起來就簡單多了,首先下載二進制文件 helm-v3.1.1,然后執行以下命令即可。

tar -zxvf helm-v3.1.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
chmod a+x /usr/local/bin/helm 

helm version
version.BuildInfo{Version:"v3.1.1", GitCommit:"afe70585407b420d0097d07b21c47dc511525ac8", GitTreeState:"clean", GoVersion:"go1.13.8"}

 

Helm3 新特性

Helm3 默認不包含任何存儲庫,所以你首先需要添加存儲庫,可從這里查詢 https://hub.helm.sh

Helm3 引入了新的 Chart(v2) 版本,該版本比Helm2版本的 Chart(v1)更緊湊, 曾經分散在多個元數據文件中的信息現已全部收集到Chart.yaml中。

不過大多數 Helm2 版本的 Chart 依然可以在 Helm3 中使用。以下是一些改變示例:

  • -n 標志從別名 name 更改為 --namespace。
  • Template中刪除一些很少使用的靜態變量,例如 .Release.Time。
  • 不再支持 crd-install 鈎子,改用 crds/ 文件夾。

 

 


其他

  【問題一】Error: error installing: the server could not find the requested resource

    問題回顧:kubernetes-1.17.4集群,安裝helm-2.13.1,進行helm init報錯

    解決方案:這是由於版本兼容性問題,安裝較新的版本helm-2.16.3問題解決

 

 

作者:Leozhanggg

出處:https://www.cnblogs.com/leozhanggg/p/12679869.html

本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM