helm 定位为包管理工具
helm学习网站:https://helm.sh/zh/docs/




gitchart 地址 学习

安装部署helm

配置命令自动补全
helm completion bash > /etc/bash_completion.d/helm
创建应用
1、创建chart
helm create test-nginx #创建chart,不指定相关资源默认创建nginx chart
[root@sealos helm]# ll
总用量 0
drwxr-xr-x 4 root root 93 2月 29 10:35 test-nginx
[root@sealos helm]# cd test-nginx/
[root@sealos test-nginx]# ls
charts Chart.yaml templates values.yaml

2、安装chart
[root@sealos helm]# ls test-nginx [root@sealos helm]# helm install test ./test-nginx # helm install 名称+chart包 -n +命名空间 NAME: test LAST DEPLOYED: Thu Feb 29 10:44:49 2024 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=test-nginx,app.kubernetes.io/instance=test" -o jsonpath="{.items[0].metadata.name}") export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT [root@sealos helm]# kubectl get pods -A | grep nginx default test-test-nginx-7bd4786cf-4bb6p 1/1 Running 0 69s
3、配置文件解析


4、业务升级和回滚
升级基于values.yaml升级
把values.yaml文件中nginx版本从1.20替换成1.24, 在upgrade升级一下, helm upgrade xin 111 -n helm-xjzw01 #只需要指定命名空间,不需要重新指定chart 文件目录 再次使用helm list查看version版本;
回滚
helm rollback xin -n helm-xjzw01
指定版本 1
helm rollback xin 1 -n helm-xjzw01
helm 仓库
- 互联网公开的chart仓库,可以直接使用他们制作好的包; 1,微软仓库:Index of /kubernetes/charts/ 2,阿里云仓库:https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm 私有仓库搭建
本地存储方式,这里设置 /root/helm/charts 为仓库地址
docker run -dit \ -p 8080:8080 \ -e DEBUG=1 \ -e STORAGE=local \ -e STORAGE_LOCAL_ROOTDIR=/charts \ -v /root/helm/charts:/charts \ ghcr.io/helm/chartmuseum:v0.16.1
S3存储方式
docker run --rm -it \ -p 8080:8080 \ -e DEBUG=1 \ -e STORAGE="amazon" \ -e STORAGE_AMAZON_BUCKET="my-s3-bucket" \ -e STORAGE_AMAZON_PREFIX="" \ -e STORAGE_AMAZON_REGION="us-east-1" \ -v ~/.aws:/home/chartmuseum/.aws:ro \ ghcr.io/helm/chartmuseum:v0.16.1
配置私有仓库
添加私有chart仓库
helm repo add local http://172.21.131.81:8888
安装helm push插件,支撑本地chart上传私有chart仓库
helm plugin install https://github.com/chartmuseum/helm-push.git
手动安装,将git 目录下载到本地
helm env
HELM_PLUGINS="/root/.local/share/helm/plugins"
手动创建目录,将git 目录移动至plugins 目录下
mkdir /root/.local/share/helm/plugins/helm-push cp helm-push_0.9.0_linux_amd64.tar.gz /root/.local/share/helm/plugins/helm-push cd /root/.local/share/helm/plugins/helm-push tar zxvf helm-push_0.9.0_linux_amd64.tar.gz helm plugin list
手动验证上传chart 包
从官网下载几个chart 包
[root@localhost ~]# helm pull az-stable/consul
[root@localhost ~]# helm pull az-stable/prometheus-consul-exporter
添加本地仓库到 helm repo
[root@localhost ~]# helm repo ls NAME URL az-stable http://mirror.azure.cn/kubernetes/charts/ local http://172.21.131.81:8080/
推送chart 测试
[root@localhost ~]# chmod 777 /root/helm/charts #提示权限不足时,需要给目录添加权限 [root@localhost ~]# helm cm-push consul-3.9.6.tgz local Pushing consul-3.9.6.tgz to local... Done. [root@localhost ~]# helm cm-push prometheus-consul-exporter-0.1.6.tgz local Pushing prometheus-consul-exporter-0.1.6.tgz to local... Done.

浙公网安备 33010602011771号