[英]AWS CDK Getting Error when try to initialize a new VPC with private isolated subnet used in Fargate Cluster
[英]AWS-CDK EKS Cluster can not be created in a VPC without at least 1 private subnet
我正在尝试使用 AWS CDK 生成 EKS 集群。 问题如下:当我为 EKS 集群定义一个不包含私有子网的 VPC 时, cdk synth
抛出以下错误。
Vpc定义和用法:
cluster = eks.Cluster(self, "airflow-eks",
endpoint_access=eks.EndpointAccess.PUBLIC,
vpc=ec2.Vpc(self, "airflow-eks-vpc", cidr="172.16.0.0/22", max_azs=2,
subnet_configuration=[
ec2.SubnetConfiguration(
name="subnet-1",
cidr_mask=27,
subnet_type=ec2.SubnetType.PUBLIC
),
ec2.SubnetConfiguration(
name="subnet-2",
cidr_mask=27,
subnet_type=ec2.SubnetType.PUBLIC
)
]
),
错误是:
jsii.errors.JSIIError:此 VPC 中没有“私有”子网组。 可用类型:公共
当我向集群定义添加额外的私有子网时,例如
ec2.SubnetConfiguration(
name="subnet-3",
cidr_mask=27,
subnet_type=ec2.SubnetType.PRIVATE
)
cdk synth
运行良好。
我想知道是否可以在不创建私有子网的情况下生成 EKS 集群,因为我根本不需要它们,并且使用私有子网会产生额外费用。 在 Terraform 中肯定可以做到,AWS CDK 怎么样?
不确定以下是根本原因,但它有所帮助。 因此eks.Cluster
init 方法包含一个参数 - vpcSubnets
,这是可选的,默认情况下包括所有公共和私有 (!) 子网。 因此,当明确定义此参数时,即
const cluster = new eks.Cluster(stack,'my-ts-eks',
{
vpc: eks_vpc,
vpcSubnets:[
{
subnetType: ec2.SubnetType.PUBLIC,
onePerAz: true
}
],
defaultCapacity: 0,
version: eks.KubernetesVersion.V1_17,
});
无需私有子网即可创建 EKS 集群。
PS上面的例子是在TypeScript而不是Python中
PPS 在 Python 中它看起来像:
cluster = eks.Cluster(self, "airflow-eks",
...
vpc_subnets = eks_vpc.select_subnets(subnet_type=ec2.SubnetType.PUBLIC, one_per_az=True).subnets,
...
)
您可以通过将assignPublicIp: true
添加到 FargateServiceProps 来尝试吗? 你可以参考github 票 #7062了解更多细节。
在Java中,实现如下
ApplicationLoadBalancedFargateService.Builder.create(this, "FargateServiceName").cluster(cluster)
.assignPublicIp(true)
.cpu(512) // Default is 256
.
.
.
.build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.