使用 Helm 在 Azure Kubernetes 服务 (AKS) 中安装现有应用程序Install existing applications with Helm in Azure Kubernetes Service (AKS)

Helm 是一种开放源打包工具,有助于安装和管理 Kubernetes 应用程序的生命周期。Helm is an open-source packaging tool that helps you install and manage the lifecycle of Kubernetes applications. 与诸如 APTYum 的 Linux 包管理器类似,Helm 用于管理 Kubernetes 图表,这些图表是预配置的 Kubernetes 资源包。Similar to Linux package managers such as APT and Yum , Helm is used to manage Kubernetes charts, which are packages of preconfigured Kubernetes resources.

本文介绍如何在 AKS 上的 Kubernetes 群集中配置和使用 Helm。This article shows you how to configure and use Helm in a Kubernetes cluster on AKS.

准备阶段Before you begin

本文假定你拥有现有的 AKS 群集。This article assumes that you have an existing AKS cluster. 如果需要 AKS 群集,请参阅 AKS 快速入门使用 Azure CLI使用 Azure 门户If you need an AKS cluster, see the AKS quickstart using the Azure CLI or using the Azure portal.

还需要安装 Helm CLI,这是在开发系统上运行的客户端。You also need the Helm CLI installed, which is the client that runs on your development system. 它允许你使用 Helm 启动、停止和管理应用程序。It allows you to start, stop, and manage applications with Helm. 如果使用 Azure 本地 Shell,则已安装 Helm CLI。If you use the Azure local Shell, the Helm CLI is already installed. 有关本地平台上的安装说明,请参阅安装 HelmFor installation instructions on your local platform, see Installing Helm.

重要

Helm 要在 Linux 节点上运行。Helm is intended to run on Linux nodes. 如果群集中有 Windows Server 节点,则必须确保 Helm Pod 仅计划在 Linux 节点上运行。If you have Windows Server nodes in your cluster, you must ensure that Helm pods are only scheduled to run on Linux nodes. 还需要确保所安装的所有 Helm 图表也计划在正确的节点上运行。You also need to ensure that any Helm charts you install are also scheduled to run on the correct nodes. 本文中的命令使用 [节点选择器][k8s-节点选择器],以确保将 Pod 安排到正确的节点,但并非所有 Helm 图表都可以公开节点选择器。The commands in this article use [node-selectors][k8s-node-selector] to make sure pods are scheduled to the correct nodes, but not all Helm charts may expose a node selector. 还可以考虑使用群集上的其他选项,例如排斥You can also consider using other options on your cluster, such as taints.

验证 Helm 版本Verify your version of Helm

使用 helm version 命令来验证已安装 Helm 3:Use the helm version command to verify you have Helm 3 installed:

helm version

以下示例演示了安装的 Helm 版本 3.0.0:The following example shows Helm version 3.0.0 installed:

$ helm version

version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}

使用 Helm v3 安装应用程序Install an application with Helm v3

添加 Helm 存储库Add Helm repositories

使用 helm repo 命令添加官方 Helm 稳定图表和 ingress-nginx 存储库。Use the helm repo command to add the official Helm stable charts and ingress-nginx repositories.

helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

查找 Helm 图表Find Helm charts

Helm 图表用来将应用程序部署到 Kubernetes 群集中。Helm charts are used to deploy applications into a Kubernetes cluster. 若要搜索预创建的 Helm 图表,请使用 helm search 命令:To search for pre-created Helm charts, use the helm search command:

helm search repo stable

以下精简示例输出显示了一些可供使用的 Helm 图表:The following condensed example output shows some of the Helm charts available for use:

$ helm search repo stable

