使用 Terraform 或 Helm 在 EKS 集群上设置 ISTIO

Setting up on ISTIO on EKS cluster using Terraform or Helm

我是 Terraform 和 Helm 世界的新手!我需要在 AWS EKS 集群上设置 Istio。我能够使用 Terraform 设置 EKS 集群。我正在考虑通过编写 Terraform 模块使用 Terraform 在 EKS 集群之上安装 ISTIO。但是,我发现我们可以使用 helm chart 在 eks 之上设置 Istio。

谁能帮我解答几个问题:

  1. 我应该使用 Terraform 安装 Istio 吗?如果是,是否有可用的 terraform 模块或如何编写一个?
  2. 我应该使用 Helm Chart 安装 Istio 吗?如果有,它的优缺点是什么?
  3. 我需要编写一个管道来在 EKS 集群上安装 Istio。我应该结合使用 Terraform 和 Helm 作为提供者吗?

非常感谢您抽出宝贵时间。感谢您的帮助!

正如@Matt Schuchard 提到的,这是一个有点基于意见的问题,这就是为什么我会根据我的理解来回答这个问题。


问题编号 1.

  1. 回答你的问题,Should I install Istio using Terraform?,是的,如果你遵循 Devops 实践,那么你应该将所有内容都写在代码中,所以我建议这样做。

  2. 根据你问题的第二部分,If yes, Is there any Terraform module available,不,据我所知目前没有用于 Terraform 的 Istio 模块,只有一个 helm .

  3. 至于第一个问题的最后一部分,How can I write Terraform module?我建议从 Terraform documentation. There is also a tutorial 开始创建模块。


问题编号 2.

  1. 要回答您的问题,Should I install Istio using Helm Chart?,取决于您的用例,您可以使用 helm 或 istioctl/istio operator。
  2. 至于以下问题,If yes, what are the pros and cons of it? 根据 Istio documentationProviding the full configuration in an IstioOperator CR is considered an Istio best practice for production environments,我不确定当前的 helm chart 是否已准备好生产,所以据我了解,您应该使用 operator 而不是 helm。还值得注意的是,helm chart 没有被几个版本使用,如果在 1.8 版中恢复生机的话。

问题编号 3.

  1. 根据最后一个问题,I need to write a pipeline to install Istio on EKS cluster. Should I use a combination of both terraform and Helm as provider?,视情况而定,它可能是 Terraform 和 Helm,但据我所知,也可以使用 Terraform 和 Istio Operator 来做到这一点,有一个 example。因此,选择哪条道路完全由您自己决定。

我还建议看看这个 reddit thread。您可能会在此处的 prod 环境中找到一些有用的评论,关于使用 Terraform 安装 Istio。

过去几个月我一直在研究这个问题,并想将我的发现添加到@Jakob 的回答中:

首先,安装方式不同的pros/cons已经有答案了,我就不多说了: https://istio.io/latest/faq/setup/#install-method-selection 基本上所有这些都可以以某种方式用 terraform 完成。

  1. terraform + istioctl with terraform null_resource provider

这基本上就是 istioctl install -f <file> 命令。您可以使用 null_resource 提供程序创建模板文件和 istictl install 命令。

resource "local_file" "setup_istio_config" {
  content = templatefile("${path.module}/istio-operator.tmpl", {
    enableHoldAppUntilProxyStarts = var.hold_app_until_proxy_starts
  })
  filename = "istio-operator.yaml"
}

resource "null_resource" "install_istio" {
  provisioner "local-exec" {
    command = "istioctl install -f \"istio-operator.yaml\" --kubeconfig ../${var.kubeconfig}"
  }
  depends_on = [local_file.setup_istio_config]
}

优点:

  • 设置非常简单

缺点:

  • 如何使用istioctl upgrade -f <file升级有待解决
  • 在处理具有不同 istio 版本的多个集群时,必须安装不同版本的 istioctl
  • 必须在设置时选择正确的 istioctl 版本

