溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Helm安裝和使用

發(fā)布時(shí)間:2020-05-25 19:07:22 來源:網(wǎng)絡(luò) 閱讀:1815 作者:FJCA 欄目:云計(jì)算

一、 Helm簡(jiǎn)介

Helm是Kubernetes首選的包管理工具,在K8S中一個(gè)應(yīng)用可能多個(gè)YAML清單文件,當(dāng)應(yīng)用很多時(shí)這些清單文件就會(huì)顯得很亂。Helm便能很好解決這種問題,Helm charts可以為K8S YAML清單文件提供模板語法,而且可以實(shí)現(xiàn)應(yīng)用的一鍵部署、更新、回滾、刪除等等。
Helm只是客戶端,服務(wù)端是Tiller,具體架構(gòu)如下:
Helm安裝和使用
相關(guān)術(shù)語:

Helm 命令行客戶端。
Tiller 服務(wù)端,部署在K8S集群中,負(fù)責(zé)監(jiān)聽Helm的請(qǐng)求、與K8S apiserver交互,實(shí)現(xiàn)應(yīng)用的應(yīng)用部署、更新等一系列操作。
Repository  chart倉庫,是一個(gè)http/https服務(wù)器。
Chart 安裝包,由一系列的清單文件組成。
Release chart部署到K8S后的實(shí)例。

二、 軟件環(huán)境

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

三、 安裝配置Helm

1. 二進(jìn)制方式部署

倉庫地址:
https://github.com/helm/helm/releases
#根據(jù)需要下載對(duì)應(yīng)版本
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配置授權(quán)帳號(hào)

#當(dāng)前Kubernetes集群?jiǎn)⒂昧薘BAC,為tiller配置指定授權(quán)帳號(hào):

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后查看創(chuàng)建結(jié)果

[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. 安裝服務(wù)端Tiller

#helm init

[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初始化默認(rèn)使用gcr.io源,由于國(guó)內(nèi)正常無法訪問,所以這里使了用阿里源。
注意tiller版本要和helm版本相同。
#helm init參數(shù)說明

--service-account 指定授權(quán)帳號(hào)
-i 指定倉庫鏡像
--skip-refresh 禁止Tiller更新索引,一般用于離線安裝
--node-selectors 選擇節(jié)點(diǎn)標(biāo)簽,將Tiller pod部署在指定節(jié)點(diǎn)上
--override 更改Tiller deployment屬性值
--output 跳過安裝,并輸出到j(luò)son或yaml格式的清單文件中,可以用于kubectl手工安裝,該選項(xiàng)類似于kubectl的—dry-run

#查看創(chuàng)建pod

[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

四、 使用Helm

#創(chuàng)建本地chart,會(huì)在本地生成一個(gè)文件夾,里面包含chart所需的所有文件
helm create chart名稱 選項(xiàng) 
#helm倉庫增刪改查
helm repo add
helm repo list
helm repo lremove
helm repo update
#從倉庫中查找可用的chart,如果不指定將列出所有的chart
helm search
helm search mysql
#查看chart的詳細(xì)信息
helm inspect chart名稱
#將倉庫中的chart下載到本地保存為tar包
helm fetch chart名稱
#從chart安裝應(yīng)用
helm install chart名稱 選項(xiàng)
#查看當(dāng)前集群中部署的release
helm list
#查看release的狀態(tài)
helm status release名稱
#查看release歷史版本
helm history release名稱
#升級(jí)release
helm upgrade release名稱 chart名稱 選項(xiàng)
#回滾release
helm rollback release名稱 版本號(hào) 選項(xiàng)
#刪除release
helm delete release名稱 選項(xiàng)

參考:
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/

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI