当前位置: 首页 > news >正文

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   33mNAME                                     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文件,然后自己重新写。 

http://www.lryc.cn/news/190595.html

相关文章:

  • Python in Visual Studio Code 2023年10月发布
  • Webmin远程命令执行漏洞复现报告
  • webstorm自定义文件模板(Vue + Scss)
  • 楔子-写在之前
  • 第 5 章 数组和广义表(稀疏矩阵的三元组顺序表存储实现)
  • 【RabbitMQ 实战】11 队列的结构和惰性队列
  • Python3-批量重命名指定目录中的一组文件,更改其扩展名
  • 渗透测试KAILI系统的安装环境(第八课)
  • 如何正确方便的理解双指针?力扣102 (二叉树的层序遍历)
  • Vue或uniapp引入自定义字体
  • ​力扣:LCR 122. 路径加密​ 题目:剑指Offer 05.替换空格(c++)
  • cJson堆内存释放问题
  • 论文阅读/写作扫盲
  • 一文拿捏对象内存布局及JMM(JAVA内存模型)
  • Android组件通信——ActivityGroup(二十五)
  • js的继承的方式
  • 聊聊HttpClient的重试机制
  • 北邮22级信通院数电:Verilog-FPGA(4)第三周实验:按键消抖、呼吸灯、流水灯 操作流程注意事项
  • Ghidra101再入门(上?)-Ghidra架构介绍
  • Vue3路由引入报错解决:无法找到模块“xxx.vue”的声明文件 xxx隐式拥有 “any“ 类型。
  • 基于若依ruoyi-nbcio支持flowable流程分类里增加流程应用类型
  • JS之同步异步promise、async、await
  • 【OpenCV • c++】自定义直方图 | 灰度直方图均衡 | 彩色直方图均衡
  • el-tree目录和el-table实现搜索定位高亮方法
  • linux常用指令
  • C语言,指针的一些运算
  • iPhone 如何强制重启
  • 数据结构--单链表操作
  • AlmaLinux (兼容centos)安装Geant4与ROOT
  • FPGA面试题(2)