microsoft / microsoft/aspire

Aspir8 and resolving service endpoints in kubernetes with DNS SRV

Open
#9,913 0 comments 0 reactions 0 assignees View on GitHub
kubernetes needs-area-label
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

The Readme for Microsoft.Extensions.ServiceDiscovery.Dns mentions

> When deploying to Kubernetes, the DNS SRV service endpoint provider can be used to resolve endpoints. For example, the following resource definition will result in a DNS SRV record being created for an endpoint named "default" and an endpoint named "dashboard", both on the service named "basket".
>
> ```yml
> apiVersion: v1
> kind: Service
> metadata:
> name: basket
> spec:
> selector:
> name: basket-service
> clusterIP: None
> ports:
> - name: default
> port: 8080
> - name: dashboard
> port: 8888
> ```

However, when using Aspir8 to generate kubernetes deployments (for example in the TestShop project), I get

```yaml
---
apiVersion: v1
kind: Service
metadata:
name: basketservice
spec:
type: ClusterIP
selector:
app: basketservice
ports:
- name: http
port: 8080
targetPort: 8080
- name: https
port: 8443
targetPort: 8443
```

Notice that the name of the 8080 port is `http` instead of `default`, meaning that DNS SRV resolution will attempt to resolve `_default._tcp._basketservice` and fail (because there is no "default" port). So the options app developer has are either:
- manually fixup the generated yaml - and risk it being overwritten on next `aspirate generate` invocation
- fix all references in code to `http://_http.basketservice` - which does not work well if I want to do local deployment via `dotnet run` in AppHost folder.

Furthermore, reading the comments and code:

https://github.com/dotnet/aspire/blob/15db8a14ce2b9005c0ba24607f899bace161427c/src/Microsoft.Extensions.ServiceDiscovery.Dns/DnsSrvServiceEndpointProviderFactory.cs#L25-L44

Specifically note the last sentece: "If serviceName parses as a URI, **we use scheme as the port name**, otherwise "default""

Bu there is no corresponding code in ServiceEndpointQuery parsing code

https://github.com/dotnet/aspire/blob/22d5ec4c07d614c6b5551acf95df4fa9b575d144/src/Microsoft.Extensions.ServiceDiscovery.Abstractions/ServiceEndpointQuery.cs#L36-L76

Given the comments in the first code snippet, I would expect referencing `http://basketservice` to lead to resolving via SRV query for `_http._tcp.basketservice`. On the other hand, it is not so clear what should happen with `http+https://basketservice`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.