0% found this document useful (0 votes)
12 views

Detailed Guide

Uploaded by

demy2014
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Detailed Guide

Uploaded by

demy2014
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Detailed Guide: Cluster setup using eksctl and BASH Scripts, initial

configuration, Security Policies for Week 1 Implementation

Project Structure

Here's a high-level project structure for setting up AWS EKS with eksctl and bash
scripts:

aws-eks-setup/

├── scripts/
│ ├── create_cluster.sh
│ ├── configure_eks.sh
│ ├── create_s3_bucket.sh
│ ├── deploy_pods.sh
│ ├── apply_policies.sh
│ └── setup_storage.sh

├── configs/
│ ├── cluster_config.yaml
│ ├── pod_deployment.yaml
│ ├── storage_class.yaml
│ ├── s3_bucket_policy.json
│ └── roles_policies.json

├── flowcharts/
│ ├── eks_setup_flowchart.png
│ ├── pod_deployment_flowchart.png
│ └── storage_setup_flowchart.png

├── README.md
└── .gitignore

Flowcharts
EKS Setup Flowchart

1. Initialize Setup
2. Create EKS Cluster with eksctl
3. Configure kubectl for EKS
4. Create S3 Bucket for Storage
5. Apply IAM Roles and Policies
6. Setup Persistent Storage

Pod Deployment Flowchart

1. Prepare Deployment Configurations


2. Deploy Pods to EKS
3. Verify Pod Deployment
4. Scale Pods as Needed

Step-by-Step Guide

1. Create AWS EKS and Cluster Setup using eksctl and Bash Scripts

Step 1: Initialize Setup

- Create a create_cluster.sh script:

#!/bin/bash

CLUSTER_NAME="my-eks-cluster"
REGION="us-west-2"
NODE_TYPE="t2.medium"
NODES=3
NODES_MIN=1
NODES_MAX=4

eksctl create cluster \


--name $CLUSTER_NAME \
--region $REGION \
--nodegroup-name standard-workers \
--node-type $NODE_TYPE \
--nodes $NODES \
--nodes-min $NODES_MIN \
--nodes-max $NODES_MAX \
--managed

Run the script:

chmod +x scripts/create_cluster.sh
./scripts/create_cluster.sh
Step 2: Configure kubectl for EKS

- Create a configure_eks.sh script:

#!/bin/bash

CLUSTER_NAME="my-eks-cluster"
REGION="us-west-2"

aws eks update-kubeconfig --name $CLUSTER_NAME --region $REGION

Run the script:

chmod +x scripts/configure_eks.sh
./scripts/configure_eks.sh

Step 3: Create S3 Bucket for Storage

- Create a create_s3_bucket.sh script:

#!/bin/bash

BUCKET_NAME="my-eks-storage"
REGION="us-west-2"

aws s3api create-bucket --bucket $BUCKET_NAME --region $REGION --create-bucket-


configuration LocationConstraint=$REGION

Run the script:

chmod +x scripts/create_s3_bucket.sh
./scripts/create_s3_bucket.sh

Step 4: Apply IAM Roles and Policies

- Create an apply_policies.sh script:

#!/bin/bash

ROLE_NAME="EKS-Cluster-Role"
POLICY_NAME="EKS-Cluster-Policy"

aws iam create-role --role-name $ROLE_NAME --assume-role-policy-document


file://configs/roles_policies.json
aws iam attach-role-policy --role-name $ROLE_NAME --policy-arn
arn:aws:iam::aws:policy/AmazonEKSClusterPolicy
aws iam attach-role-policy --role-name $ROLE_NAME --policy-arn
arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
Run the script:

chmod +x scripts/apply_policies.sh
./scripts/apply_policies.sh

Step 5: Setup Persistent Storage

- Create a setup_storage.sh script:

#!/bin/bash

kubectl apply -f configs/storage_class.yaml

Run the script:

chmod +x scripts/setup_storage.sh
./scripts/setup_storage.sh

2. Development: Apply 6 Pods per Environment

- Create a deploy_pods.sh script:

#!/bin/bash

kubectl apply -f configs/pod_deployment.yaml

Create a pod_deployment.yaml configuration:

apiVersion: apps/v1
kind: Deployment
metadata:
name: ca-agency-service
spec:
replicas: 2
selector:
matchLabels:
app: ca-agency-service
template:
metadata:
labels:
app: ca-agency-service
spec:
containers:
- name: web
image: your-docker-image
- name: worker
image: your-docker-image
# Repeat similar block for other services

Run the script:

chmod +x scripts/deploy_pods.sh
./scripts/deploy_pods.sh

3. Staging (Red): Apply 6 Pods with High-Availability Features

Repeat the steps in the Development section, ensuring high-availability features are
configured in your pod_deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
name: ca-agency-service
spec:
replicas: 2
selector:
matchLabels:
app: ca-agency-service
template:
metadata:
labels:
app: ca-agency-service
spec:
containers:
- name: web
image: your-docker-image
resources:
requests:
cpu: "500m"
memory: "256Mi"
limits:
cpu: "1000m"
memory: "512Mi"
- name: worker
image: your-docker-image
resources:
requests:
cpu: "500m"
memory: "256Mi"
limits:
cpu: "1000m"
memory: "512Mi"
# Add readiness and liveness probes for high-availability
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 5

# Repeat similar block for other services

Objective: Ensure high availability and resilience in the staging environment by deploying 6
pods per service with appropriate resource requests, limits, and health checks.

Steps:

1. Repeat Development Setup:


o Follow the same steps as in the Development section to prepare and deploy the
pods.
2. Configure High-Availability Features:
o Add readiness and liveness probes to ensure that the application is running
correctly and can recover from failures.

Summary:

In the staging environment, we aim to replicate the production environment as closely as


possible to test the application's high-availability features. This includes deploying 6 pods per
service and configuring resource requests, limits, and health probes.

4. Production (Blue): Apply 6 Pods with Auto-Scaling, Load Balancing, High-


Availability, Zero Downtime Deployments, Self-Healing, and Advanced Security

Create an autoscaling_deployment.yaml configuration:

apiVersion: apps/v1
kind: Deployment
metadata:
name: ca-agency-service
spec:
replicas: 2
selector:
matchLabels:
app: ca-agency-service
template:
metadata:
labels:
app: ca-agency-service
spec:
containers:
- name: web
image: your-docker-image
resources:
requests:
cpu: "500m"
memory: "256Mi"
limits:
cpu: "1000m"
memory: "512Mi"
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 5

# Repeat similar block for other services

Create a Horizontal Pod Autoscaler (HPA):

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: ca-agency-service-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ca-agency-service
minReplicas: 2
maxReplicas: 10
targetCPUUtilizationPercentage: 50
Apply the configurations:

kubectl apply -f configs/autoscaling_deployment.yaml

kubectl apply -f configs/hpa.yaml

Conclusion

This guide provides a detailed step-by-step approach to setting up AWS EKS using
eksctl and bash scripts, including initial configurations, role and policy applications, and
persistent storage setup. It also outlines the deployment and management of pods
across development, staging, and production environments, ensuring high availability,
auto-scaling, and advanced security.

You might also like