helm v3的引入

简介: helm v3的引入

helm介绍

helm是一个k8s的包管理工具,就像linux系统下的包管理器,如yum、apt等,可以很方便的将之前打包好的yaml文件部署到k8s上


相比之前的部署一个简单的服务流程:


(1)编写yaml文件


(2)创建pod


(3)创建svc


(4)做代理Ingress


这种部署单一的应用,相对于简单的应用比较合适,如果是微服务项目,需要几十个服务,每一个服务都有一套yaml文件,维护与更改就不是很方便


但是使用helm可以:


(1)把yaml文件整体管理起来


(2)实现yaml的高效复用


(3)使用helm应用级别的版本管理(升级降级)


 其中有3个重要的概念


(1)helm:一个命令行客户端工具,主要是用于k8s应用chart的创建、打包、发布和管理


(2)chart:应用描述,一系列用于描述k8s资源相关文件的集合,把yaml打包,是yaml的集合,支持推送到docker仓库中


(3)release:基于chart的部署实体,应用级别的版本管理。一个chart被helm运行后将会生成对应的一个release,将在k8s中创建出真实运行的资源对象。


helm v3版本安装


   (1)下载helm tar文件包,上传到linux服务器中


   (2)把helm文件移到/usr/bin目录下


   (3)完成

[root@k8s-master dwz]# tar -zxvf helm-v3.3.4-linux-amd64.tar.gz 
linux-amd64/
linux-amd64/README.md
linux-amd64/LICENSE
linux-amd64/helm
[root@k8s-master dwz]# ls
gisserver  helm-v3.3.4-linux-amd64.tar.gz  iserver  linux-amd64
[root@k8s-master dwz]# cd linux-amd64/
[root@k8s-master linux-amd64]# ls
helm  LICENSE  README.md
[root@k8s-master linux-amd64]# mv helm /usr/bin/
[root@k8s-master linux-amd64]# helm
The Kubernetes package manager
Common actions for Helm:
- helm search:    search for charts
- helm pull:      download a chart to your local directory to view
- helm install:   upload the chart to Kubernetes
- helm list:      list releases of charts
Environment variables:
| Name                               | Description                                                                       |
|------------------------------------|-----------------------------------------------------------------------------------|
| $HELM_CACHE_HOME                   | set an alternative location for storing cached files.                             |
| $HELM_CONFIG_HOME                  | set an alternative location for storing Helm configuration.                       |
| $HELM_DATA_HOME                    | set an alternative location for storing Helm data.                                |
| $HELM_DRIVER                       | set the backend storage driver. Values are: configmap, secret, memory, postgres   |
| $HELM_DRIVER_SQL_CONNECTION_STRING | set the connection string the SQL storage driver should use.                      |
| $HELM_NO_PLUGINS                   | disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins.                        |
| $KUBECONFIG                        | set an alternative Kubernetes configuration file (default "~/.kube/config")       |


配置helm仓库


(1)添加仓库


helm repo add 仓库名称 仓库地址

[root@k8s-master linux-amd64]# helm repo add aliyun https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/
"aliyun" has been added to your repositories


(2)查看仓库

[root@k8s-master linux-amd64]# helm repo list
NAME      URL                                                                      
aliyun    https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/

(3)更新仓库地址

