-
Notifications
You must be signed in to change notification settings - Fork 81
/
index.ts
168 lines (150 loc) · 5.12 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import * as aws from "@pulumi/aws";
import * as eks from "@pulumi/eks";
import * as iam from "./iam";
/**
* Identical IAM for all NodeGroups: all NodeGroups share the same `instanceRole`.
*/
// Create example IAM roles and profiles to show to use them with NodeGroups.
// Note, all roles for the instance profiles are required to at least have
// the following EKS Managed Policies attached to successfully auth and join the
// cluster:
// - "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
// - "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
// - "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
const role0 = iam.createRole("example-role0");
const instanceProfile0 = new aws.iam.InstanceProfile("example-instanceProfile0", {role: role0});
// Create an EKS cluster with a shared IAM instance role to register with the
// cluster auth.
const cluster1 = new eks.Cluster("example-nodegroup-iam-simple", {
skipDefaultNodeGroup: true,
nodeAmiId: "ami-066e69f6f03b5383e",
instanceRole: role0,
});
// There are two approaches that can be used to add additional NodeGroups.
// 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: "t3.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
labels: {"ondemand": "true"},
instanceProfile: instanceProfile0,
});
const ng = new eks.NodeGroupV2("example-ng2-simple-ondemand", {
cluster: cluster1,
instanceType: "t3.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
labels: {"ondemand": "true"},
instanceProfile: instanceProfile0,
});
// Create the second node group with spot t3.medium instance
const spot = new eks.NodeGroup("example-ng-simple-spot", {
cluster: cluster1,
instanceType: "t3.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
spotPrice: "1",
labels: {"preemptible": "true"},
taints: {
"special": {
value: "true",
effect: "NoSchedule",
},
},
instanceProfile: instanceProfile0,
}, {
providers: { kubernetes: cluster1.provider},
});
const withLaunchTemplateTagSpecifications = new eks.NodeGroupV2("example-ng2-launchtemplate-tags", {
cluster: cluster1,
instanceType: "t3.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
labels: { "ondemand": "true" },
instanceProfile: instanceProfile0,
launchTemplateTagSpecifications: [
{
resourceType: "instance",
tags: {
"foo": "bar",
},
},
{
resourceType: "volume",
tags: {
"foo2": "bar2",
},
},
],
});
// Export the cluster's kubeconfig.
export const kubeconfig1 = cluster1.kubeconfig;
/**
* Per NodeGroup IAM: each NodeGroup will bring its own, specific instance
* role and profile.
*/
const role1 = iam.createRole("example-role1");
const role2 = iam.createRole("example-role2");
const role3 = iam.createRole("example-role3");
const instanceProfile1 = new aws.iam.InstanceProfile("example-instanceProfile1", {role: role1});
const instanceProfile2 = new aws.iam.InstanceProfile("example-instanceProfile2", {role: role2});
const instanceProfile3 = new aws.iam.InstanceProfile("example-instanceProfile3", {role: role3});
// Create an EKS cluster with many IAM roles to register with the cluster auth.
const cluster2 = new eks.Cluster("example-nodegroup-iam-advanced", {
skipDefaultNodeGroup: true,
instanceRoles: [role1, role2, role3],
nodeAmiId: "ami-066e69f6f03b5383e",
});
// 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: "t3.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
labels: {"ondemand": "true"},
instanceProfile: instanceProfile1,
});
const ng2 = new eks.NodeGroupV2("example-ng-advanced-ondemand", {
cluster: cluster2,
instanceType: "t3.medium",
desiredCapacity: 1,
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
labels: {"ondemand": "true"},
instanceProfile: instanceProfile2,
});
const spot2 = new eks.NodeGroup("example-ng-advanced-spot", {
cluster: cluster2,
instanceType: "t3.medium",
desiredCapacity: 1,
spotPrice: "1",
minSize: 1,
maxSize: 2,
amiId: "ami-066e69f6f03b5383e",
labels: {"preemptible": "true"},
taints: {
"special": {
value: "true",
effect: "NoSchedule",
},
},
instanceProfile: instanceProfile3,
}, {
providers: { kubernetes: cluster2.provider},
});
// Export the cluster's kubeconfig.
export const kubeconfig2 = cluster2.kubeconfig;