Elastic Kubernetes Service - amresh087/newronaRepos GitHub Wiki
Elastic Kubernetes Service Answer
This guide contains all important Kubernetes YAML files required to deploy a Spring Boot Docker application into Amazon EKS.
- Docker image already created
- Docker image pushed to ECR
- EKS cluster already created
Example Docker Image:
123456789.dkr.ecr.ap-south-1.amazonaws.com/payment-service:latest
File: namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: banking-app
File: deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: payment-service
namespace: banking-app
labels:
app: payment-service
spec:
replicas: 3
selector:
matchLabels:
app: payment-service
template:
metadata:
labels:
app: payment-service
spec:
containers:
- name: payment-service
image: 123456789.dkr.ecr.ap-south-1.amazonaws.com/payment-service:latest
ports:
- containerPort: 8080
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "500m"
env:
- name: SPRING_PROFILES_ACTIVE
value: prod
- name: DB_HOST
value: postgres-service
- name: DB_PORT
value: "5432"
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 15
periodSeconds: 5
File: service.yaml
apiVersion: v1
kind: Service
metadata:
name: payment-service
namespace: banking-app
spec:
type: ClusterIP
selector:
app: payment-service
ports:
- protocol: TCP
port: 80
targetPort: 8080
File: ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: payment-ingress
namespace: banking-app
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- http:
paths:
- path: /payment
pathType: Prefix
backend:
service:
name: payment-service
port:
number: 80
File: configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: payment-config
namespace: banking-app
data:
application.properties: |
server.port=8080
spring.datasource.url=jdbc:postgresql://postgres-service:5432/paymentdb
spring.jpa.hibernate.ddl-auto=update
File: secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: payment-secret
namespace: banking-app
type: Opaque
data:
DB_USERNAME: cG9zdGdyZXM=
DB_PASSWORD: cGFzc3dvcmQ=
File: hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: payment-hpa
namespace: banking-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: payment-service
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
File: pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: payment-pvc
namespace: banking-app
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
kubectl apply -f namespace.yaml
kubectl apply -f configmap.yaml
kubectl apply -f secret.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
kubectl apply -f hpa.yaml
kubectl get pods -n banking-app
kubectl get svc -n banking-app
kubectl get ingress -n banking-app
kubectl describe pod <pod-name> -n banking-app
kubectl logs <pod-name> -n banking-app
Developer Push Docker Image
↓
Amazon ECR
↓
Kubernetes Deployment YAML
↓
EKS Scheduler
↓
Worker Node Selected
↓
Pod Created
↓
Service Exposes Application
↓
Ingress/ALB Exposes Public URL
Client
↓
ALB Ingress
↓
Kubernetes Service
↓
Spring Boot Pods
↓
PostgreSQL / Redis / Kafka
Deployment maintains desired pod replicas and supports rolling updates.
Provides stable networking for pods.
Exposes APIs externally and routes traffic.
Automatically scales pods based on CPU/memory.
Stores external configuration.
Stores sensitive data securely.