我有一个在 Kubernetes 内部运行的应用程序,需要使用 Leaflet 显示 map , map 数据来自 Openstreetmap。
我用来设置 map 的代码如下所示:
map = L.map('mapid', {
center: [lat, long],
zoom: 19
});
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
现在困扰我的是 url {s}.tile.openstreetmap.org
。由于 openstreetmap 数据驻留在 k8s 集群外部,因此我需要在 Kubernetes 中创建一个服务。
我尝试定义这些服务:
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
但是,在部署服务时,这导致出现以下错误消息:
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])?')
我知道我不允许在 .metadata.name 中使用点,但是是否有其他可能性可以实现这一点?据我从传单源的描述中看到,TileLayer 中的 URL 需要类似于 http://{s}.somedomain.com/blabla/{z}/{x}/{y {r}.png
最佳答案
通过名称调用外部服务应该不成问题。如果服务需要作为 Kubernetes 资源使用,例如将入口路由代理到外部服务,则可以使用 ExternalName
。
如果您仍想使用 ExternalName
服务而不是真正的 FQDN,只需使用有效名称(如 a-tile-openstreetmap-org),并将客户端脚本中的域名替换为该名称即可。不过,您可能必须设置正确的 HTTP 主机 header 以避免目标服务器出现问题。
我仍然建议使用真实姓名,因为它简单明了,而且使用别名没有任何好处。
关于kubernetes - 在 Kubernetes 中使用 Openstreetmap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57430771/