Skip to content

Commit 87229f3

Browse files
Adding an eks module on which knot can be deployed along with instuctions on how to deploy it
1 parent 8101a52 commit 87229f3

File tree

19 files changed

+693
-0
lines changed

19 files changed

+693
-0
lines changed

eks/.terraform.lock.hcl

Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eks/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
How to run knot on aws:
2+
- cd into 'eks' folder
3+
- run 'terraform apply' to create the eks cluster
4+
- run 'aws eks --region us-east-1 update-kubeconfig --name tf-cluster' in order to connect onto the remote cluster and be able to run commands on it
5+
- (optional) run 'kubectl get pods -A' to make sure that connected onto the cluster
6+
- export the KNOT_HOST envirometal as descibed in knot readme ($env:KNOT_HOST="mydns" in windows)
7+
- cd back onto the folder with knot helmfile
8+
- run 'helmfile sync --concurrency 1' to deploy knot onto the cluster
9+
-after running the helmfile make sure that knot ingress is up
10+
- goto aws route53 console and connect knot ingress to your dns
11+
- *at the bottom of this read me you'll find details on how to do this*
12+
- wait for you dns to propagate and after a while you should be able to see knot be pinging you dns
13+
14+
15+
*Creating the route53 records
16+
As an example I'm using the custon dns "boiboiapp.com"
17+
- Create a route53 hosted zone on aws
18+
- Create records of said route53 in which
19+
- record type = A
20+
- alias = on
21+
- type = Alias to Network Load Balancer
22+
- area = US East (N. Virginia)
23+
- Record name = *.boiboiapp.com/boiboiapp.com (create on record for each)
24+
![alt text](image.png)

eks/assets/EKS-With-Terraform.png

50.1 KB
Loading

eks/backend.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# terraform {
2+
# required_version = ">=0.12.0"
3+
# backend "s3" {
4+
# region = "us-east-1"
5+
# profile = "default"
6+
# key = "terraformstatefile"
7+
# bucket = ""
8+
# }
9+
# }

eks/image.png

56.2 KB
Loading

eks/main.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
################################################################################
2+
# VPC Module
3+
################################################################################
4+
5+
module "vpc" {
6+
source = "./modules/vpc"
7+
8+
main-region = var.main-region
9+
profile = var.profile
10+
}
11+
12+
################################################################################
13+
# EKS Cluster Module
14+
################################################################################
15+
16+
module "eks" {
17+
source = "./modules/eks-cluster"
18+
19+
main-region = var.main-region
20+
profile = var.profile
21+
rolearn = var.rolearn
22+
23+
vpc_id = module.vpc.vpc_id
24+
private_subnets = module.vpc.private_subnets
25+
}
26+
27+
################################################################################
28+
# AWS ALB Controller
29+
################################################################################
30+
31+
module "aws_alb_controller" {
32+
source = "./modules/aws-alb-controller"
33+
34+
main-region = var.main-region
35+
env_name = var.env_name
36+
cluster_name = var.cluster_name
37+
38+
vpc_id = module.vpc.vpc_id
39+
oidc_provider_arn = module.eks.oidc_provider_arn
40+
}
41+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
################################################################################
2+
# Load Balancer Role
3+
################################################################################
4+
5+
module "lb_role" {
6+
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
7+
8+
role_name = "${var.env_name}_eks_lb"
9+
attach_load_balancer_controller_policy = true
10+
11+
oidc_providers = {
12+
main = {
13+
provider_arn = var.oidc_provider_arn
14+
namespace_service_accounts = ["kube-system:aws-load-balancer-controller"]
15+
}
16+
}
17+
}
18+
19+
################################################################################
20+
# Aws Load balancer Controller Service Account
21+
################################################################################
22+
23+
resource "kubernetes_service_account" "service-account" {
24+
metadata {
25+
name = "aws-load-balancer-controller"
26+
namespace = "kube-system"
27+
labels = {
28+
"app.kubernetes.io/name" = "aws-load-balancer-controller"
29+
"app.kubernetes.io/component" = "controller"
30+
}
31+
annotations = {
32+
"eks.amazonaws.com/role-arn" = module.lb_role.iam_role_arn
33+
"eks.amazonaws.com/sts-regional-endpoints" = "true"
34+
}
35+
}
36+
}
37+
38+
################################################################################
39+
# Install Load Balancer Controler With Helm
40+
################################################################################
41+
42+
resource "helm_release" "lb" {
43+
name = "aws-load-balancer-controller"
44+
repository = "https://aws.github.io/eks-charts"
45+
chart = "aws-load-balancer-controller"
46+
namespace = "kube-system"
47+
depends_on = [
48+
kubernetes_service_account.service-account
49+
]
50+
51+
set {
52+
name = "region"
53+
value = var.main-region
54+
}
55+
56+
set {
57+
name = "vpcId"
58+
value = var.vpc_id
59+
}
60+
61+
set {
62+
name = "image.repository"
63+
value = "602401143452.dkr.ecr.${var.main-region}.amazonaws.com/amazon/aws-load-balancer-controller"
64+
}
65+
66+
set {
67+
name = "serviceAccount.create"
68+
value = "false"
69+
}
70+
71+
set {
72+
name = "serviceAccount.name"
73+
value = "aws-load-balancer-controller"
74+
}
75+
76+
set {
77+
name = "clusterName"
78+
value = var.cluster_name
79+
}
80+
}
81+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
################################################################################
2+
# General Variables from root module
3+
################################################################################
4+
5+
variable "main-region" {
6+
type = string
7+
}
8+
9+
variable "env_name" {
10+
type = string
11+
}
12+
13+
variable "cluster_name" {
14+
type = string
15+
}
16+
17+
################################################################################
18+
# Variables from other Modules
19+
################################################################################
20+
21+
variable "vpc_id" {
22+
description = "VPC ID which Load balancers will be deployed in"
23+
type = string
24+
}
25+
26+
variable "oidc_provider_arn" {
27+
description = "OIDC Provider ARN used for IRSA "
28+
type = string
29+
}

