1. 首页 > Linux教程 > 正文

Linux教程FG446-Kubernetes Helm包管理

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

本文档介绍Kuber

风哥提示:

netes Helm包管理工具的使用方法。

Part01-Helm基础

from PG视频:www.itpux.com

1.1 Helm概述

# Helm核心概念
[root@k8s-master ~]# cat > /root/helm-intro.txt << 'EOF' Helm核心概念 ============ 1. Chart - 应用包定义 - 包含Kubernetes资源模板 - 可配置参数 2. Release - Chart的安装实例 - 运行在集群中 - 可升级和回滚 3. Repository - Chart存储仓库 - 公有/私有仓库 - 版本管理 4. 常用命令 - helm install: 安装Chart - helm upgrade: 升级Release - helm rollback: 回滚Release - helm uninstall: 卸载Release - helm list: 列出Release EOF # 查看Helm版本 [root@k8s-master ~]# helm version version.BuildInfo{Version:"v3.13.0", GitCommit:"abc123", GitTreeState:"clean", GoVersion:"go1.21.5"} # 添加仓库 [root@k8s-master ~]# helm repo add bitnami https://charts.bitnami.com/bitnami "bitnami" has been added to your repositories [root@k8s-master ~]# helm repo add fgedu https://charts.fgedu.net.cn "fgedu" has been added to your repositories # 更新仓库 [root@k8s-master ~]# helm repo update Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "bitnami" chart repository ...Successfully got an update from the "fgedu" chart repository Update Complete. ⎈Happy Helming!⎈ # 搜索Chart [root@k8s-master ~]# helm search repo nginx NAME CHART VERSION APP VERSION DESCRIPTION bitnami/nginx 15.0.0 1.25.0 NGINX Open Source is a web server that can be ... bitnami/nginx-ingress 9.9.0 1.9.0 NGINX Ingress Controller provides an easy-to-u...

Part02-Chart安装

2.1 安装应用

# 查看Chart信息
[root@k8s-master ~]# helm show chart bitnami/nginx
annotations:
category: Infrastructure
apiVersion: v2
appVersion: 1.25.0
description: NGINX Open Source is a web server that can be used as a reverse proxy, load balancer, and more.
home: https://bitnami.com
icon: https://bitnami.com/assets/stacks/nginx/img/nginx-stack-220×234.png
keywords:
– nginx
– http
– web
– www
– reverse proxy
maintainers:
– name: VMware, Inc.
url: https://github.com/bitnami/charts
name: nginx
sources:
– https://github.com/bitnami/charts/tree/main/bitnami/nginx
version: 15.0.0

# 查看Chart默认值
[root@k8s-master ~]# helm show values bitnami/nginx > nginx-values.yaml

# 安装Chart
[root@k8s-master ~]# helm install fgedu-nginx bitnami/nginx \
–namespace fgedu-prod \
–set replicaCount=3 \
–set service.type=NodePort \
–set service.nodePorts.http=30080
NAME: fgedu-nginx
LAST DEPLOYED: Sat Apr 4 14:00:00 2026
NAMESPACE: fgedu-prod
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 15.0.0
APP VERSION: 1.25.0

** Please be patient while the chart is being deployed **

NGINX can be accessed through the following DNS name from within your cluster:

fgedu-nginx.fgedu-prod.svc.cluster.local (port 80)

To access NGINX from outside the cluster, execute the following commands:

export NODE_PORT=$(kubectl get –namespace fgedu-prod -o jsonpath=”{.spec.ports[0].nodePort}” services fgedu-nginx)
export NODE_IP=$(kubectl get nodes –namespace fgedu-prod -o jsonpath=”{.items[0].status.addresses[0].address}”)
echo http://$NODE_IP:$NODE_PORT

# 查看安装的Release
[root@k8s-master ~]# helm list -n fgedu-prod
NAME NAMESPACE REVISION STATUS CHART APP VERSION
fgedu-nginx fgedu-prod 1 deployed nginx-15.0.0 1.25.0

# 查看Release状态
[root@k8s-master ~]# helm status fgedu-nginx -n fgedu-prod
NAME: fgedu-nginx
LAST DEPLOYED: Sat Apr 4 14:00:00 2026
NAMESPACE: fgedu-prod
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 15.0.0
APP VERSION: 1.25.0

