MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 21 as of 2022-05-20 19:32:57
  • MicroServices

MicroServices

https://dzone.com/articles/microservices-communication-zuul-api-gateway-1 The crux of the microservices pattern is to create an independent service which can be scaled and deployed independently.

  • http://microservices.io/patterns/index.html

  • Monolithic architecture - architect an application as a single deployable unit

  • Microservice architecture - architect an application as a collection of loosely coupled, services

  • Decompose by business capability - define services corresponding to business capabilities

  • Remote Procedure Invocation - use an RPI-based protocol for inter-service communication (RMI, .Net Remoting , REST (JSON), SOAP (XML)

  • Messaging - use asynchronous messaging for inter-service communication (JMS, RabbitMQ, Message broker)

  • API gateway - a service that provides each client with unified interface to services

  • Client-side discovery - client queries a service registry to discover the locations of service instances

  • Server-side discovery - router queries a service registry to discover the locations of service instances

  • Service registry - a database of service instance locations

  • Self registration - service instance registers itself with the service registry

  • Circuit Breaker - invoke a remote service via a proxy that fails immediately when the failure rate of the remote call exceeds a threshold

  • Command Query Responsibility Segregation (CQRS) - Split the application into two parts: the command-side and the query-side. The command-side handles create, update, and delete requests and emits events when data changes. The query-side handles queries by executing them against one or more materialized views that are kept up to date by subscribing to the stream of events emitted when data changes. CRUD, command handles CUD and query the R.

Base components

  • service registry (service instances locations)
    • eureka 1.x Services register with Eureka and then send heartbeats to renew their leases every 30 seconds.
  • service instance (instances on demand)
  • api gateway (route requests to service instances) zuul
  • https://thenewstack.io/api-gateways-age-microservices/

kubernetes

  • https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

Kubernetes has a number of features. It can be thought of as:

  • a container platform
  • a microservices platform
  • a portable cloud platform and a lot more.

Kubernetes provides a container-centric management environment. It orchestrates computing, networking, and storage infrastructure on behalf of user workloads. This provides much of the simplicity of Platform as a Service (PaaS) with the flexibility of Infrastructure as a Service (IaaS), and enables portability across infrastructure providers.

The New Way is to deploy containers based on operating-system-level virtualization rather than hardware virtualization. These containers are isolated from each other and from the host: they have their own filesystems, they can’t see each others’ processes, and their computational resource usage can be bounded. They are easier to build than VMs, and because they are decoupled from the underlying infrastructure and from the host filesystem, they are portable across clouds and OS distributions.

Loosely coupled, distributed, elastic, liberated micro-services: Applications are broken into smaller, independent pieces and can be deployed and managed dynamically – not a monolithic stack running on one big single-purpose machine.

  • https://kubernetes.io/docs/setup/

You can run Kubernetes almost anywhere, from your laptop to VMs on a cloud provider to a rack of bare metal servers A local-machine solution is an easy way to get started with Kubernetes. You can create and test Kubernetes clusters without worrying about consuming cloud resources and quotas.

Community Supported Tools

  • Minikube is a method for creating a local, single-node Kubernetes cluster for development and testing. Setup is completely automated and doesn’t require a cloud provider account.
  • Kubeadm-dind is a multi-node (while minikube is single-node) Kubernetes cluster which only requires a docker daemon. It uses docker-in-docker technique to spawn the Kubernetes cluster.
  • Kubernetes IN Docker is a tool for running local Kubernetes clusters using Docker container “nodes”. It is primarily designed for testing Kubernetes 1.11+. You can use it to create multi-node or multi-control-plane Kubernetes clusters

Install kubectl centos

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl

Install kubectl binary using curl

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Spring cloud Netflix

  • https://spring.io/projects/spring-cloud-netflix

  • Zuul - API Gateway
  • Eureka - service registry
  • Hystrix - circuit breaker

As long as Spring Cloud Netflix and Eureka Core are on the classpath any Spring Boot application with @EnableEurekaClient will try to contact a Eureka server on http://localhost:8761 (the default value of eureka.client.serviceUrl.defaultZone):

Eureka server on http://eureka:8761. To run your own server use the spring-cloud-starter-netflix-eureka-server dependency and @EnableEurekaServer.

  • https://hub.docker.com/r/springcloud/eureka

Need to add @EnableZuulProxy annotation to the Main class to make this project a Zuul proxy server.

Zuul is a JVM-based router and server-side load balancer from Netflix.

Eureka + Spring Cloud gateway

microservice

pom.xml

   1 <?xml version="1.0" encoding="UTF-8"?>
   2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   3     <modelVersion>4.0.0</modelVersion>
   4     <groupId>bitarus.allowed.org</groupId>
   5     <artifactId>chucknorris</artifactId>
   6     <version>0.1.0</version>
   7     <parent>
   8         <groupId>org.springframework.boot</groupId>
   9         <artifactId>spring-boot-starter-parent</artifactId>
  10         <version>2.6.7</version>
  11     </parent>
  12     <dependencies>
  13         <dependency>
  14             <groupId>org.springframework.boot</groupId>
  15             <artifactId>spring-boot-starter-actuator</artifactId>
  16         </dependency>
  17         <dependency>
  18             <groupId>org.springframework.boot</groupId>
  19             <artifactId>spring-boot-starter-thymeleaf</artifactId>
  20         </dependency>
  21         <dependency>
  22             <groupId>org.springframework.boot</groupId>
  23             <artifactId>spring-boot-starter-web</artifactId>
  24         </dependency>
  25         <dependency>
  26             <groupId>org.springframework.cloud</groupId>
  27             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  28             <version>3.1.2</version>
  29         </dependency>
  30         <dependency>
  31             <groupId>com.google.code.gson</groupId>
  32             <artifactId>gson</artifactId>
  33             <version>2.9.0</version>
  34             <scope>compile</scope>
  35         </dependency>
  36     </dependencies>
  37     <properties>
  38         <start-class>chucknorris.bitarus.allowed.org.Application</start-class>
  39     </properties>
  40     <build>
  41         <plugins>
  42             <plugin>
  43                 <groupId>org.springframework.boot</groupId>
  44                 <artifactId>spring-boot-maven-plugin</artifactId>
  45             </plugin>
  46         </plugins>
  47     </build>
  48     <repositories>
  49         <repository>
  50             <id>spring-milestone</id>
  51             <url>http://repo.spring.io/libs-release</url>
  52         </repository>
  53     </repositories>
  54     <pluginRepositories>
  55         <pluginRepository>
  56             <id>spring-milestone</id>
  57             <url>http://repo.spring.io/libs-release</url>
  58         </pluginRepository>
  59     </pluginRepositories>
  60 </project>
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01