Microservices Kubernetes Project

What is microservices ?

Microservices is a software architecture pattern that involves breaking down a large, monolithic application into a collection of small, independent services that can communicate with each other through APIs. Each microservice is designed to perform a specific business function and can be deployed and scaled independently.

The main idea behind microservices is to promote flexibility, scalability, and resilience by creating a loosely coupled architecture that can adapt to changing requirements and handle failures gracefully. Microservices can be developed, tested, and deployed independently, allowing for faster release cycles and easier maintenance.

Difference Between microservices and Monolithic

The main difference between microservices and monolithic architecture is the way they are designed and structured. In a monolithic architecture, the entire application is built as a single, self-contained unit. All the components of the application, such as the user interface, business logic, and database access, are tightly coupled and run in the same process.

On the other hand, microservices architecture breaks down the application into multiple smaller services that are independently deployable and scalable. Each microservice has a specific and well-defined business function, and communicates with other services through APIs.

some key differences between microservices and monolithic architecture:

  • Scalability: Monolithic architecture scales by adding more resources (e.g., RAM, CPU) to the entire application. In contrast, microservices can scale individual services independently, depending on their usage and demand.

  • Maintainability: In a monolithic architecture, changes to one part of the application can affect other parts, making maintenance and updates more challenging. In microservices, each service can be updated and maintained independently, making it easier to manage and evolve.

  • Deployment: Monolithic architecture requires the deployment of the entire application at once, while microservices can be deployed separately, allowing for faster release cycles and easier testing.

  • Complexity: Monolithic architecture can become complex and difficult to manage as the application grows, while microservices provide a simpler, more modular approach that can be easier to understand and maintain.

Clone Source Code

you can do by this command

git clone https://github.com/harish343/k8s_microservices.git
cd k8s_microservices

Create EKS cluster

To Create cluster on eks click on create a cluster in the aws eks panel .

If you are new to creating EKS cluster I strongly recommend you watch my youtube video.

Add Node group

Create I am role for EKS

Adding users to your EKS Cluster

Let's look at the aws-auth ConfigMap before we change anything.

kubectl -n kube-system get configmap aws-auth -o yaml
apiVersion: v1
 data:
   mapRoles: |
     - groups:
       - system:bootstrappers
       - system:nodes
       rolearn: arn:aws:iam::356198252393:role/eksctl-EKSTestDrive-nodegroup-ng-NodeInstanceRole-5C1P4COCU9W1
       username: system:node:{{EC2PrivateDNSName}}

 kind: ConfigMap
 metadata:
   creationTimestamp: "2019-07-08T09:47:15Z"
   name: aws-auth
   namespace: kube-system
   resourceVersion: "719"
   selfLink: /api/v1/namespaces/kube-system/configmaps/aws-auth
   uid: 5df31bad-a165-11e9-90f3-12c84ad916b6

I am working with an IAM user with administrator rights. So, basically, I can do whatever. But I do not want to give that kind of rights to all collaborators. I will create a new IAM user called eksadmin in the AWS console. This user will not need access to the AWS console, but programmatic access will be necessary. No need to set any permissions in the creation process. No tags. Create the eksadmin user and save the credentials and IAM arn.

Edit the aws-auth configmap and add the "mapUsers" section. We will map the IAM user arn to a pre-defined systems:masters group. That group gives admin rights to our new user.

kubectl -n kube-system edit configmap aws-auth
data:
  mapRoles: |
    - groups:
      - system:bootstrappers
      - system:nodes
      rolearn: arn:aws:iam::356198252393:role/eksctl-EKSTestDrive-nodegroup-ng-NodeInstanceRole-5C1P4COCU9W1
      username: system:node:{{EC2PrivateDNSName}}
  mapUsers: |
    - userarn: arn:aws:iam::356198252393:user/eksadmin
      username: eksadmin
      groups:
        - system:masters
kind: ConfigMap
metadata:
  creationTimestamp: "2019-07-08T09:47:15Z"
  name: aws-auth
  namespace: kube-system
  resourceVersion: "4169"
  selfLink: /api/v1/namespaces/kube-system/configmaps/aws-auth
  uid: 5df31bad-a165-11e9-90f3-12c84ad916b6

Apply kubeconfig file with arn and username.

kubectl -n kube-system get configmap aws-auth -o yaml

check that all changes are applied.

I am Role for EKS cluster and EKS Node Group

To create your Amazon EKS cluster role in the IAM console

  1. Open the IAM console at https://console.aws.amazon.com/iam/.

  2. Choose Roles, then Create role.

  3. Under Trusted entity type, select AWS service.

  4. From the Use cases for other AWS services dropdown list, choose EKS.

  5. Choose EKS - Cluster for your use case, and then choose Next.

  6. On the Add permissions tab, choose Next.

  7. For Role name, enter a unique name for your role, such as eksClusterRole.

  8. For Description, enter descriptive text such as Amazon EKS - Cluster role.

  9. Choose Create role.

To check for the eksNodeRole in the IAM console

  1. Open the IAM console at https://console.aws.amazon.com/iam/.

  2. In the left navigation pane, choose Roles.

  3. Search the list of roles for eksNodeRole, AmazonEKSNodeRole, or NodeInstanceRole. If a role with one of those names doesn't exist, then see Creating the Amazon EKS node IAM role to create the role. If a role that contains eksNodeRole, AmazonEKSNodeRole, or NodeInstanceRole does exist, then select the role to view the attached policies.

  4. Choose Permissions.

  5. Ensure that the AmazonEKSWorkerNodePolicy and AmazonEC2ContainerRegistryReadOnly managed policies are attached to the role.

Nginx Ingress Controller

https://kubernetes.github.io/ingress-nginx/deploy/#aws

kubectl create clusterrolebinding cluster-admin-binding \
  --clusterrole cluster-admin \
  --user $(gcloud config get-value account)

Create deployment , services and ingress.

After some time dns address will be created.

Map dns with domain

Map your DNS address with the domain and add CNAME records.

Microservices Web app has been deployed on EKS.