Skip to content

Commit 70f6150

Browse files
authored
docs: Add Bottlerocket example (#1296)
Signed-off-by: Andrey Devyatkin <[email protected]>
1 parent 06e9078 commit 70f6150

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

examples/bottlerocket/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# AWS Bottlerocket based nodes
2+
3+
This is a minimalistic example that shows how to use functionality of this module to deploy
4+
nodes based on [AWS Bottlerocket container OS](https://github.com/bottlerocket-os/bottlerocket)
5+
6+
Example is minimalistic by purpose - it shows what knobs to turn to make Bottlerocket work.
7+
Do not use default VPC for your workloads deployment.

examples/bottlerocket/data.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
data "aws_ami" "bottlerocket_ami" {
2+
most_recent = true
3+
owners = ["amazon"]
4+
filter {
5+
name = "name"
6+
values = ["bottlerocket-aws-k8s-${var.k8s_version}-x86_64-*"]
7+
}
8+
}
9+
10+
data "aws_region" "current" {}
11+
12+
data "aws_vpc" "default" {
13+
default = true
14+
}
15+
16+
data "aws_subnet_ids" "default" {
17+
vpc_id = data.aws_vpc.default.id
18+
}
19+
20+
data "aws_iam_policy" "ssm" {
21+
arn = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
22+
}

examples/bottlerocket/main.tf

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
terraform {
2+
required_version = ">= 0.13.0"
3+
}
4+
5+
resource "tls_private_key" "nodes" {
6+
algorithm = "RSA"
7+
}
8+
9+
resource "aws_key_pair" "nodes" {
10+
key_name = "bottlerocket-nodes"
11+
public_key = tls_private_key.nodes.public_key_openssh
12+
}
13+
14+
module "eks" {
15+
source = "../.."
16+
cluster_name = "bottlerocket"
17+
cluster_version = var.k8s_version
18+
subnets = data.aws_subnet_ids.default.ids
19+
20+
vpc_id = data.aws_vpc.default.id
21+
22+
write_kubeconfig = false
23+
manage_aws_auth = false
24+
25+
worker_groups_launch_template = [
26+
{
27+
name = "bottlerocket-nodes"
28+
# passing bottlerocket ami id
29+
ami_id = data.aws_ami.bottlerocket_ami.id
30+
instance_type = "t3a.small"
31+
asg_desired_capacity = 2
32+
key_name = aws_key_pair.nodes.key_name
33+
34+
# Since we are using default VPC there is no NAT gateway so we need to
35+
# attach public ip to nodes so they can reach k8s API server
36+
# do not repeat this at home (i.e. production)
37+
public_ip = true
38+
39+
# This section overrides default userdata template to pass bottlerocket
40+
# specific user data
41+
userdata_template_file = "${path.module}/userdata.toml"
42+
# we are using this section to pass additional arguments for
43+
# userdata template rendering
44+
userdata_template_extra_args = {
45+
enable_admin_container = var.enable_admin_container
46+
enable_control_container = var.enable_control_container
47+
aws_region = data.aws_region.current.name
48+
}
49+
# example of k8s/kubelet configuration via additional_userdata
50+
additional_userdata = <<EOT
51+
[settings.kubernetes.node-labels]
52+
ingress = "allowed"
53+
EOT
54+
}
55+
]
56+
}
57+
58+
# SSM policy for bottlerocket control container access
59+
# https://github.com/bottlerocket-os/bottlerocket/blob/develop/QUICKSTART-EKS.md#enabling-ssm
60+
resource "aws_iam_policy_attachment" "ssm" {
61+
name = "ssm"
62+
roles = [module.eks.worker_iam_role_name]
63+
policy_arn = data.aws_iam_policy.ssm.arn
64+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://github.com/bottlerocket-os/bottlerocket/blob/develop/README.md#description-of-settings
2+
[settings.kubernetes]
3+
api-server = "${endpoint}"
4+
cluster-certificate = "${cluster_auth_base64}"
5+
cluster-name = "${cluster_name}"
6+
${additional_userdata}
7+
8+
# Hardening based on https://github.com/bottlerocket-os/bottlerocket/blob/develop/SECURITY_GUIDANCE.md
9+
10+
# Enable kernel lockdown in "integrity" mode.
11+
# This prevents modifications to the running kernel, even by privileged users.
12+
[settings.kernel]
13+
lockdown = "integrity"
14+
15+
# The admin host container provides SSH access and runs with "superpowers".
16+
# It is disabled by default, but can be disabled explicitly.
17+
[settings.host-containers.admin]
18+
enabled = ${enable_admin_container}
19+
20+
# The control host container provides out-of-band access via SSM.
21+
# It is enabled by default, and can be disabled if you do not expect to use SSM.
22+
# This could leave you with no way to access the API and change settings on an existing node!
23+
[settings.host-containers.control]
24+
enabled = ${enable_control_container}

examples/bottlerocket/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
variable "k8s_version" {
2+
description = "k8s cluster version"
3+
default = "1.20"
4+
type = string
5+
}
6+
7+
variable "enable_admin_container" {
8+
description = "Enable/disable admin container"
9+
default = false
10+
type = bool
11+
}
12+
13+
variable "enable_control_container" {
14+
description = "Enable/disable control container"
15+
default = true
16+
type = bool
17+
}

0 commit comments

Comments
 (0)