简体   繁体   English

使用 helm 和 kubernetes 的微服务结构

[英]Microservice structure using helm and kubernetes

We have several microservices(NodeJS based applications) which needs to communicate each other and two of them uses Redis and PostgreSQL.我们有几个需要相互通信的微服务(基于 NodeJS 的应用程序),其中两个使用 Redis 和 PostgreSQL。 Below are the name of of my microservices.以下是我的微服务的名称。 Each of them has their own SCM repository and Helm Chart.Helm version is 3.0.1.他们每个人都有自己的 SCM 存储库,Helm Chart.Helm 版本是 3.0.1。 We have two environments and we have two values.yaml per environments.We have also three nodes per cluster.我们有两个环境,每个环境有两个 values.yaml。每个集群也有三个节点。

First of all, after end user's action, UI service triggers than it goes to Backend.首先,在最终用户的操作之后,UI 服务会触发而不是去后端。 According to the end user request Backend services needs to communicate any of services such as Market, Auth and API.Some cases API and market microservice needs to communicate with Auth microservice as well.根据最终用户的请求,后端服务需要与Market、Auth、API等任何服务进行通信。在某些情况下,API和market微服务也需要与Auth微服务进行通信。

  1. UI -->用户界面-->
  2. Backend后端
  3. Market --> use postgreSQL市场 --> 使用 postgreSQL
  4. Auth --> use Redis身份验证 --> 使用 Redis
  5. API应用程序接口

So my questions are,所以我的问题是,

  • What should we take care to communicate microservices among each other?我们应该注意哪些微服务之间的通信? Is this my-svc-namespace.svc.cluster.local enough to provide developers or should we specify ENV in each pod as well?这个my-svc-namespace.svc.cluster.local足以为开发人员提供,或者我们应该在每个 pod 中指定 ENV 吗?

  • Our microservices is NodeJS application.我们的微服务是 NodeJS 应用程序。 How developers.开发商如何。 will handle this in application source code?会在应用程序源代码中处理这个吗? Did they use this service name if first question's answer is yes?如果第一个问题的答案是肯定的,他们是否使用了这个服务名称?

  • We'd like to expose our application via ingress using host per environments?我们想使用每个环境的主机通过入口公开我们的应用程序? I guess ingress should be only enabled for UI microservice, am I correct?我猜应该只为 UI 微服务启用入口,对吗?

  • What is the best way to test each service can communicate each other?测试每个服务可以相互通信的最佳方法是什么?


kubectl get svc --all-namespaces

NAMESPACE     NAME                                         TYPE            

database      my-postgres-postgresql-helm                  ClusterIP                      
dev           my-ui-dev                                    ClusterIP 
dev           my-backend-dev                               ClusterIP 
dev           my-auth-dev                                  ClusterIP                 
dev           my-api-dev                                   ClusterIP 
dev           my-market-dev                                ClusterIP
dev           redis-master                                 ClusterIP                       
ingress       ingress-traefik                              NodePort            

Two ways to perform Service Discovery in K8S在 K8S 中执行服务发现的两种方式

There are two ways to perform communication (service discovery) within a Kubernetes cluster.在 Kubernetes 集群中有两种执行通信(服务发现)的方法。

DNS is the simplest way to achieve service discovery within the cluster. DNS 是在集群内实现服务发现的最简单方式。 And it does not require any additional ENV variable setting for each pod.并且它不需要为每个 pod 设置任何额外的 ENV 变量。 As its simplest, a service within the same namespace is accessible over its service name.最简单的是,可以通过其服务名称访问同一名称空间中的服务。 eg http://my-api-dev:PORT is accessible for all the pods within the namespace, dev .例如http://my-api-dev:PORT可被命名空间dev所有 pod 访问。

Standard Application Name and K8s Service Name标准应用名称和 K8s 服务名称

As a practice, you can give each application a standard name, eg.作为一种实践,您可以为每个应用程序指定一个标准名称,例如。 my-ui , my-backend , my-api , etc. And use the same name to connect to the application. my-uimy-backendmy-api等。并使用相同的名称连接到应用程序。 That practice can be even applied testing locally from developer environment, with entry in the /etc/host as这种做法甚至可以从开发人员环境在本地应用测试,在/etc/host

127.0.0.1 my-ui my-backend my-api

(Above is nothing to do with k8s, just a practice for the communication of applications with their names in local environments) (以上与k8s无关,只是应用程序在本地环境中与其名称通信的一种实践)

Also, on k8s, you may assign service name as the same application name (Try to avoid, suffix like -dev for service name, which reflect the environments (dev, test, prod, etc), instead use namespace or separate cluster for that).此外,在 k8s 上,您可以将服务名称分配为相同的应用程序名称(尽量避免,服务名称后缀如-dev ,反映环境(开发、测试、生产等),而不是使用命名空间或单独的集群)。 So that, target application endpoints can be configured with their service name on each application's configuration file.因此,目标应用程序端点可以在每个应用程序的配置文件中使用它们的服务名称进行配置。

Ingress is for services with external access Ingress 用于具有外部访问权限的服务

Ingress should only be enabled for services which required external accesses.应该只为需要外部访问的服务启用 Ingress。

Custom Health Check Endpoints自定义健康检查端点

Also, it is a good practice to have some custom health check that verify all the depended applications are running fine, which will also verify the communications of application are working fine.此外,进行一些自定义运行状况检查以验证所有依赖的应用程序是否正常运行也是一种很好的做法,这也将验证应用程序的通信是否正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM