问题描述
我是 terraform 的新手。我需要在 AWS EKS 集群上设置 Istio。我想过使用 Istio-Operator 和 terraform 来做同样的事情。
以下是使用 Istio-Operator 在 EKS 上安装 Istio 的 shell 脚本:
install-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"
}
}
我请求您帮助我解决几个问题:
- 如何使用上述脚本和 terraform 在 EKS 集群上安装 Istio。我需要与上述脚本一起包含的 terraform 部分是什么?
- 脚本中是否有任何缺失的部分。使用上述脚本更新 Istio 会遇到任何问题吗?
- 我需要包含哪些其他参数,以便脚本可以在 EKS 集群上安装 Istio?
- 如何使用上述脚本创建 terraform 模块?
非常感谢您抽出宝贵时间。感谢您的帮助!
解决方法
我相信如果使用这样的 local-exec 配置器,您会遇到问题。
Terraform 不能很好地处理它无法协调的资源。特别是在涉及 CRD 时。此外,每次运行 terraform apply
时,都会一遍又一遍地运行 istioctl init
,这可能不是您想要的。
你能做的就是
- 使用 将 istio-operator 转换为标准的 kubernetes manifests
mkdir -p istio-operator
istio-operator dump > istio-operator/manifests.yaml
- 使用 创建一个
istio-operator/kustomization.yaml
文件
#istio-operator/kustomization.yaml
resources:
- manifests.yaml
- 安装 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
}
- 使用 terraform
istio-operator
提供程序安装kustomization
# 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]
}
- 在
IstioOperator
中创建istio/manifest.yaml
清单
# istio/manifest.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
name: istio-control-plane
...
- 用 创建一个
istio/kustomization.yaml
# istio/kustomization.yaml
resources:
- manifest.yaml
- 使用 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