[root@k8s-master ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "aliyun" chart repository
Update Complete. ⎈Happy Helming!⎈


(4)移除仓库

[root@k8s-master ~]# helm  repo remove aliyun
"aliyun" has been removed from your repositories
[root@k8s-master ~]# helm repo list
Error: no repositories to show


使用helm快速部署应用实例


添加微软仓库

[root@k8s-master ~]# helm repo add weiruan http://mirror.azure.cn/kubernetes/charts/
"weiruan" has been added to your repositories

(1)使用命令搜索应用(weave)

[root@k8s-master ~]# helm search repo weave
NAME                   CHART VERSION    APP VERSION    DESCRIPTION                                       
weiruan/weave-cloud    0.3.9            1.4.0          DEPRECATED - Weave Cloud is a add-on to Kuberne...
weiruan/weave-scope    1.1.12           1.12.0         DEPRECATED - A Helm chart for the Weave Scope c...


(2)根据搜索内容选择安装应用


[root@k8s-master ~]# helm install ui weiruan/weave-scope


(3)查看安装列表

[root@k8s-master ~]# helm list
NAME    NAMESPACE    REVISION    UPDATED                                    STATUS      CHART                APP VERSION
ui      default      1           2020-10-28 15:19:15.421361319 +0800 CST    deployed    weave-scope-1.1.8    1.12.0


(4)查看安装具体信息


[root@k8s-master ~]# helm status ui
NAME: ui
LAST DEPLOYED: Wed Oct 28 15:19:15 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
You should now be able to access the Scope frontend in your web browser, by
using kubectl port-forward:
kubectl -n default port-forward $(kubectl -n default get endpoints \
ui-weave-scope -o jsonpath='{.subsets[0].addresses[0].targetRef.name}') 8080:4040
then browsing to http://localhost:8080/.
For more details on using Weave Scope, see the Weave Scope documentation:
https://www.weave.works/docs/scope/latest/introducing/



(5)查看pod运行状态


[root@k8s-master ~]# kubectl get pod 
NAME                                            READY   STATUS        RESTARTS   AGE
weave-scope-agent-ui-655pp                      1/1     Running       3          15d
weave-scope-agent-ui-bzttt                      1/1     Running       2          15d
weave-scope-agent-ui-hkxfz                      1/1     Running       1          15d
weave-scope-cluster-agent-ui-5d4d6c97bf-5xpqf   1/1     Terminating   0          8d
weave-scope-cluster-agent-ui-5d4d6c97bf-f528k   1/1     Running       1          7d1h
weave-scope-frontend-ui-757c6668c5-vqpdj        1/1     Running       1          7d1h
weave-scope-frontend-ui-757c6668c5-zhlzp        1/1     Terminating   0          8d


(6)查看svc情况


[root@k8s-master ~]# kubectl get svc
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP        50d
ui-weave-scope   ClusterIP   10.102.105.28   <none>        80:32448/TCP   15d

现在的weave的svc类型是ClusterIP,需要给改成NodePort类型,外部就可以访问了

[root@k8s-master ~]# kubectl edit svc ui-weave-scope

1675173113084.jpg


保存退出


再查看svc

[root@k8s-master ~]# kubectl get svc
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP        50d
ui-weave-scope   NodePort    10.102.105.28   <none>        80:32448/TCP   15d


使用浏览器访问http://ip:32448

1675173130403.jpg


完成一键安装部署


创建自定义Chart


1.使用命令创建Chart

[root@k8s-master helm]# helm create mychart
Creating mychart


创建成功之后,会生成四个文件


charts


Chart.yaml     当前chart属性配置信息


templates      编写yaml文件存放的目录


values.yaml    yaml文件可以使用的全局变量


2.在templates中创建yaml文件

[root@k8s-master templates]# kubectl create deployment web --image=nginx --dry-run -o yaml > deployment-nginx.yaml
[root@k8s-master templates]# kubectl get pod 
NAME                                            READY   STATUS        RESTARTS   AGE
weave-scope-agent-ui-655pp                      1/1     Running       3          15d
weave-scope-agent-ui-bzttt                      1/1     Running       2          15d
weave-scope-agent-ui-hkxfz                      1/1     Running       1          15d
weave-scope-cluster-agent-ui-5d4d6c97bf-5xpqf   1/1     Terminating   0          8d
weave-scope-cluster-agent-ui-5d4d6c97bf-f528k   1/1     Running       1          7d4h
weave-scope-frontend-ui-757c6668c5-vqpdj        1/1     Running       1          7d4h
weave-scope-frontend-ui-757c6668c5-zhlzp        1/1     Terminating   0          8d
web-d86c95cc9-kvssx                             1/1     Running       0          30m


删除web这个pod,因为我们要用helm方式创建

[root@k8s-master templates]# kubectl delete deployment web
deployment.apps "web" deleted
kubectl expose  deployment web --port=80 --target-port=80 --type=NodePort --dry-run -o yaml > service .yaml

创建完deployment之后,pod成功启动才能创建svc,要不然会报错(这两步是为了生成yaml文件,自己写有些麻烦)

[root@k8s-master templates]# ls
deployment-nginx.yaml  service.yaml


3.安装mychart

[root@k8s-master helm]# helm install nginx mychart/
NAME: nginx
LAST DEPLOYED: Thu Nov 12 20:18:36 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None


查看pod、svc

[root@k8s-master helm]# kubectl get pod 
NAME                                            READY   STATUS        RESTARTS   AGE
weave-scope-agent-ui-655pp                      1/1     Running       3          15d
weave-scope-agent-ui-bzttt                      1/1     Running       2          15d
weave-scope-agent-ui-hkxfz                      1/1     Running       1          15d
weave-scope-cluster-agent-ui-5d4d6c97bf-5xpqf   1/1     Terminating   0          8d
weave-scope-cluster-agent-ui-5d4d6c97bf-f528k   1/1     Running       1          7d4h
weave-scope-frontend-ui-757c6668c5-vqpdj        1/1     Running       1          7d4h
weave-scope-frontend-ui-757c6668c5-zhlzp        1/1     Terminating   0          8d
web-d86c95cc9-vzmnd                             1/1     Running       0          6m23s
[root@k8s-master helm]# kubectl get svc
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP        50d
ui-weave-scope   NodePort    10.102.105.28   <none>        80:32448/TCP   15d
web              NodePort    10.98.105.180   <none>        80:31375/TCP   6m28s


浏览器访问:http://ip:31375

1675173185764.jpg


重载应用

[root@k8s-master helm]# helm upgrade nginx mychart
Release "nginx" has been upgraded. Happy Helming!
NAME: nginx
LAST DEPLOYED: Thu Nov 12 21:49:50 2020
NAMESPACE: default
STATUS: deployed
REVISION: 3
TEST SUITE: None
相关实践学习
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
12天前
|
人工智能 自然语言处理 文字识别
阿里云百炼Qwen3.7-Max简介:能力、优势、支持订阅计划参考
Qwen3.7-Max是阿里云百炼面向智能体时代推出的新一代旗舰模型,对标GPT-5.5、Claude Opus 4.7等闭源旗舰。该模型支持百万级token上下文窗口,具备顶级推理能力、多模态搜索与视觉理解增强、流式输出低延迟响应等核心优势,覆盖编程、办公、长周期自主执行等复杂场景。同时支持OpenAI接口兼容,便于系统快速迁移。用户可通过Token Plan团队或节省计划等订阅方式灵活调用,适合企业级高要求场景使用。
4841 23
阿里云百炼Qwen3.7-Max简介:能力、优势、支持订阅计划参考
|
7天前
|
存储 定位技术 数据库
CodeGraph 如何让 Claude Code减少 7 成工具调用?
CodeGraph 为 Coding Agent 提供本地代码知识图谱,把函数、类、调用链和框架路由提前整理成“项目地图”,减少盲目搜索和文件读取。它不是新 Agent,而是上下文基础设施,让 Agent 更快找到正确代码路径,平均减少 7 成工具调用。
935 0
|
14天前
|
人工智能 自然语言处理 供应链
|
20天前
|
人工智能 开发工具 iOS开发
Claude Code 新手完全上手指南:安装、国产模型配置与常用命令全解
Claude Code 是一款运行在终端环境中的 AI 编程助手,能够直接在命令行中完成代码生成、项目分析、文件修改、命令执行、Git 管理等开发全流程工作。它最大的特点是**任务驱动、终端原生、轻量高效、多模型兼容**,无需图形界面、不依赖 IDE 插件,能够深度融入开发者日常工作流。
3738 15
|
16天前
|
人工智能 Linux BI
国内用 Claude Code 终于不用翻墙了:一行命令搞定,自动接 DeepSeek
JeecgBoot AI专题研究 一键脚本:Claude Code + JeecgBoot Skills + DeepSeek 全平台接入 一行命令装好 Claude Code + JeecgBoot Skills + DeepSeek 接入,无需翻墙使用 Claude Code,支持 Wind
3365 9
国内用 Claude Code 终于不用翻墙了:一行命令搞定,自动接 DeepSeek
|
23天前
|
Shell API 开发工具
Claude Code 快速上手指南(新手友好版)
AI编程工具卷疯啦!Claude Code凭借任务驱动+终端原生的特性,成了开发者的效率搭子。本文从安装、登录、切换国产模型到常用命令,手把手带新手快速上手,全程避坑,30分钟独立用起来。
3927 25

热门文章

最新文章