Skip to content

Commit ea1b60d

Browse files
committed
deployed it on eks
1 parent 8e95ce5 commit ea1b60d

File tree

7 files changed

+227
-227
lines changed

7 files changed

+227
-227
lines changed

.DS_Store

2 KB
Binary file not shown.

.github/workflows/build.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Node.js App Deploy to EKS
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Source
13+
uses: actions/checkout@v4
14+
15+
- name: Login to Docker Hub
16+
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
17+
18+
- name: Build Docker image
19+
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/node-app:latest .
20+
21+
- name: Push Image to Docker Hub
22+
run: docker push ${{ secrets.DOCKER_USERNAME }}/node-app:latest
23+
24+
deploy:
25+
runs-on: ubuntu-latest
26+
needs: build
27+
steps:
28+
- name: Checkout Code
29+
uses: actions/checkout@v2
30+
31+
- name: Configure AWS credentials
32+
uses: aws-actions/configure-aws-credentials@v1
33+
with:
34+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
35+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
36+
aws-region: us-east-1
37+
38+
- name: Install kubectl
39+
uses: actions/install-kubectl@v3
40+
with:
41+
version: 'v1.22.0'
42+
43+
- name: Install Helm
44+
run: |
45+
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
46+
47+
- name: Update kubeconfig for EKS
48+
run: |
49+
aws eks update-kubeconfig --region us-east-1 --name node-app
50+
51+
- name: Deploy to EKS with Helm
52+
run: |
53+
helm upgrade --install node-app ./node-app --set image.repository=${{ secrets.DOCKER_USERNAME }}/node-app --set image.tag=latest
54+

terraform/.terraform.lock.hcl

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

terraform/main.tf

