apache dubbo gateway,L7 proxy,virtual host,k8s ingress controller.

dubbo 七层网关

dubbo 消费者请求统一经过网关,网关根据目标提供者application.name作为虚拟 host 进行转发,以复用同一端口,降低手动管理 dubbo 提供者服务端口的复杂度。

注:目前仅适用于开发环境

架构图

背景

由于公司内部所有服务都是跑在阿里云 k8s 上的,如果我们本地开发需要访问 k8s 内的 dubbo 提供者服务的话,需要手动通过k8s service把服务暴露到外网,我们的做法是针对每一个提供者服务暴露一个SLB IP+自定义端口,并且通过 dubbo 提供的DUBBO_IP_TO_REGISTRYDUBBO_PORT_TO_REGISTRY环境变量来把对应的SLB IP+自定义端口注册到注册中心里,可是好景不长,当 dubbo 提供者服务越来越多时,会发现这种方式管理起来会带来不小的麻烦。

于是我就在想能不能像nginx一样实现一个七层负载,通过目标提供者的application.name来做对应的转发,这样的话所有的服务只需要注册同一个SLB IP+端口就可以了,然后本项目就诞生了!

使用说明

0. 前置要求

  • dubbo 3.0+
  • dubbo 协议+hession 序列化

1. 安装dubbo-ingress-controller

下载本项目中的deploy.yaml,然后执行命令:

kubectl apply -f deploy.yaml

2. 暴露dubbo-ingress-controller服务到外网

可以通过NodePortSLB等方式进行暴露,暴露出来的外网IP+端口就是需要上报到注册中心的地址。

3. 创建服务对应的 ingress

为每个提供者服务创建对应的 ingress 资源,示例:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: user-rpc-ingress
  annotations:
    kubernetes.io/ingress.class: "dubbo"
spec:
  rules:
    - host: user-rpc
      http:
        paths:
          - backend:
              serviceName: user-rpc-service
              servicePort: 20880
            path: /

这里有几点需要注意:

  1. kubernetes.io/ingress.class注解目前固定为dubbo
  2. host为 dubbo 提供者的application.name
  3. backend.serviceName和backend.servicePort是 dubbo 提供者服务暴露的service

4. 消费者添加自定义 Filter

由于默认请求下,dubbo 请求不会携带目标提供者的application.name,为此我特意向 dubbo 官方提了个issue,那边提供的建议是通过自定义Filter来实现,附代码:

import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;


@Activate(group = CONSUMER)
public class AddTargetFilter implements Filter {

  @Override
  public Result invoke(Invoker invoker, Invocation invocation) throws RpcException {
    String targetApplication = StringUtils.isBlank(invoker.getUrl().getRemoteApplication()) ?
        invoker.getUrl().getGroup() : invoker.getUrl().getRemoteApplication();
    invocation.setAttachment("target-application", targetApplication);
    return invoker.invoke(invocation);
  }
}

添加dubbo SPI配置文件META-INF/dubbo/org.apache.dubbo.rpc.Filter,配置该 Filter。

5. 提供者启动时注入对应环境变量

通过环境变量将 dubbo ingress controller 暴露的外网 IP 和端口注册到注册中心,示例:

DUBBO_IP_TO_REGISTRY=8.8.8.8
DUBBO_PORT_TO_REGISTRY=20880

一切准备就绪之后,就可以在本地启动消费者进行 dubbo 服务调用了。

Owner
Full-stack developer, author of proxyee-down.
null
Similar Resources

Apache Traffic Control is an Open Source implementation of a Content Delivery Network

Apache Traffic Control Apache Traffic Control is an Open Source implementation of a Content Delivery Network. Documentation Intro CDN Basics Traffic C

Jan 6, 2023

Message relay written in golang for PostgreSQL and Apache Kafka

Message Relay Message relay written in golang for PostgreSQL and Apache Kafka Requirements Docker and Docker Compose Local installation and using dock

Dec 19, 2021

CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed.

CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed.

