我是 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"
}
}
我请求您帮助我解决一些问题:
- 如何使用上述脚本和 Terraform 在 EKS 集群上安装 Istio。我需要与上述脚本一起包含的 terraform 部分是什么?
- 剧本中是否有遗漏的部分。使用上述脚本更新 Istio 会遇到任何问题吗?
- 我需要包含哪些其他参数,以便脚本可以在 EKS 集群上安装 Istio?
- 如何使用上述脚本创建 Terraform 模块?
非常感谢您抽出宝贵的时间。感谢您的所有帮助!
最佳答案
我相信如果使用这样的本地执行配置程序,您会遇到问题。
Terraform 无法很好地处理无法协调的资源。尤其是涉及 CRD 时。此外,每次运行 terraform apply
时,您都会一遍又一遍地运行 istioctl init
,这可能不是您想要的。
你能做的就是
- 使用将 istio-operator 转换为标准 kubernetes list
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
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]
}
- 在
istio/manifest.yaml
中创建IstioOperator
list
# 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 安装带有第二个
kustomization
资源的IstioOperator
。
# 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
关于kubernetes - 在 EKS 上使用 Istio Operator 和 Terraform 安装 Istio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67086365/