Part03-Chart管理

3.1 升级与回滚

# 升级Release
[root@k8s-master ~]# helm upgrade fgedu-nginx bitnami/nginx \
–namespace fgedu-prod \
–set replicaCount=5 \
–set resources.requests.cpu=200m \
–set resources.requests.memory=256Mi
Release “fgedu-nginx” has been upgraded. Happy Helming!
NAME: fgedu-nginx
LAST DEPLOYED: Sat Apr 4 14:30:00 2026
NAMESPACE: fgedu-prod
STATUS: deployed
REVISION: 2

# 查看升级历史
[root@k8s-master ~]# helm history fgedu-nginx -n fgedu-prod
REVISION STATUS CHART DESCRIPTION
1 superseded nginx-15.0.0 Install complete
2 deployed nginx-15.0.0 Upgrade complete

# 回滚到版本1
[root@k8s-master ~]# helm rollback fgedu-nginx 1 -n fgedu-prod
Rollback was a success! Happy Helming!

# 查看回滚历史
[root@k8s-master ~]# helm history fgedu-nginx -n fgedu-prod
REVISION STATUS CHART DESCRIPTION
1 学习交流加群风哥微信: itpux-com superseded nginx-15.0.0 Install complete
2 superseded nginx-15.0.0 Upgrade complete
3 deployed nginx-15.0.0 Rollback to 1

# 使用values文件安装
[root@k8s-master ~]# cat > fgedu-values.yaml << 'EOF' replicaCount: 3 image: registry: docker.io repository: bitnami/nginx tag: 1.25.0 service: type: NodePort nodePorts: http: 30080 resources: requests: cpu: 100m memory: 128Mi limits: cpu: 500m memory: 512Mi ingress: enabled: true hostname: fgedu.net.cn EOF [root@k8s-master ~]# helm upgrade --install fgedu-nginx bitnami/nginx \ --namespace fgedu-prod \ -f fgedu-values.yaml Release "fgedu-nginx" has been upgraded. Happy Helming!

Part04-自定义Chart

4.1 创建Chart

# 创建Chart
[root@k8s-master ~]# helm create fgedu-app
Creating fgedu-app

# 查看Chart结构
[root@k8s-master ~]# tree fgedu-app/
fgedu-app/
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml

# 编辑Chart.yaml
[root@k8s-master ~]# cat > fgedu-app/Chart.yaml << 'EOF' apiVersion: v2 name: fgedu-app description: FGEDU Web Application type: application version: 1.0.0 appVersion: "1.0.0" maintainers: 学习交流加群风哥QQ113257174 - name: fgedu email: admin@fgedu.net.cn EOF # 编辑values.yaml [root@k8s-master ~]# cat > fgedu-app/values.yaml << 'EOF' replicaCount: 3 image: repository: nginx pullPolicy: IfNotPresent tag: "1.25" service: type: ClusterIP port: 80 resources: limits: cpu: 500m memory: 512Mi requests: cpu: 100m memory: 128Mi ingress: enabled: true className: "nginx" hosts: - host: fgedu.net.cn paths: - path: / pathType: ImplementationSpecific EOF # 验证Chart [root@k8s-mast更多学习教程公众号风哥教程itpux_comer ~]# helm lint fgedu-app ==> Linting fgedu-app
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed

# 打包Chart
[root@k8s-master ~]# helm package fgedu-app
Successfully packaged chart and saved it to: /root/fgedu-app-1.0.0.tgz

# 安装自定义Chart
[root@k8s-master ~]# helm install fgedu-web ./fgedu-app-1.0.0.tgz -n fgedu-prod
NAME: fgedu-web
LAST DEPLOYED: Sat Apr 4 15:00:00 2026
NAMESPACE: fgedu-prod
STATUS: deployed
REVISION: 1

风哥针对Helm使用建议:

  • 使用values文件管理配置
  • 版本化管理Chart
  • 使用命名空间隔离环境
  • 定期备份Release历史
  • 测试Chart后再部署

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息