Nodegroup L2 construct
The Nodegroup resource class.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { aws_eks as eks } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
declare const cluster: eks.Cluster;
declare const instanceType: ec2.InstanceType;
declare const role: iam.Role;
declare const securityGroup: ec2.SecurityGroup;
declare const subnet: ec2.Subnet;
declare const subnetFilter: ec2.SubnetFilter;
const nodegroup = new eks.Nodegroup(this, 'MyNodegroup', {
cluster: cluster,
// the properties below are optional
amiType: eks.NodegroupAmiType.AL2_X86_64,
capacityType: eks.CapacityType.SPOT,
desiredSize: 123,
diskSize: 123,
enableNodeAutoRepair: false,
forceUpdate: false,
instanceTypes: [instanceType],
labels: {
labelsKey: 'labels',
},
launchTemplateSpec: {
id: 'id',
// the properties below are optional
version: 'version',
},
maxSize: 123,
maxUnavailable: 123,
maxUnavailablePercentage: 123,
minSize: 123,
nodegroupName: 'nodegroupName',
nodeRole: role,
releaseVersion: 'releaseVersion',
remoteAccess: {
sshKeyName: 'sshKeyName',
// the properties below are optional
sourceSecurityGroups: [securityGroup],
},
removalPolicy: cdk.RemovalPolicy.DESTROY,
subnets: {
availabilityZones: ['availabilityZones'],
onePerAz: false,
subnetFilters: [subnetFilter],
subnetGroupName: 'subnetGroupName',
subnets: [subnet],
subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
},
tags: {
tagsKey: 'tags',
},
taints: [{
effect: eks.TaintEffect.NO_SCHEDULE,
key: 'key',
value: 'value',
}],
});
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_eks as eks
from aws_cdk import aws_iam as iam
# cluster: eks.Cluster
# instance_type: ec2.InstanceType
# role: iam.Role
# security_group: ec2.SecurityGroup
# subnet: ec2.Subnet
# subnet_filter: ec2.SubnetFilter
nodegroup = eks.Nodegroup(self, "MyNodegroup",
cluster=cluster,
# the properties below are optional
ami_type=eks.NodegroupAmiType.AL2_X86_64,
capacity_type=eks.CapacityType.SPOT,
desired_size=123,
disk_size=123,
enable_node_auto_repair=False,
force_update=False,
instance_types=[instance_type],
labels={
"labels_key": "labels"
},
launch_template_spec=eks.LaunchTemplateSpec(
id="id",
# the properties below are optional
version="version"
),
max_size=123,
max_unavailable=123,
max_unavailable_percentage=123,
min_size=123,
nodegroup_name="nodegroupName",
node_role=role,
release_version="releaseVersion",
remote_access=eks.NodegroupRemoteAccess(
ssh_key_name="sshKeyName",
# the properties below are optional
source_security_groups=[security_group]
),
removal_policy=cdk.RemovalPolicy.DESTROY,
subnets=ec2.SubnetSelection(
availability_zones=["availabilityZones"],
one_per_az=False,
subnet_filters=[subnet_filter],
subnet_group_name="subnetGroupName",
subnets=[subnet],
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
),
tags={
"tags_key": "tags"
},
taints=[eks.TaintSpec(
effect=eks.TaintEffect.NO_SCHEDULE,
key="key",
value="value"
)]
)
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.eks.*;
import software.amazon.awscdk.services.iam.*;
Cluster cluster;
InstanceType instanceType;
Role role;
SecurityGroup securityGroup;
Subnet subnet;
SubnetFilter subnetFilter;
Nodegroup nodegroup = Nodegroup.Builder.create(this, "MyNodegroup")
.cluster(cluster)
// the properties below are optional
.amiType(NodegroupAmiType.AL2_X86_64)
.capacityType(CapacityType.SPOT)
.desiredSize(123)
.diskSize(123)
.enableNodeAutoRepair(false)
.forceUpdate(false)
.instanceTypes(List.of(instanceType))
.labels(Map.of(
"labelsKey", "labels"))
.launchTemplateSpec(LaunchTemplateSpec.builder()
.id("id")
// the properties below are optional
.version("version")
.build())
.maxSize(123)
.maxUnavailable(123)
.maxUnavailablePercentage(123)
.minSize(123)
.nodegroupName("nodegroupName")
.nodeRole(role)
.releaseVersion("releaseVersion")
.remoteAccess(NodegroupRemoteAccess.builder()
.sshKeyName("sshKeyName")
// the properties below are optional
.sourceSecurityGroups(List.of(securityGroup))
.build())
.removalPolicy(RemovalPolicy.DESTROY)
.subnets(SubnetSelection.builder()
.availabilityZones(List.of("availabilityZones"))
.onePerAz(false)
.subnetFilters(List.of(subnetFilter))
.subnetGroupName("subnetGroupName")
.subnets(List.of(subnet))
.subnetType(SubnetType.PRIVATE_ISOLATED)
.build())
.tags(Map.of(
"tagsKey", "tags"))
.taints(List.of(TaintSpec.builder()
.effect(TaintEffect.NO_SCHEDULE)
.key("key")
.value("value")
.build()))
.build();
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.EKS;
using Amazon.CDK.AWS.IAM;
Cluster cluster;
InstanceType instanceType;
Role role;
SecurityGroup securityGroup;
Subnet subnet;
SubnetFilter subnetFilter;
var nodegroup = new Nodegroup(this, "MyNodegroup", new NodegroupProps {
Cluster = cluster,
// the properties below are optional
AmiType = NodegroupAmiType.AL2_X86_64,
CapacityType = CapacityType.SPOT,
DesiredSize = 123,
DiskSize = 123,
EnableNodeAutoRepair = false,
ForceUpdate = false,
InstanceTypes = new [] { instanceType },
Labels = new Dictionary<string, string> {
{ "labelsKey", "labels" }
},
LaunchTemplateSpec = new LaunchTemplateSpec {
Id = "id",
// the properties below are optional
Version = "version"
},
MaxSize = 123,
MaxUnavailable = 123,
MaxUnavailablePercentage = 123,
MinSize = 123,
NodegroupName = "nodegroupName",
NodeRole = role,
ReleaseVersion = "releaseVersion",
RemoteAccess = new NodegroupRemoteAccess {
SshKeyName = "sshKeyName",
// the properties below are optional
SourceSecurityGroups = new [] { securityGroup }
},
RemovalPolicy = RemovalPolicy.DESTROY,
Subnets = new SubnetSelection {
AvailabilityZones = new [] { "availabilityZones" },
OnePerAz = false,
SubnetFilters = new [] { subnetFilter },
SubnetGroupName = "subnetGroupName",
Subnets = new [] { subnet },
SubnetType = SubnetType.PRIVATE_ISOLATED
},
Tags = new Dictionary<string, string> {
{ "tagsKey", "tags" }
},
Taints = new [] { new TaintSpec {
Effect = TaintEffect.NO_SCHEDULE,
Key = "key",
Value = "value"
} }
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import cdk "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var cluster Cluster
var instanceType InstanceType
var role Role
var securityGroup SecurityGroup
var subnet Subnet
var subnetFilter SubnetFilter
nodegroup := awscdk.Aws_eks.NewNodegroup(this, jsii.String("MyNodegroup"), &NodegroupProps{
Cluster: cluster,
// the properties below are optional
AmiType: awscdk.*Aws_eks.NodegroupAmiType_AL2_X86_64,
CapacityType: awscdk.*Aws_eks.CapacityType_SPOT,
DesiredSize: jsii.Number(123),
DiskSize: jsii.Number(123),
EnableNodeAutoRepair: jsii.Boolean(false),
ForceUpdate: jsii.Boolean(false),
InstanceTypes: []InstanceType{
instanceType,
},
Labels: map[string]*string{
"labelsKey": jsii.String("labels"),
},
LaunchTemplateSpec: &LaunchTemplateSpec{
Id: jsii.String("id"),
// the properties below are optional
Version: jsii.String("version"),
},
MaxSize: jsii.Number(123),
MaxUnavailable: jsii.Number(123),
MaxUnavailablePercentage: jsii.Number(123),
MinSize: jsii.Number(123),
NodegroupName: jsii.String("nodegroupName"),
NodeRole: role,
ReleaseVersion: jsii.String("releaseVersion"),
RemoteAccess: &NodegroupRemoteAccess{
SshKeyName: jsii.String("sshKeyName"),
// the properties below are optional
SourceSecurityGroups: []ISecurityGroup{
securityGroup,
},
},
RemovalPolicy: cdk.RemovalPolicy_DESTROY,
Subnets: &SubnetSelection{
AvailabilityZones: []*string{
jsii.String("availabilityZones"),
},
OnePerAz: jsii.Boolean(false),
SubnetFilters: []SubnetFilter{
subnetFilter,
},
SubnetGroupName: jsii.String("subnetGroupName"),
Subnets: []ISubnet{
subnet,
},
SubnetType: awscdk.Aws_ec2.SubnetType_PRIVATE_ISOLATED,
},
Tags: map[string]*string{
"tagsKey": jsii.String("tags"),
},
Taints: []TaintSpec{
&TaintSpec{
Effect: awscdk.*Aws_eks.TaintEffect_NO_SCHEDULE,
Key: jsii.String("key"),
Value: jsii.String("value"),
},
},
})
Initializer
new Nodegroup(scope: Construct, id: string, props: NodegroupProps)
Nodegroup(scope: Construct, id: str, props: NodegroupProps)
new Nodegroup(Construct scope, String id, NodegroupProps props)
new Nodegroup(Construct scope, string id, NodegroupProps props)
NewNodegroup(Scope Construct, Id *string, Props NodegroupProps)
Construct Props
amiTypeNodegroupAmiTypeami_typeNodegroupAmiTypeamiTypeNodegroupAmiTypeAmiTypeNodegroupAmiTypeAmiTypeNodegroupAmiType#Default: auto-determined from the instanceTypes property when launchTemplateSpec property is not specified
If you explicitly specify the launchTemplate with custom AMI, do not specify this property, or the node group deployment will fail. In other cases, you will need to specify correct amiType for the nodegroup.
capacityTypeCapacityTypecapacity_typeCapacityTypecapacityTypeCapacityTypeCapacityTypeCapacityTypeCapacityTypeCapacityType= ON_DEMAND#If not specified, the nodewgroup will initially create minSize instances.
enableNodeAutoRepairbooleanenable_node_auto_repairboolenableNodeAutoRepairBooleanEnableNodeAutoRepairboolEnableNodeAutoRepair*bool= disabled#Node auto repair is disabled by default.
If an update fails because pods could not be drained, you can force the update after it fails to terminate the old node whether or not any pods are running on the node.
instanceTypesInstanceType[]instance_typestyping.List[InstanceType]instanceTypesList<InstanceType>InstanceTypesInstanceType[]InstanceTypes*[]InstanceType#Default: t3.medium will be used according to the cloudformation document.
labels{ [key: string]: string }labelstyping.Mapping[str, str]labelsMap<String, String>LabelsIDictionary<string, string>Labels*map[string]*string= None#launchTemplateSpecLaunchTemplateSpeclaunch_template_specLaunchTemplateSpeclaunchTemplateSpecLaunchTemplateSpecLaunchTemplateSpecLaunchTemplateSpecLaunchTemplateSpecLaunchTemplateSpec#Default: no launch template
Managed node groups can support up to 100 nodes by default.
This number must be greater than or equal to zero.
Default: resource ID
Default: None. Auto-generated if not specified.
notes
The Amazon EKS worker node kubelet daemon makes calls to AWS APIs on your behalf. Worker nodes receive permissions for these API calls through an IAM instance profile and associated policies. Before you can launch worker nodes and register them into a cluster, you must create an IAM role for those worker nodes to use when they are launched.
releaseVersionstringrelease_versionstrreleaseVersionStringReleaseVersionstringReleaseVersion*string#Default: The latest available AMI version for the node group's current Kubernetes version is used.
remoteAccessNodegroupRemoteAccessremote_accessNodegroupRemoteAccessremoteAccessNodegroupRemoteAccessRemoteAccessNodegroupRemoteAccessRemoteAccessNodegroupRemoteAccess= disabled#Disabled by default, however, if you specify an Amazon EC2 SSH key but do not specify a source security group when you create a managed node group, then port 22 on the worker nodes is opened to the internet (0.0.0.0/0)
removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= RemovalPolicy.DESTROY#notes
The removal policy controls what happens to the resource if it stops being managed by CloudFormation. This can happen in one of three situations:
- The resource is removed from the template, so CloudFormation stops managing it
- A change to the resource is made that requires it to be replaced, so CloudFormation stops managing it
- The stack is deleted, so CloudFormation stops managing all resources in it
subnetsSubnetSelectionsubnetsSubnetSelectionsubnetsSubnetSelectionSubnetsSubnetSelectionSubnetsSubnetSelection#Default: private subnets
By specifying the SubnetSelection, the selected subnets will automatically apply required tags i.e. kubernetes.io/cluster/CLUSTER_NAME with a value of shared, where CLUSTER_NAME is replaced with the name of your cluster.
tags{ [key: string]: string }tagstyping.Mapping[str, str]tagsMap<String, String>TagsIDictionary<string, string>Tags*map[string]*string= None#Each tag consists of a key and an optional value, both of which you define. Node group tags do not propagate to any other resources associated with the node group, such as the Amazon EC2 instances or subnets.
Properties
envResourceEnvironmentenvResourceEnvironmentenvResourceEnvironmentEnvResourceEnvironmentEnvResourceEnvironmentrequired#notes
For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.
nodegroupNamestringnodegroup_namestrnodegroupNameStringNodegroupNamestringNodegroupName*stringrequired#nodegroupRefNodegroupReferencenodegroup_refNodegroupReferencenodegroupRefNodegroupReferenceNodegroupRefNodegroupReferenceNodegroupRefNodegroupReferencerequired#PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#Methods
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#notes · 1 parameter
When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.
Parameters
strengthstrengthstrengthstrengthStrength— - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#notes
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).
fromNodegroupName(scope: Construct, id: string, nodegroupName: string): INodegroup@staticmethod def from_nodegroup_name(scope: Construct, id: str, nodegroup_name: str) -> INodegrouppublic static INodegroup fromNodegroupName(Construct scope, String id, String nodegroupName)public static INodegroup FromNodegroupName(Construct scope, string id, string nodegroupName)func FromNodegroupName(Scope Construct, Id *string, NodegroupName *string) INodegroupstatic#isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#notes · 1 parameter · returns
Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.
Parameters
xxxxX— Any object.
Returns: true if x is an object created from a class which extends Construct.
isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.