我每天的大部分时间都涉及创建,修改和部署Helm图表以管理应用程序的部署。Helm是Kubernetes的应用程序包管理器,负责协调应用程序的下载,安装和部署。Helm图表是我们将应用程序定义为相关Kubernetes资源的集合的方式。
那么,为什么有人会使用头盔?Helm通过模板化的方法使在Kubernetes内部管理应用程序部署更加容易。所有Helm图表都遵循相同的结构,同时仍具有足够的灵活性以表示可以在Kubernetes上运行的任何类型的应用程序。由于可以确保部署需求随时间变化,因此Helm还支持版本控制。替代方法是使用多个配置文件,这些文件手动应用于Kubernetes集群以启动应用程序。如果我们从将基础结构视为代码中学到了什么,那就是手动处理不可避免地会导致错误。Helm图表使我们有机会将同样的课程应用于Kubernetes的世界。
在此示例中,我们将逐步介绍如何将Helm与minikube结合使用,minikube是Kubernetes的单节点测试环境。我们将制作一个小的Nginx Web服务器应用程序。对于此示例,请务必确认你已经在Linux笔记本电脑上安装了minikube 1.9.2版和Helm 3.0.0版。
创建Helm图表
首先确认我们已安装了先决条件。
$ which helm ## this can be in any folder as long as it returns in the path/usr/local/bin/helm$ minikube status ## if it shows Stopped, run `minikube start`host: Runningkubelet: Runningapiserver: Runningkubeconfig: Configured
启动新的Helm图表需要一个简单的命令:
$ helm create mychartname
就本教程而言,将图表命名为buildachart:
$ helm create buildachartCreating buildachart$ ls buildachart/Chart.yaml charts/ templates/ values.yaml
检查图表的结构
现在,您已经创建了图表,请查看其结构以查看内部内容。您看到的前两个文件Chart.yaml和 values.yaml定义了图表的内容以及部署时其中的值。查看Chart.yaml,您可以看到Helm图表结构的轮廓:
apiVersion: v2name: buildachartdescription: A Helm chart for Kubernetes# A chart can be either an 'application' or a 'library' chart.## Application charts are a collection of templates that can be packaged into versioned archives# to be deployed.## Library charts provide useful utilities or functions for the chart developer. They're included as# a dependency of application charts to inject those utilities and functions into the rendering# pipeline. Library charts do not define any templates and therefore cannot be deployed.type: application# This is the chart version. This version number should be incremented each time you make changes# to the chart and its templates, including the app version.version: 0.1.0# This is the version number of the application being deployed. This version number should be# increm