DEV Community

Cover image for Deployed a Fully Microservices Stack on Kubernetes, AWS EKS
Muhammad Awais Zahid
Muhammad Awais Zahid

Posted on

Deployed a Fully Microservices Stack on Kubernetes, AWS EKS

Create an ec2 machine

First of all, create a ec2 machine of Ubuntu and t2.large and 30gb storage

Image description1

SSH into the machine

run following commands, get ssh of your ec2 machine and install some packages

ssh -i "pem-key.pem" ubuntu@ec2-3-88-54-141.compute-1.amazonaws.com

sudo apt update -y

sudo apt install unzip

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version

curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.19.6/2021-01-05/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version --short --client

curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version
Enter fullscreen mode Exit fullscreen mode

Create EKS-Cluster

Run the following commands to create eks-cluster

eksctl create cluster --name eksclicluster --region us-east-1 --zones us-east-1a,us-east-1b --without-nodegroup

eksctl utils associate-iam-oidc-provider --region us-east-1 --cluster eksclicluster --approve

eksctl create nodegroup --cluster=my-cluster --name=mynodegroup --region=us-east-1 --node-type=t3.medium --nodes=2 --nodes-min=2 --nodes-max=4 --node-volume-size=20 --ssh-access --ssh-public-key=pem-key --managed 
Enter fullscreen mode Exit fullscreen mode

Image description2

Configure Loadbalancer Controller

curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.17.0/docs/install/iam_policy.json

aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicy \
    --policy-document file://iam-policy.json

eksctl create iamserviceaccount \
--cluster=<cluster-name> \
--namespace=kube-system \
--name=aws-load-balancer-controller \
--attach-policy-arn=arn:aws:iam::<AWS_ACCOUNT_ID>:policy/AWSLoadBalancerControllerIAMPolicy \
--override-existing-serviceaccounts \
--region <region-code> \
--approve

helm repo add eks https://aws.github.io/eks-charts
helm repo update eks

helm install aws-load-balancer-controller eks/aws-load-balancer-controller \            
  -n kube-system \
  --set clusterName=<your-cluster-name> \
  --set serviceAccount.create=false \
  --set serviceAccount.name=aws-load-balancer-controller \
  --set region=<region> \
  --set vpcId=<your-vpc-id>

helm repo add eks https://aws.github.io/eks-charts
Enter fullscreen mode Exit fullscreen mode

EBS CSI Plugin configuration

The Amazon EBS CSI plugin requires IAM permissions to make calls to AWS APIs on your behalf.

Create an IAM role and attach a policy. AWS maintains an AWS-managed policy, or you can create your own custom policy. You can create an IAM role and attach the AWS managed policy with the following command. Replace my-cluster with the name of your cluster. The command deploys an AWS CloudFormation stack that creates an IAM role and attaches the IAM policy to it

eksctl create iamserviceaccount \
    --name ebs-csi-controller-sa \
    --namespace kube-system \
    --cluster <YOUR-CLUSTER-NAME> \
    --role-name AmazonEKS_EBS_CSI_DriverRole \
    --role-only \
    --attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
--approve

eksctl create addon --name aws-ebs-csi-driver --cluster <YOUR-CLUSTER-NAME> --service-account-role-arn arn:aws:iam::<AWS-ACCOUNT-ID>:role/AmazonEKS_EBS_CSI_DriverRole --force
Enter fullscreen mode Exit fullscreen mode

Install Application Project

Either create with HELM or use following method

# from the chart directory (where Chart.yaml is)
helm template three-tier . > all.yaml

# apply (and re-apply) like normal kubectl
kubectl apply -f all.yaml

kubectl apply -f ingress.yaml

kubectl get ingress -n default -w

Enter fullscreen mode Exit fullscreen mode

When you see an ADDRESS: k8s-...elb.amazonaws.com → your ALB is created.

User/Browser
    |
    | HTTPS
    v
AWS ALB  (created/managed by AWS Load Balancer Controller via Ingress)
    |
    v
Kubernetes Ingress (EKS)
    |
    v
Web Frontend Service
    |
    +--> Cart Service ------> Redis (StatefulSet)
    |
    +--> Catalogue Service -> MySQL ----\
    |                                    \
    +--> User Service ------> MongoDB -----> (PVCs -> EBS CSI Driver -> Amazon EBS)
    |
    +--> Ratings Service ---> MongoDB
    |
    +--> Shipping Service --> RabbitMQ <--- Dispatch Service
    |
    +--> Payment Service
Enter fullscreen mode Exit fullscreen mode

Top comments (0)