赞
踩
前言
编写一堆Kubernetes配置文件是一件很麻烦的事情。对于一些容器,我们可能需要10多个yaml文件。维护它们是一个问题,而且在不同的环境中运行或使用相同的文件更是是一个噩梦。
我们可以使用一些 bash 技巧来替换某些值,但这是一个不好的做法。
这就是我们为什么要使用helm。
我应该提到,还有另一个很好的工具ksonnet
,它以自己的方式进行“相同”操作。
在这篇文章中,我将介绍为什么Helm是Kubernetes应用程序必不可少的要素,将Kubernetes应用程序与Helm打包的过程,以及如何使用Helm部署可能具有的某些复杂应用程序。
为什么要使用helm
我最近在部署的微服务很复杂,我的发布文件目录中有65个以上的Kubernetes配置文件 ... o(^▽^)┛)。
主要问题是,我要如何把这个服务部署到多个环境中?
或者如何使用Kubernetes制作CI/CD?
当然做一些shell脚本是一个选择,但是我不是很喜欢这样做。
然后,我开始使用Kubernetes研究CI/CD pipline,发现一些团队正在将Helm集成到该过程中。
我们可以将理解为为像应用程序包那样的应用程序,在其中我们可以进行依赖管理,不同类型的钩子(安装前,升级前,安装后等),并且可以轻松升级或回滚。
安装
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/ 官方文档
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。