This is the multi-page printable view of this section.
Click here to print.
Return to the regular view of this page.
Name resolution provider component specs
The supported name resolution providers to enable Dapr service invocation
The following components provide name resolution for the service invocation building block.
Name resolution components are configured via the configuration.
Table headers to note:
Header |
Description |
Example |
Status |
Component certification status |
Alpha
Beta
Stable
|
Component version |
The version of the component |
v1 |
Since runtime version |
The version of the Dapr runtime when the component status was set or updated |
1.11 |
Generic
Component |
Status |
Component version |
Since runtime version |
<tr>
<td><a href="/reference/components-reference/supported-name-resolution/setup-nr-consul/">HashiCorp Consul</a>
</td>
<td>Alpha</td>
<td>v1</td>
<td>1.2</td>
</tr>
<tr>
<td><a href="/reference/components-reference/supported-name-resolution/nr-sqlite/">SQLite</a>
</td>
<td>Alpha</td>
<td>v1</td>
<td>1.13</td>
</tr>
Kubernetes
Component |
Status |
Component version |
Since runtime version |
<tr>
<td><a href="/reference/components-reference/supported-name-resolution/nr-kubernetes/">Kubernetes</a>
</td>
<td>Stable</td>
<td>v1</td>
<td>1.0</td>
</tr>
Self-Hosted
Component |
Status |
Component version |
Since runtime version |
<tr>
<td><a href="/reference/components-reference/supported-name-resolution/nr-mdns/">mDNS</a>
</td>
<td>Stable</td>
<td>v1</td>
<td>1.0</td>
</tr>
1 - HashiCorp Consul
Detailed information on the HashiCorp Consul name resolution component
Hashicorp Consul is setup within the Dapr Configuration.
Within the config, add a nameResolution
spec and set the component
field to "consul"
.
If you are using the Dapr sidecar to register your service to Consul then you will need the following configuration:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
nameResolution:
component: "consul"
configuration:
selfRegister: true
If Consul service registration is managed externally from Dapr you need to ensure that the Dapr-to-Dapr internal gRPC port is added to the service metadata under DAPR_PORT
(this key is configurable) and that the Consul service Id matches the Dapr app Id. You can then omit selfRegister
from the config above.
Behaviour
On init
the Consul component either validates the connection to the configured (or default) agent or registers the service if configured to do so. The name resolution interface does not cater for an “on shutdown” pattern so consider this when using Dapr to register services to Consul as it does not deregister services.
The component resolves target apps by filtering healthy services and looks for a DAPR_PORT
in the metadata (key is configurable) in order to retrieve the Dapr sidecar port. Consul service.meta
is used over service.port
so as to not interfere with existing Consul estates.
Spec configuration fields
The configuration spec is fixed to v1.3.0 of the Consul API
Field |
Required |
Type |
Details |
Examples |
Client |
N |
*api.Config |
Configures client connection to the Consul agent. If blank it will use the sdk defaults, which in this case is just an address of 127.0.0.1:8500 |
10.0.4.4:8500 |
QueryOptions |
N |
*api.QueryOptions |
Configures query used for resolving healthy services, if blank it will default to UseCache:true |
UseCache: false , Datacenter: "myDC" |
Checks |
N |
[]*api.AgentServiceCheck |
Configures health checks if/when registering. If blank it will default to a single health check on the Dapr sidecar health endpoint |
See sample configs |
Tags |
N |
[]string |
Configures any tags to include if/when registering services |
- "dapr" |
Meta |
N |
map[string]string |
Configures any additional metadata to include if/when registering services |
DAPR_METRICS_PORT: "${DAPR_METRICS_PORT}" |
DaprPortMetaKey |
N |
string |
The key used for getting the Dapr sidecar port from Consul service metadata during service resolution, it will also be used to set the Dapr sidecar port in metadata during registration. If blank it will default to DAPR_PORT |
"DAPR_TO_DAPR_PORT" |
SelfRegister |
N |
bool |
Controls if Dapr will register the service to Consul. The name resolution interface does not cater for an “on shutdown” pattern so please consider this if using Dapr to register services to Consul as it will not deregister services. If blank it will default to false |
true |
AdvancedRegistration |
N |
*api.AgentServiceRegistration |
Gives full control of service registration through configuration. If configured the component will ignore any configuration of Checks, Tags, Meta and SelfRegister. |
See sample configs |
Sample configurations
Basic
The minimum configuration needed is the following:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
nameResolution:
component: "consul"
Registration with additional customizations
Enabling SelfRegister
it is then possible to customize the checks, tags and meta
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
nameResolution:
component: "consul"
configuration:
client:
address: "127.0.0.1:8500"
selfRegister: true
checks:
- name: "Dapr Health Status"
checkID: "daprHealth:${APP_ID}"
interval: "15s"
http: "http://${HOST_ADDRESS}:${DAPR_HTTP_PORT}/v1.0/healthz"
- name: "Service Health Status"
checkID: "serviceHealth:${APP_ID}"
interval: "15s"
http: "http://${HOST_ADDRESS}:${APP_PORT}/health"
tags:
- "dapr"
- "v1"
- "${OTHER_ENV_VARIABLE}"
meta:
DAPR_METRICS_PORT: "${DAPR_METRICS_PORT}"
DAPR_PROFILE_PORT: "${DAPR_PROFILE_PORT}"
daprPortMetaKey: "DAPR_PORT"
queryOptions:
useCache: true
filter: "Checks.ServiceTags contains dapr"
Advanced registration
Configuring the advanced registration gives you full control over setting all the Consul properties possible when registering.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
nameResolution:
component: "consul"
configuration:
client:
address: "127.0.0.1:8500"
selfRegister: false
queryOptions:
useCache: true
daprPortMetaKey: "DAPR_PORT"
advancedRegistration:
name: "${APP_ID}"
port: ${APP_PORT}
address: "${HOST_ADDRESS}"
check:
name: "Dapr Health Status"
checkID: "daprHealth:${APP_ID}"
interval: "15s"
http: "http://${HOST_ADDRESS}:${DAPR_HTTP_PORT}/v1.0/healthz"
meta:
DAPR_METRICS_PORT: "${DAPR_METRICS_PORT}"
DAPR_PROFILE_PORT: "${DAPR_PROFILE_PORT}"
tags:
- "dapr"
Setup HashiCorp Consul
HashiCorp offer in depth guides on how to setup Consul for different hosting models. Check out the self-hosted guide here
HashiCorp offer in depth guides on how to setup Consul for different hosting models. Check out the Kubernetes guide here
2 - Kubernetes DNS
Detailed information on the Kubernetes DNS name resolution component
Generally, Kubernetes DNS name resolution is configured automatically in Kubernetes mode by Dapr. There is no configuration needed to use Kubernetes DNS as your name resolution provider unless some overrides are necessary for the Kubernetes name resolution component.
In the scenario that an override is required, within a Dapr Configuration CRD, add a nameResolution
spec and set the component
field to "kubernetes"
. The other configuration fields can be set as needed in a configuration
map, as seen below.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
nameResolution:
component: "kubernetes"
configuration:
clusterDomain: "cluster.local" # Mutually exclusive with the template field
template: "{{.ID}}-{{.Data.region}}.internal:{{.Port}}" # Mutually exclusive with the clusterDomain field
Behaviour
The component resolves target apps by using the Kubernetes cluster’s DNS provider. You can learn more in the Kubernetes docs.
Spec configuration fields
The configuration spec is fixed to v1.3.0 of the Consul API
Field |
Required |
Type |
Details |
Examples |
clusterDomain |
N |
string |
The cluster domain to be used for resolved addresses. This field is mutually exclusive with the template file. |
cluster.local |
template |
N |
string |
A template string to be parsed when addresses are resolved using text/template . The template will be populated by the fields in the ResolveRequest struct. This field is mutually exclusive with clusterDomain field. |
{{.ID}}-{{.Data.region}}.{{.Namespace}}.internal:{{.Port}} |
3 - mDNS
Detailed information on the mDNS name resolution component
Multicast DNS (mDNS) is configured automatically in self-hosted mode by Dapr. There is no configuration needed to use mDNS as your name resolution provider.
Behaviour
The component resolves target apps by using the host system’s mDNS service. You can learn more about mDNS here.
Troubleshooting
In some cloud provider virtual networks, such as Microsoft Azure, mDNS is not available. Use an alternate provider such as HashiCorp Consul instead.
On some enterprise-managed systems, mDNS may be disabled on macOS if a network filter/proxy is configured. Check with your IT department if mDNS is disabled and you are unable to use service invocation locally.
Spec configuration fields
Not applicable, as mDNS is configured by Dapr when running in self-hosted mode.
4 - SQLite
Detailed information on the SQLite name resolution component
As an alternative to mDNS, the SQLite name resolution component can be used for running Dapr on single-node environments and for local development scenarios. Dapr sidecars that are part of the cluster store their information in a SQLite database on the local machine.
Note
This component is optimized to be used in scenarios where all Dapr instances are running on the same physical machine, where the database is accessed through the same, locally-mounted disk.
Using the SQLite nameresolver with a database file accessed over the network (including via SMB/NFS) can lead to issues such as data corruption, and is not supported.
Name resolution is configured via the Dapr Configuration.
Within the Configuration YAML, set the spec.nameResolution.component
property to "sqlite"
, then pass configuration options in the spec.nameResolution.configuration
dictionary.
This is the basic example of a Configuration resource:
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
spec:
nameResolution:
component: "sqlite"
version: "v1"
configuration:
connectionString: "/home/user/.dapr/nr.db"
Spec configuration fields
When using the SQLite name resolver component, the spec.nameResolution.configuration
dictionary contains these options:
Field |
Required |
Type |
Details |
Examples |
connectionString |
Y |
string |
The connection string for the SQLite database. Normally, this is the path to a file on disk, relative to the current working directory, or absolute. |
"nr.db" (relative to the working directory), "/home/user/.dapr/nr.db" |
updateInterval |
N |
Go duration (as a string ) |
Interval for active Dapr sidecars to update their status in the database, which is used as healthcheck. Smaller intervals reduce the likelihood of stale data being returned if an application goes offline, but increase the load on the database. Must be at least 1s greater than timeout . Values with fractions of seconds are truncated (for example, 1500ms becomes 1s ). Default: 5s |
"2s" |
timeout |
N |
Go duration (as a string ). Must be at least 1s. |
Timeout for operations on the database. Integers are interpreted as number of seconds. Defaults to 1s |
"2s" , 2 |
tableName |
N |
string |
Name of the table where the data is stored. If the table does not exist, the table is created by Dapr. Defaults to hosts . |
"hosts" |
metadataTableName |
N |
string |
Name of the table used by Dapr to store metadata for the component. If the table does not exist, the table is created by Dapr. Defaults to metadata . |
"metadata" |
cleanupInterval |
N |
Go duration (as a string ) |
Interval to remove stale records from the database. Default: 1h (1 hour) |
"10m" |
busyTimeout |
N |
Go duration (as a string ) |
Interval to wait in case the SQLite database is currently busy serving another request, before returning a “database busy” error. This is an advanced setting.busyTimeout controls how locking works in SQLite. With SQLite, writes are exclusive, so every time any app is writing the database is locked. If another app tries to write, it waits up to busyTimeout before returning the “database busy” error. However the timeout setting controls the timeout for the entire operation. For example if the query “hangs”, after the database has acquired the lock (so after busy timeout is cleared), then timeout comes into effect. Default: 800ms (800 milliseconds) |
"100ms" |
disableWAL |
N |
bool |
If set to true, disables Write-Ahead Logging for journaling of the SQLite database. This is for advanced scenarios only |
true , false |