Lines changed: 28 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,31 @@
1-
# VPC Steup
2-
resource "aws_vpc" "vpc_node" {
3-
cidr_block = var.vpc_cidr
4-
tags = {
5-
Name = "Kubernetes-VPC"
6-
}
7-
}
8-
9-
resource "aws_internet_gateway" "igw" {
10-
vpc_id = aws_vpc.vpc_node.id
11-
tags = {
12-
Name = "IGW"
13-
}
14-
}
15-
16-
resource "aws_subnet" "sub_public" {
17-
vpc_id = aws_vpc.vpc_node.id
18-
cidr_block = var.public_subnet_cidr
19-
availability_zone = var.availability_zone
20-
map_public_ip_on_launch = true
21-
tags = {
22-
Name = "Public Subnet 1"
23-
}
24-
}
25-
26-
resource "aws_subnet" "sub_private" {
27-
vpc_id = aws_vpc.vpc_node.id
28-
cidr_block = var.private_subnet_cidr
29-
availability_zone = var.availability_zone
30-
map_public_ip_on_launch = false
31-
tags = {
32-
Name = "Private Subnet 1"
33-
}
34-
}
35-
36-
resource "aws_eip" "lb" {
37-
domain = "vpc"
38-
}
39-
40-
resource "aws_nat_gateway" "ng" {
41-
allocation_id = aws_eip.lb.id
42-
subnet_id = aws_subnet.sub_public.id
43-
44-
tags = {
45-
Name = "gw NAT"
46-
}
47-
}
48-
49-
50-
resource "aws_route_table" "rt_public" {
51-
vpc_id = aws_vpc.vpc_node.id
52-
route {
53-
cidr_block = var.rt_cidr
54-
gateway_id = aws_internet_gateway.igw.id
55-
}
56-
tags = {
57-
Name = "RT_PUBLIC"
58-
}
59-
}
60-
61-
resource "aws_route_table" "rt_private" {
62-
vpc_id = aws_vpc.vpc_node.id
63-
route {
64-
cidr_block = var.rt_cidr
65-
nat_gateway_id = aws_nat_gateway.ng.id
66-
}
67-
tags = {
68-
Name = "RT_PRIVATE"
69-
}
70-
}
71-
72-
resource "aws_route_table_association" "rta_public" {
73-
subnet_id = aws_subnet.sub_public.id
74-
route_table_id = aws_route_table.rt_public.id
75-
}
76-
77-
resource "aws_route_table_association" "rta_private" {
78-
subnet_id = aws_subnet.sub_private.id
79-
route_table_id = aws_route_table.rt_private.id
80-
}
81-
82-
resource "aws_security_group" "aws_sg_master" {
83-
name = "k8s-master-sg"
84-
description = "Security group for Kubernetes master node"
85-
vpc_id = aws_vpc.vpc_node.id
86-
87-
}
88-
89-
resource "aws_vpc_security_group_ingress_rule" "master_ingress_https" {
90-
security_group_id = aws_security_group.aws_sg_master.id
91-
cidr_ipv4 = aws_vpc.vpc_node.cidr_block
92-
from_port = 22
93-
ip_protocol = "tcp"
94-
to_port = 22
95-
}
96-
97-
resource "aws_vpc_security_group_ingress_rule" "master_ingress_k8s" {
98-
security_group_id = aws_security_group.aws_sg_master.id
99-
cidr_ipv4 = aws_vpc.vpc_node.cidr_block
100-
from_port = 6443
101-
ip_protocol = "tcp"
102-
to_port = 6443
103-
}
104-
105-
resource "aws_vpc_security_group_egress_rule" "master_egress" {
106-
security_group_id = aws_security_group.aws_sg_master.id
107-
cidr_ipv4 = "0.0.0.0/0"
108-
ip_protocol = "-1"
109-
}
110-
111-
resource "aws_security_group" "aws_sg_worker" {
112-
name = "k8s-worker-sg"
113-
description = "Security group for Kubernetes worker node"
114-
vpc_id = aws_vpc.vpc_node.id
1+
module "vpc" {
2+
source = "terraform-aws-modules/vpc/aws"
3+
version = "~> 5.0"
4+
name = "eks-vpc"
5+
cidr = var.vpc_cidr
6+
azs = ["${var.region}a", "${var.region}b"]
7+
private_subnets = var.private_subnets_cidr
8+
public_subnets = var.public_subnets_cidr
9+
enable_nat_gateway = true
10+
}
11+
12+
module "eks" {
13+
source = "terraform-aws-modules/eks/aws"
14+
version = "~> 19.0"
15+
cluster_name = var.cluster_name
16+
cluster_version = "1.27"
17+
vpc_id = module.vpc.vpc_id
18+
subnet_ids = module.vpc.private_subnets
19+
cluster_endpoint_public_access = true
20+
cluster_endpoint_private_access = true
11521

116-
}
117-
118-
resource "aws_vpc_security_group_ingress_rule" "worker_ingress_https" {
119-
security_group_id = aws_security_group.aws_sg_worker.id
120-
cidr_ipv4 = aws_vpc.vpc_node.cidr_block
121-
from_port = 22
122-
ip_protocol = "tcp"
123-
to_port = 22
124-
}
125-
126-
resource "aws_vpc_security_group_ingress_rule" "worker_ingress_k8s" {
127-
security_group_id = aws_security_group.aws_sg_worker.id
128-
cidr_ipv4 = aws_vpc.vpc_node.cidr_block
129-
from_port = 6443
130-
ip_protocol = "tcp"
131-
to_port = 6443
132-
}
133-
134-
resource "aws_vpc_security_group_egress_rule" "worker_egress" {
135-
security_group_id = aws_security_group.aws_sg_worker.id
136-
cidr_ipv4 = "0.0.0.0/0"
137-
ip_protocol = "-1"
138-
}
139-
140-
# EC2 Instances for Master and Worker Node
141-
142-
resource "aws_instance" "master" {
143-
ami = var.ami_id
144-
instance_type = "t3.medium"
145-
key_name = var.key_name
146-
security_groups = [aws_security_group.aws_sg_master.id]
147-
subnet_id = aws_subnet.sub_public.id
148-
149-
tags = {
150-
Name = "K8s Master"
151-
}
152-
}
153-
154-
resource "aws_instance" "worker" {
155-
count = var.worker_count
156-
ami = var.ami_id
157-
instance_type = "t3.small"
158-
key_name = var.key_name
159-
security_groups = [aws_security_group.aws_sg_worker.id]
160-
subnet_id = aws_subnet.sub_private.id
161-
162-
tags = {
163-
Name = "K8s Worker ${count.index + 1}"
22+
eks_managed_node_groups = {
23+
spot = {
24+
min_size = 0
25+
max_size = 5
26+
desired_size = 1
27+
instance_types = ["t3.small", "t3.medium"]
28+
capacity_type = "SPOT"
29+
}
16430
}
16531
}

0 commit comments

Comments
 (0)