AWS EKS Kubernetes集群无法访问:dial tcp超时

48次阅读
没有评论

问题描述

使用Terraform配置了EKS集群,并使用Helm部署了Ingress。当用户尝试应用Terraform配置时,由于无法连接到EKS集群,导致无法创建Ingress软件。
以下是用户的Terraform配置文件的一部分:

terraform {
  required_version = "~> 1.3.7"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.49.0"
    }
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = "~> 2.16.1"
    }
    helm = {
      source  = "hashicorp/helm"
      version = "~> 2.8.0"
    }
  }
}

provider "aws" {}

data "aws_eks_cluster" "main" {
  name = module.eks.cluster_name
}

data "aws_eks_cluster_auth" "main" {
  name = module.eks.cluster_name
}

provider "kubernetes" {
  host                   = data.aws_eks_cluster.main.endpoint
  cluster_ca_certificate = base64decode(data.aws_eks_cluster.main.certificate_authority.0.data)
  token                  = data.aws_eks_cluster_auth.main.token
}

provider "helm" {
  kubernetes {
    host                   = data.aws_eks_cluster.main.endpoint
    cluster_ca_certificate = base64decode(data.aws_eks_cluster.main.certificate_authority.0.data)
    token                  = data.aws_eks_cluster_auth.main.token
  }
}

用户在运行terraform apply命令时遇到以下错误:

helm_release.ingress: Creating...
helm_release.ingress: Still creating... [10s elapsed]
helm_release.ingress: Still creating... [20s elapsed]
helm_release.ingress: Still creating... [30s elapsed]
│ Error: Kubernetes cluster unreachable: Get "https://<..>.gr7.***.eks.amazonaws.com/version": dial tcp 10.0.1.59:443: i/o timeout
│
│   with helm_release.ingress,
│   on eks-cluster.tf line 47, in resource "helm_release" "ingress":
│   47: resource "helm_release" "ingress" {

用户还提供了用于Ingress策略的文件内容,如下所示:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "iam:CreateServiceLinkedRole"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "iam:AWSServiceName": "elasticloadbalancing.amazonaws.com"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeAccountAttributes",
                "ec2:DescribeAddresses",
                "ec2:DescribeAvailabilityZones",
                "ec2:DescribeInternetGateways",
                "ec2:DescribeVpcs",
                "ec2:DescribeVpcPeeringConnections",
                "ec2:DescribeSubnets",
                "ec2:DescribeSecurityGroups",
                "ec2:DescribeInstances",
                "ec2:DescribeNetworkInterfaces",
                "ec2:DescribeTags",
                "ec2:GetCoipPoolUsage",
                "ec2:DescribeCoipPools",
                "elasticloadbalancing:DescribeLoadBalancers",
                "elasticloadbalancing:DescribeLoadBalancerAttributes",
                "elasticloadbalancing:DescribeListeners",
                "elasticloadbalancing:DescribeListenerCertificates",
                "elasticloadbalancing:DescribeSSLPolicies",
                "elasticloadbalancing:DescribeRules",
                "elasticloadbalancing:DescribeTargetGroups",
                "elasticloadbalancing:DescribeTargetGroupAttributes",
                "elasticloadbalancing:DescribeTargetHealth",
                "elasticloadbalancing:DescribeTags"
            ],
            "Resource": "*"
        },
        ...
    ]
}

用户尝试手动刷新aws_eks_cluster_auth对象(使用terraform refresh命令),但没有帮助。用户还尝试在helm.kubernetes提供程序中使用exec而不是提供token密钥,但也没有成功。

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

根据用户提供的信息,可能有以下几个原因导致无法连接到EKS集群:
1. 网络连接问题:可能是由于网络连接问题导致无法连接到EKS集群。可以尝试检查网络连接是否正常,并确保网络配置正确。
2. 安全组配置问题:可能是由于安全组配置不正确导致无法连接到EKS集群。可以尝试检查安全组配置,并确保允许从Terraform部署的机器访问EKS集群。
3. 访问权限问题:可能是由于缺少访问EKS集群所需的权限导致无法连接。可以尝试检查所使用的IAM角色是否具有足够的权限来访问EKS集群。

以下是一些可能的解决方案:
1. 检查网络连接:确保网络连接正常,并尝试使用其他工具(如kubectl)连接到EKS集群,以验证网络连接是否正常。
2. 检查安全组配置:确保安全组配置允许从Terraform部署的机器访问EKS集群。可以尝试在安全组中添加入站规则,允许来自Terraform部署机器的流量访问EKS集群。
3. 检查访问权限:确保所使用的IAM角色具有足够的权限来访问EKS集群。可以尝试为IAM角色添加适当的权限策略,以允许访问EKS集群。

请注意,以上解决方案仅供参考,具体解决方法可能因实际情况而异。建议用户根据实际情况进行调试和排查,以找到解决问题的最佳方法。

方案2

如果问题仍然存在,请尝试重新创建EKS集群,并确保在创建过程中正确配置网络和访问权限。

正文完