gpt4 book ai didi

amazon-web-services - 带有 ALB 入口 Controller 的 Terraform AWS Kubernetes EKS 资源不会创建负载均衡器

转载 作者:行者123 更新时间:2023-12-02 11:27:59 24 4
gpt4 key购买 nike

我一直在尝试使用 Terraform 在 AWS 上创建一个具有自我管理节点的 EKS 集群,但我无法让我的 Kubernetes Ingress 创建负载均衡器。没有错误,但没有创建负载均衡器,它只是超时。
我确实首先在我的帐户中手动创建了一个负载均衡器,并验证了负载均衡器角色是否存在。政策 AWSElasticLoadBalancingServiceRolePolicy在我的 Terraform 代码运行时访问。
我非常依赖 this tutorial
变量:

aws_region     = "ap-southeast-1"
domain = "*.mydomain.com"
cluster_name = "my-tf-eks-cluster"
vpc_id = "vpc-0d7700e26db6b3e21"
app_subnet_ids = "subnet-03c1e8c57110c92e0, subnet-0413e8bf24cb32595, subnet-047dcce0b810f0fbd"
// gateway subnet IDs
地形代码:
terraform {
}

provider "aws" {
region = var.aws_region
version = "~> 2.8"
}

data "aws_acm_certificate" "default" {
domain = var.domain
statuses = ["ISSUED"]
}

resource "kubernetes_service_account" "alb-ingress" {
metadata {
name = "alb-ingress-controller"
namespace = "kube-system"
labels = {
"app.kubernetes.io/name" = "alb-ingress-controller"
}
}

automount_service_account_token = true
}

resource "kubernetes_cluster_role" "alb-ingress" {
metadata {
name = "alb-ingress-controller"
labels = {
"app.kubernetes.io/name" = "alb-ingress-controller"
}
}

rule {
api_groups = ["", "extensions"]
resources = ["configmaps", "endpoints", "events", "ingresses", "ingresses/status", "services"]
verbs = ["create", "get", "list", "update", "watch", "patch"]
}

rule {
api_groups = ["", "extensions"]
resources = ["nodes", "pods", "secrets", "services", "namespaces"]
verbs = ["get", "list", "watch"]
}
}

resource "kubernetes_cluster_role_binding" "alb-ingress" {
metadata {
name = "alb-ingress-controller"
labels = {
"app.kubernetes.io/name" = "alb-ingress-controller"
}
}

role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = "alb-ingress-controller"
}

subject {
kind = "ServiceAccount"
name = "alb-ingress-controller"
namespace = "kube-system"
}
}



resource "kubernetes_deployment" "alb-ingress" {
metadata {
name = "alb-ingress-controller"
labels = {
"app.kubernetes.io/name" = "alb-ingress-controller"
}
namespace = "kube-system"
}

spec {
selector {
match_labels = {
"app.kubernetes.io/name" = "alb-ingress-controller"
}
}

template {
metadata {
labels = {
"app.kubernetes.io/name" = "alb-ingress-controller"
}
}
spec {
volume {
name = kubernetes_service_account.alb-ingress.default_secret_name
secret {
secret_name = kubernetes_service_account.alb-ingress.default_secret_name
}
}
container {
# This is where you change the version when Amazon comes out with a new version of the ingress controller
image = "docker.io/amazon/aws-alb-ingress-controller:v1.1.8"
name = "alb-ingress-controller"
args = [
"--ingress-class=alb",
"--cluster-name=${var.cluster_name}",
"--aws-vpc-id=${var.vpc_id}",
"--aws-region=${var.aws_region}"
]
volume_mount {
name = kubernetes_service_account.alb-ingress.default_secret_name
mount_path = "/var/run/secrets/kubernetes.io/serviceaccount"
read_only = true
}
}

service_account_name = "alb-ingress-controller"

}
}
}
}


resource "kubernetes_ingress" "main" {
metadata {
name = "main-ingress"
annotations = {
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"kubernetes.io/ingress.class" = "alb"
"alb.ingress.kubernetes.io/subnets" = "${var.app_subnet_ids}"
"alb.ingress.kubernetes.io/certificate-arn" = "${data.aws_acm_certificate.default.arn}"
"alb.ingress.kubernetes.io/listen-ports" = <<JSON
[
{"HTTP": 80},
{"HTTPS": 443}
]
JSON
"alb.ingress.kubernetes.io/actions.ssl-redirect" = <<JSON
{
"Type": "redirect",
"RedirectConfig": {
"Protocol": "HTTPS",
"Port": "443",
"StatusCode": "HTTP_301"
}
}
JSON
}
}

spec {
rule {
host = "app.xactpos.com"
http {
path {
backend {
service_name = "ssl-redirect"
service_port = "use-annotation"
}
path = "/*"
}
path {
backend {
service_name = "app-service1"
service_port = 80
}
path = "/service1"
}
path {
backend {
service_name = "app-service2"
service_port = 80
}
path = "/service2"
}
}
}

rule {
host = "api.xactpos.com"
http {
path {
backend {
service_name = "ssl-redirect"
service_port = "use-annotation"
}
path = "/*"
}
path {
backend {
service_name = "api-service1"
service_port = 80
}
path = "/service3"
}
path {
backend {
service_name = "api-service2"
service_port = 80
}
path = "/service4"
}
}
}
}

wait_for_load_balancer = true
}

最佳答案

我绝不是 K8s 专家,但我浏览了 Terraform 代码,我认为唯一可以帮助您调试的选项似乎是 wait_for_load_balancer kubernetes_ingress 中的选项资源。来自 documentation :

Terraform will wait for the load balancer to have at least 1 endpoint before considering the resource created.

在这种情况下,输出可能会更清晰(如果创建由于某种原因失败),或者您可能会发现为什么它没有创建 LB。

关于amazon-web-services - 带有 ALB 入口 Controller 的 Terraform AWS Kubernetes EKS 资源不会创建负载均衡器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62259936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com