CoreRAD CoreRAD is an extensible and observable IPv6 Neighbor Discovery Protocol router advertisement daemon. Apache 2.0 Licensed. To get started with

Nov 14, 2022

This project provides fully automated one-click experience to create Cloud and Kubernetes environment to run Data Analytics workload like Apache Spark.

This project provides fully automated one-click experience to create Cloud and Kubernetes environment to run Data Analytics workload like Apache Spark.

Introduction This project provides a fully automated one-click tool to create Data Analytics platform in Cloud and Kubernetes environment: Single scri

Nov 25, 2022

An experimental Tor-Proxy serivce written in Go using Go-proxy and Go-libtor.

tor-proxy An experimental standalone tor-proxy service built with Go, using go-proxy, go-libtor and bine. This is a simple replacement to Tor's origin

Nov 9, 2022

mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together

mt-multiserver-proxy mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together. It is the successor to multiserv

Nov 17, 2022

A simple tool to convert socket5 proxy protocol to http proxy protocol

Socket5 to HTTP 这是一个超简单的 Socket5 代理转换成 HTTP 代理的小工具。 如何安装? Golang 用户 # Required Go 1.17+ go install github.com/mritd/s2h@master Docker 用户 docker pull m

Jan 2, 2023

IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

IP2Proxy Go Package This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data

Sep 15, 2022
LazySSH is an SSH server that acts as a jump host only, and dynamically starts temporary virtual machines.

LazySSH is an SSH server that acts as a jump host only, and dynamically starts temporary virtual machines. If you find yourself briefly starti

Dec 11, 2022
The Durudex gateway combines all durudex services so that it can be used through a single gateway.

The Durudex gateway combines all durudex services so that it can be used through a single gateway.

Dec 13, 2022
Grpc-gateway-map-null - gRPC Gateway test using nullable values in map

Demonstrate gRPC gateway behavior with nullable values in maps Using grpc-gatewa

Jan 6, 2022
Read k8S-source-code notes, help quickly understand the K8S-code organization rules
Read k8S-source-code notes, help quickly understand the K8S-code organization rules

K8S源码阅读笔记 以下笔记针对 kubernetes V1.23.1(截至2022年01月01日最新版本),并不保证对其它版本的有效性 一、架构图 二、阅读前准备 由于kubernetes项目巧妙的设计和代码高度的封装性,建议在阅读代码前,尽可能的进行以下内容的准备: 1. 编程知识配备 编程语准

Feb 16, 2022
Traefik plugin to proxy requests to owasp/modsecurity-crs:apache container
Traefik plugin to proxy requests to owasp/modsecurity-crs:apache container

Traefik Modsecurity Plugin Traefik plugin to proxy requests to owasp/modsecurity-crs:apache Traefik Modsecurity Plugin Demo Full Configuration with do

Dec 27, 2022
Proxy your Go Module`s Import Path from your own domain to a public host (e.g. github.com).

Go Modules Remote Import Path Proxy Proxy your Go Module`s Import Path from your own domain to a public host (e.g. github.com). For example Uber (buil

Nov 2, 2021
Automatic AWS Security Group ingress through DDNS

Auto DDNS Security Lambda Update AWS Security Group rules to an IP resolved from a DNS hostname. Useful to dynamically allow ingress from a DDNS hostn

Oct 19, 2021
Apache RocketMQ go client

RocketMQ Client Go A product ready RocketMQ Client in pure go, which supports almost the full features of Apache RocketMQ, such as pub and sub message

Jan 4, 2023
Paster 服务端核心模块,使用字节跳动开源的微服务 RPC 框架 KiteX ,以 Apache Thrift 作为通信协议
Paster 服务端核心模块,使用字节跳动开源的微服务 RPC 框架 KiteX ,以 Apache Thrift 作为通信协议

paster_core Paster 服务端核心模块,使用字节跳动开源的微服务 RPC 框架 KiteX ,以 Apache Thrift 作为通信协议。 Todo: 实现 KiteX 服务注册扩展接口,使用 Consul 服务注册 新增 frame 层,通过 PreProcessor, PostP

Aug 4, 2022