original_dst cluster 定义如下:
- name: cluster1
type: ORIGINAL_DST
lb_policy: ORIGINAL_DST_LB
type
设置成 ORIGINAL_DST
,同时 lb_policy
需要设置为 ORIGINAL_DST_LB
,否则配置解析的时候会报错:
[critical][main] [external/envoy/source/server/server.cc:92] error initializing configuration 'echo2_server.yaml': cluster: cluster type 'original_dst' may only be used with LB type 'original_dst_lb'
orignal_dst cluster 获取 upstream
的 ip 信息时来源有两个,一个是由设置了 use_original_dst: true
的 listener
所初始化 Envoy::Extensions::ListenerFilters::OriginalDst::OriginalDstFilter
解析请求的 original_dst
(通常是 iptable redirect 而来):
// envoy/source/extensions/filters/listener/original_dst.cc
Network::FilterStatus OriginalDstFilter::onAccept(Network::ListenerFilterCallbacks& cb) {
ENVOY_LOG(debug, "original_dst: New connection accepted");
Network::ConnectionSocket& socket = cb.socket();
const Network::Address::Instance& local_address = *socket.localAddress();
if (local_address.type() == Network::Address::Type::Ip) {
Network::Address::InstanceConstSharedPtr original_local_address =
getOriginalDst(socket.ioHandle().fd());
// A listener that has the use_original_dst flag set to true can still receive
// connections that are NOT redirected using iptables. If a connection was not redirected,
// the address returned by getOriginalDst() matches the local address of the new socket.
// In this case the listener handles the connection directly and does not hand it off.
if (original_local_address) {
// Restore the local address to the original one.
socket.restoreLocalAddress(original_local_address);
}
}
return Network::FilterStatus::Continue;
}
另外一个是,如果 cluster
设置了 use_http_header: true
: