|
| 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 | +``` |
0 commit comments