helm使用

前言

类似于 Linux 的 YUM、APT,Helm 是 K8S 的包管理工具。

Helm, 一个二进制工具,用来安装、升级、卸载 K8S 中的应用程序。

Helm Chart,一个 tgz 包,类似安卓的 APK。

K8S 应用打包成 Chart,通过 Helm 安装到 K8S 集群中。

一、安装Helm

用二进制版本安装

每个Helm 版本都提供了各种操作系统的二进制版本,这些版本可以手动下载和安装。

下载 需要的版本

复制代码
wget https://repo.huaweicloud.com/helm/v3.5.4/helm-v3.5.4-linux-amd64.tar.gz

解压

复制代码
tar -zxvf helm-v3.5.4-linux-amd64.tar.gz

在解压目录中找到helm程序,移动到需要的目录中

复制代码
mv linux-amd64/helm /usr/local/bin/helm

然后就可以执行客户端程序并 添加稳定仓库: helm help

二、配置helm

微软仓库(http://mirror.azure.cn/kubernetes/charts/)

阿里云仓库(https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

推荐仓库(https://charts.bitnami.com/bitnami

添加仓库 :helm repo add 自定义仓库名 仓库地址 (仓库地址就是上面几个网站地址)

复制代码
[root@k8s-master-136 samve]# helm repo add apphub https://charts.bitnami.com/bitnami

删除仓库 : helm repo remove 仓库名

更新仓库 : helm repo update

查看仓库 : helm repo list

搜索仓库的chart: helm search repo chart名称

三、使用helm快速部署一个应用

使用搜索命令搜索应用

helm search repo 应用名称

复制代码
[root@k8s-master-136 samve]# helm search repo nginx
NAME                            CHART VERSION   APP VERSION     DESCRIPTION                                       
apphub/nginx                    15.3.3          1.25.2          NGINX Open Source is a web server that can be a...
apphub/nginx-ingress-controller 9.9.0           1.9.0           NGINX Ingress Controller is an Ingress controll...
apphub/nginx-intel              2.1.15          0.4.9           DEPRECATED NGINX Open Source for Intel is a lig...

根据搜索内容选择安装

helm install 安装后应用的名称 搜索之后应用的名称

复制代码
[root@k8s-master-136 samve]# helm install my-nginx apphub/nginx
NAME: my-nginx
LAST DEPLOYED: Thu Oct 12 22:16:31 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 15.3.3
APP VERSION: 1.25.2

** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:

    my-nginx.default.svc.cluster.local (port 80)

To access NGINX from outside the cluster, follow the steps below:

1. Get the NGINX URL by running these commands:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w my-nginx'

    export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-nginx)
    export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo "http://${SERVICE_IP}:${SERVICE_PORT}"

查看安装之后的状态

helm list

复制代码
[root@k8s-master-136 samve]# helm list
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
my-nginx        default         1               2023-10-12 22:16:31.191334159 +0800 CST deployed        nginx-15.3.3            1.25.2     
nginx           default         1               2023-10-12 21:52:49.36634682 +0800 CST  deployed        nginx-intel-2.1.15      0.4.9   

helm status 安装之后应用的名称

复制代码
[root@k8s-master-136 samve]# helm status my-nginx
NAME: my-nginx
LAST DEPLOYED: Thu Oct 12 22:16:31 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 15.3.3
APP VERSION: 1.25.2

** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:

    my-nginx.default.svc.cluster.local (port 80)

To access NGINX from outside the cluster, follow the steps below:

1. Get the NGINX URL by running these commands:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w my-nginx'

    export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-nginx)
    export SERVICE_IP=$(kubectl get svc --namespace default my-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo "http://${SERVICE_IP}:${SERVICE_PORT}"

当然我们也可以通过kubectl命令查看相关的pod是否创建成功

复制代码
[root@k8s-master-136 samve]# kubectl get svc,pod
NAME                        TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/kubernetes          ClusterIP      10.10.0.1       <none>        443/TCP                      258d
service/my-nginx            LoadBalancer   10.10.200.7     <pending>     80:32374/TCP                 9m37s
service/nginx               NodePort       10.10.183.194   <none>        80:30111/TCP                 258d
service/nginx-nginx-intel   LoadBalancer   10.10.72.168    <pending>     80:32756/TCP,443:30799/TCP   33m

NAME                                     READY   STATUS             RESTARTS   AGE
pod/my-nginx-8568bb4694-gn5b7            1/1     Running            0          9m37s
pod/nginx-2-69947fd9df-plct2             1/1     Running            2          47h
pod/nginx-6799fc88d8-2jh5z               1/1     Running            2          47h
pod/nginx-nginx-intel-668b58fb4b-8cm6z   0/1     ImagePullBackOff   0          33m
pod/nginx1-b7fb675cb-rhtvn               0/1     CrashLoopBackOff   50         47h
pod/nginx2-74ff6c9fbc-2gb7r              0/1     CrashLoopBackOff   50         47h

四、自定义chart

自定义选项是因为并不是所有的 chart 都能按照默认配置运行成功,可能会需要一些环境 依赖,例如 PV。 所以我们需要自定义 chart 配置选项,安装过程中有两种方法可以传递配置数据:

  • --values(或-f):指定带有覆盖的 YAML 文件。这可以多次指定,最右边的文件 优先
  • --set:在命令行上指定替代。如果两者都用,--set 优先级高

第一步:使用命令创建chart

helm create chart名称

复制代码
[root@k8s-master-136 samve]# helm create mychart
Creating mychart

[root@k8s-master-136 samve]# ls mychart/
charts  Chart.yaml  templates  values.yaml
[root@k8s-master-136 samve]# cd mychart/
[root@k8s-master-136 mychart]# ls -al
总用量 16
drwxr-xr-x   4 root  root    93 10月 12 22:33 .
drwx------. 17 samve samve 4096 10月 12 22:33 ..
drwxr-xr-x   2 root  root     6 10月 12 22:33 charts
-rw-r--r--   1 root  root  1143 10月 12 22:33 Chart.yaml
-rw-r--r--   1 root  root   349 10月 12 22:33 .helmignore
drwxr-xr-x   3 root  root   162 10月 12 22:33 templates
-rw-r--r--   1 root  root  1899 10月 12 22:33 values.yaml
  • charts:普通文件夹,刚开始创建为空;
  • Chart.yaml:用于配置当前chart的属性信息,可以作为全局变量提供给模板文件使用;
  • templates:目标信息文件,里面有很多的yaml模板文件,我们使用helm创建应用相当于helm帮我去执行这些yaml文件了;
  • values.yaml:全局变量文件,提供给templates里面的yaml文件用。

因为我们需要自己自定义chart,因此我们可以修改这些yaml文件,也可以删除这些默认生成的yaml文件,然后自己重新写。

相关推荐
幻灭行度14 小时前
CKA考试知识点分享(16)---cri-dockerd
kubernetes
IguoChan18 小时前
8. Redis Operator (1) —— 单机部署
kubernetes
dsd233320 小时前
K8S 专栏 —— Pod 篇
docker·容器·kubernetes
风清再凯1 天前
k8s的开篇学习和安装
学习·容器·kubernetes
listhi5201 天前
k8s使用私有harbor镜像源
java·docker·kubernetes
程序员阿超的博客1 天前
云原生核心技术 (9/12): K8s 实战:如何管理应用的配置 (ConfigMap/Secret) 与数据 (Volume)?
云原生·容器·kubernetes
ahhhhaaaa-2 天前
【k8s】阿里云ACK服务中GPU实例部署问题
阿里云·云原生·容器·kubernetes·云计算
955.2 天前
k8s从入门到放弃之k3s轻量级
云原生·容器·kubernetes