我想你可以通过某种方式解决升级过程,但漏洞过程还不够“基础设施即代码”。我没有进一步研究它,因为它不是很好的练习。

  1. terraform + istio operator with terraform null_resource provider 和 kubectl provider

类似的,istio operator 设置会初始化 operator pod 并使用 istio-operator.yml 为您设置 istio。

resource "null_resource" "init_operator" {
  provisioner "local-exec" {
    command = "istioctl operator init --kubeconfig ../${var.kubeconfig}"
  }
}

resource "kubectl_manifest" "setup_istio" {
  yaml_body = <<YAML
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
    name: istio-setup
    namespace: istio-system
spec:
  profile: default
  hub: gcr.io/istio-release
  tag: 1.9.2
  components:
    ingressGateways:
      - name: istio-ingressgateway
        enabled: true
  meshConfig:
    defaultConfig:
      holdApplicationUntilProxyStarts: ${var.hold_app_until_proxy_starts}"
YAML
  depends_on = [null_resource.init_operator]
}

在初始化和应用配置之间等待几秒钟是个好主意。

这是一篇关于使用 Azure 的 aks 执行此操作的好文章: https://medium.com/@vipinagarwal18/install-istio-on-azure-kubernetes-cluster-using-terraform-214f6d3f611

优点:

  • 易于设置
  • 使用 kubectl 提供程序轻松升级 istio

只要 helm 处于 alpha 阶段,这可能是最好的方法。

  1. terraform + helm with terraform helm provider

Istio 在下载istioctl 时为不同的组件提供了一些图表。这些可用于使用 helm 安装它。

resource "helm_release" "istio_base" {
  name       = "istio-base"
  chart      = "./manifests/charts/base"
  namespace  = "istio-system"
}

缺点:

  • 尚未准备好生产

奖金

  1. istio 清单 + helm

前段时间我读了一篇关于如何使用 istioctl manifest generate 中的 istio 清单结合 helm 来安装和管理 istio 的文章。这种方法需要一些自定义代码,但也可以使用 terraform 和 helm 提供程序来完成。

请阅读:https://karlstoney.com/2021/03/04/ci-for-istio-mesh/index.html

结论

使用 terraform 安装 istio 可以,但目前接缝有点脏。一旦 helm 设置稳定,我想这将是最好的方法。通过 helm provider,它可以与其他资源的 terraform 创建组合在一起。 Terraform 肯定缺少 istio 提供程序,但我认为他们不会在可预见的未来创建一个。

扩展@Chris terraform + helm provider 的第三个选项,

至于 istio 的 1.12.0+ 版本,他们正式拥有一个可用的 helm 存储库:

istio helm install

还有 terraform 的 helm provider Terraform helm provider 允许仅由 terraform 配置的简单设置:

provider "helm" {
  kubernetes {
    // enter the relevant authentication
  }
}

locals {
  istio_charts_url = "https://istio-release.storage.googleapis.com/charts"
}

resource "helm_release" "istio-base" {
  repository       = local.istio_charts_url
  chart            = "base"
  name             = "istio-base"
  namespace        = var.istio-namespace
  version          = "1.12.1"
  create_namespace = true
}

resource "helm_release" "istiod" {
  repository       = local.istio_charts_url
  chart            = "istiod"
  name             = "istiod"
  namespace        = var.istio-namespace
  create_namespace = true
  version          = "1.12.1"
  depends_on       = [helm_release.istio-base]
}

resource "kubernetes_namespace" "istio-ingress" {
  metadata {
    labels = {
      istio-injection = "enabled"
    }

    name = "istio-ingress"
  }
}

resource "helm_release" "istio-ingress" {
  repository = local.istio_charts_url
  chart      = "gateway"
  name       = "istio-ingress"
  namespace  = kubernetes_namespace.istio-ingress-label.id
  version    = "1.12.1"
  depends_on = [helm_release.istiod]
}

这是使此产品准备就绪所缺少的最后一步

不再需要使用 null_resource

在本地保存 helm 图表

如果你想覆盖默认的 helm 值,这里很好地显示了它: Artifact hub,选择相关图表并查看数值