Coder Social home page Coder Social logo

mimic-micro-service's Introduction

This is a test project where I trying to build(mimicking) a small microservice frontend ๐Ÿ’–

Before integrate Kubernetes ๐Ÿ˜‡

service ENDPOINT available HTTP method description
http://localhost:4000 GET/POST post service: get all posts and create a post
http://localhost:4001 GET/POST comment service: get all comments and create a comment
http://localhost:4002 GET/POST query service: combine post and comment data
http://localhost:4003 POST moderation service: watch 'commentCreated' event
http://localhost:4005 GET/POST eventbus service: watch event and dispatch event
http://localhost:3000 - frontend

After integrate Kubernetes with ingress-nginx tweaking with localhost into posts.com ๐Ÿ˜ต

spec:
  rules:
    - host: posts.com 
      http: 
        paths: 
          - path: /posts/create
            backend: 
              serviceName: posts-clusterip-srv
              servicePort: 4000
          - path: /posts
            backend: 
              serviceName: query-srv
              servicePort: 4002
          - path: /posts/?(.*)/comments
            backend: 
              serviceName: comments-srv
              servicePort: 4001
          - path: /?(.*)
            backend:
              serviceName: client-srv 
              servicePort: 3000

What is kubernetes?

Detail

Kubernetes enable you to use the cluster as if it is signle PC. You donโ€™t need to care the detail of the infrastructure. Just declare the what you want in yaml file, you will get what you want.

  • When you use Kubernetes, you can use kubectl command to control the kubernetes cluster
  • If you want to orchestrate the container in Kubernetes, you can use yaml file
  • A pod is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers
  • A Deployment controller provides declarative updates for Pods and ReplicaSets
  • A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them - sometimes called a micro-service
  • Kubernetes Pods are mortal. They are born and when they die, they are not resurrected. If you use a Deployment to run your app, it can create and destroy Pods dynamically
  • Each Pod gets its own IP address, however, in a Deployment, the set of Pods running in one moment in time could be different from the set of Pods running that application a moment later

This leads to a problem: if some set of Pods (call them โ€œbackendsโ€) provides functionality to other Pods (call them โ€œfrontendsโ€) inside your cluster, how do the frontends find out and keep track of which IP address to connect to, so that the frontend can use the backend part of the workload? Here come Services

Kubernetes has several Master nodes and Worker nodes. Your containers work on Worker nodes. Worker nodes scales. Once you deploy kubernetes resources using Yaml file with kubectl command, it send Post request to the API server. The API server store the data into ectd(is a distributed reliable key-value store for the most critical data of a distributed system), which is the distributed key value store. Other resources like Controller Manager, Scheduler, observe the change state of the API server. When you create a some.yaml file with a deployment then kubectl create -f some.yaml It send the yaml data to the API Server. It create a Deployment object on the API Server. Deployment controller detect the change of the deployment, it create ReplicaSet object on the API Server. The Replica Set Controller detect the change then according to the number of replica, create Pod objects. The Scheduler, that is in charge of the pod resource allocation, commnd the kubelet, which reside on every worker nodes, execute docker command and create containers. Every worker nodes have a kube proxy to control the routing. For example, If you create a service object on the API Server, Endpoint Controller create an Endpoint object on the API Server. Kube Proxy watch the API server Endpoint state, then configure iptable to route the endpoint to the container.

Bad things with this Application

  • flow of events inside this application is important. ๐Ÿ˜ง
  • If commentCreated Event reach before postCreated event then our entire application will break. ๐Ÿ˜ฅ

Things I learnt via this project

Promise.allSettled(promises)

axios concurrent mode link

Kubernetes Dashboard link

Updating the image used by Kubernetes deployment object

  • The deployment must be using the 'latest' tag in the pod spec
  • Make an update to your code
  • Build the image
  • Push the image to docker hub
  • Run kubectl rollout restart deployment <deployment_name>

To make connection with different pods/deployments

  • Create a service
  • Change API endpoint inside container as other container are running as pod/deployment now (http://localhostservice_name:port)

Install tree.exe to print directory in windows machine ๐Ÿ˜

remaining Issues to fix ๐Ÿ˜–

  • when event bus got error at axios.post() then it haunt the process that why comment is not moderated after the query server alive That Solved by Promise.allSettled(promises)
  • need refresh to fetch updated data in react application

mimic-micro-service's People

Contributors

emonhossainraihan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.