1. 程式人生 > 其它 >Kubernetes(K8S) helm 安裝

Kubernetes(K8S) helm 安裝

Helm 是一個 Kubernetes 的包管理工具, 就像 Linux 下的包管理器, 如 yum/apt 等, 可以很方便的將之前打包好的 yaml 檔案部署到 kubernetes 上。
Helm 有 3 個重要概念:

  • helm: 一個命令列客戶端工具, 主要用於 Kubernetes 應用 chart 的建立、 打包、 釋出和管理。
  • Chart: 應用描述, 一系列用於描述 k8s 資源相關檔案的集合。
  • Release: 基於 Chart 的部署實體, 一個 chart 被 Helm 執行後將會生成對應的一個release; 將在 k8s 中創建出真實執行的資源物件。

在部署微服務專案時,可能有幾十個服務,每個服務都有一套 yaml 檔案,需要維護大量 yaml 檔案,版本管理特別不方便
使用 helm 可以解決下列問題:

  • 可以把微服務中的幾十個 yaml 作為一個整體管理
  • 實現 yaml 高效複用
  • 應用級別的版本管理,當前V3,回滾到V2

helm 2019年 V3版本,變化項

  • V3 版本刪除 Tiller (架構變化)
  • Release 可以在不同名稱空間重用
  • 將 Chart 推送到 docker 倉庫中

安裝

https://helm.sh/
https://helm.sh/zh/docs/intro/install/

下載 helm 安裝壓縮包,上傳到 linux
解壓 helm,把目錄複製到 usr/bin 目錄中

[root@k8smaster ~]# cd /opt/k8s/
[root@k8smaster k8s]# tar zxfv helm-v3.0.0-linux-amd64.tar.gz 
linux-amd64/
linux-amd64/helm
linux-amd64/README.md
linux-amd64/LICENSE
[root@k8smaster k8s]# mv ./linux-amd64/helm /usr/bin/
# 顯示版本,安裝完成
[root@k8smaster k8s]# helm version
version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
[root@k8smaster k8s]# 

配置

新增倉庫

# 新增 倉庫
[root@k8smaster ~]# helm repo add stable http://mirror.azure.cn/kubernetes/charts
"stable" has been added to your repositories
# 新增 阿里雲倉庫
[root@k8smaster ~]# helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"aliyun" has been added to your repositories
# 檢視
[root@k8smaster ~]# helm repo list
NAME    URL
stable  http://mirror.azure.cn/kubernetes/charts
aliyun  https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
# 更新
[root@k8smaster ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "aliyun" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈ 
# 刪除阿里雲
[root@k8smaster ~]# helm repo remove aliyun
"aliyun" has been removed from your repositories
[root@k8smaster ~]# helm repo list
NAME    URL
stable  http://mirror.azure.cn/kubernetes/charts
[root@k8smaster ~]# 

部署應用

# 查詢 chart
[root@k8smaster ~]# helm search repo weave
NAME                    CHART VERSION   APP VERSION     DESCRIPTION                                       
stable/weave-cloud      0.3.9           1.4.0           DEPRECATED - Weave Cloud is a add-on to Kuberne...
stable/weave-scope      1.1.12          1.12.0          DEPRECATED - A Helm chart for the Weave Scope c...
# 檢視 chrt 資訊
[root@k8smaster ~]# helm show chart stable/weave-scope
apiVersion: v1
appVersion: 1.12.0
deprecated: true
description: DEPRECATED - A Helm chart for the Weave Scope cluster visualizer.
home: https://www.weave.works/oss/scope/
icon: https://avatars1.githubusercontent.com/u/9976052?s=64
keywords:
- containers
- dashboard
- monitoring
name: weave-scope
sources:
- https://github.com/weaveworks/scope
version: 1.1.12
# 安裝,名字叫 ui
[root@k8smaster ~]# helm install ui stable/weave-scope
NAME: ui
LAST DEPLOYED: Mon Nov 28 13:15:05 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:

kubectl -n default port-forward $(kubectl -n default get endpoints \
ui-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040

then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:

https://www.weave.works/docs/scope/latest/introducing/
# 檢視列表
[root@k8smaster ~]# helm list
NAME    NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
ui      default         1               2022-11-28 13:15:05.404335352 +0800 CST deployed        weave-scope-1.1.12      1.12.0 # 檢視釋出狀態
[root@k8smaster ~]# helm status ui
NAME: ui
LAST DEPLOYED: Mon Nov 28 13:15:05 2022
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:

kubectl -n default port-forward $(kubectl -n default get endpoints \
ui-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040

then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:

https://www.weave.works/docs/scope/latest/introducing/
# 檢視服務 當前是不暴露埠的
[root@k8smaster ~]# kubectl get svc
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
javademo1        NodePort    10.106.43.46   <none>        8111:31452/TCP   40d
kubernetes       ClusterIP   10.96.0.1      <none>        443/TCP          45d
nginx            NodePort    10.103.87.81   <none>        80:30339/TCP     45d
nginx-nfs        NodePort    10.99.84.9     <none>        80:30205/TCP     19d
ui-weave-scope   ClusterIP   10.101.4.212   <none>        80/TCP           3m19s
# 修改 ui-weave-scpoe 暴露埠
[root@k8smaster ~]# kubectl edit svc ui-weave-scope
#  type: ClusterIP =>  改成 type: NodePort
service/ui-weave-scope edited
# 再次檢視,暴露了 30690 埠
[root@k8smaster ~]# kubectl get svc
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
javademo1        NodePort    10.106.43.46   <none>        8111:31452/TCP   40d
kubernetes       ClusterIP   10.96.0.1      <none>        443/TCP          45d
nginx            NodePort    10.103.87.81   <none>        80:30339/TCP     45d
nginx-nfs        NodePort    10.99.84.9     <none>        80:30205/TCP     19d
ui-weave-scope   NodePort    10.101.4.212   <none>        80:30690/TCP     5m26s
# 刪除 ui-weave-scope
[root@k8smaster ~]# kubectl delete deployment ui-weave-scope
[root@k8smaster ~]# kubectl delete svc ui-weave-scope

測試