Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an eks module on which knot can be deployed along with instuct… #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions eks/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions eks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Deploy on EKS with Terraform

How to run Knot on AWS's EKS with [Terraform](https://www.terraform.io):
```bash
terraform apply # Create the EKS cluster
aws eks --region us-east-1 update-kubeconfig --name tf-cluster # Connect to it
```

You should now be able to run `kubectl get pods -A` and see the cluster's pods with no errors.

Install Knot:
```bash
export KNOT_HOST=example.com # $env:KNOT_HOST="example.com" in Windows
helmfile -f git::https://github.com/CARV-ICS-FORTH/[email protected] sync --concurrency 1
```

Now you need to go to Route53's console, create a hosted zone for your DNS name and two records that point to Knot's ingress: `example.com` and `*.example.com`.

The screenshot below shows an example DNS entry.

![Example Route53 DNS entry](assets/example-dns.png)

For each record, make sure that:
- Record type is `A`.
- Alias is on.
- Type is `Alias to Network Load Balancer`.
- Area is `US East (N. Virginia)` (or your preferred region).
- You select Knot's ingress service.

Now wait for the DNS settings to propagate. After a while you should be able to visit Knot in your browser.
Binary file added eks/assets/example-dns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions eks/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# terraform {
# required_version = ">=0.12.0"
# backend "s3" {
# region = "us-east-1"
# profile = "default"
# key = "terraformstatefile"
# bucket = ""
# }
# }
41 changes: 41 additions & 0 deletions eks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
################################################################################
# VPC Module
################################################################################

module "vpc" {
source = "./modules/vpc"

main-region = var.main-region
profile = var.profile
}

################################################################################
# EKS Cluster Module
################################################################################

module "eks" {
source = "./modules/eks-cluster"

main-region = var.main-region
profile = var.profile
rolearn = var.rolearn

vpc_id = module.vpc.vpc_id
private_subnets = module.vpc.private_subnets
}

################################################################################
# AWS ALB Controller
################################################################################

module "aws_alb_controller" {
source = "./modules/aws-alb-controller"

main-region = var.main-region
env_name = var.env_name
cluster_name = var.cluster_name

vpc_id = module.vpc.vpc_id
oidc_provider_arn = module.eks.oidc_provider_arn
}

81 changes: 81 additions & 0 deletions eks/modules/aws-alb-controller/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
################################################################################
# Load Balancer Role
################################################################################

module "lb_role" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"

role_name = "${var.env_name}_eks_lb"
attach_load_balancer_controller_policy = true

oidc_providers = {
main = {
provider_arn = var.oidc_provider_arn
namespace_service_accounts = ["kube-system:aws-load-balancer-controller"]
}
}
}

################################################################################
# Aws Load balancer Controller Service Account
################################################################################

resource "kubernetes_service_account" "service-account" {
metadata {
name = "aws-load-balancer-controller"
namespace = "kube-system"
labels = {
"app.kubernetes.io/name" = "aws-load-balancer-controller"
"app.kubernetes.io/component" = "controller"
}
annotations = {
"eks.amazonaws.com/role-arn" = module.lb_role.iam_role_arn
"eks.amazonaws.com/sts-regional-endpoints" = "true"
}
}
}

################################################################################
# Install Load Balancer Controler With Helm
################################################################################

resource "helm_release" "lb" {
name = "aws-load-balancer-controller"
repository = "https://aws.github.io/eks-charts"
chart = "aws-load-balancer-controller"
namespace = "kube-system"
depends_on = [
kubernetes_service_account.service-account
]

set {
name = "region"
value = var.main-region
}

set {
name = "vpcId"
value = var.vpc_id
}

set {
name = "image.repository"
value = "602401143452.dkr.ecr.${var.main-region}.amazonaws.com/amazon/aws-load-balancer-controller"
}

set {
name = "serviceAccount.create"
value = "false"
}

set {
name = "serviceAccount.name"
value = "aws-load-balancer-controller"
}

set {
name = "clusterName"
value = var.cluster_name
}
}

29 changes: 29 additions & 0 deletions eks/modules/aws-alb-controller/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
################################################################################
# General Variables from root module
################################################################################

variable "main-region" {
type = string
}

variable "env_name" {
type = string
}

variable "cluster_name" {
type = string
}

################################################################################
# Variables from other Modules
################################################################################

variable "vpc_id" {
description = "VPC ID which Load balancers will be deployed in"
type = string
}

variable "oidc_provider_arn" {
description = "OIDC Provider ARN used for IRSA "
type = string
}
Loading