<p>I have an application that is running inside of Kubernetes which needs to display a map using Leaflet, the map data comes from Openstreetmap. </p>

<p>The code I use to set up the map looks like this:</p>

<pre class="lang-js prettyprint-override"><code>map = L.map('mapid', {
        center: [lat, long],
        zoom: 19
    });
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&amp;copy; &lt;a href="https://www.openstreetmap.org/copyright"&gt;OpenStreetMap&lt;/a&gt; contributors'
    }).addTo(map);
</code></pre>

<p>What is bothering me right now is the url <code>{s}.tile.openstreetmap.org</code>. As the openstreetmap data resides outside the k8s cluster, I need to create a Service in Kubernetes. </p>

<p>I tried to define these services: </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: a.tile.openstreetmap.org
spec:
  type: ExternalName
  externalName: a.tile.openstreetmap.org
---
apiVersion: v1
kind: Service
metadata:
  name: b.tile.openstreetmap.org
spec:
  type: ExternalName
  externalName: b.tile.openstreetmap.org
---
apiVersion: v1
kind: Service
metadata:
  name: c.tile.openstreetmap.org
spec:
  type: ExternalName
  externalName: c.tile.openstreetmap.org
</code></pre>

<p>However that resulted in the following error message when deploying the service:</p>

<pre><code>Error from server (Invalid): error when creating "openstreetmap-service.yaml": Service "a.tile.openstreetmap.org" is invalid: metadata.name: Invalid value: "a.tile.openstreetmap.org": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name',  or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
Error from server (Invalid): error when creating "openstreetmap-service.yaml": Service "b.tile.openstreetmap.org" is invalid: metadata.name: Invalid value: "b.tile.openstreetmap.org": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name',  or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
Error from server (Invalid): error when creating "openstreetmap-service.yaml": Service "c.tile.openstreetmap.org" is invalid: metadata.name: Invalid value: "c.tile.openstreetmap.org": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name',  or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
</code></pre>

<p>I understand that I am not allowed to use dots in .metadata.name, but is there a different possibility to achieve this? As far as I can see from the description of the leaflet source, the URL in TileLayer needs to be something like <code>http://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png</code></p>

purzel
<p>Calling an external service by it's name shouldn't be a problem. <code>ExternalName</code> can be used, if the service needs to be available as a Kubernetes resource, for example to proxy an ingress route to an external service.</p>

<p>If you still want to use the <code>ExternalName</code> service instead of the real FQDN, simply use valid names like a-tile-openstreetmap-org and replace the domain name in your client script with that name. You might have to set a correct HTTP host header though to avoid problems with the target server.</p>

<p>I'd still suggest using the real name, as it's simple and straight forward and there's no benefit in aliasing it.</p>
