【问题标题】:Using Openstreetmap in Kubernetes在 Kubernetes 中使用 Openstreetmap
【发布时间】:2019-08-09 21:39:42
【问题描述】:

我有一个在 Kubernetes 内部运行的应用程序,它需要使用 Leaflet 显示地图,地图数据来自 Openstreetmap。

我用来设置地图的代码如下所示:

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

现在困扰我的是网址{s}.tile.openstreetmap.org。由于 openstreetmap 数据驻留在 k8s 集群之外,我需要在 Kubernetes 中创建一个 Service。

我尝试定义这些服务:

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 leaflet openstreetmap


    【解决方案1】:

    通过名称调用外部服务应该不是问题。 ExternalName 可以用于,如果服务需要作为 Kubernetes 资源可用,例如将入口路由代理到外部服务。

    如果您仍想使用ExternalName 服务而不是真正的 FQDN,只需使用有效名称(如 a-tile-openstreetmap-org)并将客户端脚本中的域名替换为该名称即可。不过,您可能必须设置正确的 HTTP 主机标头以避免目标服务器出现问题。

    我仍然建议使用真实姓名,因为它简单明了,而且别名没有任何好处。

    【讨论】:

    • 哦,非常感谢!我的印象是我需要在我的应用程序中使用的所有外部资源之上创建一个服务。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多