2

我是 Terraform 的新手。我需要在 AWS EKS 集群上设置 Istio。我想过使用 Istio-Operator 和 Terraform 来做同样的事情。

下面是使用 Istio-Operator 在 EKS 上安装 Istio 的 shell 脚本:

安装 istio.sh

# Download and install the Istio istioctl client binary

# Specify the Istio version that will be leveraged throughout these instructions
ISTIO_VERSION=1.7.3

curl -sL "https://github.com/istio/istio/releases/download/$ISTIO_VERSION/istioctl-$ISTIO_VERSION-linux-amd64.tar.gz" | tar xz

sudo mv ./istioctl /usr/local/bin/istioctl
sudo chmod +x /usr/local/bin/istioctl

# Install the Istio Operator on EKS
istioctl operator init

# The Istio Operator is installed into the istio-operator namespace. Query the namespace.
kubectl get all -n istio-operator

# Install Istio components
istioctl profile dump default

# Create the istio-system namespace and deploy the Istio Operator Spec to that namespace.
kubectl create ns istio-system
kubectl apply -f istio-operator.yaml

# Validate the Istio installation
kubectl get all -n istio-system

下面是 install-istio.sh 使用的 istio-operator.yaml 文件

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  namespace: istio-system
  name: istio-control-plane
spec:
  # Use the default profile as the base
  # More details at: https://istio.io/docs/setup/additional-setup/config-profiles/
  profile: default
  # Enable the addons that we will want to use
  addonComponents:
    grafana:
      enabled: true
    prometheus:
      enabled: true
    tracing:
      enabled: true
    kiali:
      enabled: true
  values:
    global:
      # Ensure that the Istio pods are only scheduled to run on Linux nodes
      defaultNodeSelector:
        beta.kubernetes.io/os: linux
    kiali:
      dashboard:
        auth:
          strategy: anonymous

下面是执行脚本的 main.tf 文件

resource "null_resource" "install_istio" {

 provisioner "local-exec" {

    command = "/bin/bash install-istio.sh"
  }
}

我请求您帮助我解决几个问题:

  1. 如何使用上述脚本和 Terraform 在 EKS 集群上安装 Istio。我需要与上述脚本一起包含的 terraform 部分是什么?
  2. 脚本中是否缺少任何部分。使用上述脚本更新 Istio 时会遇到任何问题吗?
  3. 为了让脚本可以在 EKS 集群上安装 Istio,我还需要包含哪些其他参数?
  4. 如何使用上述脚本创建 Terraform 模块?

非常感谢您的宝贵时间。感谢您的所有帮助!

4

1 回答 1

3

我相信如果使用这样的 local-exec 配置器,您会遇到问题。

Terraform 不能很好地处理它无法协调的资源。尤其是在 CRD 方面。而且,每次你跑的时候terraform apply,你都会istioctl init一遍又一遍地跑,这可能不是你想要的。

你能做的,就是

  1. 使用以下命令将 istio-operator 转换为标准 Kubernetes 清单
mkdir -p istio-operator
istio-operator dump > istio-operator/manifests.yaml
  1. 创建一个istio-operator/kustomization.yaml文件
#istio-operator/kustomization.yaml

resources:
- manifests.yaml
  1. 安装 terraformkustomization提供程序
# terraform.tf

terraform {
  required_providers {
    kustomization = {
      source  = "kbst/kustomization"
      version = "0.4.3"
    }
  }
}

provider "kustomization" {
  // See online documentation on how to configure this
}
  1. istio-operator使用 terraformkustomization提供程序安装
# istio-operator.tf

data "kustomization" "istio_operator" {
  path     = "./istio-operator"
}

resource "kustomization_resource" "istio_operator" {
  for_each = data.kustomization.istio_operator.ids
  manifest = data.kustomization.istio_operator.manifests[each.value]
}


  1. 在中创建IstioOperator清单istio/manifest.yaml
# istio/manifest.yaml

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
  name: istio-control-plane
...
  1. 创建istio/kustomization.yaml一个
# istio/kustomization.yaml

resources:
- manifest.yaml
  1. 使用 terraform安装IstioOperator第二个资源。kustomization
# istio.tf

data "kustomization" "istio" {
  path     = "./istio"
}

resource "kustomization_resource" "istio" {
  for_each = data.kustomization.istio.ids
  manifest = data.kustomization.istio.manifests[each.value]
  depends_on = [kustomization_resource.istio_operator]
}


我建议将整个内容放在一个单独的文件夹中,例如这个

/home
  /project
    /terraform
      /istio
        terraform.tf
        istio_operator.tf
        istio.tf
        /istio
          kustomization.yaml
          manifest.yaml
        /istio-operator
          kustomization.yaml
          manifest.yaml

      
于 2021-04-15T13:27:03.713 回答