NAME                                    CHART VERSION   APP VERSION                     DESCRIPTION                                       
stable/acs-engine-autoscaler            2.2.2           2.1.1                           DEPRECATED Scales worker nodes within agent pools 
stable/aerospike                        0.3.1           v4.5.0.5                        A Helm chart for Aerospike in Kubernetes          
stable/airflow                          4.10.0          1.10.4                          Airflow is a platform to programmatically autho...
stable/ambassador                       4.4.7           0.85.0                          A Helm chart for Datawire Ambassador              
stable/anchore-engine                   1.3.7           0.5.2                           Anchore container analysis and policy evaluatio...
stable/apm-server                       2.1.5           7.0.0                           The server receives data from the Elastic APM a...
stable/ark                              4.2.2           0.10.2                          DEPRECATED A Helm chart for ark                   
stable/artifactory                      7.3.1           6.1.0                           DEPRECATED Universal Repository Manager support...
stable/artifactory-ha                   0.4.1           6.2.0                           DEPRECATED Universal Repository Manager support...
stable/atlantis                         3.8.4           v0.8.2                          A Helm chart for Atlantis https://www.runatlant...
stable/auditbeat                        1.1.0           6.7.0                           A lightweight shipper to audit the activities o...
stable/aws-cluster-autoscaler           0.3.3                                           Scales worker nodes within autoscaling groups.    
stable/aws-iam-authenticator            0.1.1           1.0                             A Helm chart for aws-iam-authenticator            
stable/bitcoind                         0.2.2           0.17.1                          Bitcoin is an innovative payment network and a ...
stable/bookstack                        1.1.2           0.27.4-1                        BookStack is a simple, self-hosted, easy-to-use...
stable/buildkite                        0.2.4           3                               DEPRECATED Agent for Buildkite                    
stable/burrow                           1.5.2           0.29.0                          Burrow is a permissionable smart contract machine 
stable/centrifugo                       3.1.0           2.1.0                           Centrifugo is a real-time messaging server.       
stable/cerebro                          1.3.1           0.8.5                           A Helm chart for Cerebro - a web admin tool tha...
stable/cert-manager                     v0.6.7          v0.6.2                          A Helm chart for cert-manager                     
stable/chaoskube                        3.1.2           0.14.0                          Chaoskube periodically kills random pods in you...
stable/chartmuseum                      2.4.0           0.8.2                           Host your own Helm Chart Repository               
stable/chronograf                       1.1.0           1.7.12                          Open-source web application written in Go and R...
stable/clamav                           1.0.4           1.6                             An Open-Source antivirus engine for detecting t...
stable/cloudserver                      1.0.3           8.1.5                           An open-source Node.js implementation of the Am...
stable/cluster-autoscaler               6.2.0           1.14.6                          Scales worker nodes within autoscaling groups.    
stable/cluster-overprovisioner          0.2.6           1.0                             Installs the a deployment that overprovisions t...
stable/cockroachdb                      2.1.16          19.1.5                          CockroachDB is a scalable, survivable, strongly...
stable/collabora-code                   1.0.5           4.0.3.1                         A Helm chart for Collabora Office - CODE-Edition  
stable/concourse                        8.2.7           5.6.0                           Concourse is a simple and scalable CI system.     
stable/consul                           3.9.2           1.5.3                           Highly available and distributed service discov...
stable/contour                          0.1.0           v0.15.0                         Contour Ingress controller for Kubernetes         
stable/coredns                          1.7.4           1.6.4                           CoreDNS is a DNS server that chains plugins and...
stable/cosbench                         1.0.1           0.0.6                           A benchmark tool for cloud object storage services
stable/coscale                          1.0.0           3.16.0                          CoScale Agent                                     
stable/couchbase-operator               1.0.1           1.2.1                           A Helm chart to deploy the Couchbase Autonomous...
stable/couchdb                          2.3.0           2.3.1                           DEPRECATED A database featuring seamless multi-...
stable/dask                             3.1.0           1.1.5                           Distributed computation in Python with task sch...
stable/dask-distributed                 2.0.2                                           DEPRECATED: Distributed computation in Python     
stable/datadog                          1.38.3          6.14.0                          DataDog Agent 
...

若要更新图表列表,请使用 helm repo update 命令。To update the list of charts, use the helm repo update command.

helm repo update

以下示例显示了成功的存储库更新:The following example shows a successful repo update:

