Kubernetes 编排神器之 Helm
2019-12-24 13:37
369 查看
什么是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就执行成功了.
另,出现以下错误,代表pod
tiller-deploy-*未启动成功:
Error: could not find a ready tiller pod
详细资料参见 https://helm.sh/docs/ 官方文档
相关文章推荐
- Kubernetes编排工具-helm源码分析(helm客户端)
- Helm - Kubernetes服务编排的利器
- Kubernetes编排工具-helm源码分析(Tiller中status命令处理流程)
- Kubernetes编排工具-helm源码分析(模板解析流程)
- Kubernetes编排工具-helm源码分析(install命令处理流程)
- Kubernetes编排工具-helm中使用grpc
- Helm神器,让管理Kubernetes像yum安装包一样简单
- 初试 Kubernetes 集群中使用 Helm 搭建 Spinnaker 平台
- Kubernetes部署(十一):管理之Helm和Rancher部署
- kubernetes之helm简介、安装、配置、使用指南
- kubernetes容器编排系统介绍
- 将Node.js项目docker容器化并纳入kubernetes调度编排的实践
- 编排管理成容器云关键 Kubernetes(K8s)和Swarm对比分析
- kubernetes实战(十):k8s使用Helm安装harbor
- 看Kubernetes 1.5之后如何称霸容器编排管理界
- 为Kubernetes集群安装helm
- helm 部署 kubernetes-dashboard
- 利用Helm简化Kubernetes应用部署
- kubernetes 1.6集群再遇rbac问题(helm安装spark)
- 8月最新基于kubernetes的应用编排实践