什么是 Kubernetes Helm? 为什么要使用 Helm?
前言
编写一堆 Kubernetes 配置文件是一件很麻烦的事情. 对于一些容器, 我们可能需要 10 多个 YAML 文件. 维护它们是一个问题, 而且在不同的环境中运行或使用相同的文件更是是一个噩梦.
我们可以使用一些 bash 技巧来替换某些值, 但这是一个不好的做法.
这就是我们为什么要使用 helm.
我应该提到, 还有另一个很好的工具 ksonnet, 它以自己的方式进行 "相同" 操作.
在这篇文章中, 我将介绍为什么 Helm 是 Kubernetes 应用程序必不可少的要素, 将 Kubernetes 应用程序与 Helm 打包的过程, 以及如何使用 Helm 部署可能具有的某些复杂应用程序.
为什么要使用 helm
我最近在部署的微服务很复杂, 我的发布文件目录中有 65 个以上的 Kubernetes 配置文件 ... o(^▽^)┛).
主要问题是, 我要如何把这个服务部署到多个环境中?
或者如何使用 Kubernetes 制作 CI/CD?
当然做一些 shell 脚本是一个选择, 但是我不是很喜欢这样做.
然后, 我开始使用 Kubernetes 研究 CI/CD pipline, 发现一些团队正在将 Helm 集成到该过程中.
我们可以将理解为为像应用程序包那样的应用程序, 在其中我们可以进行依赖管理, 不同类型的钩子 (安装前, 升级前, 安装后等), 并且可以轻松升级或回滚.
安装
选择一个你需要安装的版本 https://github.com/helm/helm/releases
解压
tar -zxvf helm-v3.0.0-Linux-amd64.tar.gz
找到解压目录中的二进制文件, 把它移动到你的系统变量目录中 例如
- mv Linux-amd64/helm /usr/local/bin/helm
- [root@localhost helm-test]# helm init
- Creating /root/.helm
- Creating /root/.helm/repository
- Creating /root/.helm/repository/cache
- Creating /root/.helm/repository/local
- Creating /root/.helm/plugins
- Creating /root/.helm/starters
- Creating /root/.helm/cache/archive
- Creating /root/.helm/repository/repositories.YAML
- Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
- Adding local repo with URL: http://127.0.0.1:8879/charts
- $HELM_HOME has been configured at /root/.helm.
- Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
- Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
- To prevent this, run `helm init` with the --tiller-tls-verify flag.
- For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
- [root@localhost helm-test]#
查看 kubernetes kube-system 的 namespace 下的 pods
- [root@localhost test-App]# kubectl get pods --namespace=kube-system
- NAME READY STATUS RESTARTS AGE
- coredns-58cc8c89f4-q7lgg 1/1 Running 4 40d
- coredns-58cc8c89f4-wdqqx 1/1 Running 4 40d
- etcd-localhost.localdomain 1/1 Running 4 40d
- kube-apiserver-localhost.localdomain 1/1 Running 4 40d
- kube-controller-manager-localhost.localdomain 1/1 Running 4 40d
- kube-proxy-gt72b 1/1 Running 4 40d
- kube-scheduler-localhost.localdomain 1/1 Running 4 40d
- tiller-deploy-58f57c5787-t2b7w 0/1 ImagePullBackOff 0 22m
- weave.NET-qdr2l 2/2 Running 8 40d
- [root@localhost test-App]#
会发现 tiller-deploy-* 正在启动.
创建示例
- [root@localhost helm-test]# helm create test-App
- Creating test-App
创建完成后目录结构如下
- [root@localhost helm-test]# tree test-App/
- test-App/
├── charts
├── Chart.YAML
├── templates
│ ├── deployment.YAML
│ ├── _helpers.tpl
│ ├── ingress.YAML
│ ├── NOTES.txt
│ ├── serviceaccount.YAML
│ ├── service.YAML
│ └── tests
│ └── test-connection.YAML
└── values.YAML
- 3 directories, 9 files
- [root@localhost helm-test]#
Chart.YAML: 这是包含对图表的描述的主文件
values.YAML: 这是包含图表默认值的文件
templates: 这是 Kubernetes 资源定义为模板的目录
charts: 这是一个可选目录, 可能包含子图表
% 重点 %
正像我们看到的一样, 所有 templates 文件夹中 Kubernetes 配置文件都是模板.
你可以使用 Chart.YAML 文件来描述当前的项目, 并且可以对它进行版本控制.
我们只需要一个文件, 用于配置应用程序, 并在 values.YAML 中存储所有值.
运行 :
helm install --name test test-App/
这样我们第一个 helm 的 demo 就执行成功了.
另, 出现以下错误, 代表 podtiller-deploy-* 未启动成功:
Error: could not find a ready tiller pod
详细资料参见 https://helm.sh/docs/ 官方文档
来源: https://www.cnblogs.com/jasondayee/p/12091046.html