很喜欢杨绛说过的一句话,读书不是为了拿个好文凭也不是为了发财,读书的意义在于成为一个有温度、懂情趣、会思考的人。
Helm 使用
一、 Helm基本介绍
1、背景介绍
linux操作系统中我们会通过yum进行包的安装,k8s中也有对应的包管理工具—Helm
对于单体服务,部署一套测试环境比较快,但是对于微服务架构的应用,就相对有点麻烦。Helm就相当于k8s环境下的yum包管理工具,可以方便快捷的将之前打包好的yaml文件快速部署进kubernetes内。说到底,就是对chart的管理,比如集中管理yaml,利用模板动态对yaml中的字段进行修改等。
2、两个重要概念
chart: 是创建一个应用的信息集合,包括各种配置模板、定义参数以及说明等
release: chart的一个运行实例,代表了一个正在运行的应用
3、基本组件
客户端 (helm命令行操作) 和 服务端 (V2,必须同时部署客户端和服务端才可以使用)gRPC协议  V3版本之后 直接通过 Helm客户端与apiserver进行交互
二、helm基本命令&集中管理yaml
查看helm版本
helm version

kubectl get pod -n kube-system

查看当前的服务
kubectl get svc
helm list |grep wangzi
删除service
helm delete wangzilaoshi
删除之后发现 pod deployment等也一并被删除,这就是helm的管理功能,一起部署一起删除。
 
创建一个chart
helm create nginx
 _helpers.tpl 放yaml都可能用到的一些字段信息 values.yaml 模板下的yaml文件用到的一些变量的值 Chart.yaml 模板下的yaml文件可以引用,主要是对这个chart的一些描述信息  templates文件夹下主要是一些yaml文件模板 
查看chart元数据信息
helm inspect chart nginx

helm package nginx

helm升级版本
helm upgrade mc-service mc-service
查看Release历史版本
helm history mc-service

版本回滚
helm rollback [服务名称] 服务版本

 
kubectl create deployment wangzi --image=nginx -o yaml --dry-run=client > deployment.yaml
dry-run=client 创建 deployment 的配置,但 将其以 YAML 格式在标准输出上打印而不是发送给 API 服务器

通过yaml手动部署
kubectl apply -f deployment.yaml

删除deployment
kubectl delete deploy wangzi

通过helm 直接进行安装 /root/test表示chart目录 可以通过--name指定svc名字
helm install --name wangzi /root/test

三、利用模板动态对yaml中的字段进行修改
常见的内置对象
Release.Name release名字
Release.NameSpace release命名空间
Release.Service release服务名字
Release.Revision release修订版本号,从1开始累加
 手动将其中可能会变化的字段进行替换  value.yaml中的键值对需要和deployment.yaml中的保持一致 
测试一下配置文件有没有问题,dry-run命令运行成功之后,helm list中不会有相应的svc产生
helm install /root/test/nginx --dry-run
helm lint nginx/

 21行的字段缩进有问题,更新之后重新检查,没有报错可以正常进行安装
 
helm install --name wangzilaoshi /root/test/nginx
安装之后检查对应的pod数量,已经按照模板中定义的数量启动成功了

查询一个特定release的状态
helm status resop

查看一些被 helm delete [服务名字] 命令删除的服务
helm ls --deleted

彻底删除所有相关的kubernetes资源和历史记录
helm delete --purge dianxia

|