Overview
Discovery Service is becoming a bothering and complex issue in production, as the micro-service
architecture has been widely used. Number of services may scales, communication between services must be guranteed to be configurable, avaliable and reliable.
One of the drivers for Service Mesh
is to decouple discovery service
from app’s business logic. There are serveral open-source solutions, and this post will do comparison of them, by architecture, performance and scale. Note that although some service meshes are platform-independent and compatible with multiple enviroments, this post only focus on kubernetes environment.
Table of Content
Envoy & Pilot
Envoy interacts with Pilot to discover dynamic services. An universal data plane API, named xDS, has been introduced for envoy process to discover different grantity of services.
Envoy discovers its various dynamic resources via the filesystem or by querying one or more management servers. Collectively, these discovery services and their corresponding APIs are referred to as xDS
This envoy official post has illustrated driver and original design of xDS and its iteration form v1 to v2. The detailded xDS protocol is documented here.
You may also notice a protocol, named Mesh Config Protocol (MCP), a subscription-based configuration distribution API. However, MCP server
has been disabled by default in Galley since istio 1.15
. Apart fromMCP
, there are alternatives for pilot to get config resouce
.
It is important to know that the machanism to discover dynamic Service
and Config Resource
are different:
xDS
deals withService Discovery
, forEnvoy
to getpod
,service
,node
, andendpoint
fromPilot
.Config Resources
refers to resources likeVirtualService
,RouteRule
and other istio configurations.Istio
utilizes CRDs to represents config resource. Also remind that CRDs are registered to kubenetes apiserver via istioctl or helm (deprecated) during istio setup. ForPilot
, dynamicConfig Resources
can be got via Config Controller’s implementations as the following listed:MCP Controller
, which will not be discussed in this post.- Filesystem, for testing usage.
Kube Config Controller
, which will be covered with more details in this post, and it will be refer asConfig Controller
.

The above diagram is to illustrate interaction between Pilot
and Envoy
.
- User newly deployed service instances firstly notify paltform adaptor to register themself.
- Then pilot utilizes the abstract model to transfer platform-related metadatas to the schema it konws.
- Finally, pilot distributes these service changes.
However, remind that Platform Adaptor
, Abstract model
and Envoy API
are conceptual design that build a skeleton for internal implementation. Pilot consists of two components/binaries, pilot-discovery
and pilot-agent
.
pilot-discovery
deployed as kubernetesdeployment
.pilot-agent
runs as a process located in each sidecar container.- As the official design diagram shown below,
Discovery services
ispilot-discovery
, andàgent
ispilot-agent
correspondingly. Here are cmd arguments for pilot-discovery and pilot-agent.
Istio Pilot agent runs in the sidecar or gateway container and bootstraps Envoy.
Istio Pilot provides fleet-wide traffic management capabilities in the Istio Service Mesh.

Pilot-agent
- Its functionalty is to configures, initializes and controls
Envoy
proxy lifecycle, - It shares same image with Envoy.Thus actually within
Envoy sidecar
container, there are two running processes of two binaries,/usr/local/bin/pilot-agent
and/usr/local/bin/envoy
respectively. - Check here for source code implementation. This piece of code is simple and obvious that it contains three critical functions,
restart
,run
andcleanup
. The following description is cited from the comment:
The restart protocol matches Envoy semantics for restart epochs: to successfully launch
a new Envoy process that will replace the running Envoy processes, ...
...
Run function is a call to start the proxy and must block until the proxy exits.
...
Cleanup function is executed immediately after the proxy exits and must be non-blocking since it
is executed synchronously in the main agent control loop
Pilot-discovery
Pilot-discovery is the main process of Pilot
. The following subtopic covers functionality overview, how pilot dicover and distribute service & config, Mesh Config Protocol in detail and finally, summary.
Functionality Overview
It implements Platform Adaptor
, Abstract model
and Envoy API
functionalities:
Platform Adaptor
: Pilot provides a option for users to configure Service Registry. The concept ofService Registry
roughly means platforms likeKubernetes
andConsul
, which are service discovery systems, provideing API to inform consumer changes of service and its service endpoint. The component to handle these kinds of API isService Controller
. Another component,Config Controller
handles config resource changes API.Abstact Model
: Covert bothconfig resources
andservice
into an universal schema.Envoy API
: Pilot provides a set of gRPC APIs for service distirubution.
Config Resources & Service Discovery
-
The whole sets of CRDs for config resources can be check here, and note that this
yaml
config file is used as an input of code generating tool defined here, which generates schema here. -
Config resource can also be configured to store in a filesystem, for testing purpose, as this approach does not provide indexing, data consistency model and so on.
If FileDir is set, that directory will be monitored for CRD yaml files and will update the controller as those files change (This is used for testing purposes). Otherwise, a CRD client is created based on the config.
-
Pilot-discovery
implementsConfig Controller
andService Controller
to handle config resources changes and service changes respectively as mentioned. They both leverage kuberntes client-go, which is a RESTful client with built-in cache and queue machanism to for developer do CRUD andWatch
action for a given set of resources stroed inetcd
. WhileService Controller
implements Controller interface,Config Controller
implements ConfigStoreCache interface, and both of them enable handler register, so that event handlers for config and service updates can be set up. Remind that these event handler functions are critical that it sends wrap updates to a defined data structure and send them to the gRPC server using channel. -
Config Controller
's implementation, source code here, loads all CRDs that pilot needs, which has been registered to kubernetes apiserver before. Then here it creates dedicated goroutine(roughly 23+ goroutines) to subscribe to different config resource. -
Service Controller
source code here handle service changes. Its Run function has created 4 goroutines forsharedInformers
ofPod
,Node
,Service
andEndpoint
correspondingly. -
Kubernetes
CRD
,Client-go
, andController
machanism can be check in another post of mine.
Service Distribution
-
For
Envoy API
,pilot-discovery
launches a gRPC server here in a goroutine to serve service. Http servers has also been started here as seperated goroutines, for and readiness probe and k8s webhook usage. -
EnvoyXdsServer
, the core implementation of the gRPC server:- Protobuf used is defined here, it generates golang interfaces that the discovery service should implement.
pilot
's gRPC server implements these interfaces in here , for ADS handling.- The registered handle functions here are passing service and config updates from
Service Controller
andConfig Controller
toEnvoyXdsServer
using golang channel, and then let the gRPC server push these updates to consumer asMCP
designed. - 3 goroutines are created here for updates handling, pushing, and metric.
xDS In Detail
After illustration of how service and config from kubernetes apiserver
to pilot-discovery
. It comes to the most sophisticated part, the xDS, which play an important role in service distribution and it may bring performance impact, e.g. endpoint push. Also incremental xDS will be discussed.
Summary
We can see that pilot
handle service and config from kuberntes to envoy
. The full path can be described as :
gRPC RESTful gRPC
Etcd ---> Kubernetes Apiserver ---> Pilot ---> Envoy
Linkerd2-proxy
// linkerd soluction of xds