alt*_*-f4 5 amazon-web-services aws-fargate amazon-eks
我希望能够使用 Fargate 部署 AWS EKS。我已经成功地使部署与node_group. 然而,当我转而使用 Fargate 时,Pod 似乎都陷入了挂起状态。
我正在使用 Terraform 进行配置(不一定是在寻找 Terraform 答案)。这就是我创建 EKS 集群的方式:
module "eks_cluster" {
source = "terraform-aws-modules/eks/aws"
version = "13.2.1"
cluster_name = "${var.project_name}-${var.env_name}"
cluster_version = var.cluster_version
vpc_id = var.vpc_id
cluster_enabled_log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
enable_irsa = true
subnets = concat(var.private_subnet_ids, var.public_subnet_ids)
create_fargate_pod_execution_role = true
write_kubeconfig = false
fargate_pod_execution_role_name = "${var.project_name}-role"
# Assigning worker groups
node_groups = {
my_nodes = {
desired_capacity = 1
max_capacity = 1
min_capacity = 1
instance_type = var.nodes_instance_type
subnets = var.private_subnet_ids
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我配置 Fargate 配置文件的方式:
//# Create EKS Fargate profile
resource "aws_eks_fargate_profile" "fargate_profile" {
cluster_name = module.eks_cluster.cluster_id
fargate_profile_name = "${var.project_name}-fargate-profile-${var.env_name}"
pod_execution_role_arn = aws_iam_role.fargate_iam_role.arn
subnet_ids = var.private_subnet_ids
selector {
namespace = var.project_name
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我创建并附加所需策略的方式:
//# Create IAM Role for Fargate Profile
resource "aws_iam_role" "fargate_iam_role" {
name = "${var.project_name}-fargate-role-${var.env_name}"
force_detach_policies = true
assume_role_policy = jsonencode({
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "eks-fargate-pods.amazonaws.com"
}
}]
Version = "2012-10-17"
})
}
# Attach IAM Policy for Fargate
resource "aws_iam_role_policy_attachment" "fargate_pod_execution" {
role = aws_iam_role.fargate_iam_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy"
}
Run Code Online (Sandbox Code Playgroud)
运行kubectl describe pod我得到:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 14s fargate-scheduler Misconfigured Fargate Profile: fargate profile fargate-airflow-fargate-profile-dev blocked for new launches due to: Pod execution role is not found in auth config or does not have all required permissions for launching fargate pods.
Run Code Online (Sandbox Code Playgroud)
我尝试通过模块的功能映射角色,例如:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 14s fargate-scheduler Misconfigured Fargate Profile: fargate profile fargate-airflow-fargate-profile-dev blocked for new launches due to: Pod execution role is not found in auth config or does not have all required permissions for launching fargate pods.
Run Code Online (Sandbox Code Playgroud)
但我的尝试没有成功。我该如何调试这个问题?其背后的原因是什么?
好吧,我看到你的问题了。我也刚刚修复了我的,尽管我使用了不同的方法。
在您的eks_cluster模块中,您已经告诉模块创建角色并为其提供名称,因此以后无需创建角色资源。该模块应该为您处理它,包括aws-auth在 Kubernetes 中填充配置映射。
在您的aws_eks_fargate_profile资源中,您应该使用模块提供的角色,即pod_execution_role_arn = module.eks_cluster.fargate_profile_arns[0]。
我相信修复这些问题应该可以解决您第一次配置尝试的问题。
对于第二次尝试,map_roles输入适用于 IAM 角色,但您要提供有关 Fargate 配置文件的信息。您想做以下两件事之一:
create_fargate_pod_execution_role禁用创建您的角色(和)的模块fargate_pod_execution_role_name,而是创建您自己的 IAM 角色,类似于您在第一个配置中所做的操作,并将该信息提供给map_roles.map_roles并在您的 Fargate 配置文件中引用模块生成的 IAM 角色,与第一个配置的解决方案类似。如果其中任何内容令人困惑,请告诉我。看来你们真的很亲近啊!
| 归档时间: |
|
| 查看次数: |
4785 次 |
| 最近记录: |