Week 1 Implementation Detailed Guide to Create AWS EKS Cluster and Cluster Setup Using eksctl and Bash Scripts
Week 1 Implementation Detailed Guide to Create AWS EKS Cluster and Cluster Setup Using eksctl and Bash Scripts
Step-by-Step Guide
1. Initial Setup
# AWS CLI
aws configure
# eksctl
curl --location "https://github.com/weaveworks/eksctl/releases/download/v0.27.0/eksctl_$
(uname -s)_amd64.tar.gz" | tar xz -C /tmp
# kubectl
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s
https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/
kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
#!/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 create_cluster.sh
./create_cluster.sh
trust-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
trust-policy-node.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
s3-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my-eks-storage",
"arn:aws:s3:::my-eks-storage/*"
]
}
]
}
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"
Apply Deployment
kubectl apply -f pod_deployment.yaml
Project Structure
aws-eks-setup/
├── scripts/
│ ├── create_cluster.sh
│ └── delete_cluster.sh
├── iam/
│ ├── trust-policy.json
│ ├── trust-policy-node.json
│ └── s3-policy.json
├── manifests/
│ ├── pod_deployment.yaml
│ └── service.yaml
└── README.md
Flowchart
1. Initialize Setup
o Install AWS CLI, eksctl, and kubectl
o Create create_cluster.sh script
o Run the script to create EKS cluster
2. Configure IAM Roles and Policies
o Create IAM roles for EKS and nodes
o Attach necessary policies
3. Create S3 Bucket
o Create S3 bucket for persistent storage
o Create and attach S3 policy to node role
4. Development Environment
o Create deployment YAML files
o Apply deployments to Kubernetes cluster
#!/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
chmod +x scripts/deploy_pods.sh
./scripts/deploy_pods.sh
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
- name: worker
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/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: ca-agency-service
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: ca-agency-service
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
Apply HPA
apiVersion: v1
kind: Service
metadata:
name: ca-agency-service
spec:
type: LoadBalancer
selector:
app: ca-agency-service
ports:
- protocol: TCP
port: 80
targetPort: 8080
Apply Service
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
- name: worker
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
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
Summary
Flowchart