Skip to content

Commit d453e19

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
authored andcommitted
Welcome to Stack Simplify
1 parent 1f431f4 commit d453e19

9 files changed

+455
-0
lines changed
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
# Microservices Deployment on EKS
2+
3+
## Step-00: What are Microservices?
4+
- Understand what are microservices on a very high level
5+
6+
## Step-01: What are we going to learn in this section?
7+
- We are going to deploy two microservices.
8+
- User Management Service
9+
- Notification Service
10+
11+
### Usecase Description
12+
- User Management **Create User API** will call Notification service **Send Notification API** to send an email to user when we create a user.
13+
14+
15+
### List of Docker Images used in this section
16+
| Application Name | Docker Image Name |
17+
| ------------------------------- | --------------------------------------------- |
18+
| User Management Microservice | stacksimplify/kube-usermanagement-microservice:1.0.0 |
19+
| Notifications Microservice | stacksimplify/kube-notifications-microservice:1.0.0 |
20+
21+
## Step-02: Pre-requisite -1: AWS RDS Database, ALB Ingress Controller & External DNS
22+
23+
### AWS RDS Database
24+
- We have created AWS RDS Database as part of section [06-EKS-Storage-with-RDS-Database](/06-EKS-Storage-with-RDS-Database/README.md)
25+
- We even created a `externalName service: 01-MySQL-externalName-Service.yml` in our Kubernetes manifests to point to that RDS Database.
26+
27+
### ALB Ingress Controller & External DNS
28+
- We are going to deploy a application which will also have a `ALB Ingress Service` and also will register its DNS name in Route53 using `External DNS`
29+
- Which means we should have both related pods running in our EKS cluster.
30+
```
31+
# Verify alb-ingress-controller pod running in namespace kube-system
32+
kubectl get pods -n kube-system
33+
34+
# Verify external-dns pod running in default namespace
35+
kubectl get pods
36+
```
37+
38+
39+
## Step-03: Pre-requisite-2: Create Simple Email Service - SES SMTP Credentials
40+
### SMTP Credentials
41+
- Go to Services -> Simple Email Service
42+
- SMTP Settings --> Create My SMTP Credentials
43+
- **IAM User Name:** append the default generated name with microservice or something so we have a reference of this IAM user created for our ECS Microservice deployment
44+
- Download the credentials and update the same for below environment variables which you are going to provide in kubernetes manifest `04-NotificationMicroservice-Deployment.yml`
45+
```
46+
AWS_MAIL_SERVER_HOST=email-smtp.us-east-1.amazonaws.com
47+
AWS_MAIL_SERVER_USERNAME=****
48+
AWS_MAIL_SERVER_PASSWORD=***
49+
AWS_MAIL_SERVER_FROM_ADDRESS= [email protected]
50+
```
51+
- **Important Note:** Environment variable AWS_MAIL_SERVER_FROM_ADDRESS value should be a **valid** email address and also verified in SES.
52+
53+
### Verfiy Email Addresses to which notifications we need to send.
54+
- We need two email addresses for testing Notification Service.
55+
- **Email Addresses**
56+
- Verify a New Email Address
57+
- Email Address Verification Request will be sent to that address, click on link to verify your email.
58+
- **From Address:** [email protected] (replace with your ids during verification)
59+
- **To Address:** [email protected] (replace with your ids during verification)
60+
- **Important Note:** We need to ensure all the emails (FromAddress email) and (ToAddress emails) to be verified here.
61+
- Reference Link: https://docs.aws.amazon.com/ses/latest/DeveloperGuide/verify-email-addresses.html
62+
- Environment Variables
63+
- AWS_MAIL_SERVER_HOST=email-smtp.us-east-1.amazonaws.com
64+
- AWS_MAIL_SERVER_USERNAME=*****
65+
- AWS_MAIL_SERVER_PASSWORD=*****
66+
- AWS_MAIL_SERVER_FROM_ADDRESS=[email protected]
67+
68+
69+
## Step-04: Create Notification Microservice Deployment Manifest
70+
- Update environment Variables for Notification Microservice
71+
- **Notification Microservice Deployment**
72+
```yml
73+
- name: AWS_MAIL_SERVER_HOST
74+
value: "smtp-service"
75+
- name: AWS_MAIL_SERVER_USERNAME
76+
value: "AKIABCDEDFASUBKLDOAX"
77+
- name: AWS_MAIL_SERVER_PASSWORD
78+
value: "Bdsdsadsd32qcsads65B4oLo7kMgmKZqhJtEipuE5unLx"
79+
- name: AWS_MAIL_SERVER_FROM_ADDRESS
80+
81+
```
82+
83+
## Step-05: Create Notification Microservice SMTP ExternalName Service
84+
```yml
85+
apiVersion: v1
86+
kind: Service
87+
metadata:
88+
name: smtp-service
89+
spec:
90+
type: ExternalName
91+
externalName: email-smtp.us-east-1.amazonaws.com
92+
```
93+
94+
## Step-06: Create Notification Microservice NodePort Service
95+
```yml
96+
apiVersion: v1
97+
kind: Service
98+
metadata:
99+
name: notification-clusterip-service
100+
labels:
101+
app: notification-restapp
102+
spec:
103+
type: ClusterIP
104+
selector:
105+
app: notification-restapp
106+
ports:
107+
- port: 8096
108+
targetPort: 8096
109+
```
110+
## Step-07: Update User Management Microservice Deployment Manifest with Notification Service Environment Variables.
111+
- User Management Service new environment varibales related to Notification Microservice in addition to already which were configured related to MySQL
112+
- Update in `02-UserManagementMicroservice-Deployment.yml`
113+
```yml
114+
- name: NOTIFICATION_SERVICE_HOST
115+
value: "notification-clusterip-service"
116+
- name: NOTIFICATION_SERVICE_PORT
117+
value: "8096"
118+
```
119+
## Step-08: Update ALB Ingress Service Kubernetes Manifest
120+
- Update Ingress Service to ensure only target it is going to have is User Management Service
121+
- Remove /app1, /app2 contexts
122+
```yml
123+
# External DNS - For creating a Record Set in Route53
124+
external-dns.alpha.kubernetes.io/hostname: ums.kubeoncloud.com
125+
spec:
126+
rules:
127+
- http:
128+
paths:
129+
- path: /* # SSL Redirect Setting
130+
backend:
131+
serviceName: ssl-redirect
132+
servicePort: use-annotation
133+
- path: /*
134+
backend:
135+
serviceName: usermgmt-restapp-nodeport-service
136+
servicePort: 8095
137+
```
138+
139+
## Step-09: Deploy Microservices manifests
140+
```
141+
# Deploy Microservices manifests
142+
kubectl apply -f V1-Microservices/
143+
```
144+
145+
## Step-10: Verify the Deployment using kubectl
146+
```
147+
# List Pods
148+
kubectl get pods
149+
150+
# User Management Microservice Logs
151+
kubectl logs -f $(kubectl get po | egrep -o 'usermgmt-microservice-[A-Za-z0-9-]+')
152+
153+
# Notification Microservice Logs
154+
kubectl logs -f $(kubectl get po | egrep -o 'notification-microservice-[A-Za-z0-9-]+')
155+
156+
# External DNS Logs
157+
kubectl logs -f $(kubectl get po | egrep -o 'external-dns-[A-Za-z0-9-]+')
158+
159+
# List Ingress
160+
kubectl get ingress
161+
```
162+
163+
## Step-11: Verify Microservices health-status via browser
164+
```
165+
# User Management Service Health-Status
166+
https://services.kubeoncloud.com/usermgmt/health-status
167+
168+
# Notification Microservice Health-Status via User Management
169+
https://services.kubeoncloud.com/usermgmt/notification-health-status
170+
https://services.kubeoncloud.com/usermgmt/notification-service-info
171+
```
172+
173+
## Step-12: Import postman project to Postman client on our desktop.
174+
- Import postman project
175+
- Add environment url
176+
- https://services.kubeoncloud.com (**Replace with your ALB DNS registered url on your environment**)
177+
178+
## Step-13: Test both Microservices using Postman
179+
### User Management Service
180+
- **Create User**
181+
- Verify the email id to confirm account creation email received.
182+
- **List User**
183+
- Verify if newly created user got listed.
184+
185+
186+
187+
## Step-14: Rollout New Deployment - Set Image Option
188+
```
189+
# Rollout New Deployment using Set Image
190+
kubectl set image deployment/notification-microservice notification-service=stacksimplify/kube-notifications-microservice:2.0.0 --record=true
191+
192+
# Verify Rollout Status
193+
kubectl rollout status deployment/notification-microservice
194+
195+
# Verify ReplicaSets
196+
kubectl get rs
197+
198+
# Verify Rollout History
199+
kubectl rollout history deployment/notification-microservice
200+
201+
# Access Application (Should see V2)
202+
https://services.kubeoncloud.com/usermgmt/notification-health-status
203+
204+
# Roll back to Previous Version
205+
kubectl rollout undo deployment/notification-microservice
206+
207+
# Access Application (Should see V1)
208+
https://services.kubeoncloud.com/usermgmt/notification-health-status
209+
```
210+
211+
## Step-15: Rollout New Deployment - kubectl Edit
212+
```
213+
# Rollout New Deployment using kubectl edit, change image version to 2.0.0
214+
kubectl edit deployment/notification-microservice
215+
216+
# Verify Rollout Status
217+
kubectl rollout status deployment/notification-microservice
218+
219+
# Verify ReplicaSets
220+
kubectl get rs
221+
222+
# Verify Rollout History
223+
kubectl rollout history deployment/notification-microservice
224+
225+
# Access Application (Should see V2)
226+
https://services.kubeoncloud.com/usermgmt/notification-health-status
227+
228+
# Roll back to Previous Version
229+
kubectl rollout undo deployment/notification-microservice
230+
231+
# Access Application (Should see V1)
232+
https://services.kubeoncloud.com/usermgmt/notification-health-status
233+
```
234+
235+
## Step-16: Rollout New Deployment - Update manifest & kubectl apply
236+
```
237+
# Rollout New Deployment by updating yaml manifest 2.0.0
238+
kubectl apply -f kube-manifests/
239+
240+
# Verify Rollout Status
241+
kubectl rollout status deployment/notification-microservice
242+
243+
# Verify ReplicaSets
244+
kubectl get rs
245+
246+
# Verify Rollout History
247+
kubectl rollout history deployment/notification-microservice
248+
249+
# Access Application (Should see V2)
250+
https://services.kubeoncloud.com/usermgmt/notification-health-status
251+
252+
# Roll back to Previous Version
253+
kubectl rollout undo deployment/notification-microservice
254+
255+
# Access Application (Should see V1)
256+
https://services.kubeoncloud.com/usermgmt/notification-health-status
257+
```
258+
259+
## Step-17: Clean-up
260+
```
261+
kubectl delete -f kube-manifests/
262+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: mysql
5+
spec:
6+
type: ExternalName
7+
externalName: usermgmtdb.cxojydmxwly6.us-east-1.rds.amazonaws.com
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: usermgmt-microservice
5+
labels:
6+
app: usermgmt-restapp
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: usermgmt-restapp
12+
template:
13+
metadata:
14+
labels:
15+
app: usermgmt-restapp
16+
spec:
17+
initContainers:
18+
- name: init-db
19+
image: busybox:1.31
20+
command: ['sh', '-c', 'echo -e "Checking for the availability of MySQL Server deployment"; while ! nc -z mysql 3306; do sleep 1; printf "-"; done; echo -e " >> MySQL DB Server has started";']
21+
containers:
22+
- name: usermgmt-restapp
23+
image: stacksimplify/kube-usermanagement-microservice:1.0.0
24+
resources:
25+
requests:
26+
memory: "128Mi"
27+
cpu: "500m"
28+
limits:
29+
memory: "500Mi"
30+
cpu: "1000m"
31+
ports:
32+
- containerPort: 8095
33+
env:
34+
- name: DB_HOSTNAME
35+
value: "mysql"
36+
- name: DB_PORT
37+
value: "3306"
38+
- name: DB_NAME
39+
value: "usermgmt"
40+
- name: DB_USERNAME
41+
value: "dbadmin"
42+
- name: DB_PASSWORD
43+
valueFrom:
44+
secretKeyRef:
45+
name: mysql-db-password
46+
key: db-password
47+
- name: NOTIFICATION_SERVICE_HOST
48+
value: "notification-clusterip-service"
49+
- name: NOTIFICATION_SERVICE_PORT
50+
value: "8096"
51+
livenessProbe:
52+
exec:
53+
command:
54+
- /bin/sh
55+
- -c
56+
- nc -z localhost 8095
57+
initialDelaySeconds: 60
58+
periodSeconds: 10
59+
readinessProbe:
60+
exec:
61+
command:
62+
- /bin/sh
63+
- -c
64+
- nc -z localhost 8095
65+
initialDelaySeconds: 60
66+
periodSeconds: 10
67+
---
68+
# Kubernetes Secrets
69+
apiVersion: v1
70+
kind: Secret
71+
metadata:
72+
name: mysql-db-password
73+
#type: Opaque means that from kubernetes's point of view the contents of this Secret is unstructured, it can contain arbitrary key-value pairs. In contrast, there is the Secret storing ServiceAccount credentials, or the ones used as ImagePullSecret . These have a constrained contents.
74+
type: Opaque
75+
data:
76+
# Output of echo -n 'dbpassword11' | base64
77+
db-password: ZGJwYXNzd29yZDEx
78+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: usermgmt-restapp-nodeport-service
5+
labels:
6+
app: usermgmt-restapp
7+
annotations:
8+
#Important Note: Need to add health check path annotations in service level if we are planning to use multiple targets in a load balancer
9+
alb.ingress.kubernetes.io/healthcheck-path: /usermgmt/health-status
10+
spec:
11+
type: NodePort
12+
selector:
13+
app: usermgmt-restapp
14+
ports:
15+
- port: 8095
16+
targetPort: 8095
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: notification-microservice
5+
labels:
6+
app: notification-restapp
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: notification-restapp
12+
template:
13+
metadata:
14+
labels:
15+
app: notification-restapp
16+
spec:
17+
containers:
18+
- name: notification-service
19+
image: stacksimplify/kube-notifications-microservice:1.0.0
20+
ports:
21+
- containerPort: 8096
22+
imagePullPolicy: Always
23+
env:
24+
- name: AWS_MAIL_SERVER_HOST
25+
value: "smtp-service"
26+
- name: AWS_MAIL_SERVER_USERNAME
27+
value: "AKIASUF7HC7SRJABCDEM"
28+
- name: AWS_MAIL_SERVER_PASSWORD
29+
value: "BF3RY7UUuhCjMr7Mgj2vE/Lrc/JTJNvoWBzQokKOMlQ/"
30+
- name: AWS_MAIL_SERVER_FROM_ADDRESS
31+

0 commit comments

Comments
 (0)