我对Terraform很陌生。我需要在AWS EKS集群上设置Istio。我想用Istio操作符和Terraform一起来做同样的事情。
下面是使用Istio操作符在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"
}
}我请求你帮我解决几个问题:
,
非常感谢你抽出时间。感谢你的帮助!
发布于 2021-04-15 13:27:03
我相信你会遇到问题,如果使用这样的本地-exec供应程序。
Terraform并不善用它无法调和的资源。尤其是在CRD方面。而且,每次运行terraform apply时,您都会一次又一次地运行istioctl init,这可能不是您想要的。
你能做的就是
将istio运算符转换为标准kubernetes清单。
mkdir -p istio-operator
istio-operator dump > istio-operator/manifests.yaml创建istio-operator/kustomization.yaml文件
#istio-operator/kustomization.yaml
resources:
- manifests.yamlkustomization provider# terraform.tf
terraform {
required_providers {
kustomization = {
source = "kbst/kustomization"
version = "0.4.3"
}
}
}
provider "kustomization" {
// See online documentation on how to configure this
}istio-operator与terraform kustomization provider# 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清单# istio/manifest.yaml
apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
metadata:
name: istio-control-plane
...创建istio/kustomization.yaml
# istio/kustomization.yaml
resources:
- manifest.yaml使用第二个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.yamlhttps://stackoverflow.com/questions/67086365
复制相似问题