Skip to content

Commit 2354450

Browse files
authored
How to create EKS Cluster using Terraform MODULES (antonputra#95)
1 parent 39c0b9f commit 2354450

15 files changed

+720
-26
lines changed

docs/contents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@
5656
- [122 - How to send AWS CloudWatch Alarms to Slack?](../lessons/122)
5757
- [123 - Creating a Linux service with systemd](../lessons/123)
5858
- [124 - AWS Lambda Go vs. Node.js performance benchmark](../lessons/124)
59+
- [125 - How to create EKS Cluster using Terraform MODULES?](../lessons/125)

lessons/124/terraform/4-nodejs-lambda.tf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ POLICY
1818
}
1919

2020
resource "aws_iam_policy" "nodejs_s3_bucket_access" {
21-
name = "NodejsS3BucketAccess"
21+
name = "NodejsS3BucketAccess"
2222

2323
policy = jsonencode({
2424
Version = "2012-10-17"
@@ -35,23 +35,23 @@ resource "aws_iam_policy" "nodejs_s3_bucket_access" {
3535
}
3636

3737
resource "aws_iam_policy" "nodejs_dynamodb_access" {
38-
name = "NodejsDynamoDBAccess"
38+
name = "NodejsDynamoDBAccess"
3939

4040
policy = jsonencode({
4141
Version = "2012-10-17"
4242
Statement = [
4343
{
4444
Action = [
45-
"dynamodb:GetItem",
46-
"dynamodb:DeleteItem",
47-
"dynamodb:PutItem",
48-
"dynamodb:Scan",
49-
"dynamodb:Query",
50-
"dynamodb:UpdateItem",
51-
"dynamodb:BatchWriteItem",
52-
"dynamodb:BatchGetItem",
53-
"dynamodb:DescribeTable",
54-
"dynamodb:ConditionCheckItem"
45+
"dynamodb:GetItem",
46+
"dynamodb:DeleteItem",
47+
"dynamodb:PutItem",
48+
"dynamodb:Scan",
49+
"dynamodb:Query",
50+
"dynamodb:UpdateItem",
51+
"dynamodb:BatchWriteItem",
52+
"dynamodb:BatchGetItem",
53+
"dynamodb:DescribeTable",
54+
"dynamodb:ConditionCheckItem"
5555
]
5656
Effect = "Allow"
5757
Resource = "arn:aws:dynamodb:*:*:table/Meta"
@@ -83,7 +83,7 @@ resource "aws_lambda_function" "nodejs" {
8383

8484
environment {
8585
variables = {
86-
BUCKET_NAME = aws_s3_bucket.images_bucket.id
86+
BUCKET_NAME = aws_s3_bucket.images_bucket.id
8787
}
8888
}
8989

lessons/124/terraform/5-go-lambda.tf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ POLICY
1818
}
1919

2020
resource "aws_iam_policy" "go_s3_bucket_access" {
21-
name = "goS3BucketAccess"
21+
name = "goS3BucketAccess"
2222

2323
policy = jsonencode({
2424
Version = "2012-10-17"
@@ -35,23 +35,23 @@ resource "aws_iam_policy" "go_s3_bucket_access" {
3535
}
3636

3737
resource "aws_iam_policy" "go_dynamodb_access" {
38-
name = "goDynamoDBAccess"
38+
name = "goDynamoDBAccess"
3939

4040
policy = jsonencode({
4141
Version = "2012-10-17"
4242
Statement = [
4343
{
4444
Action = [
45-
"dynamodb:GetItem",
46-
"dynamodb:DeleteItem",
47-
"dynamodb:PutItem",
48-
"dynamodb:Scan",
49-
"dynamodb:Query",
50-
"dynamodb:UpdateItem",
51-
"dynamodb:BatchWriteItem",
52-
"dynamodb:BatchGetItem",
53-
"dynamodb:DescribeTable",
54-
"dynamodb:ConditionCheckItem"
45+
"dynamodb:GetItem",
46+
"dynamodb:DeleteItem",
47+
"dynamodb:PutItem",
48+
"dynamodb:Scan",
49+
"dynamodb:Query",
50+
"dynamodb:UpdateItem",
51+
"dynamodb:BatchWriteItem",
52+
"dynamodb:BatchGetItem",
53+
"dynamodb:DescribeTable",
54+
"dynamodb:ConditionCheckItem"
5555
]
5656
Effect = "Allow"
5757
Resource = "arn:aws:dynamodb:*:*:table/Meta"
@@ -83,7 +83,7 @@ resource "aws_lambda_function" "go" {
8383

8484
environment {
8585
variables = {
86-
BUCKET_NAME = aws_s3_bucket.images_bucket.id
86+
BUCKET_NAME = aws_s3_bucket.images_bucket.id
8787
}
8888
}
8989

lessons/125/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# How to create EKS Cluster using Terraform MODULES (AWS Load Balancer Controller + Autoscaler + IRSA)
2+
3+
You can find tutorial [here](https://antonputra.com/amazon/create-eks-cluster-using-terraform-modules/).

lessons/125/k8s/echoserver.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: echoserver
6+
namespace: default
7+
spec:
8+
selector:
9+
matchLabels:
10+
app: echoserver
11+
replicas: 1
12+
template:
13+
metadata:
14+
labels:
15+
app: echoserver
16+
spec:
17+
containers:
18+
- image: k8s.gcr.io/e2e-test-images/echoserver:2.5
19+
name: echoserver
20+
ports:
21+
- containerPort: 8080
22+
---
23+
apiVersion: v1
24+
kind: Service
25+
metadata:
26+
name: echoserver
27+
namespace: default
28+
spec:
29+
ports:
30+
- port: 8080
31+
protocol: TCP
32+
type: ClusterIP
33+
selector:
34+
app: echoserver
35+
---
36+
apiVersion: networking.k8s.io/v1
37+
kind: Ingress
38+
metadata:
39+
name: echoserver
40+
namespace: default
41+
annotations:
42+
alb.ingress.kubernetes.io/scheme: internet-facing
43+
alb.ingress.kubernetes.io/target-type: ip
44+
spec:
45+
ingressClassName: alb
46+
rules:
47+
- host: echo.devopsbyexample.io
48+
http:
49+
paths:
50+
- path: /
51+
pathType: Exact
52+
backend:
53+
service:
54+
name: echoserver
55+
port:
56+
number: 8080

lessons/125/k8s/nginx.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: nginx-deployment
6+
spec:
7+
replicas: 4
8+
selector:
9+
matchLabels:
10+
app: nginx
11+
template:
12+
metadata:
13+
labels:
14+
app: nginx
15+
spec:
16+
containers:
17+
- name: nginx
18+
image: nginx:1.14.2
19+
resources:
20+
requests:
21+
cpu: "1"

lessons/125/terraform/.terraform.lock.hcl

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
provider "aws" {
2+
region = "us-east-1"
3+
}
4+
5+
terraform {
6+
required_providers {
7+
kubectl = {
8+
source = "gavinbunney/kubectl"
9+
version = ">= 1.14.0"
10+
}
11+
helm = {
12+
source = "hashicorp/helm"
13+
version = ">= 2.6.0"
14+
}
15+
}
16+
17+
required_version = "~> 1.0"
18+
}

lessons/125/terraform/1-vpc.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module "vpc" {
2+
source = "terraform-aws-modules/vpc/aws"
3+
version = "3.14.3"
4+
5+
name = "main"
6+
cidr = "10.0.0.0/16"
7+
8+
azs = ["us-east-1a", "us-east-1b"]
9+
private_subnets = ["10.0.0.0/19", "10.0.32.0/19"]
10+
public_subnets = ["10.0.64.0/19", "10.0.96.0/19"]
11+
12+
public_subnet_tags = {
13+
"kubernetes.io/role/elb" = "1"
14+
}
15+
private_subnet_tags = {
16+
"kubernetes.io/role/internal-elb" = "1"
17+
}
18+
19+
enable_nat_gateway = true
20+
single_nat_gateway = true
21+
one_nat_gateway_per_az = false
22+
23+
enable_dns_hostnames = true
24+
enable_dns_support = true
25+
26+
tags = {
27+
Environment = "staging"
28+
}
29+
}

0 commit comments

Comments
 (0)