Microservices Deployment using Kubernetes Managed Service(AWS EKS)

Ian Kisali
7 min readApr 25, 2024

Introduction

Microservices has become an emerging architectural technology since the early 2000s, when it was first conceptualized, changing how software engineers build and deploy applications. Traditionally, monolithic architecture was preferred, but as applications have grown larger and more complex, alternative technologies have been needed to be scalable, agile, and easier to maintain.

Microservices vs Monolithic

Microservices in software design engineering is an approach where applications consist of small single services deployed independently solving the modern infrastructure needs, especially large applications. Advantages of microservices include fault isolation, mixed technology stack, loosely coupled software hence easy to maintain, granular scaling, and independent development and deployment.

Monolithic architecture is a traditional technology involving building applications as one single and integrated deployable unit hence simple in development, debugging, and deployment.

There are best-case scenarios of when to use either microservice or monolithic architectural design in developing applications. For small applications with limited complexity then monolithic design will be the best fit. This is applied in initial developments of software or implementing proof of concept. The requirements may not be set out in the early software development, therefore, having a single development and deployable unit would be the starting point. As the application grows and starts to experience more traffic, it will necessitate developers to migrate to a microservices architecture. This would make the application easy to maintain due to its independent and loosely coupled design.

Prerequisites

  • awscli - AWS Command Line Interface providing access to multiple AWS services from the command line.
  • eksctlCommand Line Interface tool for working with Amazon EKS including creating and managing Kubernetes clusters in the cloud
  • kubectlCommand Line tool for running commands in the Kubernetes cluster. Communicates with K8s control plane using its API.
  • helm - Package manager for Kubernetes used to automate the creation, packaging, and deployment of K8S applications.
  • helmfilecommand line tool and declarative specification for managing and installing a collection of Helm charts.

Architecture

This project uses the Google Microservices demo repository, an online boutique shop application. The application is a web-based e-commerce app allowing users to browse items, add them to cart, and purchase them.

The application is comprised of 11 microservices written in different languages that includes C#(cartservice), Go(frontend, shippingservice, checkout and productcatalogservice), NodeJS(currencyservice and paymentservice), Python(emailservice, recommendationservice and loadgenerator) and Java(adservice).

Quickstart (AWS EKS)

  1. Ensure you have the following installed locally:
  • git, awscli, kubectl, eksctl, helm and helmfile

2. Clone the repository to your local machine and change the working directory to the cloned repo:

git clone https://github.com/iankisali/microservice-deployment.git
cd microservices-deployment

3. Configure aws region and security credentials:

aws configure
AWS Access Key ID [None]: accesskey
AWS Secret Access Key [None]: secretkey
Default region name [None]: us-east-1
Default output format [None]: json

Access key id and secret access key are part of your AWS credentials in your account and will be written to the shared credentials file. Replace accesskey and secretkey with your AWS account keys. By default the credentials and config files are stored in ~/.aws folder in your local machine. If you don’t select a region, then the us-east-1 region will be used by default.

4. Create a cluster using the command:

eksctl create cluster

This creates an EKS cluster in the default region set up in ~/.aws/config file with one managed node group having two m5.large EC2 instances(nodes). The Kubernetes configuration can be found in the file ~/.kube/config locally. This process will take around 10 to 20 minutes to set up all the required services.

AWS uses cloud formation template to set up the cluster. The networking of the EKS in the cloud environment is as shown. Notice that the nodes in the subnets are in two different availability zones, us-east-1b and us-east-1c.

5. Confirm the creation of the two nodes using kubectl command:

kubectl get nodes
NAME                             STATUS   ROLES    AGE     VERSION
ip-192-168-22-140.ec2.internal Ready <none> 2m31s v1.27.9-eks-5e0fdde
ip-192-168-56-129.ec2.internal Ready <none> 2m28s v1.27.9-eks-5e0fdde

6. Listing helm files in the repository:

helmfile list
NAME                    NAMESPACE       ENABLED INSTALLED       LABELS  CHART                   VERSION
rediscart true true chart/redis
emailservice true true chart/microservice
cartservice true true chart/microservice
currencyservice true true chart/microservice
paymentservice true true chart/microservice
recommendationservice true true chart/microservice
productcatalogservice true true chart/microservice
shippingservice true true chart/microservice
adservice true true chart/microservice
checkoutservice true true chart/microservice
frontendservice true true chart/microservice

7. Applying helmfile:

helmfile apply/sync
UPDATED RELEASES:
NAME CHART VERSION DURATION
currencyservice chart/microservice 0.1.0 9s
rediscart chart/redis 0.1.0 9s
recommendationservice chart/microservice 0.1.0 9s
productcatalogservice chart/microservice 0.1.0 9s
emailservice chart/microservice 0.1.0 9s
cartservice chart/microservice 0.1.0 10s
shippingservice chart/microservice 0.1.0 10s
checkoutservice chart/microservice 0.1.0 10s
frontendservice chart/microservice 0.1.0 10s
paymentservice chart/microservice 0.1.0 10s
adservice chart/microservice 0.1.0 10s

All the deployments and services will be released with a default version.

Another option for deploying the helm charts is applying the commands to deploy individual charts, the same as deploying one microservice. An example of deploying a single microservice in the microservice namespace is:

helm install -f values/email-service-values.yaml emailservice chart/microservice -n microservice

This is useful when developers are working on a single microservice and want to deploy it. This won’t necessarily bring the whole application down as would happen when working with a single monolithic application.

You can also run the install shell script to deploy all the microservices.

8. Getting running pods from the EKS cluster:

