如何在 Azure AKS 上自动部署 Elasticsearch

如何在 Azure AKS 上自动部署 Elasticsearch

作者:来自 Elastic Eduard Martin

学习如何使用 Azure 上的 AKS Automatic 和 ECK 部署 Elasticsearch 与 Kibana,以实现部分托管的 Elasticsearch 设置配置。

Elasticsearch 新手?加入我们的 Elasticsearch 入门网络研讨会。你也可以开始免费 cloud 试用,或者现在在你的机器上尝试 Elastic。


这篇文章是一个系列的一部分,我们将学习如何使用不同的基础设施安装 Elasticsearch。

ECK 比基于 Marketplace 的 Elastic Cloud 方案需要更多工作量,但比你自己部署 VM 更自动化,因为 Kuber***es operator 会负责系统编排和节点扩缩。

这次我们将使用 Azure Kuber***es Service (AKS),采用 Automatic。在其他文章中,你将学习如何使用 Azure VM 和 Azure Marketplace。

什么是 AKS Automatic?

Azure Kuber***es Service (AKS) 会自动管理集群设置、动态分配资源,并集成安全最佳实践,同时保留 Kuber***es 灵活性,让开发者能够在几分钟内从容器镜像到已部署应用。

AKS Automatic 去除了大部分集群管理开销,并在简单性与灵活性之间取得良好平衡。根据你的使用场景选择最佳方案,但如果你计划:

  •  部署测试环境:部署快速且简单,非常适合快速实验或短期集群
  • 不需要严格 VM、存储或网络要求:AKS Automatic 提供预设默认值,如果它们适合你的需求,可以避免额外配置
  • 第一次使用 Kuber***es:它处理大量集群设置,降低学习门槛,让团队专注在应用本身
Source: Quickstart: Create an Azure Kuber***es Service (AKS) Automatic cluster (preview)

对于 Elasticsearch,我们将使用 Elastic Cloud on Kuber***es (ECK),它是官方的 Elastic Kuber***es operator,用来简化 Elastic Stack 在 Kuber***es 上的部署编排。

如何设置 AKS Automatic

1)登录 Microsoft Azure Portal。

2)在右上角点击 Cloud Shell 按钮进入控制台,并从那里部署 AKS 集群。或者,你也可以使用 Azure Cloud Shell。

记得在教程过程中把 project ID 更新成你自己的

打开 AKS 后应该会和上面的截图类似。

3)安装 aks-preview Azure CLI 扩展。这个预览版本允许我们在创建集群时选择 --sku automatic,从而启用 AKS Automatic 功能。

az extension add --name aks-preview

如果你看到这个消息,表示 AKS 扩展已经正确安装。

4)使用 az feature register 命令注册 feature flags

az feature register --namespace Microsoft.ContainerService --name AutomaticSKUPreview

你将看到我们刚创建的 feature 订阅的详细信息:

检查注册状态,直到它从 “Registering” 变为 “Registered”。注册完成可能需要几分钟。

az feature show --namespace Microsoft.ContainerService --name AutomaticSKUPreview

运行 az provider register 来传播更改。

az provider register --namespace Microsoft.ContainerService

5)创建资源组

资源组是用于管理和部署的一组逻辑 Azure 资源。

az group create --name elastic-resource --location eastus

6)创建 Autopilot 集群。我们将其命名为 myAKSAutomati***luster,并使用刚创建的资源组。确保你在以下任意 VM 类型上有 16 个 vCPU 可用:Standard_D4pds_v5Standard_D4lds_v5Standard_D4ads_v5Standard_D4ds_v5Standard_D4d_v5Standard_D4d_v4Standard_DS3_v2Standard_DS12_v2,以便 AKS 分配资源。

az aks create \
    --resource-group elastic-resource \
    --name myAKSAutomati***luster \
    --sku automatic \
    --generate-ssh-keys

如果出现 MissingSubscriptionRegistration 错误,请回到第 4 步处理缺失的订阅。例如,如果提示 “The subscription is not registered to use namespace 'microsoft.insights'”,则需要运行 az provider register --namespace Microsoft.Insights

按照交互式登录操作:

系统会提示你运行 az login。你需要执行该命令,然后等待完成。

7)等待集群准备就绪。创建大约需要 10 分钟。

8)配置 kubectl 命令行访问权限。

az aks get-credentials --resource-group elastic-resource --name myAKSAutomati***luster

注意,我们安装的扩展启用了 AKS Automatic。

9)确认节点已部署。

kubectl get nodes

你会看到一个 forbidden 错误消息;从错误中复制用户 ID。

10)将你的用户添加到 AKS 访问控制中。

获取 AKS ID,并复制命令的输出。

使用 AKS ID 和你的用户 principal ID 创建角色分配。

az role assignment create --role "Azure Kuber***es Service RBAC Cluster Admin" --assignee <PRINCIPAL_ID> --scope <AKS_ID>

