Kubernetes包管理工具helm
·
华子目录
为什么要用helm
- 在早期的
Linux系统中,维护和安装软件包是⼀件极其麻烦的事情。为了安装⼀个应⽤程序,我们需要使⽤到编译的⽅式,⽽编译软件包,⾸先有⼀定的技术⻔槛,同时对于⼀些⽐较挑剔的应⽤程序,它可能在编译过程中对内核版本或系统环境有特定的要求。为了解决这个问题,就引⼊了包管理⼯具rpm,虽然rpm能在⼀定程度上减轻安装应⽤的压⼒,但任然会⾯临应⽤程序间依赖关系的困扰。直到后来yum的出现,我们才能轻松地解决依赖关系,实现⼀键安装应⽤程序 - 然⽽,当我们将
应⽤迁移到Kubernetes系统时,我们部署应⽤通常需要编写⼀份配置清单⽂件。⽽每个清单⽂件都对应集群中的⼀个资源,如Deployment、Service、Ingress等。但在实际⽣产环境中,我们需要部署和维护⼤量的应⽤,且每个应⽤都需要多个yaml资源清单。这意味着我们需要编写和维护⼤量的yaml清单⽂件。因此,我们迫切需要在Kubernetes中引⼊⼀个类似yum这样的⼯具,通过⼀条特定的命令就可以在系统上完成应⽤的安装、升级、以及后期的维护。⽽这个⼯具就是Helm
helm简介
官方:https://helm.sh/zh/docs/intro/quickstart/

Helm是Kubernetes应用的包管理工具,主要用来管理Charts,类似Linux系统的yumHelm Charts是用来封装Kubernetes原生应用程序的一系列yaml文件。可以在你部署应用的时候自定义应用程序的一些Metadata,以便于应用程序的分发- 对于
应用发布者而言:通过Helm打包应用、管理应用依赖关系、管理应用版本并发布应用到软件仓库 - 对于
使用者而言:使用Helm后可以以简单的方式在Kubernetes上查找、安装、升级、回滚、卸载应用程序

Helm是CNCF学院毕业的项⽬,它是Kubernetes中的包管理⼯具,它能让我们在Kubernetes中⾮常⽅便的安装、升级、卸载我们的应⽤。Helm的⼯作原理与yum⾮常相似。⾸先Helm会将应⽤所需要yaml配置清单⽂件打包成⼀个单元,称为chart。⽽这个chart通常是保存在Helm仓库中,当需要时进⾏调⽤。⽽每个chart都包含了部署⼀个应⽤所需要的所有资源和配置,包括但不限于Deployment、Service、Ingress、ConfigMap 等。因此借助Helm⼯具,我们就可以使⽤⼀条命令来部署和管理⼀个完整的应⽤Helm Chart中的资源清单⽂件并⾮是固定的,⽽是采⽤了模板的形式。在应⽤部署过程中,我们还需要借助values.yaml这个变量配置⽂件来渲染这些模板⽂件,从⽽⽣成真正要部署的资源清单。也就是说helm它需要将模板⽂件与⽤户定义的values.yaml变量配置⽂件结合起来,从⽽⽣成⼀份完整的应⽤部署清单,最后将这个清单部署到Kubernetes集群上

helm核心概念
Helm的核⼼组成部分包括Chart、Repository和Release,我们可以将其分别理解为应⽤程序包、应⽤程序包商店和已安装的应⽤
Chart(应⽤程序包):Chart是Helm的⼀种打包格式,就像apk⽂件⼀ 样。它包含了部署⼀个应⽤所有的必要资源清单⽂件和配置Repository(应⽤商店):Repository是存储和分享Chart的地⽅,就像⼀个应⽤商店⼀样。你可以在这⾥找到并下载你需要的Chart,然后进⾏安装Release(已安装的应⽤):当你⽤Chart在Kubernetes集群上部署⼀个应⽤或服务,这就产⽣了⼀个Release,就像你在⼿机上安装了⼀个APP。同时你也可以根据同⼀份Chart在集群上部署多次,每次都会⽣成⼀个新的Release,就像同⼀个apk可以在⼿机上安装多次(例如安装多个微信、淘 宝、京东)
helm架构
Helm架构分为V2和V3版- 在
Helm v2的架构中,有⼀个重要的组件叫做Tiller。Tiller是Helm v2的服务端,它在Kubernetes集群中运⾏,并负责响应Helm客户端的请求,同时管理Release的⽣命周期,包括部署、更新、删除等操作。但由于Tiller必须在Kubernetes集群中的每个命名空间都安装⼀个实例,以使Helm能在该命名空间中部署应⽤,这种要求增加了管理的复杂性

