Skip to content

Commit 4f10200

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
authored andcommitted
Welcome to Stack Simplify
1 parent 8a4faf7 commit 4f10200

12 files changed

+470
-0
lines changed

12-Microservices-Deployment-on-EKS/temp

Whitespace-only changes.
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# Microservices Distributed Tracing with X-Ray on AWS EKS
2+
3+
## Step-01: Introduction
4+
### Introduction to AWS XRay & k8s DaemonSets
5+
- Understand about AWS X-Ray Services
6+
- Understand Kubernetes DaemonSets
7+
- Understand the AWS X-Ray and Microservices network design on EKS Cluster
8+
- Understand about Service Map, Traces and Segments in AWS X-Ray
9+
10+
### Usecase Description
11+
- User Management **getNotificationAppInfo** will call Notification service **notification-xray** which will evetually send traces to AWS X-Ray service
12+
- We are going to depict one Microservice calling other Microservice
13+
14+
### List of Docker Images used in this section
15+
| Application Name | Docker Image Name |
16+
| ------------------------------- | --------------------------------------------- |
17+
| User Management Microservice | stacksimplify/kube-usermanagement-microservice:3.0.0-AWS-XRay-MySQLDB |
18+
| Notifications Microservice V1 | stacksimplify/kube-notifications-microservice:3.0.0-AWS-XRay |
19+
20+
## Step-02: Pre-requisite: AWS RDS Database, ALB Ingress Controller & External DNS
21+
22+
### AWS RDS Database
23+
- We have created AWS RDS Database as part of section [06-EKS-Storage-with-RDS-Database](/06-EKS-Storage-with-RDS-Database/README.md)
24+
- We even created a `externalName service: 01-MySQL-externalName-Service.yml` in our Kubernetes manifests to point to that RDS Database.
25+
26+
### ALB Ingress Controller & External DNS
27+
- 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`
28+
- Which means we should have both related pods running in our EKS cluster.
29+
- 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)
30+
- 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)
31+
```
32+
# Verify alb-ingress-controller pod running in namespace kube-system
33+
kubectl get pods -n kube-system
34+
35+
# Verify external-dns pod running in default namespace
36+
kubectl get pods
37+
```
38+
39+
## Step-03: Create IAM permissions for AWS X-Ray daemon
40+
```
41+
# Template
42+
eksctl create iamserviceaccount \
43+
--name service_account_name \
44+
--namespace service_account_namespace \
45+
--cluster cluster_name \
46+
--attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \
47+
--approve \
48+
--override-existing-serviceaccounts
49+
50+
# Replace Name, Namespace, Cluster Info (if any changes)
51+
eksctl create iamserviceaccount \
52+
--name xray-daemon \
53+
--namespace default \
54+
--cluster eksdemo1 \
55+
--attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \
56+
--approve \
57+
--override-existing-serviceaccounts
58+
```
59+
60+
### Verify Service Account and AWS IAM Role
61+
```
62+
# List k8s Service Accounts
63+
kubectl get sa
64+
65+
# Describe Service Account (Verify IAM Role annotated)
66+
kubectl describe sa xray-daemon
67+
68+
# List IAM Roles on eksdemo1 Cluster created with eksctl
69+
eksctl get iamserviceaccount --cluster eksdemo1
70+
```
71+
72+
## Step-04: Update IAM Role ARN in xray-k8s-daemonset.yml
73+
### Get AWS IAM Role ARN for xray-daemon
74+
```
75+
# Get AWS IAM Role ARN
76+
eksctl get iamserviceaccount xray-daemon --cluster eksdemo1
77+
```
78+
### Update xray-k8s-daemonset.yml
79+
- File Name: kube-manifests/01-XRay-DaemonSet/xray-k8s-daemonset.yml
80+
```yml
81+
apiVersion: v1
82+
kind: ServiceAccount
83+
metadata:
84+
labels:
85+
app: xray-daemon
86+
name: xray-daemon
87+
namespace: default
88+
# Update IAM Role ARN created for X-Ray access
89+
annotations:
90+
eks.amazonaws.com/role-arn: arn:aws:iam::180789647333:role/eksctl-eksdemo1-addon-iamserviceaccount-defa-Role1-20F5AWU2J61F
91+
```
92+
93+
### Deploy X-Ray DaemonSet on our EKS Cluster
94+
```
95+
# Deploy
96+
kubectl apply -f kube-manifests/01-XRay-DaemonSet/xray-k8s-daemonset.yml
97+
98+
# Verify Deployment, Service & Pod
99+
kubectl get deploy,svc,pod
100+
101+
# Verify X-Ray Logs
102+
kubectl logs -f <X-Ray Pod Name>
103+
kubectl logs -f xray-daemon-phszp
104+
105+
# List & Describe DaemonSet
106+
kubectl get daemonset
107+
kubectl describe daemonset xray-daemon
108+
```
109+
110+
## Step-05: Review Deployment Manifests
111+
- **02-UserManagementMicroservice-Deployment.yml**
112+
```yml
113+
# Change-1: Image Tag is 3.0.0-AWS-XRay-MySQLDB
114+
containers:
115+
- name: usermgmt-restapp
116+
image: stacksimplify/kube-usermanagement-microservice:3.0.0-AWS-XRay-MySQLDB
117+
118+
# Change-2: New Environment Variables related to AWS X-Ray
119+
- name: AWS_XRAY_TRACING_NAME
120+
value: "User-Management-Microservice"
121+
- name: AWS_XRAY_DAEMON_ADDRESS
122+
value: "xray-service.default:2000"
123+
- name: AWS_XRAY_CONTEXT_MISSING
124+
value: "LOG_ERROR" # Log an error and continue, Ideally RUNTIME_ERROR – Throw a runtime exception which is default option if not configured
125+
```
126+
- **04-NotificationMicroservice-Deployment.yml**
127+
```yml
128+
# Change-1: Image Tag is 3.0.0-AWS-XRay
129+
spec:
130+
containers:
131+
- name: notification-service
132+
image: stacksimplify/kube-notifications-microservice:3.0.0-AWS-XRay
133+
134+
# Change-2: New Environment Variables related to AWS X-Ray
135+
- name: AWS_XRAY_TRACING_NAME
136+
value: "V1-Notification-Microservice"
137+
- name: AWS_XRAY_DAEMON_ADDRESS
138+
value: "xray-service.default:2000"
139+
- name: AWS_XRAY_CONTEXT_MISSING
140+
value: "LOG_ERROR" # Log an error and continue, Ideally RUNTIME_ERROR – Throw a runtime exception which is default option if not configured
141+
142+
```
143+
144+
## Step-06: Review Ingress Manifest
145+
```yml
146+
# Change-1-For-You: Update with your SSL Cert ARN when using template
147+
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/9f042b5d-86fd-4fad-96d0-c81c5abc71e1
148+
149+
# Change-2-For-You: Update with your "yourdomainname.com"
150+
# External DNS - For creating a Record Set in Route53
151+
external-dns.alpha.kubernetes.io/hostname: services.kubeoncloud.com, ums.kubeoncloud.com
152+
```
153+
154+
## Step-07: Deploy Manifests
155+
```
156+
# Deploy
157+
kubectl apply -f kube-manifests/02-Applications
158+
159+
# Verify
160+
kubectl get pods
161+
```
162+
163+
## Step-08: Test
164+
```
165+
# Test
166+
https://ums.kubeoncloud.com/usermgmt/notification-xray
167+
https://services.kubeoncloud.com/usermgmt/notification-xray
168+
169+
# Your Domain Name
170+
https://<Replace-your-domain-name>/usermgmt/notification-xray
171+
```
172+
173+
174+
## References
175+
- https://github.com/aws-samples/aws-xray-kubernetes/
176+
- https://github.com/aws-samples/aws-xray-kubernetes/blob/master/xray-daemon/xray-k8s-daemonset.yaml
177+
- https://aws.amazon.com/blogs/compute/application-tracing-on-kubernetes-with-aws-x-ray/
178+
- https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-configuration.html
179+
- https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-configuration.html#xray-sdk-java-configuration-plugins
180+
- https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-httpclients.html
181+
- https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-filters.html
182+
- https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-sqlclients.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
labels:
5+
app: xray-daemon
6+
name: xray-daemon
7+
namespace: default
8+
# Update IAM Role ARN created for X-Ray access
9+
annotations:
10+
eks.amazonaws.com/role-arn: arn:aws:iam::180789647333:role/eksctl-eksdemo1-addon-iamserviceaccount-defa-Role1-20F5AWU2J61F
11+
---
12+
apiVersion: apps/v1
13+
kind: DaemonSet
14+
metadata:
15+
name: xray-daemon
16+
namespace: default
17+
spec:
18+
updateStrategy:
19+
type: RollingUpdate
20+
selector:
21+
matchLabels:
22+
app: xray-daemon
23+
template:
24+
metadata:
25+
labels:
26+
app: xray-daemon
27+
spec:
28+
serviceAccountName: xray-daemon
29+
volumes:
30+
- name: config-volume
31+
configMap:
32+
name: "xray-config"
33+
containers:
34+
- name: xray-daemon
35+
image: amazon/aws-xray-daemon
36+
command: ["/usr/bin/xray", "-c", "/aws/xray/config.yaml"]
37+
resources:
38+
requests:
39+
cpu: 256m
40+
memory: 32Mi
41+
limits:
42+
cpu: 512m
43+
memory: 64Mi
44+
ports:
45+
- name: xray-ingest
46+
containerPort: 2000
47+
hostPort: 2000
48+
protocol: UDP
49+
- name: xray-tcp
50+
containerPort: 2000
51+
hostPort: 2000
52+
protocol: TCP
53+
volumeMounts:
54+
- name: config-volume
55+
mountPath: /aws/xray
56+
readOnly: true
57+
---
58+
# Configuration for AWS X-Ray daemon
59+
apiVersion: v1
60+
kind: ConfigMap
61+
metadata:
62+
name: xray-config
63+
namespace: default
64+
data:
65+
config.yaml: |-
66+
TotalBufferSizeMB: 24
67+
Socket:
68+
UDPAddress: "0.0.0.0:2000"
69+
TCPAddress: "0.0.0.0:2000"
70+
Version: 2
71+
---
72+
# k8s service definition for AWS X-Ray daemon headless service
73+
apiVersion: v1
74+
kind: Service
75+
metadata:
76+
name: xray-service
77+
namespace: default
78+
spec:
79+
selector:
80+
app: xray-daemon
81+
clusterIP: None
82+
ports:
83+
- name: xray-ingest
84+
port: 2000
85+
protocol: UDP
86+
- name: xray-tcp
87+
port: 2000
88+
protocol: TCP
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
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-MySQLDB
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+
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

0 commit comments

Comments
 (0)