【问题标题】:Install Istio using Istio Operator and Terraform on EKS在 EKS 上使用 Istio Operator 和 Terraform 安装 Istio
【发布时间】:2021-07-09 04:27:49
【问题描述】:

我是 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 模块?

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

【问题讨论】:

    标签: kubernetes terraform istio amazon-eks servicemesh


    【解决方案1】:

    我相信如果使用这样的 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. 安装 terraform kustomization 提供程序
    # terraform.tf
    
    terraform {
      required_providers {
        kustomization = {
          source  = "kbst/kustomization"
          version = "0.4.3"
        }
      }
    }
    
    provider "kustomization" {
      // See online documentation on how to configure this
    }
    
    1. 使用 terraform kustomization 提供程序安装 istio-operator
    # 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. istio/manifest.yaml 中创建IstioOperator 清单
    # 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
    
          
    

    【讨论】:

    • 不,这不会解决它,因为 terraform 不知道如何删除 null_resource。一遍又一遍地运行terraform-apply起作用,但你会浪费宝贵的时间。您也可以使用 istioctl 手动安装 istio。
    • kubernetes-alpha terraform 提供程序最终不会是实验性的,也许它会使将来使用 terraform 安装 kubernetes 资源变得更容易。
    • 感谢 Ludovic 回答和分享知识。
    • 不客气。如果您遇到“鸡或蛋”错误(在安装 istio CRD 之前无法安装 IstioOperator),那么只需使用 2 个不同的 terraform 模块,您将分别使用 terraform apply。一个用于 istio-operator,另一个用于Istio control plane
    • 你也可以这样做。我不喜欢使用 Helm,因为我更喜欢能够手动配置清单。使用 helm 很困难,如果您打印出完整的清单(使用 istioctl dumphelm template)会容易得多。这就是我为所有企业项目所做的。
    猜你喜欢
    • 2021-07-07
    • 2021-06-25
    • 2021-01-14
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多