下载:wget https://get.helm.sh/helm-v3.18.4-linux-amd64.tar.gz 解压指定位置:tar xf helm-v3.18.4-linux-amd64.tar.gz -C /usr/local/bin/ linux-amd64/helm --strip-components=1 查看版本:helm version 补全命令: helm completion bash > /etc/bash_completion.d/helm source /etc/bash_completion.d/helm echo 'source /etc/bash_completion.d/helm' >> ~/.bashrc
helm有点类似于Linux的yum,apt工具,帮助我们管理K8S集群的资源清单。 Helm 帮助您管理 Kubernetes 应用—— Helm Chart,即使是最复杂的 Kubernetes 应用程序,都可以帮助您定义,安装和升级。 Helm Chart 易于创建、发版、分享和发布,所以停止复制粘贴,开始使用 Helm 吧。 Helm 是 CNCF 的毕业项目,由 Helm 社区维护。 官方文档: https://helm.sh/zh/
2019年11月Helm团队发布V3版本,相比v2版本最大变化是将Tiller删除,并大部分代码重构。 helm v3相比helm v2还做了很多优化,比如不同命名空间资源同名的情况在v3版本是允许的,我们在生产环境中使用建议大家使用v3版本,不仅仅是因为它版本功能较强,而且相对来说也更加稳定了。 官方地址: https://helm.sh/docs/intro/install/ github地址: https://github.com/helm/helm/releases
wget https://get.helm.sh/helm-v3.18.4-linux-amd64.tar.gz SVIP: [root@master231 ~]# wget http://192.168.21.253/Resources/Kubernetes/Add-ons/helm/softwares/helm-v3.18.4-linux-amd64.tar.gz [root@master231 ~]# tar xf helm-v3.18.4-linux-amd64.tar.gz -C /usr/local/bin/ linux-amd64/helm --strip-components=1 [root@master231 ~]# [root@master231 ~]# ll /usr/local/bin/helm -rwxr-xr-x 1 1001 fwupd-refresh 59715768 Jul 9 04:36 /usr/local/bin/helm* [root@master231 ~]# [root@master231 ~]# helm version version.BuildInfo{Version:"v3.18.4", GitCommit:"d80839cf37d860c8aa9a0503fe463278f26cd5e2", GitTreeState:"clean", GoVersion:"go1.24.4"} [root@master231 ~]#
[root@master231 ~]# helm completion bash > /etc/bash_completion.d/helm [root@master231 ~]# source /etc/bash_completion.d/helm [root@master231 ~]# echo 'source /etc/bash_completion.d/helm' >> ~/.bashrc
创建:helm create 文件 查看仓库:egrep "repository:|tag:" oldboyedu-linux98/values.yaml 替换仓库:sed -i "/repository\:/s#nginx#registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps#" oldboyedu-linux98/values.yaml 替换版本:sed -ri '/tag\:/s#tag: ""#tag: v1#' oldboyedu-linux98/values.yaml 部署服务:helm install xiuxian oldboyedu-linux98 卸载服务:helm uninstall xiuxian
[root@master231 add-ons]# mkdir 05-helm [root@master231 add-ons]# cd 05-helm [root@master231 05-helm]# ll total 8 drwxr-xr-x 2 root root 4096 Jul 28 09:29 ./ drwxr-xr-x 7 root root 4096 Jul 28 09:29 ../ [root@master231 05-helm]# [root@master231 05-helm]# [root@master231 05-helm]# helm create oldboyedu-linux98 Creating oldboyedu-linux98 [root@master231 05-helm]# [root@master231 05-helm]# ll total 12 drwxr-xr-x 3 root root 4096 Jul 28 09:29 ./ drwxr-xr-x 7 root root 4096 Jul 28 09:29 ../ drwxr-xr-x 4 root root 4096 Jul 28 09:29 oldboyedu-linux98/ [root@master231 05-helm]#
[root@master231 helm-Chart]# tree oldboyedu-linux98/ oldboyedu-linux98/ ├── charts # 包含chart依赖的其他chart ├── Chart.yaml # 包含了chart信息的YAML文件 ├── templates # 模板目录, 当和values 结合时,可生成有效的Kubernetes manifest文件 │ ├── deployment.yaml # deployment资源清单模板。 │ ├── _helpers.tpl # 自定义模板 │ ├── hpa.yaml # hpa资源清单模板。 │ ├── ingress.yaml # Ingress资源清单模板。 │ ├── NOTES.txt # 可选: 包含简要使用说明的纯文本文件 │ ├── serviceaccount.yaml # sa资源清单模板。 │ ├── service.yaml # svc资源清单模板。 │ └── tests # 测试目录 │ └── test-connection.yaml └── values.yaml # chart 默认的配置值 3 directories, 10 files [root@master231 helm-Chart]# 参考链接: https://helm.sh/zh/docs/topics/charts/#chart-%E6%96%87%E4%BB%B6%E7%BB%93%E6%9E%84
[root@master231 05-helm]# egrep "repository:|tag:" oldboyedu-linux98/values.yaml repository: nginx tag: "" [root@master231 05-helm]# [root@master231 05-helm]# sed -i "/repository\:/s#nginx#registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps#" oldboyedu-linux98/values.yaml [root@master231 05-helm]# [root@master231 05-helm]# sed -ri '/tag\:/s#tag: ""#tag: v1#' oldboyedu-linux98/values.yaml [root@master231 05-helm]# [root@master231 05-helm]# egrep "repository:|tag:" oldboyedu-linux98/values.yaml repository: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps tag: v1 [root@master231 05-helm]#
[root@master231 05-helm]# helm install xiuxian oldboyedu-linux98 NAME: xiuxian LAST DEPLOYED: Mon Jul 28 09:41:31 2025 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=oldboyedu-linux98,app.kubernetes.io/instance=xiuxian" -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@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 1 2025-07-28 09:34:21.622905261 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]#
[root@master231 05-helm]# kubectl get deploy,svc,pods NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 1/1 1 1 84s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d22h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.231.250 <none> 80/TCP 84s NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-68c6c66bb6-srwkx 1/1 Running 0 84s [root@master231 05-helm]# [root@master231 05-helm]# curl 10.200.231.250 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v1</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: green">凡人修仙传 v1 </h1> <div> <img src="1.jpg"> <div> </body> </html>
[root@master231 05-helm]# kubectl get deploy,svc,pods NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 1/1 1 1 2m1s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d22h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.231.250 <none> 80/TCP 2m1s NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-68c6c66bb6-srwkx 1/1 Running 0 2m1s [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 1 2025-07-28 09:34:21.622905261 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# [root@master231 05-helm]# helm uninstall xiuxian release "xiuxian" uninstalled [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION [root@master231 05-helm]# [root@master231 05-helm]# kubectl get deploy,svc,pods NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d22h [root@master231 05-helm]#
修改value.yaml的值,如replicaCount 或 image.tag 修改镜像版本 仓库更新Chart后升级 基于文件升级:helm upgrade xiuxian -f oldboyedu-linux98/values.yaml oldboyedu-linux98/
[root@master231 05-helm]# helm install xiuxian oldboyedu-linux98 NAME: xiuxian LAST DEPLOYED: Mon Jul 28 10:32:42 2025 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=oldboyedu-linux98,app.kubernetes.io/instance=xiuxian" -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@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 1 2025-07-28 10:32:42.441533118 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# kubectl get deploy,svc,po -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR deployment.apps/xiuxian-oldboyedu-linux98 1/1 1 1 20s oldboyedu-linux98 registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1 app.kubernetes.io/instance=xiuxian,app.kubernetes.io/name=oldboyedu-linux98 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 15d <none> service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.6.132 <none> 80/TCP 20s app.kubernetes.io/instance=xiuxian,app.kubernetes.io/name=oldboyedu-linux98 NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/xiuxian-oldboyedu-linux98-68c6c66bb6-twg4p 1/1 Running 0 20s 10.100.1.80 worker232 <none> <none> [root@master231 05-helm]# curl 10.200.6.132 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v1</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: green">凡人修仙传 v1 </h1> <div> <img src="1.jpg"> <div> </body> </html>
[root@master231 05-helm]# egrep "replicaCount|tag:" oldboyedu-linux98/values.yaml replicaCount: 1 tag: v1 [root@master231 05-helm]# [root@master231 05-helm]# sed -i '/replicaCount/s#1#3#' oldboyedu-linux98/values.yaml [root@master231 05-helm]# [root@master231 05-helm]# sed -i "/tag:/s#v1#v2#" oldboyedu-linux98/values.yaml [root@master231 05-helm]# [root@master231 05-helm]# egrep "replicaCount|tag:" oldboyedu-linux98/values.yaml replicaCount: 3 tag: v2 [root@master231 05-helm]# [root@master231 05-helm]#
[root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 1 2025-07-28 10:15:47.695220923 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# [root@master231 05-helm]# helm upgrade xiuxian -f oldboyedu-linux98/values.yaml oldboyedu-linux98/ Release "xiuxian" has been upgraded. Happy Helming! NAME: xiuxian LAST DEPLOYED: Mon Jul 28 10:21:07 2025 NAMESPACE: default STATUS: deployed REVISION: 2 NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=oldboyedu-linux98,app.kubernetes.io/instance=xiuxian" -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@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 2 2025-07-28 10:21:07.155788336 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]#
[root@master231 05-helm]# kubectl get deploy,svc,po NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 3/3 3 3 5m35s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d23h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.67.55 <none> 80/TCP 5m35s NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-5b48f4cb6c-fvwfv 1/1 Running 0 15s pod/xiuxian-oldboyedu-linux98-5b48f4cb6c-jjc6c 1/1 Running 0 13s pod/xiuxian-oldboyedu-linux98-5b48f4cb6c-scrpn 1/1 Running 0 12s [root@master231 05-helm]# [root@master231 05-helm]# curl 10.200.67.55 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v2</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: red">凡人修仙传 v2 </h1> <div> <img src="2.jpg"> <div> </body> </html> [root@master231 05-helm]#
[root@master231 05-helm]# helm upgrade xiuxian --set replicaCount=5,image.tag=v3 oldboyedu-linux98 Release "xiuxian" has been upgraded. Happy Helming! NAME: xiuxian LAST DEPLOYED: Mon Jul 28 10:24:33 2025 NAMESPACE: default STATUS: deployed REVISION: 3 NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=oldboyedu-linux98,app.kubernetes.io/instance=xiuxian" -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@master231 05-helm]#
[root@master231 05-helm]# kubectl get deploy,svc,po NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 5/5 5 5 8m53s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d23h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.67.55 <none> 80/TCP 8m53s NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-6989979888-574ss 1/1 Running 0 5s pod/xiuxian-oldboyedu-linux98-6989979888-bsmp5 1/1 Running 0 6s pod/xiuxian-oldboyedu-linux98-6989979888-kd5j2 1/1 Running 0 7s pod/xiuxian-oldboyedu-linux98-6989979888-nrwfq 1/1 Running 0 7s pod/xiuxian-oldboyedu-linux98-6989979888-shdnk 1/1 Running 0 7s [root@master231 05-helm]# [root@master231 05-helm]# curl 10.200.67.55 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v3</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: pink">凡人修仙传 v3 </h1> <div> <img src="3.jpg"> <div> </body> </html> [root@master231 05-helm]#
查看版本:helm history xiuxian 回滚指定版本:helm rollback xiuxian 1
注:直接回滚上一个版本,如第一次3—>2,第二次2—>3。
[root@master231 05-helm]# helm history xiuxian REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Mon Jul 28 10:15:47 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Install complete 2 Mon Jul 28 10:21:07 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 3 Mon Jul 28 10:24:33 2025 deployed oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 3 2025-07-28 10:24:33.168320177 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# [root@master231 05-helm]#
[root@master231 05-helm]# helm rollback xiuxian Rollback was a success! Happy Helming! [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 4 2025-07-28 10:27:07.456398093 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# [root@master231 05-helm]# helm history xiuxian REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Mon Jul 28 10:15:47 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Install complete 2 Mon Jul 28 10:21:07 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 3 Mon Jul 28 10:24:33 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 4 Mon Jul 28 10:27:07 2025 deployed oldboyedu-linux98-0.1.0 1.16.0 Rollback to 2 [root@master231 05-helm]#
[root@master231 05-helm]# kubectl get deploy,svc,po NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 3/3 3 3 11m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d23h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.67.55 <none> 80/TCP 11m NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-5b48f4cb6c-2wgvt 1/1 Running 0 32s pod/xiuxian-oldboyedu-linux98-5b48f4cb6c-4r4vx 1/1 Running 0 33s pod/xiuxian-oldboyedu-linux98-5b48f4cb6c-mctq7 1/1 Running 0 30s [root@master231 05-helm]# [root@master231 05-helm]# curl 10.200.67.55 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v2</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: red">凡人修仙传 v2 </h1> <div> <img src="2.jpg"> <div> </body> </html> [root@master231 05-helm]#
[root@master231 05-helm]# helm rollback xiuxian Rollback was a success! Happy Helming! [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 5 2025-07-28 10:29:10.472334011 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# [root@master231 05-helm]# helm history xiuxian REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Mon Jul 28 10:15:47 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Install complete 2 Mon Jul 28 10:21:07 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 3 Mon Jul 28 10:24:33 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 4 Mon Jul 28 10:27:07 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Rollback to 2 5 Mon Jul 28 10:29:10 2025 deployed oldboyedu-linux98-0.1.0 1.16.0 Rollback to 3 [root@master231 05-helm]# [root@master231 05-helm]# kubectl get deploy,svc,po NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 5/5 5 5 13m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d23h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.67.55 <none> 80/TCP 13m NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-6989979888-2l9rt 1/1 Running 0 15s pod/xiuxian-oldboyedu-linux98-6989979888-dq2d4 1/1 Running 0 15s pod/xiuxian-oldboyedu-linux98-6989979888-hg5pr 1/1 Running 0 15s pod/xiuxian-oldboyedu-linux98-6989979888-k82x6 1/1 Running 0 13s pod/xiuxian-oldboyedu-linux98-6989979888-qwsmf 1/1 Running 0 13s [root@master231 05-helm]# [root@master231 05-helm]# curl 10.200.67.55 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v3</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: pink">凡人修仙传 v3 </h1> <div> <img src="3.jpg"> <div> </body> </html> [root@master231 05-helm]#
[root@master231 05-helm]# helm rollback xiuxian 1 Rollback was a success! Happy Helming! [root@master231 05-helm]# [root@master231 05-helm]# helm history xiuxian REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION 1 Mon Jul 28 10:15:47 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Install complete 2 Mon Jul 28 10:21:07 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 3 Mon Jul 28 10:24:33 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Upgrade complete 4 Mon Jul 28 10:27:07 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Rollback to 2 5 Mon Jul 28 10:29:10 2025 superseded oldboyedu-linux98-0.1.0 1.16.0 Rollback to 3 6 Mon Jul 28 10:30:01 2025 deployed oldboyedu-linux98-0.1.0 1.16.0 Rollback to 1 [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION xiuxian default 6 2025-07-28 10:30:01.204347883 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]#
[root@master231 05-helm]# kubectl get deploy,svc,pod NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/xiuxian-oldboyedu-linux98 1/1 1 1 14m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d23h service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.67.55 <none> 80/TCP 14m NAME READY STATUS RESTARTS AGE pod/xiuxian-oldboyedu-linux98-68c6c66bb6-dd7st 1/1 Running 0 13s [root@master231 05-helm]# [root@master231 05-helm]# curl 10.200.67.55 <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>yinzhengjie apps v1</title> <style> div img { width: 900px; height: 600px; margin: 0; } </style> </head> <body> <h1 style="color: green">凡人修仙传 v1 </h1> <div> <img src="1.jpg"> <div> </body> </html> [root@master231 05-helm]#
helm添加仓库:helm repo add 名字 仓库地址 查看仓库:helm repo list 更新仓库:helm repo update 搜索仓库指定软件:helm search repo elasticsearch 查找指定信息:helm show chart oldboyedu-aliyun/elasticsearch-exporter 拉取Chart包:helm pull oldboyedu-aliyun/elasticsearch-exporter --version 0.1.1 # 拉取指定Chart版本 不指定则拉取最新 安装服务:helm install myes-exporter elasticsearch-exporter 删除仓库:helm repo remove 名字
互联网公开Chart仓库,可以直接使用他们制作好的Chart包: 微软仓库: http://mirror.azure.cn/kubernetes/charts/ 阿里云仓库: https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
[root@master231 05-helm]# helm repo add azure http://mirror.azure.cn/kubernetes/charts/ "azure" has been added to your repositories [root@master231 05-helm]# [root@master231 05-helm]# helm repo add oldboyedu-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts "oldboyedu-aliyun" has been added to your repositories [root@master231 05-helm]#
[root@master231 05-helm]# helm repo list NAME URL azure http://mirror.azure.cn/kubernetes/charts/ oldboyedu-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts [root@master231 05-helm]#
[root@master231 05-helm]# helm repo update Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "oldboyedu-aliyun" chart repository ...Successfully got an update from the "azure" chart repository Update Complete. ⎈Happy Helming!⎈ [root@master231 05-helm]#
[root@master231 05-helm]# helm search repo elasticsearch NAME CHART VERSION APP VERSION DESCRIPTION azure/elasticsearch 1.32.5 6.8.6 DEPRECATED Flexible and powerful open source, d... azure/elasticsearch-curator 2.2.3 5.7.6 DEPRECATED A Helm chart for Elasticsearch Curator azure/elasticsearch-exporter 3.7.1 1.1.0 DEPRECATED Elasticsearch stats exporter for Pro... azure/fluentd-elasticsearch 2.0.7 2.3.2 DEPRECATED! - A Fluentd Helm chart for Kubernet... oldboyedu-aliyun/elasticsearch-exporter 0.1.2 1.0.2 Elasticsearch stats exporter for Prometheus azure/apm-server 2.1.7 7.0.0 DEPRECATED The server receives data from the El... azure/dmarc2logstash 1.3.1 1.0.3 DEPRECATED Provides a POP3-polled DMARC XML rep... azure/elastabot 1.2.1 1.1.0 DEPRECATED A Helm chart for Elastabot - a Slack... azure/elastalert 1.5.1 0.2.4 DEPRECATED ElastAlert is a simple framework for... azure/fluentd 2.5.3 v2.4.0 DEPRECATED A Fluentd Elasticsearch Helm chart f... azure/kibana 3.2.8 6.7.0 DEPRECATED - Kibana is an open source data visu... oldboyedu-aliyun/elastalert 0.1.1 0.1.21 ElastAlert is a simple framework for alerting o... oldboyedu-aliyun/kibana 0.2.2 6.0.0 Kibana is an open source data visualization plu... [root@master231 05-helm]# [root@master231 05-helm]# helm search repo elasticsearch -l # 显示所有的版本信息列表 NAME CHART VERSION APP VERSION DESCRIPTION ... oldboyedu-aliyun/elasticsearch-exporter 0.1.2 1.0.2 Elasticsearch stats exporter for Prometheus oldboyedu-aliyun/elasticsearch-exporter 0.1.1 1.0.2 Elasticsearch stats exporter for Prometheus ...
[root@master231 05-helm]# helm show chart oldboyedu-aliyun/elasticsearch-exporter apiVersion: v1 appVersion: 1.0.2 description: Elasticsearch stats exporter for Prometheus keywords: - metrics - elasticsearch - monitoring maintainers: - email: sven.mueller@commercetools.com name: svenmueller name: elasticsearch-exporter sources: - https://github.com/justwatchcom/elasticsearch_exporter version: 0.1.2 [root@master231 05-helm]# [root@master231 05-helm]# helm show chart oldboyedu-aliyun/elasticsearch-exporter --version 0.1.1 # 指定Chart版本信息 apiVersion: v1 appVersion: 1.0.2 description: Elasticsearch stats exporter for Prometheus keywords: - metrics - elasticsearch - monitoring maintainers: - email: sven.mueller@commercetools.com name: svenmueller name: elasticsearch-exporter sources: - https://github.com/justwatchcom/elasticsearch_exporter version: 0.1.1
[root@master231 05-helm]# helm pull oldboyedu-aliyun/elasticsearch-exporter # 若不指定,拉取最新的Chart [root@master231 05-helm]# [root@master231 05-helm]# ll elasticsearch* -rw-r--r-- 1 root root 3761 Jul 28 10:52 elasticsearch-exporter-0.1.2.tgz [root@master231 05-helm]# [root@master231 05-helm]# helm pull oldboyedu-aliyun/elasticsearch-exporter --version 0.1.1 # 拉取指定Chart版本 [root@master231 05-helm]# [root@master231 05-helm]# ll elasticsearch* -rw-r--r-- 1 root root 3718 Jul 28 10:53 elasticsearch-exporter-0.1.1.tgz -rw-r--r-- 1 root root 3761 Jul 28 10:52 elasticsearch-exporter-0.1.2.tgz [root@master231 05-helm]#
[root@master231 05-helm]# tar xf elasticsearch-exporter-0.1.2.tgz [root@master231 05-helm]# tree elasticsearch-exporter elasticsearch-exporter ├── Chart.yaml ├── README.md ├── templates │ ├── cert-secret.yaml │ ├── deployment.yaml │ ├── _helpers.tpl │ ├── NOTES.txt │ └── service.yaml └── values.yaml 1 directory, 8 files [root@master231 05-helm]# [root@master231 05-helm]# grep apiVersion elasticsearch-exporter/templates/deployment.yaml apiVersion: apps/v1beta2 [root@master231 05-helm]# [root@master231 05-helm]# sed -ri '/apiVersion/s#(apps\/v1)beta2#\1#' elasticsearch-exporter/templates/deployment.yaml [root@master231 05-helm]# grep apiVersion elasticsearch-exporter/templates/deployment.yaml apiVersion: apps/v1 [root@master231 05-helm]#
[root@master231 05-helm]# helm install myes-exporter elasticsearch-exporter NAME: myes-exporter LAST DEPLOYED: Mon Jul 28 10:56:18 2025 NAMESPACE: default STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app=myes-exporter-elasticsearch-exporter" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:9108/metrics to use your application" kubectl port-forward $POD_NAME 9108:9108 --namespace default [root@master231 05-helm]# [root@master231 05-helm]# helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION myes-exporter default 1 2025-07-28 10:56:18.011736108 +0800 CST deployed elasticsearch-exporter-0.1.2 1.0.2 xiuxian default 6 2025-07-28 10:30:01.204347883 +0800 CST deployed oldboyedu-linux98-0.1.0 1.16.0 [root@master231 05-helm]# [root@master231 05-helm]# kubectl get deploy,svc,po -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR deployment.apps/myes-exporter-elasticsearch-exporter 1/1 1 1 2m13s elasticsearch-exporter justwatch/elasticsearch_exporter:1.0.2 app=elasticsearch-exporter,release=myes-exporter deployment.apps/xiuxian-oldboyedu-linux98 1/1 1 1 42m oldboyedu-linux98 registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1 app.kubernetes.io/instance=xiuxian,app.kubernetes.io/name=oldboyedu-linux98 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/kubernetes ClusterIP 10.200.0.1 <none> 443/TCP 2d23h <none> service/myes-exporter-elasticsearch-exporter ClusterIP 10.200.210.74 <none> 9108/TCP 2m13s app=elasticsearch-exporter,release=myes-exporter service/xiuxian-oldboyedu-linux98 ClusterIP 10.200.67.55 <none> 80/TCP 42m app.kubernetes.io/instance=xiuxian,app.kubernetes.io/name=oldboyedu-linux98 NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/myes-exporter-elasticsearch-exporter-5b68b7f954-ctzgw 1/1 Running 0 3s 10.100.2.184 worker233 <none> <none> pod/xiuxian-oldboyedu-linux98-68c6c66bb6-dd7st 1/1 Running 0 28m 10.100.2.182 worker233 <none> <none> [root@master231 05-helm]# [root@master231 05-helm]# curl -s 10.200.210.74:9108/metrics | tail process_open_fds 7 # HELP process_resident_memory_bytes Resident memory size in bytes. # TYPE process_resident_memory_bytes gauge process_resident_memory_bytes 6.7584e+06 # HELP process_start_time_seconds Start time of the process since unix epoch in seconds. # TYPE process_start_time_seconds gauge process_start_time_seconds 1.75367150895e+09 # HELP process_virtual_memory_bytes Virtual memory size in bytes. # TYPE process_virtual_memory_bytes gauge process_virtual_memory_bytes 1.0010624e+07 [root@master231 05-helm]# 温馨提示: 如果镜像拉取不成功,可以在我的仓库中找到即可。 http://192.168.21.253/Resources/Kubernetes/Add-ons/helm/ [root@worker232 ~]# wget http://192.168.21.253/Resources/Kubernetes/Add-ons/helm/oldboyedu-elasticsearch_exporter-v1.0.2.tar.gz --2025-07-28 11:16:33-- http://192.168.21.253/Resources/Kubernetes/Add-ons/helm/oldboyedu-elasticsearch_exporter-v1.0.2.tar.gz Connecting to 192.168.21.253:80... connected. HTTP request sent, awaiting response... 200 OK Length: 10606080 (10M) [application/octet-stream] Saving to: ‘oldboyedu-elasticsearch_exporter-v1.0.2.tar.gz’ oldboyedu-elasticsearch_expor 100%[===============================================>] 10.11M 8.69MB/s in 1.2s 2025-07-28 11:16:34 (8.69 MB/s) - ‘oldboyedu-elasticsearch_exporter-v1.0.2.tar.gz’ saved [10606080/10606080] [root@worker232 ~]# docker load -i oldboyedu-elasticsearch_exporter-v1.0.2.tar.gz 6a749002dd6a: Loading layer [==================================================>] 1.338MB/1.338MB 5f70bf18a086: Loading layer [==================================================>] 1.024kB/1.024kB 1692ded805c8: Loading layer [==================================================>] 2.629MB/2.629MB 9d1baef0b628: Loading layer [==================================================>] 6.618MB/6.618MB Loaded image: justwatch/elasticsearch_exporter:1.0.2
[root@master231 05-helm]# helm repo list NAME URL azure http://mirror.azure.cn/kubernetes/charts/ oldboyedu-aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts [root@master231 05-helm]# helm repo remove oldboyedu-aliyun "oldboyedu-aliyun" has been removed from your repositories [root@master231 05-helm]# helm repo list NAME URL azure http://mirror.azure.cn/kubernetes/charts/ [root@master231 05-helm]# helm repo remove azure "azure" has been removed from your repositories [root@master231 05-helm]# helm repo list Error: no repositories to show
Ingress和Service的区别 1.Service是实现了四层代理,不需要部署额外组件,原生支持; 2.Ingress实现的是七层代理,但需要部署附加组件(IngressClass)来解析Ingress资源清单;
Ingress-Nginx是K8S官方写的一个Ingress Controller,而"nginx-Ingress"是Nginx官方写的资源清单。 注意,部署时要观察对比一下K8S和Ingress-Nginx对应的版本以来关系哟。 github地址: https://github.com/kubernetes/ingress-nginx 安装文档: https://kubernetes.github.io/ingress-nginx/deploy/#installation-guide
如上图所示,官方推荐了三种安装方式: - 使用"helm"安装; - 使用"kubectl apply"创建yaml资源清单的方式进行安装; - 使用第三方插件的方式进行安装;
[root@master231 ingress-nginx]# helm repo add oldboyedu-ingress https://kubernetes.github.io/ingress-nginx "oldboyedu-ingress" has been added to your repositories [root@master231 ingress-nginx]# [root@master231 ingress-nginx]# helm repo list NAME URL oldboyedu-ingress https://kubernetes.github.io/ingress-nginx [root@master231 ingress-nginx]#
[root@master231 ingress-nginx]# helm search repo ingress-nginx NAME CHART VERSION APP VERSION DESCRIPTION oldboyedu-ingress/ingress-nginx 4.13.0 1.13.0 Ingress controller for Kubernetes using NGINX a... [root@master231 ingress-nginx]# [root@master231 ingress-nginx]# helm search repo ingress-nginx -l NAME CHART VERSION APP VERSION DESCRIPTION oldboyedu-ingress/ingress-nginx 4.13.0 1.13.0 Ingress controller for Kubernetes using NGINX a... oldboyedu-ingress/ingress-nginx 4.12.4 1.12.4 Ingress controller for Kubernetes using NGINX a... oldboyedu-ingress/ingress-nginx 4.12.3 1.12.3 Ingress controller for Kubernetes using NGINX a... oldboyedu-ingress/ingress-nginx 4.12.2 1.12.2 Ingress controller for Kubernetes using NGINX a... ... [root@master231 ingress-nginx]#
[root@master231 ingress-nginx]# helm pull oldboyedu-ingress/ingress-nginx --version 4.2.5 [root@master231 ingress-nginx]# [root@master231 ingress-nginx]# ll total 52 drwxr-xr-x 2 root root 4096 Jun 10 11:40 ./ drwxr-xr-x 8 root root 4096 Jun 10 11:40 ../ -rw-r--r-- 1 root root 42132 Jun 10 11:40 ingress-nginx-4.2.5.tgz [root@master231 ingress-nginx]# [root@master231 ingress-nginx]# svip: [root@master231 ingress-nginx]# wget http://192.168.21.253/Resources/Kubernetes/Add-ons/ingress-nginx/ingress-nginx-4.2.5.tgz
[root@master231 helm]# tar xf ingress-nginx-4.2.5.tgz [root@master231 helm]# [root@master231 helm]# sed -i '/registry:/s#registry.k8s.io#registry.cn-hangzhou.aliyuncs.com#g' ingress-nginx/values.yaml [root@master231 helm]# sed -i 's#ingress-nginx/controller#yinzhengjie-k8s/ingress-nginx#' ingress-nginx/values.yaml [root@master231 helm]# sed -i 's#ingress-nginx/kube-webhook-certgen#yinzhengjie-k8s/ingress-nginx#' ingress-nginx/values.yaml [root@master231 helm]# sed -i 's#v1.3.0#kube-webhook-certgen-v1.3.0#' ingress-nginx/values.yaml [root@master231 helm]# sed -ri '/digest:/s@^@#@' ingress-nginx/values.yaml [root@master231 helm]# sed -i '/hostNetwork:/s#false#true#' ingress-nginx/values.yaml [root@master231 helm]# sed -i '/dnsPolicy/s#ClusterFirst#ClusterFirstWithHostNet#' ingress-nginx/values.yaml [root@master231 helm]# sed -i '/kind/s#Deployment#DaemonSet#' ingress-nginx/values.yaml [root@master231 helm]# sed -i '/default:/s#false#true#' ingress-nginx/values.yaml
温馨提示: - 修改镜像为国内的镜像,否则无法下载海外镜像,除非你会FQ; - 如果使用我提供的镜像需要将digest注释掉,因为我的镜像是从海外同步过来的,被重新构建过,其digest不一致; - 建议大家使用宿主机网络效率最高,但是使用宿主机网络将来DNS解析策略会直接使用宿主机的解析; - 如果还想要继续使用K8S内部的svc名称解析,则需要将默认的"ClusterFirst"的DNS解析策略修改为"ClusterFirstWithHostNet"; - 建议将Deployment类型改为DaemonSet类型,可以确保在各个节点部署一个Pod,也可以修改"nodeSelector"字段让其调度到指定节点; - 如果仅有一个ingress controller,可以考虑将"ingressClassResource.default"设置为true,表示让其成为默认的ingress controller;
[root@master231 ingress-nginx]# vim ingress-nginx/values.yaml ... admissionWebhooks: ... 596 enabled: false # 关闭admissionWebhooks功能,避免后面使用Ingress时报错!
[root@master231 ingress-nginx]# helm upgrade --install ingress-server ingress-nginx -n ingress-nginx --create-namespace Release "ingress-server" does not exist. Installing it now. NAME: ingress-server LAST DEPLOYED: Mon Jul 28 11:50:11 2025 NAMESPACE: ingress-nginx STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: The ingress-nginx controller has been installed. It may take a few minutes for the LoadBalancer IP to be available. You can watch the status by running 'kubectl --namespace ingress-nginx get services -o wide -w ingress-server-ingress-nginx-controller' An example Ingress that makes use of the controller: apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example namespace: foo spec: ingressClassName: nginx rules: - host: www.example.com http: paths: - pathType: Prefix backend: service: name: exampleService port: number: 80 path: / # This section is only required if TLS is to be enabled for the Ingress tls: - hosts: - www.example.com secretName: example-tls If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided: apiVersion: v1 kind: Secret metadata: name: example-tls namespace: foo data: tls.crt: <base64 encoded cert> tls.key: <base64 encoded key> type: kubernetes.io/tls [root@master231 ingress-nginx]#
[root@master231 ingress-nginx]# helm list -n ingress-nginx NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION ingress-server ingress-nginx 1 2025-07-28 11:50:11.629524463 +0800 CST deployed ingress-nginx-4.2.5 1.3.1 [root@master231 ingress-nginx]# [root@master231 ingress-nginx]# kubectl get ingressclass,deploy,svc,po -n ingress-nginx -o wide NAME CONTROLLER PARAMETERS AGE ingressclass.networking.k8s.io/nginx k8s.io/ingress-nginx <none> 61s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/ingress-server-ingress-nginx-controller LoadBalancer 10.200.35.157 10.0.0.150 80:32384/TCP,443:31918/TCP 61s app.kubernetes.io/component=controller,app.kubernetes.io/instance=ingress-server,app.kubernetes.io/name=ingress-nginx NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/ingress-server-ingress-nginx-controller-58m2j 1/1 Running 0 61s 10.0.0.233 worker233 <none> <none> pod/ingress-server-ingress-nginx-controller-hfrrc 1/1 Running 0 61s 10.0.0.232 worker232 <none> <none> [root@master231 ingress-nginx]# [root@master231 ingress-nginx]# 温馨提示: 如果镜像拉取失败,可以使用我的仓库地址导入即可。 http://192.168.21.253/Resources/Kubernetes/Add-ons/ingress-nginx/images/
[root@master231 ingress-nginx]# curl http://10.0.0.150/ <html> <head><title>404 Not Found</title></head> <body> <center><h1>404 Not Found</h1></center> <hr><center>nginx</center> </body> </html>
本文作者:张龙龙
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!