当前位置:   article > 正文

Kubernetes 编排神器之 Helm_helmchart可视化编排工具

helmchart可视化编排工具
什么是Kubernetes Helm?为什么要使用Helm?
时光小说网 wap.youxs.org

前言

编写一堆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
  1. [root@localhost helm-test]# helm init
  2. Creating /root/.helm
  3. Creating /root/.helm/repository
  4. Creating /root/.helm/repository/cache
  5. Creating /root/.helm/repository/local
  6. Creating /root/.helm/plugins
  7. Creating /root/.helm/starters
  8. Creating /root/.helm/cache/archive
  9. Creating /root/.helm/repository/repositories.yaml
  10. Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
  11. Adding local repo with URL: http://127.0.0.1:8879/charts
  12. $HELM_HOME has been configured at /root/.helm.
  13. Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
  14. Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
  15. To prevent this, run `helm init` with the --tiller-tls-verify flag.
  16. For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
  17. [root@localhost helm-test]#

查看kubernetes kube-system的namespace下的pods

  1. [root@localhost test-app]# kubectl get pods --namespace=kube-system
  2. NAME READY STATUS RESTARTS AGE
  3. coredns-58cc8c89f4-q7lgg 1/1 Running 4 40d
  4. coredns-58cc8c89f4-wdqqx 1/1 Running 4 40d
  5. etcd-localhost.localdomain 1/1 Running 4 40d
  6. kube-apiserver-localhost.localdomain 1/1 Running 4 40d
  7. kube-controller-manager-localhost.localdomain 1/1 Running 4 40d
  8. kube-proxy-gt72b 1/1 Running 4 40d
  9. kube-scheduler-localhost.localdomain 1/1 Running 4 40d
  10. tiller-deploy-58f57c5787-t2b7w 0/1 ImagePullBackOff 0 22m
  11. weave-net-qdr2l 2/2 Running 8 40d
  12. [root@localhost test-app]#

会发现tiller-deploy-*正在启动.

创建示例

  1. [root@localhost helm-test]# helm create test-app
  2. Creating test-app
  • 创建完成后目录结构如下
  1. [root@localhost helm-test]# tree test-app/
  2. test-app/
  3. ├── charts
  4. ├── Chart.yaml
  5. ├── templates
  6. │   ├── deployment.yaml
  7. │   ├── _helpers.tpl
  8. │   ├── ingress.yaml
  9. │   ├── NOTES.txt
  10. │   ├── serviceaccount.yaml
  11. │   ├── service.yaml
  12. │   └── tests
  13. │   └── test-connection.yaml
  14. └── values.yaml
  15. 3 directories, 9 files
  16. [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/ 官方文档

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/246627
推荐阅读
相关标签
  

闽ICP备14008679号