kubectl get pods
NAME                                     READY   STATUS             RESTARTS   AGE
adservice-6c86cc499b-859bp 1/1 Running 0 12s
adservice-6c86cc499b-wvfxl 1/1 Running 0 7s
cartservice-9c6b6bd4b-hpf8t 1/1 Running 0 6m15s
cartservice-9c6b6bd4b-m76nr 1/1 Running 0 6m15s
currencyservice-666d8ff7cd-fgcf6 1/1 Running 0 6m16s
currencyservice-666d8ff7cd-qgtm7 1/1 Running 0 6m16s
emailservice-5fb6f888b-c56f8 1/1 Running 0 6m15s
emailservice-5fb6f888b-ksnzl 1/1 Running 0 6m15s
frontend-6f6848848d-cct79 1/1 Running 0 6m14s
frontend-6f6848848d-r84pc 1/1 Running 0 6m14s
paymentservice-7c779bb99c-g2542 1/1 Running 0 6m15s
paymentservice-7c779bb99c-kfsn8 1/1 Running 0 6m15s
productcatalogservice-7dc8f75df9-b22kc 1/1 Running 0 6m15s
productcatalogservice-7dc8f75df9-xjk9j 1/1 Running 0 6m15s
recommendationservice-cfd8c7ff-2gztd 1/1 Running 0 6m15s
recommendationservice-cfd8c7ff-kf9d2 1/1 Running 0 6m15s
redis-cart-79f595698b-wgrsz 1/1 Running 0 6m16s
servicename-69466db65-2xppk 1/1 Running 0 6m15s
servicename-69466db65-45789 1/1 Running 0 6m15s
shippingservice-57b9d4b877-hdwj6 1/1 Running 0 6m15s
shippingservice-57b9d4b877-nlf5f 1/1 Running 0 6m15s

Each microservice has two running pods since the Kubernetes chart specifies two replicas running at all times.

9. Getting services running in the cluster:

kubectl get services
NAME                    TYPE           CLUSTER-IP       EXTERNAL-IP                                                              PORT(S)        AGE
adservice ClusterIP 10.100.34.105 <none> 9555/TCP 7m5s
cartservice ClusterIP 10.100.83.237 <none> 7070/TCP 7m5s
currencyservice ClusterIP 10.100.83.75 <none> 7000/TCP 7m5s
emailservice ClusterIP 10.100.153.11 <none> 5000/TCP 7m5s
frontend LoadBalancer 10.100.189.28 a47783fa778ec46839250e141d651596-399789749.us-east-1.elb.amazonaws.com 80:31636/TCP 7m5s
kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 19m
paymentservice ClusterIP 10.100.172.147 <none> 50051/TCP 7m5s
productcatalogservice ClusterIP 10.100.159.1 <none> 3550/TCP 7m5s
recommendationservice ClusterIP 10.100.114.91 <none> 8080/TCP 7m5s
redis-cart ClusterIP 10.100.177.169 <none> 6379/TCP 7m5s
servicename ClusterIP 10.100.68.238 <none> 5050/TCP 7m5s
shippingservice ClusterIP 10.100.164.233 <none> 50051/TCP 7m5s

The internet-facing service is the frontend which is interfaced with the load balancer endpoint. Such endpoint from the list of services is:

a47783fa778ec46839250e141d651596-399789749.us-east-1.elb.amazonaws.com

Entering this link in a web browser to obtain the landing page of the online boutique.

Congratulations on deploying your microservice application. Now we can play around with the running pods to observe the properties of a microservice application.

Deleting a pod will cause another pod to start immediately after deletion. Replace the pod name with your pod.

kubectl delete pod currencyservice-666d8ff7cd-fgcf6 --force
NAME                                     READY   STATUS             RESTARTS   AGE
adservice-b7d9c95bd-hqfwc 1/1 Running 0 13m
adservice-b7d9c95bd-lprr4 1/1 Running 0 13m
cartservice-9c6b6bd4b-hpf8t 1/1 Running 0 13m
cartservice-9c6b6bd4b-m76nr 1/1 Running 0 13m
currencyservice-666d8ff7cd-lqfdq 1/1 Running 0 3m3s
currencyservice-666d8ff7cd-qgtm7 1/1 Running 0 13m
emailservice-5fb6f888b-c56f8 1/1 Running 0 13m
emailservice-5fb6f888b-ksnzl 1/1 Running 0 13m
frontend-6f6848848d-cct79 1/1 Running 0 13m
frontend-6f6848848d-r84pc 1/1 Running 0 13m
paymentservice-7c779bb99c-g2542 1/1 Running 0 13m
paymentservice-7c779bb99c-klppf 1/1 Running 0 35s
productcatalogservice-7dc8f75df9-b22kc 1/1 Running 0 13m
productcatalogservice-7dc8f75df9-xjk9j 1/1 Running 0 13m
recommendationservice-cfd8c7ff-2gztd 1/1 Running 0 13m

Another pod is started immediately after a pod is stopped ensuring that there are always two pods running for each microservice in the cluster. This can be seen from the age of the pod.

10. Destroying the cluster:

eksctl delete cluster --name attractive-monster-1713964627

Remember to destroy the running cluster to avoid further charges from AWS. Replace the attractive-monster-1713964627 with your cluster name. Ensure you get such a message after running the command to ensure the cluster is successfully stopped.

2024-04-24 17:18:00 [✔]  all cluster resources were deleted

Summary

Microservices play an important role in modern large applications offering a collection of small independent services that are connected via defined APIs(Application Programming Interfaces). From the Online Boutique deployment as a microservice, we see the advantages offered including a mixed technology stack and easy maintenance of the services. The services are also loosely coupled hence they can be independently developed and deployed while isolating in case one of the services is faulty. Each service can also be scaled granularly hence ensuring they are always running.

--

--