$ helm repo update

Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "ingress-nginx" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈

运行 Helm 图表Run Helm charts

若要使用 Helm 安装图表,请使用 helm install 命令并指定版本名称和要安装的图表的名称。To install charts with Helm, use the helm install command and specify a release name and the name of the chart to install. 若要查看实际安装的 Helm 图表,让我们使用 Helm 图表安装基本的 nginx 部署。To see installing a Helm chart in action, let's install a basic nginx deployment using a Helm chart.

helm install my-nginx-ingress ingress-nginx/ingress-nginx \
    --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
    --set controller.image.registry=usgcr.azk8s.cn \
    --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
    --set defaultBackend.image.repository=gcr.azk8s.cn/google_containers/defaultbackend-amd64

以下精简示例输出显示了 Helm 图表创建的 Kubernetes 资源的部署状态:The following condensed example output shows the deployment status of the Kubernetes resources created by the Helm chart:

$ helm install my-nginx-ingress ingress-nginx/ingress-nginx \
>     --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux \
>     --set controller.image.registry=usgcr.azk8s.cn \
>     --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux \
>     --set defaultBackend.image.repository=gcr.azk8s.cn/google_containers/defaultbackend-amd64

NAME: my-nginx-ingress
LAST DEPLOYED: Fri Nov 22 10:08:06 2019
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The nginx-ingress controller has been installed.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl --namespace default get services -o wide -w my-nginx-ingress-ingress-nginx-controller'
...

使用 kubectl get services 命令获取服务的 EXTERNAL-IPUse the kubectl get services command to get the EXTERNAL-IP of your service.

kubectl --namespace default get services -o wide -w my-nginx-ingress-ingress-nginx-controller

例如,下面的命令显示 my-nginx-ingress-ingress-nginx-controller 服务的 EXTERNAL-IP :For example, the below command shows the EXTERNAL-IP for the my-nginx-ingress-ingress-nginx-controller service:

$ kubectl --namespace default get services -o wide -w my-nginx-ingress-ingress-nginx-controller

NAME                                        TYPE           CLUSTER-IP   EXTERNAL-IP      PORT(S)                      AGE   SELECTOR
my-nginx-ingress-ingress-nginx-controller   LoadBalancer   10.0.2.237   <EXTERNAL-IP>    80:31380/TCP,443:32239/TCP   72s   app.kubernetes.io/component=controller,app.kubernetes.io/instance=my-nginx-ingress,app.kubernetes.io/name=ingress-nginx

列出版本List releases

若要查看群集上已安装的版本列表,请使用 helm list 命令。To see a list of releases installed on your cluster, use the helm list command.

helm list

以下示例显示了上一步中部署的 my-nginx-ingress 版本:The following example shows the my-nginx-ingress release deployed in the previous step:

$ helm list

NAME                NAMESPACE   REVISION    UPDATED                                 STATUS      CHART                   APP VERSION
my-nginx-ingress    default     1           2019-11-22 10:08:06.048477 -0600 CST    deployed    nginx-ingress-1.25.0    0.26.1 

清理资源Clean up resources

在部署 Helm 图表时,会创建若干 Kubernetes 资源。When you deploy a Helm chart, a number of Kubernetes resources are created. 这些资源包括 pod、部署和服务。These resources include pods, deployments, and services. 若要清理这些资源,请使用 helm uninstall 命令并指定版本名称,如上一个 helm list 命令中所示。To clean up these resources, use the helm uninstall command and specify your release name, as found in the previous helm list command.

helm uninstall my-nginx-ingress

下面的示例显示了已卸载的名为 my-nginx-ingress 的版本:The following example shows the release named my-nginx-ingress has been uninstalled:

$ helm uninstall my-nginx-ingress

release "my-nginx-ingress" uninstalled

后续步骤Next steps

有关使用 Helm 管理 Kubernetes 应用程序部署的详细信息,请参阅 Helm 文档。For more information about managing Kubernetes application deployments with Helm, see the Helm documentation.