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