过去几个月我一直在研究这个问题,并想将我的发现添加到@Jakob 的回答中:
首先,对于不同安装方法的优缺点有一个答案,所以我不会说什么:
https://istio.io/latest/faq/setup/#install-method-selection
基本上所有这些都可以用 terraform 以某种方式完成。
- terraform + istioctl 与 terraform null_resource 提供程序
这基本上是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 版本
我猜你可以以某种方式解决升级过程,但漏洞过程还不够“基础设施即代码”。我没有进一步研究它,因为它似乎不是一个好的做法。
- terraform + istio 运算符,带有 terraform null_resource 提供程序和 kubectl 提供程序
类似于 istio operator setup 初始化 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 阶段,这可能是最好的方法。
- terraform + helm 与 terraform helm 提供程序
Istio 在下载 istioctl 时为不同的组件提供了一些图表。这些可用于通过 helm 安装它。
resource "helm_release" "istio_base" {
name = "istio-base"
chart = "./manifests/charts/base"
namespace = "istio-system"
}
缺点:
奖金
- istio manifest + helm
前段时间,我从istioctl manifest generate 读到一篇关于如何使用 istio manifest 结合 helm 来安装和管理 istio 的文章。这种方法需要一些自定义代码,但也可以使用 terraform 和 helm 提供程序来完成。
请阅读:https://karlstoney.com/2021/03/04/ci-for-istio-mesh/index.html
结论
使用 terraform 安装 istio 是可行的,但目前接缝有点脏。一旦 helm 设置稳定,我想这将是最好的方法。使用 helm 提供程序,它可以与其他资源的 terraform 创建组合在一起。 Terraform 肯定会错过一个 istio 提供者,但我认为他们不会在可预见的未来创建一个。