Detailed Guide
Detailed Guide
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
Step-by-Step Guide
1. Create AWS EKS and Cluster Setup using eksctl and Bash Scripts
#!/bin/bash
CLUSTER_NAME="my-eks-cluster"
REGION="us-west-2"
NODE_TYPE="t2.medium"
NODES=3
NODES_MIN=1
NODES_MAX=4
chmod +x scripts/create_cluster.sh
./scripts/create_cluster.sh
Step 2: Configure kubectl for EKS
#!/bin/bash
CLUSTER_NAME="my-eks-cluster"
REGION="us-west-2"
chmod +x scripts/configure_eks.sh
./scripts/configure_eks.sh
#!/bin/bash
BUCKET_NAME="my-eks-storage"
REGION="us-west-2"
chmod +x scripts/create_s3_bucket.sh
./scripts/create_s3_bucket.sh
#!/bin/bash
ROLE_NAME="EKS-Cluster-Role"
POLICY_NAME="EKS-Cluster-Policy"
chmod +x scripts/apply_policies.sh
./scripts/apply_policies.sh
#!/bin/bash
chmod +x scripts/setup_storage.sh
./scripts/setup_storage.sh
#!/bin/bash
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
chmod +x scripts/deploy_pods.sh
./scripts/deploy_pods.sh
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
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:
Summary:
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
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:
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.