Skip to content

Commit 56f30f5

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
authored andcommitted
Welcome to Stack Simplify
1 parent e35c0d1 commit 56f30f5

10 files changed

+364
-0
lines changed

13-Microservices-Distributed-Tracing-using-AWS-XRay-on-EKS/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ kubectl describe daemonset xray-daemon
142142
```
143143

144144
## Step-06: Review Ingress Manifest
145+
- **07-ALB-Ingress-SSL-Redirect-ExternalDNS.yml**
145146
```yml
146147
# Change-1-For-You: Update with your SSL Cert ARN when using template
147148
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/9f042b5d-86fd-4fad-96d0-c81c5abc71e1
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Microservices Canary Deployments using Labels & Selectors
2+
3+
4+
## Step-01: Introduction
5+
### Usecase Description
6+
- User Management **getNotificationAppInfo** will call Notification service V1 and V2 versions.
7+
- We will distribute traffic between V1 and V2 versions of Notification service as per our choice based on Replicas
8+
| NS V1 Replicas | NS V2 Replicas | Traffic Distribution |
9+
| -------------- | -------------- | -------------------- |
10+
| 4 | 0 | 100% traffic to NS V1 Version |
11+
| 3 | 1 | 25% traffic to NS V2 Version |
12+
| 2 | 2 | 50% traffic to NS V2 Version |
13+
| 1 | 3 | 75% traffic to NS V2 Version |
14+
| 0 | 4 | 100% traffic to NS V2 Version |
15+
16+
- In our demo, we are going to distribute 50% traffic to each version (V1 and V2).
17+
- NS V1 - 2 replicas and NS V2 - 2 replicas
18+
- We are going to depict one Microservice calling other Microservices with different versions in AWS X-Ray
19+
20+
### List of Docker Images used in this section
21+
| Application Name | Docker Image Name |
22+
| ------------------------------- | --------------------------------------------- |
23+
| User Management Microservice | stacksimplify/kube-usermanagement-microservice:3.0.0-AWS-XRay-MySQLDB |
24+
| Notifications Microservice V1 | stacksimplify/kube-notifications-microservice:3.0.0-AWS-XRay |
25+
| Notifications Microservice V1 | stacksimplify/kube-notifications-microservice:4.0.0-AWS-XRay |
26+
27+
## Step-02: Pre-requisite: AWS RDS Database, ALB Ingress Controller, External DNS & X-Ray Daemon
28+
29+
### AWS RDS Database
30+
- We have created AWS RDS Database as part of section [06-EKS-Storage-with-RDS-Database](/06-EKS-Storage-with-RDS-Database/README.md)
31+
- We even created a `externalName service: 01-MySQL-externalName-Service.yml` in our Kubernetes manifests to point to that RDS Database.
32+
33+
### ALB Ingress Controller & External DNS
34+
- 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`
35+
- Which means we should have both related pods running in our EKS cluster.
36+
- We have installed **ALB Ingress Controller** as part of section [08-01-ALB-Ingress-Install](/08-ELB-Application-LoadBalancers/08-01-ALB-Ingress-Install/README.md)
37+
- We have installed **External DNS** as part of section [08-06-01-Deploy-ExternalDNS-on-EKS](/08-ELB-Application-LoadBalancers/08-06-ALB-Ingress-ExternalDNS/08-06-01-Deploy-ExternalDNS-on-EKS/README.md)
38+
39+
### XRay Daemon
40+
- We are going to view the application traces in AWS X-Ray.
41+
- We need XRay Daemon running as Daemonset for that.
42+
```
43+
# Verify alb-ingress-controller pod running in namespace kube-system
44+
kubectl get pods -n kube-system
45+
46+
# Verify external-dns & xray-daemon pod running in default namespace
47+
kubectl get pods
48+
```
49+
50+
## Step-03: Review Deployment Manifest for V2 Notification Service
51+
- We are going to distribute 50% traffic to each of the V1 and V2 version of application
52+
| NS V1 Replicas | NS V2 Replicas | Traffic Distribution |
53+
| -------------- | -------------- | -------------------- |
54+
| 2 | 2 | 50% traffic to NS V2 Version |
55+
56+
- **08-V2-NotificationMicroservice-Deployment copy.yml**
57+
```yml
58+
# Change-1: Image Tag is 4.0.0-AWS-XRay
59+
spec:
60+
containers:
61+
- name: notification-service
62+
image: stacksimplify/kube-notifications-microservice:4.0.0-AWS-XRay
63+
64+
# Change-2: New Environment Variables related to AWS X-Ray
65+
- name: AWS_XRAY_TRACING_NAME
66+
value: "V2-Notification-Microservice"
67+
- name: AWS_XRAY_DAEMON_ADDRESS
68+
value: "xray-service.default:2000"
69+
- name: AWS_XRAY_CONTEXT_MISSING
70+
value: "LOG_ERROR" # Log an error and continue, Ideally RUNTIME_ERROR – Throw a runtime exception which is default option if not configured
71+
```
72+
73+
74+
## Step-04: Review Ingress Manifest
75+
- **07-ALB-Ingress-SSL-Redirect-ExternalDNS.yml**
76+
```yml
77+
# Change-1-For-You: Update with your SSL Cert ARN when using template
78+
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/9f042b5d-86fd-4fad-96d0-c81c5abc71e1
79+
80+
# Change-2-For-You: Update with your "yourdomainname.com"
81+
# External DNS - For creating a Record Set in Route53
82+
external-dns.alpha.kubernetes.io/hostname: canarydemo.kubeoncloud.com
83+
```
84+
85+
## Step-05: Deploy Manifests
86+
```
87+
# Deploy
88+
kubectl apply -f kube-manifests/
89+
90+
# Verify
91+
kubectl get deploy,svc,pod
92+
```
93+
## Step-06: Test
94+
```
95+
# Test
96+
https://canarydemo.kubeoncloud.com/usermgmt/notification-xray
97+
98+
# Your Domain Name
99+
https://<Replace-your-domain-name>/usermgmt/notification-xray
100+
```
101+
102+
## Step-07: What is happening in the background?
103+
- As far as `Notification Cluster IP Service` selector label matches to `Notificaiton V1 and V2 Deployment manifests selector.matchLables` those respective pods are picked to send traffic.
104+
```yml
105+
# Notification Cluster IP Service - Selector Label
106+
selector:
107+
app: notification-restapp
108+
109+
# Notification V1 and V2 Deployment - Selector Match Labels
110+
selector:
111+
matchLabels:
112+
app: notification-restapp
113+
```
114+
115+
## Step-08: Clean-Up
116+
- We are going to delete applications created as part of this section
117+
```
118+
# Delete Apps
119+
kubectl delete -f kube-manifests/
120+
```
121+
122+
## Step-09: Downside of this approach
123+
- We will review the downside in a presentation
124+
125+
## Step-10: Best ways for Canary Deployments
126+
- Istio (Open Source)
127+
- AWS AppMesh (AWS version of Istio)
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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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:3.0.0-AWS-XRay
24+
ports:
25+
- containerPort: 8095
26+
imagePullPolicy: Always
27+
env:
28+
- name: DB_HOSTNAME
29+
value: "mysql"
30+
- name: DB_PORT
31+
value: "3306"
32+
- name: DB_NAME
33+
value: "usermgmt"
34+
- name: DB_USERNAME
35+
value: "dbadmin"
36+
- name: DB_PASSWORD
37+
valueFrom:
38+
secretKeyRef:
39+
name: mysql-db-password
40+
key: db-password
41+
- name: NOTIFICATION_SERVICE_HOST
42+
value: "notification-clusterip-service"
43+
- name: NOTIFICATION_SERVICE_PORT
44+
value: "8096"
45+
- name: AWS_XRAY_TRACING_NAME
46+
value: "User-Management-Microservice"
47+
- name: AWS_XRAY_DAEMON_ADDRESS
48+
value: "xray-service.default:2000"
49+
- name: AWS_XRAY_CONTEXT_MISSING
50+
value: "LOG_ERROR" # Log an error and continue, Ideally RUNTIME_ERROR – Throw a runtime exception which is default option if not configured
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+
httpGet:
61+
path: /usermgmt/health-status
62+
port: 8095
63+
initialDelaySeconds: 60
64+
periodSeconds: 10
65+
---
66+
# Kubernetes Secrets
67+
apiVersion: v1
68+
kind: Secret
69+
metadata:
70+
name: mysql-db-password
71+
#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.
72+
type: Opaque
73+
data:
74+
# Output of echo -n 'dbpassword11' | base64
75+
db-password: ZGJwYXNzd29yZDEx
76+
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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: v1-notification-microservice
5+
labels:
6+
app: notification-restapp
7+
spec:
8+
replicas: 2
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:3.0.0-AWS-XRay
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: "AKIASUF7HC7SQJ6BCLVS"
28+
- name: AWS_MAIL_SERVER_PASSWORD
29+
value: "BARcmLiC68wgmhTy/cQvz/E8vFzeizGqdeASNtCs6+Nv"
30+
- name: AWS_MAIL_SERVER_FROM_ADDRESS
31+
32+
- name: AWS_XRAY_TRACING_NAME
33+
value: "V1-Notification-Microservice"
34+
- name: AWS_XRAY_DAEMON_ADDRESS
35+
value: "xray-service.default:2000"
36+
- name: AWS_XRAY_CONTEXT_MISSING
37+
value: "LOG_ERROR" # Log an error and continue, Ideally RUNTIME_ERROR – Throw a runtime exception which is default option if not configured
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: smtp-service
5+
spec:
6+
type: ExternalName
7+
externalName: email-smtp.us-east-1.amazonaws.com
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: notification-clusterip-service
5+
labels:
6+
app: notification-restapp
7+
spec:
8+
type: ClusterIP
9+
selector:
10+
app: notification-restapp
11+
ports:
12+
- port: 8096
13+
targetPort: 8096
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Annotations Reference: https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/
2+
apiVersion: extensions/v1beta1
3+
kind: Ingress
4+
metadata:
5+
name: eks-microservices-demo
6+
labels:
7+
app: usermgmt-restapp
8+
annotations:
9+
# Ingress Core Settings
10+
kubernetes.io/ingress.class: "alb"
11+
alb.ingress.kubernetes.io/scheme: internet-facing
12+
# Health Check Settings
13+
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
14+
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
15+
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
16+
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
17+
alb.ingress.kubernetes.io/success-codes: '200'
18+
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
19+
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
20+
## SSL Settings
21+
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
22+
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/9f042b5d-86fd-4fad-96d0-c81c5abc71e1
23+
#alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-1-2017-01 #Optional (Picks default if not used)
24+
# SSL Redirect Setting
25+
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
26+
# External DNS - For creating a Record Set in Route53
27+
external-dns.alpha.kubernetes.io/hostname: canarydemo.kubeoncloud.com
28+
spec:
29+
rules:
30+
- http:
31+
paths:
32+
- path: /* # SSL Redirect Setting
33+
backend:
34+
serviceName: ssl-redirect
35+
servicePort: use-annotation
36+
- path: /*
37+
backend:
38+
serviceName: usermgmt-restapp-nodeport-service
39+
servicePort: 8095
40+
# Important Note-1: In path based routing order is very important, if we are going to use "/*", try to use it at the end of all rules.
41+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: v2-notification-microservice
5+
labels:
6+
app: notification-restapp
7+
spec:
8+
replicas: 2
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:4.0.0-AWS-XRay
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: "AKIASUF7HC7SQJ6BCLVS"
28+
- name: AWS_MAIL_SERVER_PASSWORD
29+
value: "BARcmLiC68wgmhTy/cQvz/E8vFzeizGqdeASNtCs6+Nv"
30+
- name: AWS_MAIL_SERVER_FROM_ADDRESS
31+
32+
- name: AWS_XRAY_TRACING_NAME
33+
value: "V2-Notification-Microservice"
34+
- name: AWS_XRAY_DAEMON_ADDRESS
35+
value: "xray-service.default:2000"
36+
- name: AWS_XRAY_CONTEXT_MISSING
37+
value: "LOG_ERROR" # Log an error and continue, Ideally RUNTIME_ERROR – Throw a runtime exception which is default option if not configured
38+

0 commit comments

Comments
 (0)