- 在
Helm v3的架构中,开发者移除了Tiller这个服务端组件。让Helm客户端可以直接通过kubeconfig的⽂件,与Kubernetes的APIServer进⾏交互。这个改变带来了两个主要的好处- ⾸先,
Helm可以直接使⽤Kubernetes⾃带的⻆⾊访问控制。这意味着,我们可以根据每个⽤户的需求和权限,提供定制的kubeconfig⽂件。这种改变增强了系统的安全,因为我们可以更精细地控制那个用户可以访问什么资源,以及他们可以进⾏什么操作 - 其次,去掉
Tiller后,Helm的架构和部署流程都变得更简洁、更清晰,这使得使⽤Helm变得更加简单和⽅便
- ⾸先,

helm安装
helm下载地址:https://github.com/helm/helm/releases

下载完之后,使用mobaxterm将.gz的helm包上传到master上
[root@k8s-master ~]# mkdir helm
[root@k8s-master ~]# cd helm/
[root@k8s-master helm]# ls
helm-v3.15.4-linux-amd64.tar.gz
解压并将helm执行文件cp到/usr/bin/下(helm是一个绿色文件)
[root@k8s-master helm]# tar -zxvf helm-v3.15.4-linux-amd64.tar.gz
[root@k8s-master helm]# ls
helm-v3.15.4-linux-amd64.tar.gz linux-amd64
[root@k8s-master linux-amd64]# ls
helm LICENSE README.md
[root@k8s-master linux-amd64]# cp -p helm /usr/bin/
设置helm命令补全
[root@k8s-master linux-amd64]# echo "source <(helm completion bash)" >> ~/.bashrc
[root@k8s-master linux-amd64]# source ~/.bashrc
测试:查看helm版本
[root@k8s-master linux-amd64]# helm version
version.BuildInfo{Version:"v3.15.4", GitCommit:"fa9efb07d9d8debbb4306d72af76a383895aa8c4", GitTreeState:"clean", GoVersion:"go1.22.6"}
helm常用操作
| 命令 | 描述 |
|---|---|
completion | 生成指定shell的自动补全脚本 |
plugin | 安装、列出或卸载Helm插件 |
env | 显示Helm客户端的环境信息 |
create | 创建一个chart并指定名字 |
dependency | 管理chart依赖 |
get | 下载一个release,可用子命令:all、hooks、manifest、notes、values |
history | 获取release历史 |
install | 安装并运行一个chart。-n指定命名空间 |
list | 列出release |
package | 将chart目录打包到chart存档文件中 |
pull | 从远程仓库中下载chart并解压到本地。helm pull stable/mysql --untar |
repo | 添加,列出,移除,更新和索引chart仓库。可用子命令:add、index、list、remove、update |
rollback | 从之前的版本回滚 |
search | 根据关键字搜索chart。可用子命令:hub、repo |
show | 查看chart详细信息。可用子命令:all、chart、readme、values |
status | 显示已安装版本的状态 |
template | 本地呈现模板 |
uninstall | 卸载一个release |
upgrade | 更新一个release |
version | 查看helm客户端版本 |
[root@k8s-master helm]# helm search
hub (search for charts in the Artifact Hub or your own hub instance)
repo (search repositories for a keyword in charts)
#在官方仓库中搜索含有关键字为nginx的chart
[root@k8s-master helm]# helm search hub nginx
#在本地仓库中搜索含有关键字为nginx的chart
#由于这里我们还没有添加本地仓库,所以会报错
[root@k8s-master helm]# helm search repo nginx
Error: no repositories configured
管理第三方repo源
阿里云仓库:https://kubernetes.oss-cn-hangzhou.aliyuncs.com/chartsbitnami仓库:https://charts.bitnami.com/bitnami微软仓库:http://mirror.azure.cn/kubernetes/charts/官方仓库:https://hub.kubeapps.com/charts/incubator
添加一个名为huazi-aliyun的阿里云仓库
#添加一个名为huazi-aliyun的阿里云仓库
[root@k8s-master helm]# helm repo add huazi-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
"huazi-aliyun" has been added to your repositories
#列出添加的本地仓库
[root@k8s-master helm]# helm repo list
NAME URL
huazi-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
#在本地仓库中搜索含有关键字为nginx的chart
[root@k8s-master helm]# helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
huazi-aliyun/nginx-ingress 0.9.5 0.10.2 An nginx Ingress controller that uses ConfigMap...
huazi-aliyun/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
huazi-aliyun/gcloud-endpoints 0.1.0 Develop, deploy, protect and monitor your APIs ...
添加一个名为huazi-bitnami的bitnami仓库
#添加一个名为`huazi-bitnami`的`bitnami`仓库
[root@k8s-master helm]# helm repo add huazi-bitnami https://charts.bitnami.com/bitnami
"huazi-bitnami" has been added to your repositories
#列出添加的本地仓库
[root@k8s-master helm]# helm repo list
NAME URL
huazi-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
huazi-bitnami https://charts.bitnami.com/bitnami
#在本地仓库中搜索含有关键字为nginx的chart
[root@k8s-master helm]# helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTIO N
huazi-aliyun/nginx-ingress 0.9.5 0.10.2 An nginx I ngress controller that uses ConfigMap...
huazi-aliyun/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
huazi-bitnami/nginx 18.2.5 1.27.2 NGINX Open Source is a web server that can be a...
huazi-bitnami/nginx-ingress-controller 11.5.4 1.11.3 NGINX Ingr ess Controller is an Ingress controll...
huazi-bitnami/nginx-intel 2.1.15 0.4.9 DEPRECATED NGINX Open Source for Intel is a lig...
huazi-aliyun/gcloud-endpoints 0.1.0 Develop, d eploy, protect and monitor your APIs ...
查看指定仓库中的所有chart
#查看指定仓库huazi-aliyun中的所有chart
[root@k8s-master helm]# helm search repo huazi-aliyun
NAME CHART VERSION APP VERSION DESCRIPTION
#应用名称 #chart版本 #应用软件版本 #应用软件描述
huazi-aliyun/acs-engine-autoscaler 2.1.3 2.1.1 Scales worker nodes within agent pools
huazi-aliyun/aerospike 0.1.7 v3.14.1.2 A Helm chart for Aerospike in Kubernetes
huazi-aliyun/anchore-engine 0.1.3 0.1.6 Anchore container analysis and policy evaluatio...
huazi-aliyun/artifactory 7.0.3 5.8.4 Universal Repository Manager supporting all maj...
huazi-aliyun/artifactory-ha 0.1.0 5.8.4 Universal Repository Manager supporting all maj...
huazi-aliyun/aws-cluster-autoscaler 0.3.2 Scales worker nodes within autoscaling groups.
......
......
......
删除第三方仓库
[root@k8s-master helm]# helm repo list
NAME URL
huazi-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
huazi-bitnami https://charts.bitnami.com/bitnami
#删除名为huazi-bitnami的仓库
[root@k8s-master helm]# helm repo remove huazi-bitnami
"huazi-bitnami" has been removed from your repositories
[root@k8s-master helm]# helm repo list
NAME URL
huazi-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm的使用方法
在本地仓库中搜索含有关键字为nginx的chart
[root@k8s-master helm]# helm search repo nginx
NAME CHART VERSION APP VERSION DESCRIPTION
huazi-aliyun/nginx-ingress 0.9.5 0.10.2 An nginx Ingress controller that uses ConfigMap...
huazi-aliyun/nginx-lego 0.3.1 Chart for nginx-ingress-controller and kube-lego
huazi-aliyun/gcloud-endpoints 0.1.0 Develop, deploy, protect and monitor your APIs ...
查看chart的详细信息
[root@k8s-master helm]# helm show chart huazi-bitnami/nginx
annotations:
category: Infrastructure
images: |
- name: git
image: docker.io/bitnami/git:2.47.0-debian-12-r0
- name: nginx
image: docker.io/bitnami/nginx:1.27.2-debian-12-r1
- name: nginx-exporter
image: docker.io/bitnami/nginx-exporter:1.3.0-debian-12-r7
licenses: Apache-2.0
apiVersion: v2
appVersion: 1.27.2
dependencies:
- name: common
repository: oci://registry-1.docker.io/bitnamicharts
tags:
- bitnami-common
version: 2.x.x
description: NGINX Open Source is a web server that can be also used as a reverse
proxy, load balancer, and HTTP cache. Recommended for high-demanding sites due to
its ability to provide faster content.
home: https://bitnami.com
icon: https://bitnami.com/assets/stacks/nginx/img/nginx-stack-220x234.png
keywords:
- nginx
- http
- web
- www
- reverse proxy
maintainers:
- name: Broadcom, Inc. All Rights Reserved.
url: https://github.com/bitnami/charts
name: nginx
sources:
- https://github.com/bitnami/charts/tree/main/bitnami/nginx
version: 18.2.5
安装并运行chart
#在huazi-bitnami仓库中安装一个nginx,并起名为huazi-nginx
[root@k8s-master helm]# helm install huazi-nginx huazi-bitnami/nginx
[root@k8s-master helm]# kubectl get pods
NAME READY STATUS RESTARTS AGE
huazi-nginx-6fbcbb44f5-vzvnq 1/1 Running 0 4s
#查看名为huazi-nginx的项目
[root@k8s-master helm]# helm status huazi-nginx
NAME: huazi-nginx
LAST DEPLOYED: Tue Nov 12 01:54:29 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 18.2.5
APP VERSION: 1.27.2
#列出安装的chart,即列出release
[root@k8s-master helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
huazi-nginx default 1 2024-11-12 01:33:37.384075701 -0500 EST deployed nginx-18.2.5 1.27.2
#卸载chart
[root@k8s-master helm]# helm uninstall huazi-nginx
release "huazi-nginx" uninstalled
#发现自动清除了
[root@k8s-master helm]# kubectl get pods
No resources found in default namespace.
[root@k8s-master helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
仅下载,不运行
[root@k8s-master helm]# helm pull huazi-aliyun/nginx-ingress
#此时在当前目录下,就会出现chart包,这个包没有解压
[root@k8s-master helm]# ls
nginx-ingress-0.9.5.tgz
#删除
[root@k8s-master helm]# rm -rf nginx-ingress-0.9.5.tgz
#如果说需要解压,则可以加上--untar参数
[root@k8s-master helm]# helm pull huazi-aliyun/nginx-ingress --untar
#我们发现已经自动解压了
[root@k8s-master helm]# ls
nginx-ingress
[root@k8s-master helm]# cd nginx-ingress/
[root@k8s-master nginx-ingress]# ls
Chart.yaml README.md templates values.yaml
安装项目前进行预定义
#下载并解压
[root@k8s-master helm]# helm pull huazi-bitnami/nginx --untar
[root@k8s-master helm]# cd nginx/
[root@k8s-master nginx]# ls
Chart.lock Chart.yaml templates values.yaml
charts README.md values.schema.json
#修改项目变量文件
[root@k8s-master nginx]# vim values.yaml

上传项目所需镜像到仓库
[root@k8s-master helm]# docker load -i nginx-1.27.1-debian-12-r2.tar
30f5b1069b7f: Loading layer 190.1MB/190.1MB
Loaded image: bitnami/nginx:1.27.1-debian-12-r2

[root@k8s-master helm]# docker tag bitnami/nginx:1.27.1-debian-12-r2 harbor.huazi.org/bitnami/nginx:1.27.1-debian-12-r2
[root@k8s-master helm]# docker push harbor.huazi.org/bitnami/nginx:1.27.1-debian-12-r2
#把原本的旧chart包删了
[root@k8s-master helm]# rm -rf nginx-18.1.11.tgz
#将修改过的chart包,压缩为新的chart包
[root@k8s-master helm]# tar -zcvf nginx-18.1.11.tgz nginx
#从本地安装(第一种方式)-n指定命名空间
[root@k8s-master helm]# helm install hua nginx-18.1.11.tgz -n default
#从本地安装(第二种方式)-n指定命名空间
[root@k8s-master nginx]# helm install hua /root/helm/nginx -n default
#发现运行成功了
[root@k8s-master helm]# kubectl get pods
NAME READY STATUS RESTARTS AGE
huazi-nginx-7c4685fcf4-sl59s 1/1 Running 0 35s
#发现又自动建立了一个名为hua-nginx的svc
[root@k8s-master helm]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hua-nginx LoadBalancer 10.96.155.61 172.25.254.51 80:33288/TCP,443:35144/TCP 16s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38d
#测试
[root@k8s-master helm]# curl 172.25.254.51
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
更新项目
[root@k8s-master nginx]# vim values.yaml




[root@k8s-master nginx]# helm upgrade hua .
[root@k8s-master nginx]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hua-nginx ClusterIP 10.96.155.61 <none> 80/TCP,443/TCP 12m
测试
[root@k8s-master nginx]# curl 10.96.155.61
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@k8s-master nginx]# kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
hua-nginx nginx myapp.huazi.org 172.25.254.10 80 2m24s
[root@k8s-master nginx]# vim /etc/hosts

[root@k8s-master nginx]# curl myapp.huazi.org
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
#查看历史版本
[root@k8s-master nginx]# helm history hua
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Nov 12 02:40:39 2024 superseded nginx-18.1.11 1.27.1 Install complete
2 Tue Nov 12 02:51:21 2024 deployed nginx-18.1.11 1.27.1 Upgrade complete
#删除项目
[root@k8s-master nginx]# helm uninstall hua
release "hua" uninstalled
构建helm中的chart包
chart目录结构
#创建一个名为huazi的chart项目
[root@k8s-master helm]# helm create huazi
Creating huazi
#创建后发现,自动生成了一个名为huazi的目录
[root@k8s-master helm]# ls
huazi
[root@k8s-master helm]# tree huazi/
huazi/
├── charts #目录里存放这个chart依赖的所有子chart
├── Chart.yaml #用于描述这个 Chart 的基本信息,包括名字、描述信息以及版本等
├── templates #目录里面存放所有yaml模板文件
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml #用于存储templates目录中模板文件中用到变量的值
构建方法
[root@k8s-master helm]# cd huazi/
[root@k8s-master huazi]# ls
charts Chart.yaml templates values.yaml
[root@k8s-master huazi]# vim Chart.yaml

[root@k8s-master huazi]# vim values.yaml



#语法检测
[root@k8s-master huazi]# helm lint /root/helm/huazi/
==> Linting /root/helm/huazi/
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
#项目打包
[root@k8s-master helm]# helm package huazi/
Successfully packaged chart and saved it to: /root/helm/huazi-0.1.0.tgz
[root@k8s-master helm]# ls
huazi-0.1.0.tgz
#安装并运行项目
[root@k8s-master helm]# helm install hua huazi-0.1.0.tgz
NAME: hua
LAST DEPLOYED: Tue Nov 12 04:24:23 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
http://myapp.huazi.org/
[root@k8s-master helm]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hua-huazi-77799d6dfb-lsq69 1/1 Running 0 51s 10.224.114.172 k8s-node1.org <none> <none>
[root@k8s-master helm]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hua-huazi LoadBalancer 10.98.221.79 172.25.254.51 80:31363/TCP 31s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 38d
[root@k8s-master ~]# vim /etc/hosts

#测试
[root@k8s-master helm]# curl myapp.huazi.org
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
做版本升级
[root@k8s-master helm]# cd huazi/
[root@k8s-master huazi]# vim Chart.yaml

[root@k8s-master helm]# helm package huazi
Successfully packaged chart and saved it to: /root/helm/huazi-0.2.0.tgz
[root@k8s-master helm]# ls
huazi-0.1.0.tgz
huazi huazi-0.2.0.tgz
构建helm仓库
在harbor仓库中构建一个公开的项目


安装helm push插件
官方网址:https://github.com/chartmuseum/helm-push
[root@k8s-master helm]# helm plugin
install (install a Helm plugin) uninstall (uninstall one or more Helm plugins)
list (list installed Helm plugins) update (update one or more Helm plugins)
在线安装
如果网络没有问题,可以直接在线安装
#先装git
[root@k8s-master helm]# yum install git -y
[root@k8s-master helm]# helm plugin install https://github.com/chartmuseum/helm-push
离线安装

[root@k8s-master helm]# mkdir -p ~/.local/share/helm/plugins/helm-push
[root@k8s-master helm]# tar -zxvf helm-push_0.10.4_linux_amd64.tar.gz -C ~/.local/share/helm/plugins/helm-push/
#测试
[root@k8s-master helm]# helm cm-push --help
Helm plugin to push chart package to ChartMuseum
Examples:
$ helm cm-push mychart-0.1.0.tgz chartmuseum # push .tgz from "helm package"
$ helm cm-push . chartmuseum # package and push chart directory
$ helm cm-push . --version="1.2.3" chartmuseum # override version in Chart.yaml
$ helm cm-push . https://my.chart.repo.com # push directly to chart repo URL
#测试成功
上传chart项目到仓库
#我们发现添加仓库时错误,是因为我们用的是https加密访问,但是helm没有证书
[root@k8s-master helm]# helm repo add huazi https://harbor.huazi.org/chartrepo/hua
Error: looks like "https://harbor.huazi.org/chartrepo/hua" is not a valid chart repository or cannot be reached: Get "https://harbor.huazi.org/chartrepo/hua/index.yaml": tls: failed to verify certificate: x509: certificate signed by unknown authority
#为helm添加证书
[root@k8s-master helm]# cp /etc/docker/certs.d/harbor.huazi.org/ca.crt /etc/pki/ca-trust/source/anchors/
#更新本地ca认证库
[root@k8s-master helm]# update-ca-trust
#再次添加仓库
[root@k8s-master helm]# helm repo add huazi https://harbor.huazi.org/chartrepo/hua "huazi" has been added to your repositories
[root@k8s-master helm]# helm repo list
NAME URL
huazi-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
huazi-bitnami https://charts.bitnami.com/bitnami
huazi https://harbor.huazi.org/chartrepo/hua
上传本地chart项目
[root@k8s-master helm]# helm cm-push 项目名称 仓库名称 -u harbor账户 -p 密码
#上传成功
[root@k8s-master helm]# helm cm-push huazi-0.1.0.tgz huazi -u admin -p 123456

#上传一次,更新一次
[root@k8s-master helm]# helm repo update huazi
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "huazi" chart repository
Update Complete. ⎈Happy Helming!⎈
[root@k8s-master helm]# helm cm-push huazi-0.2.0.tgz huazi -u admin -p 123456
Pushing huazi-0.2.0.tgz to huazi...
Done.


#上传一次,更新一次
[root@k8s-master helm]# helm repo update huazi
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "huazi" chart repository
Update Complete. ⎈Happy Helming!⎈
[root@k8s-master helm]# helm search repo huazi
NAME CHART VERSION APP VERSION DESCRIPTION
huazi/huazi 0.2.0 v2 A Helm chart for Kubernetes
#-l列出所有版本
[root@k8s-master helm]# helm search repo huazi -l
NAME CHART VERSION APP VERSION DESCRIPTION
huazi/huazi 0.2.0 v2 A Helm chart for Kubernetes
huazi/huazi 0.1.0 v1 A Helm chart for Kubernetes
[root@k8s-master helm]# helm uninstall hua
release "hua" uninstalled
[root@k8s-master helm]# helm repo list
NAME URL
huazi https://harbor.huazi.org/chartrepo/hua
#如果不加--version,会部署最新的版本
[root@k8s-master helm]# helm install huazi huazi/huazi --version 0.1.0
NAME: huazi
LAST DEPLOYED: Tue Nov 12 05:15:28 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
http://myapp.huazi.org/
[root@k8s-master helm]# curl myapp.huazi.org
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
helm的版本迭代
[root@k8s-master helm]# curl myapp.huazi.org
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
#原来安装的是1.0,现在更新为2.0
[root@k8s-master helm]# helm upgrade huazi huazi/huazi --version 0.2.0
Release "huazi" has been upgraded. Happy Helming!
NAME: huazi
LAST DEPLOYED: Tue Nov 12 05:18:17 2024
NAMESPACE: default
STATUS: deployed
REVISION: 2
NOTES:
1. Get the application URL by running these commands:
http://myapp.huazi.org/
[root@k8s-master helm]# curl myapp.huazi.org
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
[root@k8s-master helm]# helm history huazi
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Nov 12 05:15:28 2024 superseded huazi-0.1.0 v1 Install complete
2 Tue Nov 12 05:18:17 2024 deployed huazi-0.2.0 v2 Upgrade complete
回滚
[root@k8s-master helm]# helm rollback huazi
Rollback was a success! Happy Helming!
[root@k8s-master helm]# curl myapp.huazi.org
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
更多推荐


所有评论(0)