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.
#
PipelineThe 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 selectorsTag, 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.
#
DiscoveryDiscovery job dynamically discovers targets using one of the supported service-discovery mechanisms.
Supported mechanisms:
Discovery configuration:
#
KubernetesKubernetes 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:
pod
service
#
Pod RoleThe 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 RoleThe 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 |
#
TagTag 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:
glob
reports whether arg1 matches the shell file name pattern.re
reports 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) ...
#
BuildBuild 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:
glob
reports whether arg1 matches the shell file name pattern.re
reports 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) ...
#
ExportExport job exports configurations built by build job.
Supported exporters:
file
Export configuration:
#
FileFile exporter writes configurations to a specific file.
#
TroubleshootingService-discovery has debug mode and special stdout
exporter which is enabled only when it's running from the
terminal.
CLI: