Skip to content

Commit a4c930f

Browse files
committed
Welcome to StackSimplify
1 parent b3e0333 commit a4c930f

File tree

28 files changed

+765
-45
lines changed

28 files changed

+765
-45
lines changed

04-EKS-Storage-with-EBS-ElasticBlockStore/04-03-UserManagement-MicroService-with-MySQLDB/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ http://<EKS-WorkerNode-Public-IP>:31231/usermgmt/health-status
112112
## Step-05: Verify Users in MySQL Database
113113
```
114114
# Connect to MYSQL Database
115-
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -pdbpassword11
115+
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -u root -pdbpassword11
116116
117117
# Verify usermgmt schema got created which we provided in ConfigMap
118118
mysql> show schemas;
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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
ports:
25+
- containerPort: 8095
26+
env:
27+
- name: DB_HOSTNAME
28+
value: "mysql"
29+
- name: DB_PORT
30+
value: "3306"
31+
- name: DB_NAME
32+
value: "usermgmt"
33+
- name: DB_USERNAME
34+
value: "dbadmin"
35+
- name: DB_PASSWORD
36+
valueFrom:
37+
secretKeyRef:
38+
name: mysql-db-password
39+
key: db-password
40+
- name: NOTIFICATION_SERVICE_HOST
41+
value: "notification-clusterip-service"
42+
- name: NOTIFICATION_SERVICE_PORT
43+
value: "8096"
44+
livenessProbe:
45+
exec:
46+
command:
47+
- /bin/sh
48+
- -c
49+
- nc -z localhost 8095
50+
initialDelaySeconds: 60
51+
periodSeconds: 10
52+
readinessProbe:
53+
httpGet:
54+
path: /usermgmt/health-status
55+
port: 8095
56+
initialDelaySeconds: 60
57+
periodSeconds: 10
58+
---
59+
# Kubernetes Secrets
60+
apiVersion: v1
61+
kind: Secret
62+
metadata:
63+
name: mysql-db-password
64+
#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.
65+
type: Opaque
66+
data:
67+
# Output of echo -n 'dbpassword11' | base64
68+
db-password: ZGJwYXNzd29yZDEx
69+
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: "AKIASUF7HC7SQJ6BCLVS"
28+
- name: AWS_MAIL_SERVER_PASSWORD
29+
value: "BARcmLiC68wgmhTy/cQvz/E8vFzeizGqdeASNtCs6+Nv"
30+
- name: AWS_MAIL_SERVER_FROM_ADDRESS
31+
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: services.kubeoncloud.com, ums.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: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
# Annotations Reference: https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/
2-
apiVersion: extensions/v1beta1
1+
# Annotations Reference: https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/ingress/annotations/
2+
apiVersion: networking.k8s.io/v1
33
kind: Ingress
44
metadata:
55
name: eks-microservices-demo
66
labels:
77
app: usermgmt-restapp
8+
runon: fargate
9+
namespace: ns-ums
810
annotations:
11+
# Load Balancer Name
12+
alb.ingress.kubernetes.io/load-balancer-name: eks-microservices-demo
913
# Ingress Core Settings
10-
kubernetes.io/ingress.class: "alb"
14+
#kubernetes.io/ingress.class: "alb" (OLD INGRESS CLASS NOTATION - STILL WORKS BUT RECOMMENDED TO USE IngressClass Resource)
1115
alb.ingress.kubernetes.io/scheme: internet-facing
1216
# Health Check Settings
1317
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
1418
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
19+
#Important Note: Need to add health check path annotations in service level if we are planning to use multiple targets in a load balancer
1520
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
1621
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
1722
alb.ingress.kubernetes.io/success-codes: '200'
1823
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
19-
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
24+
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
2025
## SSL Settings
2126
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
27+
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/d86de939-8ffd-410f-adce-0ce1f5be6e0d
2328
#alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-1-2017-01 #Optional (Picks default if not used)
2429
# SSL Redirect Setting
25-
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
30+
alb.ingress.kubernetes.io/ssl-redirect: '443'
2631
# External DNS - For creating a Record Set in Route53
27-
external-dns.alpha.kubernetes.io/hostname: services.kubeoncloud.com, ums.kubeoncloud.com
32+
external-dns.alpha.kubernetes.io/hostname: services.kubeoncloud.com, ums.kubeoncloud.com
2833
spec:
2934
rules:
3035
- http:
31-
paths:
32-
- path: /* # SSL Redirect Setting
36+
paths:
37+
- path: /
38+
pathType: Prefix
3339
backend:
34-
serviceName: ssl-redirect
35-
servicePort: use-annotation
36-
- path: /*
37-
backend:
38-
serviceName: usermgmt-restapp-nodeport-service
39-
servicePort: 8095
40+
service:
41+
name: usermgmt-restapp-nodeport-service
42+
port:
43+
number: 8095
4044
# 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.
4145

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-VR2R60B6MMDV
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:3.2.0
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

0 commit comments

Comments
 (0)