11)再次尝试确认节点是否已部署。

kubectl get nodes

12)安装 Elastic Cloud on Kuber***es (ECK) operator。

# Install ECK Custom Resource Definitions
kubectl create -f https://download.elastic.co/downloads/eck/2.16.1/crds.yaml

# Install the ECK operator
kubectl apply -f https://download.elastic.co/downloads/eck/2.16.1/operator.yaml

13)我们来创建一个使用默认值的单节点 Elasticsearch 实例。

cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  version: 9.0.0
  nodeSets:
  - name: default
    count: 1
    config:
      node.store.allow_mmap: false
EOF

我们禁用了 nmap,因为默认 AKS 机器的 vm.max_map_count 值太低。禁用它不推荐用于生产环境,正确做法是增加 vm.max_map_count 的值。你可以在这里了解更多操作方法。

14)我们还将部署一个 Kibana 单节点集群。对于 Kibana,我们将添加一个负载均衡器,这样我们就能获得一个外部 IP,从设备访问 Kibana。

cat <<EOF | kubectl apply -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
  name: quickstart
spec:
  version: 9.0.0
  http:
    service:
      spec:
        type: LoadBalancer
  count: 1
  elasticsearchRef:
    name: quickstart
EOF

默认情况下,AKS Automatic 会将负载均衡器配置为 public;你可以通过设置 metadata annotation 来更改此行为:

service.beta.kuber***es.io/azure-load-balancer-internal: "true"

15)检查你的 pods 是否正在运行。

kubectl get pods

16)你也可以运行 kubectl get elasticsearchkubectl get kibana 来查看更具体的统计信息,如 Elasticsearch 版本、节点和健康状态。

17)访问你的服务。

kubectl get svc

这会在 EXTERNAL-IP 下显示 Kibana 的外部 URL。负载均衡器的配置可能需要几分钟。复制 EXTERNAL-IP 的值。

18)获取 elastic 用户的 Elasticsearch 密码:

kubectl get secret quickstart-es-elastic-user -o=jsonpath='{.data.elastic}' | base64 --decode

19)通过浏览器访问 Kibana:

  • URL:https://<EXTERNAL_IP>:5601
  • 用户名:elastic
  • 密码:c44A295CaEt44D6xIzN6Zs5m(来自上一步)

2)从浏览器访问 Elastic Cloud 时,你会看到欢迎界面。

如果你想更改 Elasticsearch 集群规格,比如更改或调整节点大小,可以使用新的设置再次应用 YML 清单:

cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  version: 9.0.0
  nodeSets:
    - name: default
      count: 2
      config:
        node.store.allow_mmap: false
      podTemplate:
        spec:
          containers:
            - name: elasticsearch
              resources:
                requests:
                  memory: 1.5Gi
                  cpu: 2
                limits:
                  memory: 1.5Gi
                  cpu: 2
EOF

在这个示例中,我们将添加一个节点并修改 RAM 和 CPU。正如你所看到的,现在 kubectl get elasticsearch 显示有 2 个节点:

Kibana 也同样适用:

cat <<EOF | kubectl apply -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
  name: quickstart
spec:
  version: 9.0.0
  http:
    service:
      spec:
        type: LoadBalancer
  count: 1
  elasticsearchRef:
    name: quickstart
  podTemplate:
    spec:
      containers:
        - name: kibana
          env:
            - name: NODE_OPTIONS
              value: "--max-old-space-size=1024"
          resources:
            requests:
              memory: 0.5Gi
              cpu: 0.5
            limits:
              memory: 1Gi
              cpu: 1
EOF

我们可以调整容器的 CPU/RAM,也可以调整 Node.js 的内存使用(max-old-space-size)。

请记住,已有的 volume claim 不能缩小。应用更新后,operator 会在最小中断时间内完成更改。

测试完成后记得删除集群,以避免不必要的费用。

az aks delete --name myAKSAutomati***luster --resource-group elastic-resource

结论

使用 Azure AKS Automatic 配合 ECK 为部署 Elasticsearch 和 Kibana 提供了一个平衡的解决方案:它降低了运维复杂性,保证了自动扩展和更新,并利用了 Kuber***es 的灵活性。这种方法非常适合希望获得可靠、可重复和可维护部署流程的团队,而无需手动管理每一个基础设施细节,是测试和生产环境的实用选择。

下一步

如果你想了解更多关于 Kuber***es 的内容,可以查看官方文档:

  • Elastic Cloud on Kuber***es | Elastic Docs

  • Introduction to Azure Kuber***es Service (AKS) Automatic (preview)

  • AKS Automatic - AKS Engineering Blog

原文:https://www.elastic.co/search-labs/blog/elasticsearch-azure-aks-automatic-deployment

转载请说明出处内容投诉
CSS教程网 » 如何在 Azure AKS 上自动部署 Elasticsearch

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买