├── 3-Tier-EKS-Architecture
├── terraform
│ ├── igw.tf
│ ├── backend.tf
│ ├── provider.tf
│ ├── helm-provider.tf
│ ├── autoscaler-iam.tf
│ ├── vpc.tf
│ ├── variable.tf
│ ├── eks.tf
│ ├── helm-lb.tf
│ ├── monitorng.tf
│ ├── iam.tf
│ └── autoscaler-manifests.tf
├── app
│ ├── frontend
│ │ ├── public
│ │ │ ├── robots.txt
│ │ │ ├── favicon.ico
│ │ │ ├── logo192.png
│ │ │ ├── logo512.png
│ │ │ ├── manifest.json
│ │ │ └── index.html
│ │ ├── src
│ │ │ ├── index.js
│ │ │ ├── index.css
│ │ │ ├── services
│ │ │ │ └── taskServices.js
│ │ │ ├── App.css
│ │ │ ├── Tasks.js
│ │ │ └── App.js
│ │ ├── Dockerfile
│ │ └── package.json
│ └── backend
│ │ ├── models
│ │ └── task.js
│ │ ├── package.json
│ │ ├── index.js
│ │ ├── Dockerfile
│ │ ├── db.js
│ │ ├── routes
│ │ └── tasks.js
│ │ └── package-lock.json
├── Manifests
│ ├── mongo
│ │ ├── secrets.yaml
│ │ ├── service.yaml
│ │ └── deploy.yaml
│ ├── backend-service.yaml
│ ├── frontend-service.yaml
│ ├── hpa.yaml
│ ├── job.yaml
│ ├── daemonset.yaml
│ ├── cron.yaml
│ ├── stateful.yaml
│ ├── monitoring-lb.yaml
│ ├── frontend-deployment.yaml
│ ├── full_stack_lb.yaml
│ ├── backend-deployment.yaml
│ └── values.yaml
└── Readme.md
├── 3-Tier-Architecture
├── eip.tf
├── vpc.tf
├── internet-gw.tf
├── variable.tf
├── provider.tf
├── natgw.tf
├── subnet.tf
├── ec2.tf
├── route-tb.tf
├── alb.tf
├── sg.tf
└── Readme.md
├── EKS-Cluster
├── 3-igw.tf
├── 0-locals.tf
├── 13-pod-Identity-addon.tf
├── 2-vpc.tf
├── values
│ ├── metrics-server.yaml
│ └── nginx-ingress.yaml
├── 1-providers.tf
├── 5-nat.tf
├── 19-openid-connect-provider.tf
├── 12-metrics-server.tf
├── 16-nginx-ingress.tf
├── 17-cert-manager.tf
├── 11-helm-provider.tf
├── 9-add-developer-user.tf
├── 7-eks.tf
├── 6-routes.tf
├── 15-aws-lbc.tf
├── 4-subnets.tf
├── 18-ebs-csi-driver.tf
├── 8-nodes.tf
├── 10-add-manager-role.tf
├── 21-secrets-store-csi-driver.tf
├── 14-cluster-autoscaler.tf
├── 20-efs.tf
└── iam
│ └── AWSLoadBalancerController.json
├── 2-Tier-Architecture
├── providers.tf
├── rds.tf
├── ec2.tf
├── Readme.md
└── vpc.tf
├── LICENSE
└── README.md
/3-Tier-EKS-Architecture/terraform/igw.tf:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/eip.tf:
--------------------------------------------------------------------------------
1 | resource "aws_eip" "myeip" {
2 | //instance = aws_instance.web.id
3 | vpc = true
4 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/vpc.tf:
--------------------------------------------------------------------------------
1 | resource "aws_vpc" "main" {
2 | cidr_block = "10.0.0.0/16"
3 |
4 | tags = {
5 | Name = "CustomVPC"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/internet-gw.tf:
--------------------------------------------------------------------------------
1 | resource "aws_internet_gateway" "gw" {
2 | vpc_id = aws_vpc.main.id
3 |
4 | tags = {
5 | Name = "main"
6 | }
7 | }
--------------------------------------------------------------------------------
/EKS-Cluster/3-igw.tf:
--------------------------------------------------------------------------------
1 | resource "aws_internet_gateway" "igw" {
2 | vpc_id = aws_vpc.main.id
3 |
4 | tags = {
5 | Name = "${local.env}-igw"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yashpimple/Terraform-AWS-Architecture/HEAD/3-Tier-EKS-Architecture/app/frontend/public/favicon.ico
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yashpimple/Terraform-AWS-Architecture/HEAD/3-Tier-EKS-Architecture/app/frontend/public/logo192.png
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yashpimple/Terraform-AWS-Architecture/HEAD/3-Tier-EKS-Architecture/app/frontend/public/logo512.png
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/terraform/backend.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | backend "s3" {
3 | bucket = "eks-tfstate-bucket"
4 | key = "eks/terraform.tfstate"
5 | region = "ap-northeast-1"
6 | }
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/EKS-Cluster/0-locals.tf:
--------------------------------------------------------------------------------
1 | locals {
2 | env = "staging"
3 | region = "us-east-2"
4 | zone1 = "us-east-2a"
5 | zone2 = "us-east-2b"
6 | eks_name = "demo"
7 | eks_version = "1.29"
8 | }
9 |
--------------------------------------------------------------------------------
/EKS-Cluster/13-pod-Identity-addon.tf:
--------------------------------------------------------------------------------
1 | resource "aws_eks_addon" "pod_identity" {
2 | cluster_name = aws_eks_cluster.eks.name
3 | addon_name = "eks-pod-identity-agent"
4 | addon_version = "v1.2.0-eksbuild.1"
5 | }
6 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/variable.tf:
--------------------------------------------------------------------------------
1 | variable "cidr" {
2 | type = list
3 | default = ["10.0.1.0/24","10.0.2.0/24"]
4 | }
5 |
6 | variable "az" {
7 | type = list
8 | default = ["ap-northeast-1a","ap-northeast-1c"]
9 | }
10 |
--------------------------------------------------------------------------------
/EKS-Cluster/2-vpc.tf:
--------------------------------------------------------------------------------
1 | resource "aws_vpc" "main" {
2 | cidr_block = "10.0.0.0/16"
3 |
4 | enable_dns_support = true
5 | enable_dns_hostnames = true
6 |
7 | tags = {
8 | Name = "${local.env}-main"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/provider.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_providers {
3 | aws = {
4 | source = "hashicorp/aws"
5 | version = "4.20.1"
6 | }
7 | }
8 | }
9 |
10 | provider "aws" {
11 | region = "ap-south-1"
12 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/mongo/secrets.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Secret
3 | metadata:
4 | namespace: workshop
5 | name: mongo-sec
6 | type: Opaque
7 | data:
8 | password: cGFzc3dvcmQxMjM= #password123
9 | username: YWRtaW4= #admin
--------------------------------------------------------------------------------
/EKS-Cluster/values/metrics-server.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | defaultArgs:
3 | - --cert-dir=/tmp
4 | - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
5 | - --kubelet-use-node-status-port
6 | - --metric-resolution=15s
7 | - --secure-port=10250
8 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/backend-service.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: api
6 | namespace: workshop
7 | spec:
8 | ports:
9 | - port: 8080
10 | protocol: TCP
11 | type: ClusterIP
12 | selector:
13 | role: api
14 |
--------------------------------------------------------------------------------
/EKS-Cluster/1-providers.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = local.region
3 | }
4 |
5 | terraform {
6 | required_version = ">= 1.0"
7 |
8 | required_providers {
9 | aws = {
10 | source = "hashicorp/aws"
11 | version = "~> 5.49"
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/2-Tier-Architecture/providers.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_providers {
3 | aws = {
4 | source = "hashicorp/aws"
5 | version = "~> 4.57.0"
6 | }
7 | }
8 |
9 | required_version = "~> 1.4.6"
10 | }
11 |
12 | provider "aws" {
13 | region = "ap-northeast-1"
14 | }
15 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/frontend-service.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: frontend
6 | namespace: workshop
7 | spec:
8 | ports:
9 | - port: 3000
10 | protocol: TCP
11 | type: ClusterIP
12 | selector:
13 | role: frontend
14 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/mongo/service.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | namespace: workshop
5 | name: mongodb-svc
6 | spec:
7 | selector:
8 | app: mongodb
9 | ports:
10 | - name: mongodb-svc
11 | protocol: TCP
12 | port: 27017
13 | targetPort: 27017
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import "./index.css";
4 | import App from "./App";
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById("root")
11 | );
12 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/hpa.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: autoscaling/v1
3 | kind: HorizontalPodAutoscaler
4 | metadata:
5 | name: api
6 | namespace: shepherd
7 | spec:
8 | minReplicas: 2
9 | maxReplicas: 10
10 | scaleTargetRef:
11 | apiVersion: apps/v1
12 | kind: Deployment
13 | name: api
14 | targetCPUUtilizationPercentage: 50
15 |
--------------------------------------------------------------------------------
/EKS-Cluster/values/nginx-ingress.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | controller:
3 | ingressClassResource:
4 | name: external-nginx
5 | service:
6 | annotations:
7 | service.beta.kubernetes.io/aws-load-balancer-type: external
8 | service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
9 | service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
10 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/natgw.tf:
--------------------------------------------------------------------------------
1 | resource "aws_nat_gateway" "natgw" {
2 | allocation_id = aws_eip.myeip.id
3 | subnet_id = aws_subnet.public[0].id
4 |
5 | tags = {
6 | Name = "gw NAT"
7 | }
8 |
9 | # To ensure proper ordering, it is recommended to add an explicit dependency
10 | # on the Internet Gateway for the VPC.
11 | depends_on = [aws_internet_gateway.gw]
12 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/job.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: batch/v1
2 | kind: Job
3 | metadata:
4 | name: example-job
5 | spec:
6 | template:
7 | metadata:
8 | name: example-pod
9 | spec:
10 | containers:
11 | - name: job-container
12 | image: your-image:tag
13 | command: ["echo", "Hello, Kubernetes Job!"]
14 | restartPolicy: Never
15 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/daemonset.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: DaemonSet
3 | metadata:
4 | name: example-daemonset
5 | spec:
6 | selector:
7 | matchLabels:
8 | app: my-app
9 | template:
10 | metadata:
11 | labels:
12 | app: my-app
13 | spec:
14 | containers:
15 | - name: my-app-container
16 | image: your-image:tag
17 |
--------------------------------------------------------------------------------
/EKS-Cluster/5-nat.tf:
--------------------------------------------------------------------------------
1 | resource "aws_eip" "nat" {
2 | domain = "vpc"
3 |
4 | tags = {
5 | Name = "${local.env}-nat"
6 | }
7 | }
8 |
9 | resource "aws_nat_gateway" "nat" {
10 | allocation_id = aws_eip.nat.id
11 | subnet_id = aws_subnet.public_zone1.id
12 |
13 | tags = {
14 | Name = "${local.env}-nat"
15 | }
16 |
17 | depends_on = [aws_internet_gateway.igw]
18 | }
19 |
--------------------------------------------------------------------------------
/EKS-Cluster/19-openid-connect-provider.tf:
--------------------------------------------------------------------------------
1 | data "tls_certificate" "eks" {
2 | url = aws_eks_cluster.eks.identity[0].oidc[0].issuer
3 | }
4 |
5 | resource "aws_iam_openid_connect_provider" "eks" {
6 | client_id_list = ["sts.amazonaws.com"]
7 | thumbprint_list = [data.tls_certificate.eks.certificates[0].sha1_fingerprint]
8 | url = aws_eks_cluster.eks.identity[0].oidc[0].issuer
9 | }
10 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/backend/models/task.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | const Schema = mongoose.Schema;
3 |
4 | const taskSchema = new Schema({
5 | task: {
6 | type: String,
7 | required: true,
8 | },
9 | completed: {
10 | type: Boolean,
11 | default: false,
12 | },
13 | });
14 |
15 | module.exports = mongoose.model("task", taskSchema);
16 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/terraform/provider.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = var.region
3 | }
4 |
5 | terraform {
6 | required_providers {
7 | kubectl = {
8 | source = "gavinbunney/kubectl"
9 | version = ">= 1.7.0"
10 | }
11 |
12 | helm = {
13 | source = "hashicorp/helm"
14 | version = ">= 2.6.0"
15 | }
16 | }
17 |
18 | required_version = "~> 1.0"
19 | }
--------------------------------------------------------------------------------
/EKS-Cluster/12-metrics-server.tf:
--------------------------------------------------------------------------------
1 | resource "helm_release" "metrics_server" {
2 | name = "metrics-server"
3 |
4 | repository = "https://kubernetes-sigs.github.io/metrics-server/"
5 | chart = "metrics-server"
6 | namespace = "kube-system"
7 | version = "3.12.1"
8 |
9 | values = [file("${path.module}/values/metrics-server.yaml")]
10 |
11 | depends_on = [aws_eks_node_group.general]
12 | }
13 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/backend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "server",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "cors": "^2.8.5",
14 | "express": "^4.17.1",
15 | "mongoose": "^5.12.14"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/EKS-Cluster/16-nginx-ingress.tf:
--------------------------------------------------------------------------------
1 | resource "helm_release" "external_nginx" {
2 | name = "external"
3 |
4 | repository = "https://kubernetes.github.io/ingress-nginx"
5 | chart = "ingress-nginx"
6 | namespace = "ingress"
7 | create_namespace = true
8 | version = "4.10.1"
9 |
10 | values = [file("${path.module}/values/nginx-ingress.yaml")]
11 |
12 | depends_on = [helm_release.aws_lbc]
13 | }
14 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/cron.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: batch/v1beta1
2 | kind: CronJob
3 | metadata:
4 | name: example-cronjob
5 | spec:
6 | schedule: "*/5 * * * *"
7 | jobTemplate:
8 | spec:
9 | template:
10 | spec:
11 | containers:
12 | - name: job-container
13 | image: your-image:tag
14 | command: ["echo", "Hello, Kubernetes CronJob!"]
15 | restartPolicy: OnFailure
16 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/EKS-Cluster/17-cert-manager.tf:
--------------------------------------------------------------------------------
1 | # resource "helm_release" "cert_manager" {
2 | # name = "cert-manager"
3 |
4 | # repository = "https://charts.jetstack.io"
5 | # chart = "cert-manager"
6 | # namespace = "cert-manager"
7 | # create_namespace = true
8 | # version = "v1.14.5"
9 |
10 | # set {
11 | # name = "installCRDs"
12 | # value = "true"
13 | # }
14 |
15 | # depends_on = [helm_release.external_nginx]
16 | # }
17 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/terraform/helm-provider.tf:
--------------------------------------------------------------------------------
1 | provider "helm" {
2 | kubernetes {
3 | host = data.aws_eks_cluster.default.endpoint
4 | cluster_ca_certificate = base64decode(data.aws_eks_cluster.default.certificate_authority[0].data)
5 | exec {
6 | api_version = "client.authentication.k8s.io/v1beta1"
7 | args = ["eks", "get-token", "--cluster-name", data.aws_eks_cluster.default.id]
8 | command = "aws"
9 | }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/EKS-Cluster/11-helm-provider.tf:
--------------------------------------------------------------------------------
1 | data "aws_eks_cluster" "eks" {
2 | name = aws_eks_cluster.eks.name
3 | }
4 |
5 | data "aws_eks_cluster_auth" "eks" {
6 | name = aws_eks_cluster.eks.name
7 | }
8 |
9 | provider "helm" {
10 | kubernetes {
11 | host = data.aws_eks_cluster.eks.endpoint
12 | cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks.certificate_authority[0].data)
13 | token = data.aws_eks_cluster_auth.eks.token
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/backend/index.js:
--------------------------------------------------------------------------------
1 | const tasks = require("./routes/tasks");
2 | const connection = require("./db");
3 | const cors = require("cors");
4 | const express = require("express");
5 | const app = express();
6 |
7 | connection();
8 |
9 | app.use(express.json());
10 | app.use(cors());
11 |
12 | app.get('/ok', (req, res) => {
13 | res.status(200).send('ok')
14 | })
15 |
16 | app.use("/api/tasks", tasks);
17 |
18 | const port = process.env.PORT || 8080;
19 | app.listen(port, () => console.log(`Listening on port ${port}...`));
20 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use the official Node.js 14 image as a base image
2 | FROM node:14
3 |
4 | # Set the working directory in the container
5 | WORKDIR /usr/src/app
6 |
7 | # Copy the package.json and package-lock.json files to the container
8 | COPY package*.json ./
9 |
10 | # Install the application's dependencies inside the container
11 | RUN npm install
12 |
13 | # Copy the rest of the application code to the container
14 | COPY . .
15 |
16 | # Specify the command to run when the container starts
17 | CMD [ "npm", "start" ]
18 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/backend/Dockerfile:
--------------------------------------------------------------------------------
1 | # Use the official Node.js 14 image as a base image
2 | FROM node:14
3 |
4 | # Set the working directory in the container
5 | WORKDIR /usr/src/app
6 |
7 | # Copy the package.json and package-lock.json files to the container
8 | COPY package*.json ./
9 |
10 | # Install the application's dependencies inside the container
11 | RUN npm install
12 |
13 | # Copy the rest of the application code to the container
14 | COPY . .
15 |
16 | # Specify the command to run when the container starts
17 | CMD [ "node", "index.js" ]
18 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/src/services/taskServices.js:
--------------------------------------------------------------------------------
1 | import axios from "axios";
2 | const apiUrl = process.env.REACT_APP_BACKEND_URL //"http://localhost:8080/api/tasks";
3 | console.log(apiUrl)
4 | export function getTasks() {
5 | return axios.get(apiUrl);
6 | }
7 |
8 | export function addTask(task) {
9 | return axios.post(apiUrl, task);
10 | }
11 |
12 | export function updateTask(id, task) {
13 | return axios.put(apiUrl + "/" + id, task);
14 | }
15 |
16 | export function deleteTask(id) {
17 | return axios.delete(apiUrl + "/" + id);
18 | }
19 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/terraform/autoscaler-iam.tf:
--------------------------------------------------------------------------------
1 | module "cluster_autoscaler_irsa_role" {
2 | source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
3 | version = "5.3.1"
4 |
5 | role_name = "cluster-autoscaler"
6 | attach_cluster_autoscaler_policy = true
7 | cluster_autoscaler_cluster_ids = [module.eks.cluster_id]
8 |
9 | oidc_providers = {
10 | ex = {
11 | provider_arn = module.eks.oidc_provider_arn
12 | namespace_service_accounts = ["kube-system:cluster-autoscaler"]
13 | }
14 | }
15 | }
16 |
17 |
18 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/subnet.tf:
--------------------------------------------------------------------------------
1 | resource "aws_subnet" "public" {
2 | vpc_id = aws_vpc.main.id
3 | cidr_block = var.cidr[count.index]
4 | availability_zone = var.az[count.index]
5 | count = 2
6 |
7 | tags = {
8 | Name = "public-sub"
9 | }
10 | }
11 |
12 | resource "aws_subnet" "private" {
13 | vpc_id = aws_vpc.main.id
14 | cidr_block = "10.0.3.0/24"
15 | availability_zone = "ap-northeast-1b"
16 |
17 | tags = {
18 | Name = "private-sub3"
19 | }
20 | }
21 |
22 | data "aws_subnets" "sid" {
23 | filter {
24 | name = "vpc-id"
25 | values = [aws_vpc.main.id]
26 | }
27 |
28 | tags = {
29 | Tier = "Public"
30 | }
31 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/frontend/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | width: 100vw;
3 | height: 100vh;
4 | background: #f5f5f5;
5 | }
6 |
7 | .heading {
8 | font-size: 20px;
9 | font-weight: bold;
10 | text-align: center;
11 | }
12 |
13 | .flex {
14 | display: flex;
15 | justify-content: center;
16 | align-items: center;
17 | }
18 |
19 | .container {
20 | width: 500px;
21 | min-height: 300px;
22 | padding: 10px;
23 | }
24 |
25 | .task_container {
26 | margin: 10px 0;
27 | cursor: pointer;
28 | }
29 |
30 | .task {
31 | flex-grow: 1;
32 | margin-left: 10px;
33 | }
34 |
35 | .line_through {
36 | text-decoration: line-through;
37 | }
38 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/Manifests/stateful.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: StatefulSet
3 | metadata:
4 | name: example-statefulset
5 | spec:
6 | replicas: 3
7 | serviceName: my-stateful-service
8 | selector:
9 | matchLabels:
10 | app: my-app
11 | template:
12 | metadata:
13 | labels:
14 | app: my-app
15 | spec:
16 | containers:
17 | - name: my-app-container
18 | image: your-image:tag
19 | ports:
20 | - containerPort: 80
21 | volumeClaimTemplates:
22 | - metadata:
23 | name: data
24 | spec:
25 | accessModes: [ "ReadWriteOnce" ]
26 | resources:
27 | requests:
28 | storage: 1Gi
29 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/ec2.tf:
--------------------------------------------------------------------------------
1 | resource "aws_instance" "web" {
2 | ami = "ami-0d52744d6551d851e"
3 | instance_type = "t2.micro"
4 | key_name = "mykeypair"
5 | subnet_id = aws_subnet.public[count.index].id
6 | vpc_security_group_ids = [aws_security_group.allow_tls.id]
7 | associate_public_ip_address = true
8 | count = 2
9 |
10 | tags = {
11 | Name = "WebServer"
12 | }
13 | }
14 |
15 | resource "aws_instance" "db" {
16 | ami = "ami-0d52744d6551d851e"
17 | instance_type = "t2.micro"
18 | key_name = "mykeypair"
19 | subnet_id = aws_subnet.private.id
20 | vpc_security_group_ids = [aws_security_group.allow_tls_db.id]
21 |
22 | tags = {
23 | Name = "DB Server"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/3-Tier-Architecture/route-tb.tf:
--------------------------------------------------------------------------------
1 | resource "aws_route_table" "rtb" {
2 | vpc_id = aws_vpc.main.id
3 |
4 | route {
5 | cidr_block = "0.0.0.0/0"
6 | gateway_id = aws_internet_gateway.gw.id
7 | }
8 |
9 | tags = {
10 | Name = "MyRoute"
11 | }
12 | }
13 |
14 | resource "aws_route_table_association" "a" {
15 | subnet_id = aws_subnet.public[count.index].id
16 | route_table_id = aws_route_table.rtb.id
17 | count = 2
18 | }
19 |
20 | //Adding NAT Gateway into the default main route table
21 | resource "aws_default_route_table" "dftb" {
22 | default_route_table_id = aws_vpc.main.default_route_table_id
23 |
24 | route {
25 | cidr_block = "0.0.0.0/0"
26 | gateway_id = aws_nat_gateway.natgw.id
27 | }
28 |
29 | tags = {
30 | Name = "dftb"
31 | }
32 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/terraform/vpc.tf:
--------------------------------------------------------------------------------
1 | module "vpc" {
2 | source = "terraform-aws-modules/vpc/aws"
3 | version = "5.5.1"
4 |
5 | name = "main"
6 | cidr = "10.0.0.0/16"
7 |
8 | azs = var.availability_zones
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 | // This tag applied to subnets is for internal and external-facing load balancers when they are deployed.
13 | public_subnet_tags = {
14 | "kubernetes.io/role/elb" = "1"
15 | }
16 |
17 | private_subnet_tags = {
18 | "kubernetes.io/role/internal-elb" = "1"
19 | }
20 |
21 |
22 | enable_dns_hostnames = true
23 | enable_dns_support = true
24 |
25 | enable_nat_gateway = true
26 | single_nat_gateway = true
27 | one_nat_gateway_per_az = true
28 |
29 | tags = {
30 | Environment = "dev"
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/terraform/variable.tf:
--------------------------------------------------------------------------------
1 | variable "cluster_name" {
2 | type = string
3 | default = "my-eks-cluster"
4 | }
5 |
6 | variable "cluster_version" {
7 | type = number
8 | default = 1.25
9 | }
10 |
11 | variable "region" {
12 | type = string
13 | default = "ap-northeast-1"
14 | }
15 |
16 | variable "availability_zones" {
17 | type = list
18 | default = ["ap-northeast-1a", "ap-northeast-1b"]
19 | }
20 |
21 | variable "addons" {
22 | type = list(object({
23 | name = string
24 | version = string
25 | }))
26 |
27 | default = [
28 | {
29 | name = "kube-proxy"
30 | version = "v1.25.6-eksbuild.1"
31 | },
32 | {
33 | name = "vpc-cni"
34 | version = "v1.12.2-eksbuild.1"
35 | } ,
36 | {
37 | name = "coredns"
38 | version = "v1.9.3-eksbuild.2"
39 | },
40 | {
41 | name = "aws-ebs-csi-driver"
42 | version = "v1.23.0-eksbuild.1"
43 | }
44 | ]
45 | }
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/backend/db.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 |
3 | module.exports = async () => {
4 | try {
5 | const connectionParams = {
6 | // user: process.env.MONGO_USERNAME,
7 | // pass: process.env.MONGO_PASSWORD,
8 | useNewUrlParser: true,
9 | // useCreateIndex: true,
10 | useUnifiedTopology: true,
11 | };
12 | const useDBAuth = process.env.USE_DB_AUTH || false;
13 | if(useDBAuth){
14 | connectionParams.user = process.env.MONGO_USERNAME;
15 | connectionParams.pass = process.env.MONGO_PASSWORD;
16 | }
17 | await mongoose.connect(
18 | process.env.MONGO_CONN_STR,
19 | connectionParams
20 | );
21 | console.log("Connected to database.");
22 | } catch (error) {
23 | console.log("Could not connect to database.", error);
24 | }
25 | };
26 |
--------------------------------------------------------------------------------
/EKS-Cluster/9-add-developer-user.tf:
--------------------------------------------------------------------------------
1 | # resource "aws_iam_user" "developer" {
2 | # name = "developer"
3 | # }
4 |
5 | # resource "aws_iam_policy" "developer_eks" {
6 | # name = "AmazonEKSDeveloperPolicy"
7 |
8 | # policy = <0.2%",
31 | "not dead",
32 | "not op_mini all"
33 | ],
34 | "development": [
35 | "last 1 chrome version",
36 | "last 1 firefox version",
37 | "last 1 safari version"
38 | ]
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Yash Pimple
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/3-Tier-EKS-Architecture/app/backend/routes/tasks.js:
--------------------------------------------------------------------------------
1 | const Task = require("../models/task");
2 | const express = require("express");
3 | const router = express.Router();
4 |
5 | router.post("/", async (req, res) => {
6 | try {
7 | const task = await new Task(req.body).save();
8 | res.send(task);
9 | } catch (error) {
10 | res.send(error);
11 | }
12 | });
13 |
14 | router.get("/", async (req, res) => {
15 | try {
16 | const tasks = await Task.find();
17 | res.send(tasks);
18 | } catch (error) {
19 | res.send(error);
20 | }
21 | });
22 |
23 | router.put("/:id", async (req, res) => {
24 | try {
25 | const task = await Task.findOneAndUpdate(
26 | { _id: req.params.id },
27 | req.body
28 | );
29 | res.send(task);
30 | } catch (error) {
31 | res.send(error);
32 | }
33 | });
34 |
35 | router.delete("/:id", async (req, res) => {
36 | try {
37 | const task = await Task.findByIdAndDelete(req.params.id);
38 | res.send(task);
39 | } catch (error) {
40 | res.send(error);
41 | }
42 | });
43 |
44 | module.exports = router;
45 |
--------------------------------------------------------------------------------
/EKS-Cluster/7-eks.tf:
--------------------------------------------------------------------------------
1 | resource "aws_iam_role" "eks" {
2 | name = "${local.env}-${local.eks_name}-eks-cluster"
3 |
4 | assume_role_policy = <This is My Custom Project Tier 1