Service discovery
Service discovery extracts all the potentially useful information from different sources, converts it to the configurations and exports them to the different destinations.
Pipeline#
The service discovery pipeline has four jobs:
- discovery: dynamically discovers targets.
- tag: tags discovered targets.
- build: creates configuration files from the targets.
- export: exports configurations.
Routing in a job and between jobs based on tags and selector.
Pipeline configuration:
Tags and selectors#
Tag, build and export jobs have selector, the pipeline routes a target/config to the job only if its tags matches job
selectors.
Both tags and selector are just lists of words.
A word must match the regex ^[a-zA-Z][a-zA-Z0-9=_.]*$.
Tags special cases:
-word: the word will be removed on tags merging.
Selectors special cases:
!word: should not contain the word.word|word|word: should contain any word.
Discovery#
Discovery job dynamically discovers targets using one of the supported service-discovery mechanisms.
Supported mechanisms:
Discovery configuration:
Kubernetes#
Kubernetes discoverer retrieves targets from Kubernetes' REST API. It always stays synchronized with the cluster state.
Kubernetes discovery configuration options:
One of the following role types can be configured to discover targets:
podservice
Pod Role#
The pod role discovers all pods and exposes their containers as targets. For each declared port of a container, it
generates single target. If there is no declared port it generates one target with empty Port, PortName
and PortProtocol fields.
Available pod target fields:
| Name | Type | Value |
|---|---|---|
TUID | string | Namespace_Name_ContName_PortProtocol_Port |
Address | string | PodIP:Port |
Namespace | string | pod.metadata.namespace |
Name | string | pod.metadata.name |
Annotations | map[string]string | pod.metadata.annotations |
Labels | map[string]string | pod.metadata.labels |
NodeName | string | pod.spec.nodeName |
PodIP | string | pod.status.podIP |
ContName | string | pod.spec.containers.name |
Image | string | pod.spec.containers.image |
Env | map[string]string | pod.spec.containers.env + pod.spec.containers.envFrom |
Port | string | pod.spec.containers.ports.containerPort |
PortName | string | pod.spec.containers.ports.name |
PortProtocol | string | pod.spec.containers.ports.protocol |
Service Role#
The service role discovers a target for each service port for each service.
Available service target fields:
| Name | Type | Value |
|---|---|---|
TUID | string | Namespace_Name_PortProtocol_Port |
Address | string | Name.Namespace.svc:Port |
Namespace | string | svc.metadata.namespace |
Name | string | svc.metadata.name |
Annotations | map[string]string | svc.metadata.annotations |
Labels | map[string]string | svc.metadata.labels |
Port | string | pod.spec.containers.ports.containerPort |
PortName | string | pod.spec.containers.ports.name |
PortProtocol | string | pod.spec.containers.ports.protocol |
ClusterIP | string | svc.spec.clusterIP |
ExternalName | string | svc.spec.externalName |
Type | string | svc.spec.ports.type |
Tag#
Tag job tags targets discovered by discovery job. Its purpose is service identification.
Configuration is a list of tag rules:
Tag rule configuration options:
Match expression evaluation result should be true or false.
Expression syntax is go-template.
Available functions#
- go-template built-in functions.
- sprig functions.
- custom functions.
Custom functions:
globreports whether arg1 matches the shell file name pattern.rereports whether arg1 contains any match of the regular expression pattern.
All these functions accepts two or more arguments, returning in effect:
func(arg1, arg2) || func(arg1, arg3) || func(arg1, arg4) ...
Build#
Build job creates configurations from targets.
Configuration is a list of build rules:
Build rule configuration options:
Template syntax is go-template.
Available functions#
- go-template built-in functions.
- sprig functions.
- custom functions.
Custom functions:
globreports whether arg1 matches the shell file name pattern.rereports whether arg1 contains any match of the regular expression pattern.
All these functions accepts two or more arguments, returning in effect:
func(arg1, arg2) || func(arg1, arg3) || func(arg1, arg4) ...
Export#
Export job exports configurations built by build job.
Supported exporters:
file
Export configuration:
File#
File exporter writes configurations to a specific file.
Troubleshooting#
Service-discovery has debug mode and special stdout exporter which is enabled only when it's running from the
terminal.
CLI: