Skip to content

Commit 236fd68

Browse files
authored
add: --encrypt-secrets flag to create cluster (#206)
1 parent 625eb1c commit 236fd68

File tree

3 files changed

+99
-57
lines changed

3 files changed

+99
-57
lines changed

docs/create-cluster.md

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
`eksdemo` can manage applications in any EKS cluster and the cluster doesn’t have to be created by `eksdemo`. You can use `eksctl` to create the cluster and then manage application using `eksdemo`. However, there are a number of benefits to using `eksdemo` to create your cluster:
44
* Cluster logging is enabled by default
55
* OIDC is enabled by default so IAM Roles for Service Accounts (IRSA) works out of the box
6-
* The Managed Node Group ASG max is set to 10 so cluster autoscaling can work out of the box
6+
* The Managed Node Group ASG max is set to 10 so Cluster Autoscaler can work out of the box
77
* Private networking for nodes is set by default
8-
* VPC CNI is configured as a Managed Add-on and configured with IRSA by default
8+
* VPC CNI is configured as a Managed Add-on and configured with IRSA, with network policy enabled
99
* t3.large instances used by default instead of m5.large for cost savings, but can be easily changed with the `--instance` flag or the shorthand `-i`
10-
* To use containerd as the CRI on Amazon EKS optimized Amazon Linux AMIs is as easy as using the `--containerd` boolean flag
1110
* To create a Fargate profile that selects workloads in the “fargate” namespace, use the `--fargate` boolean flag
12-
* Choose a supported EKS version with the `--version` flag or the shorthand `-v` like `-v 1.21`
13-
* Using a different OS like Bottlerocket or Ubuntu is as easy as `--os bottlerocket` or `--os ubuntu`
11+
* Choose a supported EKS version with the `--version` flag or the shorthand `-v` like `-v 1.29`
12+
* Using a different OS like Bottlerocket or AL2023 is as easy as `--os bottlerocket` or `--os amazonlinux2023`
1413
* To use IPv6 networking, set the `--ipv6` boolean flag
1514
* If you need to further customize the config, add the `--dry-run` flag and it will output the eksctl YAML config file and you can copy/paste it into a file, make your edits and run `eksctl create cluster -f cluster.yaml`
1615

@@ -27,19 +26,26 @@ Aliases:
2726
cluster, clusters
2827
2928
Flags:
30-
--containerd use containerd runtime
31-
--dry-run don't create, just print out all creation steps
32-
--fargate create a Fargate profile
33-
-h, --help help for cluster
34-
-i, --instance string instance type (default "t3.large")
35-
--ipv6 use IPv6 networking
36-
--max int max nodes (default 10)
37-
--min int min nodes
38-
--no-roles don't create IAM roles
39-
-N, --nodes int desired number of nodes (default 2)
40-
--os string Operating System (default "AmazonLinux2")
41-
--private private cluster (includes ECR, S3, and other VPC endpoints)
42-
-v, --version string Kubernetes version (default "1.24")
29+
--disable-network-policy don't enable network policy for Amazon VPC CNI
30+
--dry-run don't create, just print out all creation steps
31+
--encrypt-secrets string alias of KMS key to encrypt secrets
32+
--fargate create a Fargate profile
33+
-h, --help help for cluster
34+
-H, --hostname-type string type of hostname to use for EC2 instances (default "resource-name")
35+
-i, --instance string instance type (default "t3.large")
36+
--ipv6 use IPv6 networking
37+
--kubeconfig string path to write kubeconfig (default "/Users/jsmith/.kube/config")
38+
--max int max nodes (default 10)
39+
--min int min nodes
40+
--no-roles don't create IAM roles
41+
--no-taints don't taint nodes with GPUs or Neuron cores
42+
-N, --nodes int desired number of nodes (default 2)
43+
--os string Operating System (default "AmazonLinux2")
44+
--prefix-assignment configure VPC CNI for prefix assignment
45+
--private private cluster (includes ECR, S3, and other VPC endpoints)
46+
-v, --version string Kubernetes version (default "1.30")
47+
--vpc-cidr string CIDR to use for EKS Cluster VPC (default "192.168.0.0/16")
48+
--zones strings list of AZs to use. ie. us-east-1a,us-east-1b,us-east-1c
4349
4450
Global Flags:
4551
--profile string use the specific profile from your credential file
@@ -68,10 +74,15 @@ kind: ClusterConfig
6874
metadata:
6975
name: blue
7076
region: us-west-2
71-
version: "1.24"
77+
version: "1.30"
7278
7379
addons:
7480
- name: vpc-cni
81+
version: latest
82+
configurationValues: |-
83+
enableNetworkPolicy: "true"
84+
env:
85+
ENABLE_PREFIX_DELEGATION: "false"
7586
7687
cloudWatch:
7788
clusterLogging:
@@ -88,12 +99,12 @@ iam:
8899
attachPolicy:
89100
<snip>
90101
- metadata:
91-
name: cluster-autoscaler
102+
name: ebs-csi-controller-sa
92103
namespace: kube-system
93-
roleName: eksdemo.blue.kube-system.cluster-autoscaler
104+
roleName: eksdemo.blue.kube-system.ebs-csi-controller-sa
94105
roleOnly: true
95-
attachPolicy:
96-
<snip>
106+
attachPolicyARNs:
107+
- arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy
97108
- metadata:
98109
name: external-dns
99110
namespace: external-dns
@@ -109,17 +120,21 @@ iam:
109120
attachPolicy:
110121
<snip>
111122
123+
vpc:
124+
cidr: 192.168.0.0/16
125+
hostnameType: resource-name
126+
112127
managedNodeGroups:
113128
- name: main
114129
amiFamily: Bottlerocket
130+
desiredCapacity: 3
115131
iam:
116132
attachPolicyARNs:
117133
- arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
118134
- arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
119135
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
120136
instanceType: t3.xlarge
121137
minSize: 0
122-
desiredCapacity: 3
123138
maxSize: 10
124139
privateNetworking: true
125140
spot: false
@@ -131,36 +146,37 @@ After reviewing the output above, go ahead and create your cluster.
131146

132147
```
133148
» eksdemo create cluster blue --os bottlerocket -i t3.xlarge -N 3
134-
2023-01-25 09:04:24 [ℹ] eksctl version 0.126.0
135-
2023-01-25 09:04:24 [ℹ] using region us-west-2
136-
2023-01-25 09:04:24 [ℹ] setting availability zones to [us-west-2d us-west-2b us-west-2a]
137-
2023-01-25 09:04:24 [ℹ] subnets for us-west-2d - public:192.168.0.0/19 private:192.168.96.0/19
138-
2023-01-25 09:04:24 [ℹ] subnets for us-west-2b - public:192.168.32.0/19 private:192.168.128.0/19
139-
2023-01-25 09:04:24 [ℹ] subnets for us-west-2a - public:192.168.64.0/19 private:192.168.160.0/19
140-
2023-01-25 09:04:24 [ℹ] nodegroup "main" will use "" [Bottlerocket/1.24]
141-
2023-01-25 09:04:24 [ℹ] using Kubernetes version 1.24
142-
2023-01-25 09:04:24 [ℹ] creating EKS cluster "blue" in "us-west-2" region with managed nodes
143-
2023-01-25 09:04:24 [ℹ] 1 nodegroup (main) was included (based on the include/exclude rules)
149+
2024-07-30 18:52:39 [ℹ] eksctl version 0.180.0
150+
2024-07-30 18:52:39 [ℹ] using region us-west-2
151+
2024-07-30 18:52:39 [ℹ] setting availability zones to [us-west-2c us-west-2a us-west-2d]
152+
2024-07-30 18:52:39 [ℹ] subnets for us-west-2c - public:192.168.0.0/19 private:192.168.96.0/19
153+
2024-07-30 18:52:39 [ℹ] subnets for us-west-2a - public:192.168.32.0/19 private:192.168.128.0/19
154+
2024-07-30 18:52:39 [ℹ] subnets for us-west-2d - public:192.168.64.0/19 private:192.168.160.0/19
155+
2024-07-30 18:52:39 [ℹ] nodegroup "main" will use "" [Bottlerocket/1.30]
156+
2024-07-30 18:52:39 [ℹ] using Kubernetes version 1.30
157+
2024-07-30 18:52:39 [ℹ] creating EKS cluster "blue" in "us-west-2" region with managed nodes
158+
2024-07-30 18:52:39 [ℹ] 1 nodegroup (main) was included (based on the include/exclude rules)
144159
<snip>
145-
2023-01-25 09:23:26 [ℹ] waiting for CloudFormation stack "eksctl-blue-nodegroup-main"
146-
2023-01-25 09:23:26 [ℹ] waiting for the control plane to become ready
147-
2023-01-25 09:23:28 [✔] saved kubeconfig as "/Users/awsuser/.kube/config"
148-
2023-01-25 09:23:28 [ℹ] no tasks
149-
2023-01-25 09:23:28 [✔] all EKS cluster resources for "blue" have been created
150-
2023-01-25 09:23:29 [ℹ] kubectl command should work with "/Users/awsuser/.kube/config", try 'kubectl get nodes'
151-
2023-01-25 09:23:29 [✔] EKS cluster "blue" in "us-west-2" region is ready
160+
2024-07-30 19:09:37 [ℹ] waiting for CloudFormation stack "eksctl-blue-nodegroup-main"
161+
2024-07-30 19:09:37 [ℹ] waiting for the control plane to become ready
162+
2024-07-30 19:09:38 [✔] saved kubeconfig as "/Users/awsuser/.kube/config"
163+
2024-07-30 19:09:38 [ℹ] no tasks
164+
2024-07-30 19:09:38 [✔] all EKS cluster resources for "blue" have been created
165+
2024-07-30 19:09:38 [✔] created 1 managed nodegroup(s) in cluster "blue"
166+
2024-07-30 19:09:40 [ℹ] kubectl command should work with "/Users/awsuser/.kube/config", try 'kubectl get nodes'
167+
2024-07-30 19:09:40 [✔] EKS cluster "awsuser" in "us-west-2" region is ready
152168
```
153169

154170
To view the status and info about your cluster you can run the **`eksdemo get cluster`** command.
155171

156172
```
157173
» eksdemo get cluster
158-
+------------+--------+---------+---------+----------+----------+---------+
159-
| Age | Status | Cluster | Version | Platform | Endpoint | Logging |
160-
+------------+--------+---------+---------+----------+----------+---------+
161-
| 3 weeks | ACTIVE | green | 1.23 | eks.5 | Public | true |
162-
| 20 minutes | ACTIVE | *blue | 1.24 | eks.3 | Public | true |
163-
+------------+--------+---------+---------+----------+----------+---------+
174+
+------------+--------+---------+---------+----------+----------+
175+
| Age | Status | Cluster | Version | Platform | Endpoint |
176+
+------------+--------+---------+---------+----------+----------+
177+
| 3 weeks | ACTIVE | green | 1.28 | eks.16 | Public |
178+
| 20 minutes | ACTIVE | *blue | 1.30 | eks.5 | Public |
179+
+------------+--------+---------+---------+----------+----------+
164180
* Indicates current context in local kubeconfig
165181
```
166182

@@ -171,21 +187,21 @@ To view detail on the node group, use the **`eksdemo get nodegroup`** command. F
171187
+-----------+--------+------+-------+-----+-----+-----------------+-----------+-------------+
172188
| Age | Status | Name | Nodes | Min | Max | Version | Type | Instance(s) |
173189
+-----------+--------+------+-------+-----+-----+-----------------+-----------+-------------+
174-
| 5 minutes | ACTIVE | main | 3 | 0 | 10 | 1.11.1-104f8e0f | ON_DEMAND | t3.xlarge |
190+
| 5 minutes | ACTIVE | main | 3 | 0 | 10 | 1.20.5-a3e8bda1 | ON_DEMAND | t3.xlarge |
175191
+-----------+--------+------+-------+-----+-----+-----------------+-----------+-------------+
176192
```
177193

178194
To view detail on the nodes, use the **`eksdemo get node`** command. Here we’ll use the `-c` flag which is the shorthand version of the `--cluster` flag.
179195

180196
```
181197
» eksdemo get node -c blue
182-
+-----------+----------------------+---------------------+-----------+------------+-----------+
183-
| Age | Name | Instance Id | Type | Zone | Nodegroup |
184-
+-----------+----------------------+---------------------+-----------+------------+-----------+
185-
| 5 minutes | ip-192-168-112-160.* | i-01049dccf2e58d265 | t3.xlarge | us-west-2d | main |
186-
| 5 minutes | ip-192-168-141-119.* | i-003139b73a29ff1b7 | t3.xlarge | us-west-2b | main |
187-
| 5 minutes | ip-192-168-186-156.* | i-0583cab4366088ac2 | t3.xlarge | us-west-2a | main |
188-
+-----------+----------------------+---------------------+-----------+------------+-----------+
198+
+-----------+-----------------------+---------------------+-----------+------------+-----------+
199+
| Age | Name | Instance Id | Type | Zone | Nodegroup |
200+
+-----------+-----------------------+---------------------+-----------+------------+-----------+
201+
| 5 minutes | i-058de3c37e4d56968.* | i-058de3c37e4d56968 | t3.xlarge | us-west-2b | main |
202+
| 5 minutes | i-05e74a812e705a2b4.* | i-05e74a812e705a2b4 | t3.xlarge | us-west-2c | main |
203+
| 5 minutes | i-0d14753576296c6e0.* | i-0d14753576296c6e0 | t3.xlarge | us-west-2a | main |
204+
+-----------+-----------------------+---------------------+-----------+------------+-----------+
189205
* Names end with "us-west-2.compute.internal"
190206
```
191207

pkg/resource/cluster/cluster.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ kubernetesNetworkConfig:
7676
privateCluster:
7777
enabled: true
7878
{{- end }}
79+
{{- if .KMSKeyArn }}
80+
81+
secretsEncryption:
82+
keyARN: {{ .KMSKeyArn }}
83+
{{- end }}
7984
8085
vpc:
8186
cidr: {{ .VpcCidr }}

pkg/resource/cluster/options.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/awslabs/eksdemo/pkg/resource"
1919
"github.com/awslabs/eksdemo/pkg/resource/cloudformation_stack"
2020
"github.com/awslabs/eksdemo/pkg/resource/irsa"
21+
"github.com/awslabs/eksdemo/pkg/resource/kms/key"
2122
"github.com/awslabs/eksdemo/pkg/resource/nodegroup"
2223
"github.com/awslabs/eksdemo/pkg/template"
2324
"github.com/spf13/cobra"
@@ -32,6 +33,8 @@ type ClusterOptions struct {
3233
Fargate bool
3334
HostnameType string
3435
IPv6 bool
36+
KMSKeyAlias string
37+
KMSKeyArn string
3538
Kubeconfig string
3639
NoRoles bool
3740
PrefixAssignment bool
@@ -99,6 +102,24 @@ func addOptions(res *resource.Resource) *resource.Resource {
99102
},
100103
Option: &options.DisableNetworkPolicy,
101104
},
105+
&cmd.StringFlag{
106+
CommandFlag: cmd.CommandFlag{
107+
Name: "encrypt-secrets",
108+
Description: "alias of KMS key to encrypt secrets",
109+
Validate: func(_ *cobra.Command, _ []string) error {
110+
if options.KMSKeyAlias == "" {
111+
return nil
112+
}
113+
key, err := key.NewGetter(aws.NewKMSClient()).GetByAlias(options.KMSKeyAlias)
114+
if err != nil {
115+
return err
116+
}
117+
options.KMSKeyArn = awssdk.ToString(key.Key.Arn)
118+
return nil
119+
},
120+
},
121+
Option: &options.KMSKeyAlias,
122+
},
102123
&cmd.BoolFlag{
103124
CommandFlag: cmd.CommandFlag{
104125
Name: "fargate",
@@ -126,7 +147,7 @@ func addOptions(res *resource.Resource) *resource.Resource {
126147
CommandFlag: cmd.CommandFlag{
127148
Name: "kubeconfig",
128149
Description: "path to write kubeconfig",
129-
Validate: func(cmd *cobra.Command, args []string) error {
150+
Validate: func(_ *cobra.Command, _ []string) error {
130151
// Set the KUBECONFIG environment variable to configure eksctl
131152
_ = os.Setenv("KUBECONFIG", options.Kubeconfig)
132153
return nil
@@ -172,7 +193,7 @@ func addOptions(res *resource.Resource) *resource.Resource {
172193
&cmd.StringSliceFlag{
173194
CommandFlag: cmd.CommandFlag{
174195
Name: "zones",
175-
Description: "Specify comma delimited AZs to use. ie. us-east-1a,us-east-1b,us-east-1c",
196+
Description: "list of AZs to use. ie. us-east-1a,us-east-1b,us-east-1c",
176197
},
177198
Option: &options.Zones,
178199
},

0 commit comments

Comments
 (0)