[k8s]helm使用

news/2025/3/26 15:42:28/

helm

linux 安装

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

  • 每个Helm 版本都提供了各种操作系统的二进制版本,这些版本可以手动下载和安装。

  1. 下载 需要的版本
  2. 解压(tar -zxvf helm-v3.0.0-linux-amd64.tar.gz)
  3. 在解压目录中找到helm程序,移动到需要的目录中(mv linux-amd64/helm /usr/local/bin/helm)
  4. 添加仓库: helm repo add bitnami https://charts.bitnami.com/bitnami
  5. 验证安装: helm help.

概念

  • Chart 代表着 Helm 包。它包含在 Kubernetes 集群内部运行应用程序,工具或服务所需的所有资源定义。你可以把它看作是 Homebrew formula,Apt dpkg,或 Yum RPM 在Kubernetes 中的等价物。
  • Repository(仓库) 是用来存放和共享 charts 的地方。它就像 Perl 的 CPAN 档案库网络 或是 Fedora 的 软件包仓库,只不过它是供 Kubernetes 包所使用的。
  • Release 是运行在 Kubernetes 集群中的 chart 的实例。一个 chart 通常可以在同一个集群中安装多次。每一次安装都会创建一个新的 release。以 MySQL chart为例,如果你想在你的集群中运行两个数据库,你可以安装该chart两次。每一个数据库都会拥有它自己的 release 和 release name。

使用

搜索

  • helm search hub 从 Artifact Hub 中查找并列出 helm charts。 Artifact Hub中存放了大量不同的仓库。
  • helm search repo 从你添加(使用 helm repo add)到本地 helm 客户端中的仓库中进行查找。该命令基于本地数据进行搜索,无需连接互联网。

安装

  • 需要有k8s环境
  • [root@k8s-node1 ~]# helm install nginx bitnami/nginx‘
  • 注意: 安装chart时创建了一个新的 release 对象。上述发布被命名为 nginx。 (如果想让Helm生成一个名称,删除发布名称并使用–generate-name
  • helm list
  • helm status nginx
  • helm uninstall nginx

创建功能chart

  • 自定义的 chart
helm create app
  • 查看 chart 目录结构
    • templates/ 目录包括了模板文件。当Helm评估chart时,会通过模板渲染引擎将所有文件发送到templates/目录中。 然后收集模板的结果并发送给Kubernetes。
    • values.yaml 文件也导入到了模板。这个文件包含了chart的 默认值 。这些值会在用户执行helm install 或 helm upgrade时被覆盖。
    • Chart.yaml 文件包含了该chart的描述。你可以从模板中访问它。charts/目录 可以 包含其他的chart(称之为 子chart)。
app/Chart.yamlvalues.yamlcharts/templates/...

自定义模板


rm -rf mychart/templates/*
  • 编写 namespace.yaml
apiVersion: v1
kind: Namespace
metadata:name: {{ .Chart.Name }}namespace: {{ .Values.namespace }}
  • 编写 deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:name: {{ .Chart.Name}}namespace: {{.Values.namespace}}labels:app: {{ .Chart.Name}}
spec:replicas: {{ .Values.replicas }}template:metadata:name: {{ .Chart.Name}}labels:app: {{ .Chart.Name}}spec:containers:- name: {{ .Chart.Name}}image: {{ .Values.image}}imagePullPolicy: {{.Values.imagePullPolicy}}ports:- containerPort: {{.Values.containerPort}}restartPolicy: {{ .Values.restartPolicy }}selector:matchLabels:app: {{ .Chart.Name}}
  • 编写 service.yml
apiVersion: v1
kind: Service
metadata:name: {{.Chart.Name}}namespace: {{.Values.namespace}}
spec:selector:app: {{.Chart.Name}}ports:- port: {{.Values.service.port}}targetPort: {{.Values.containerPort}}type: {{ .Values.service.type }}
  • 编写chart.yaml
apiVersion: v2
name: app
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
  • 编写 values.yaml
replicas: 1
namespace: app
image: nginx:1.19
imagePullPolicy: IfNotPresent
restartPolicy: Always
containerPort: 80service:port: 80type: ClusterIP
  • 验证是否存在错误
helm lint app
  • 打包自定义 chart
helm package app
  • 安装
helm install app app-0.1.0.tgz

http://www.ppmy.cn/news/1035059.html

相关文章

实战:工作中对并发问题的处理 | 京东物流技术团队

1. 问题背景 问题发生在快递分拣的流程中,我尽可能将业务背景简化,让大家只关注并发问题本身。 分拣业务针对每个快递包裹都会生成一个任务,我们称它为 task。task 中有两个字段需要关注,一个是分拣中发生的异常(exp…

vue3 如果切换角色后权限不同 怎么清空之前添加动态路由。

项目中切换角色后发现会保留前面一个角色的权限,方法一是到login页面,权限重新reload,不过这样确实会影响体验,如果不采用此方案的话,你可以看下我从发现问题到解决问题的思路: 1、首先要找到一个初始状态…

Docker容器:docker基础及安装

文章目录 一.docker容器概述1.什么是容器2. docker与虚拟机的区别2.1 docker虚拟化产品有哪些及其对比2.2 Docker与虚拟机的区别 3.Docker容器的使用场景4.Docker容器的优点5.Docker 的底层运行原理6.namespace的六项隔离7.Docker核心概念 二.Docker安装 及管理1.安装 Docker1.…

opencv实现以图搜图

这里写目录标题 1. 步骤1.1 导入OpenCV库:1.2 加载图像1.3 提取特征1.4 匹配特征1.5 显示结果 2. 完整代码3. 测试图片及效果 1. 步骤 1.1 导入OpenCV库: 在您的C代码中,首先需要导入OpenCV库。您可以使用以下语句导入核心模块:…

MongoDB增删改查操作

数据库操作&#xff1a; 在MongoDB中&#xff0c;文档集合存在数据库中。 要选择使用的数据库&#xff0c;请在mongo shell程序中发出 use <db> 语句 // 查看有哪些数据库 show dbs;// 如果数据库不存在&#xff0c;则创建并切换到该数据库&#xff0c;存在则直接切换到…

ChatGPT​保密吗?它有哪些潜在风险?如何规避?

自2022年11月公开发布以来&#xff0c;ChatGPT已成为许多企业和个人的必备工具&#xff0c;但随着该技术越来越多地融入我们的日常生活&#xff0c;人们很自然地想知道&#xff1a;ChatGPT是否是保密的。 问&#xff1a;ChatGPT保密吗&#xff1f; 答&#xff1a;否&#xff0…

Python Flask+Echarts+sklearn+MySQL(评论情感分析、用户推荐、BI报表)项目分享

Python FlaskEchartssklearnMySQL(评论情感分析、用户推荐、BI报表)项目分享 项目背景&#xff1a; 随着互联网的快速发展和智能手机的普及&#xff0c;人们越来越倾向于在网上查找餐厅、购物中心、酒店和旅游景点等商户的点评和评分信息&#xff0c;以便做出更好的消费决策。…

JIRA:项目管理的秘密武器

引言 在当今动态且快速变化的商业环境中&#xff0c;项目管理已经成为任何组织成功的关键因素。能够有效地管理项目&#xff0c;保证项目在设定的时间和预算内按照预期的质量完成&#xff0c;是每个项目经理的目标。为了实现这个目标&#xff0c;项目经理需要依赖强大的工具&a…