Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
clusterSecurityGroupTags: { "ClusterSecurityGroupTag": "true" },
nodeSecurityGroupTags: { "NodeSecurityGroupTag": "true" },
enabledClusterLogTypes: ["api", "audit", "authenticator", "controllerManager", "scheduler"],
// endpointPublicAccess: false, // Requires bastion to access cluster API endpoint
// endpointPrivateAccess: true, // Requires bastion to access cluster API endpoint
});
// Export the cluster details.
export const kubeconfig = cluster.kubeconfig.apply(JSON.stringify);
export const clusterName = cluster.core.cluster.name;
export const region = aws.config.region;
export const securityGroupIds = [cluster.nodeSecurityGroup.id];
// Create a Standard node group of t2.medium workers.
const ngStandard = new eks.NodeGroup(`${projectName}-ng-standard`, {
cluster: cluster,
instanceProfile: new aws.iam.InstanceProfile("ng-standard", {role: stdNodegroupIamRoleName}),
nodeAssociatePublicIpAddress: false,
nodeSecurityGroup: cluster.nodeSecurityGroup,
clusterIngressRule: cluster.eksClusterIngressRule,
amiId: "ami-0ca5998dc2c88e64b", // k8s v1.14.7 in us-west-2
instanceType: "t2.medium",
desiredCapacity: 3,
minSize: 3,
maxSize: 10,
labels: {"amiId": "ami-0ca5998dc2c88e64b"},
cloudFormationTags: clusterName.apply(clusterName => ({
"CloudFormationGroupTag": "true",
"k8s.io/cluster-autoscaler/enabled": "true",
[`k8s.io/cluster-autoscaler/${clusterName}`]: "true",
})),// 2. A `NodeGroup` resource which accepts an `eks.Cluster` as input
// Create the node group using an on-demand instance and resource tags.
cluster2.createNodeGroup("example-ng-tags-ondemand", {
instanceType: "t2.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
labels: {"ondemand": "true"},
instanceProfile: instanceProfile0,
cloudFormationTags: { "myCloudFormationTag2": "true" },
});
// Create the second node group using a spot price instance, resource tags, and
// specialized resource tags such as the autoScalingGroupTags.
const spot = new eks.NodeGroup("example-ng-tags-spot", {
cluster: cluster2,
instanceType: "t2.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
spotPrice: "1",
instanceProfile: instanceProfile0,
labels: {"preemptible": "true"},
taints: {
"special": {
value: "true",
effect: "NoSchedule",
},
},
autoScalingGroupTags: cluster2.core.cluster.name.apply(clusterName => ({
"myAutoScalingGroupTag3": "true",// 1. A `createNodeGroup` API on `eks.Cluster`
// 2. A `NodeGroup` resource which accepts an `eks.Cluster` as input
// Create the node group using an `instanceProfile` tied to the shared, cluster
// instance role registered with the cluster auth through `instanceRole`.
cluster1.createNodeGroup("example-ng-simple-ondemand", {
instanceType: "t2.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
labels: {"ondemand": "true"},
instanceProfile: instanceProfile0,
});
// Create the second node group with spot t2.medium instance
const spot = new eks.NodeGroup("example-ng-simple-spot", {
cluster: cluster1,
instanceType: "t2.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
spotPrice: "1",
labels: {"preemptible": "true"},
taints: {
"special": {
value: "true",
effect: "NoSchedule",
},
},
kubeletExtraArgs: "--alsologtostderr",
bootstrapExtraArgs: "--aws-api-retry-attempts 10",
instanceProfile: instanceProfile0,instanceType: "t2.medium",
desiredCapacity: 3,
minSize: 3,
maxSize: 10,
labels: {"amiId": "ami-0ca5998dc2c88e64b"},
cloudFormationTags: clusterName.apply(clusterName => ({
"CloudFormationGroupTag": "true",
"k8s.io/cluster-autoscaler/enabled": "true",
[`k8s.io/cluster-autoscaler/${clusterName}`]: "true",
})),
}, {
providers: { kubernetes: cluster.provider},
});
// Create a 2xlarge node group of t3.2xlarge workers with taints for special workloads.
const ng2xlarge = new eks.NodeGroup(`${projectName}-ng-2xlarge`, {
cluster: cluster,
instanceProfile: new aws.iam.InstanceProfile("ng-2xlarge", {role: perfNodegroupIamRoleName}),
nodeAssociatePublicIpAddress: false,
nodeSecurityGroup: cluster.nodeSecurityGroup,
clusterIngressRule: cluster.eksClusterIngressRule,
amiId: "ami-0ca5998dc2c88e64b", // k8s v1.14.7 in us-west-2
instanceType: "t3.2xlarge",
desiredCapacity: 5,
minSize: 5,
maxSize: 10,
labels: {"amiId": "ami-0ca5998dc2c88e64b"},
taints: { "special": { value: "true", effect: "NoSchedule"}},
cloudFormationTags: clusterName.apply(clusterName => ({
"CloudFormationGroupTag": "true",
"k8s.io/cluster-autoscaler/enabled": "true",
[`k8s.io/cluster-autoscaler/${clusterName}`]: "true",deployDashboard: false,
instanceRoles: [role1, role2],
});
// Create node groups using a different `instanceProfile` tied to one of the many
// instance roles registered with the cluster auth through `instanceRoles`.
cluster2.createNodeGroup("example-ng-advanced-ondemand", {
instanceType: "t2.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
labels: {"ondemand": "true"},
instanceProfile: instanceProfile1,
});
const spot2 = new eks.NodeGroup("example-ng-advanced-spot", {
cluster: cluster2,
instanceType: "t2.medium",
desiredCapacity: 1,
spotPrice: "1",
minSize: 1,
maxSize: 2,
labels: {"preemptible": "true"},
taints: {
"special": {
value: "true",
effect: "NoSchedule",
},
},
instanceProfile: instanceProfile2,
}, {
providers: { kubernetes: cluster2.provider},export function createNodeGroup(
name: string,
args: NodeGroupArgs,
): eks.NodeGroup {
return new eks.NodeGroup(name, {
cluster: args.cluster,
nodeSecurityGroup: args.cluster.nodeSecurityGroup,
clusterIngressRule: args.cluster.eksClusterIngressRule,
instanceType: args.instanceType,
amiId: args.ami,
nodeAssociatePublicIpAddress: false,
desiredCapacity: args.desiredCapacity,
minSize: args.desiredCapacity,
maxSize: 10,
instanceProfile: args.instanceProfile,
labels: {"amiId": args.ami},
taints: args.taints,
}, {
providers: { kubernetes: args.cluster.provider},
});
}