eks/modules/eks-cluster/main.tf

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
################################################################################
2+
# EKS Cluster
3+
################################################################################
4+
5+
module "eks" {
6+
source = "terraform-aws-modules/eks/aws"
7+
version = "~> 19.0"
8+
9+
cluster_name = "tf-cluster"
10+
cluster_version = "1.27"
11+
12+
providers = {
13+
aws = aws.us-east-1
14+
}
15+
16+
cluster_endpoint_public_access = true
17+
18+
create_kms_key = false
19+
create_cloudwatch_log_group = false
20+
cluster_encryption_config = {}
21+
22+
cluster_addons = {
23+
coredns = {
24+
most_recent = true
25+
}
26+
kube-proxy = {
27+
most_recent = true
28+
}
29+
vpc-cni = {
30+
most_recent = true
31+
}
32+
aws-ebs-csi-driver = {
33+
most_recent = true
34+
}
35+
}
36+
37+
vpc_id = var.vpc_id
38+
subnet_ids = var.private_subnets
39+
control_plane_subnet_ids = var.private_subnets
40+
41+
# EKS Managed Node Group(s)
42+
eks_managed_node_group_defaults = {
43+
instance_types = ["m5.xlarge", "m5.large", "t3.medium"]
44+
iam_role_additional_policies = {
45+
AmazonEBSCSIDriverPolicy = "arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy"
46+
}
47+
}
48+
49+
eks_managed_node_groups = {
50+
blue = {
51+
min_size = 1
52+
max_size = 10
53+
desired_size = 3
54+
}
55+
green = {
56+
min_size = 1
57+
max_size = 10
58+
desired_size = 3
59+
60+
instance_types = ["t3.medium"]
61+
capacity_type = "ON_DEMAND"
62+
}
63+
}
64+
65+
# aws-auth configmap
66+
# manage_aws_auth_configmap = true
67+
#create_aws_auth_configmap = true
68+
69+
aws_auth_roles = [
70+
{
71+
rolearn = var.rolearn
72+
username = "skanyi"
73+
groups = ["system:masters"]
74+
},
75+
]
76+
77+
tags = {
78+
env = "dev"
79+
terraform = "true"
80+
}
81+
}
82+

0 commit comments

Comments
 (0)