helm 基本使用

Helm是Kubernetes的包管理器,類似于Python的pip centos的yum,主要用來管理 Charts
Helm Chart是用來封裝Kubernetes原生應(yīng)用程序的一系列YAML文件??梢栽谀悴渴饝?yīng)用的時(shí)候自定義應(yīng)用程序的一些Metadata,
以便于應(yīng)用程序的分發(fā)。對于應(yīng)用發(fā)布者而言,可以通過Helm打包應(yīng)用、管理應(yīng)用依賴關(guān)系、管理應(yīng)用版本并發(fā)布應(yīng)用到軟件倉庫。
對于使用者而言,使用Helm后不用需要編寫復(fù)雜的應(yīng)用部署文件,可以以簡單的方式在Kubernetes上查找、安裝、升級、回滾、卸載應(yīng)用程序
注意本文使用的helm 是v3.3.1

[root@master nginx]# helm version
version.BuildInfo{Version:"v3.3.1", GitCommit:"249e5215cde0c3fa72e27eb7a30e8d55c9696144", GitTreeState:"clean", GoVersion:"go1.14.7"}

是直接與k8s api互通 無需再helm init 創(chuàng)建服務(wù)端,
比較大的改動是,移除?Tiller(Helm 2?是一種?Client-Server?結(jié)構(gòu),客戶端稱為?Helm,服務(wù)器稱為?Tiller)。Helm 3?只有客戶端結(jié)構(gòu),客戶端仍稱為?Helm。如下圖所示,它的操作類似于?Helm 2?客戶端,但客戶端直接與?Kubernetes API?服務(wù)器交互
去除Tiller后關(guān)系圖如下


image.png

開始使用

#先添加常用的chart源
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com  
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo add aliyuncs https://apphub.aliyuncs.com

#查看chart列表
[root@master nginx]# helm repo list
NAME        URL                                                       
stable      https://kubernetes-charts.storage.googleapis.com          
incubator   https://kubernetes-charts-incubator.storage.googleapis.com
bitnami     https://charts.bitnami.com/bitnami                        
aliyuncs    https://apphub.aliyuncs.com 

安裝應(yīng)用 本人使用nginx作為例子,先看下都有哪些版本提供

[root@master nginx]# helm search repo nginx
NAME                                CHART VERSION   APP VERSION             DESCRIPTION                                       
aliyuncs/nginx                      5.1.5           1.16.1                  Chart for the nginx server                        
aliyuncs/nginx-ingress              1.30.3          0.28.0                  An nginx Ingress controller that uses ConfigMap...
aliyuncs/nginx-ingress-controller   5.3.4           0.29.0                  Chart for the nginx Ingress controller            
aliyuncs/nginx-lego                 0.3.1                                   Chart for nginx-ingress-controller and kube-lego  
aliyuncs/nginx-php                  1.0.0           nginx-1.10.3_php-7.0    Chart for the nginx php server                    
bitnami/nginx                       6.2.1           1.19.2                  Chart for the nginx server                        
bitnami/nginx-ingress-controller    5.5.1           0.35.0                  Chart for the nginx Ingress controller            
stable/nginx-ingress                1.41.3          v0.34.1                 DEPRECATED! An nginx Ingress controller that us...
stable/nginx-ldapauth-proxy         0.1.4           1.13.5                  nginx proxy with ldapauth                         
stable/nginx-lego                   0.3.1                                   Chart for nginx-ingress-controller and kube-lego  
bitnami/kong                        1.3.2           2.1.3                   Kong is a scalable, open source API layer (aka ...
stable/gcloud-endpoints             0.1.2           1                       DEPRECATED Develop, deploy, protect and monitor...

我們選擇aliyuncs/nginx 的chart包 先下載看看包有什么內(nèi)容

helm pull aliyuncs/nginx --untar #將nginx包從創(chuàng)庫拉到當(dāng)前目錄
#查看結(jié)構(gòu)
[root@master charts]# tree nginx/
nginx/
├── Chart.yaml
├── ci
│   └── values-with-ingress-metrics-and-serverblock.yaml
├── README.md
├── templates
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   ├── ingress.yaml
│   ├── NOTES.txt
│   ├── server-block-configmap.yaml
│   ├── servicemonitor.yaml
│   ├── svc.yaml
│   └── tls-secrets.yaml
├── values.schema.json
└── values.yaml

2 directories, 13 files

沒有安裝tree工具的可以

yum install tree 

有興趣的可以看看各個(gè)yaml文件的內(nèi)容,比較重要的是values.yaml

現(xiàn)在開始正式安裝nginx到我們的集群中
直接在線安裝aliyuncs/nginx,my-ngiinx為release名稱;service.type=NodePort表示將tomcat的service對外暴露端口的方式改為NodePort(缺省為LoadBalancer);persistence.enabled=false表示將不啟用持久化存儲卷,測試暫不需要使用這個(gè)

[root@master charts]# helm install my-nginx aliyuncs/nginx --set service.type=NodePort --set persistence.enabled=false
NAME: my-nginx
LAST DEPLOYED: Thu Sep 10 15:48:41 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Get the NGINX URL:

  export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services my-nginx)
  export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
  echo "NGINX URL: http://$NODE_IP:$NODE_PORT/"

查看是否安裝成功

[root@master charts]# kubectl get all
NAME                            READY   STATUS    RESTARTS   AGE
pod/my-nginx-5b69568b97-c7rbz   1/1     Running   0          59s

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
service/kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP                      24h
service/my-nginx     NodePort    10.98.148.75   <none>        80:32218/TCP,443:30893/TCP   59s

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/my-nginx   1/1     1            1           59s

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/my-nginx-5b69568b97   1         1         1       59s

從列表中是可以看到my-nginx的 我們直接訪問
http://192.168.0.158:32218/
http://192.168.0.159:32218/
http://192.168.0.160:32218/


image.png

image.png

image.png

通過k8s我們知道本集群上是只有三個(gè)節(jié)點(diǎn)的

[root@master charts]# kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
master   Ready    master   25h   v1.19.0
node1    Ready    <none>   24h   v1.19.0
node2    Ready    <none>   24h   v1.19.0
[root@master charts]# cat /etc/hosts
127.0.0.1   localhost master
::1         localhost master

192.168.0.158 master
192.168.0.159 node1
192.168.0.160 node2

三個(gè)節(jié)點(diǎn)都通了,說明應(yīng)用my-nginx 安裝成功
helm管理k8s的軟件的確比較方便

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容