Is there an efficient way to create a mechanism for automatic updating osrm map data in kubernetes?

1.1k views Asked by At

We have created .yaml file to deploy osrm/osrm-backend (https://hub.docker.com/r/osrm/osrm-backend/tags) in a Kubernetes cluster.

We initially download the pbf file in the node's volume, then we create the necessary files for the service and finally the service starts.

You may find the yaml file below:

apiVersion: v1
kind: Service
metadata:
  name: osrm-albania
  labels:
    app: osrm-albania
spec:
  ports:
  - port: 5000
    targetPort: 5000
    name: http
  selector:
    app: osrm-albania
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: osrm-albania
spec:
  replicas: 1
  selector:
    matchLabels:
     app: osrm-albania
  template:
    metadata:
      labels:
        app: osrm-albania
    spec:
      containers:
      - name: osrm-albania
        image: osrm/osrm-backend:latest
        command: ["/bin/sh", "-c"]
        args: ["osrm-extract -p /opt/car.lua /data/albania-latest.osm.pbf && osrm-partition /data/albania-latest.osrm && osrm-customize /data/albania-latest.osrm && osrm-routed --algorithm mld /data/albania-latest.osrm"]
        ports:
        - containerPort: 5000
          name: osrm-port
        volumeMounts:
        - name: albania
          readOnly:  false
          mountPath: /data
      initContainers:
      - name: get-osrm-file
        image: busybox
        command: ['wget', 'http://download.geofabrik.de/europe/albania-latest.osm.pbf', '--directory-prefix=/data']
        volumeMounts:
        - name: albania
          readOnly: false
          mountPath: /data
      volumes:
      - name: albania
        emptyDir: {}

The problem is that we need to update the map data used by the osrm service, regularly. Which means to be able to re-download the pbf file and recreate the necessary files to be used by the service.

This might be achieved via kubernetes cronjobs which might has to use persistent volumes instead (Cron Jobs in Kubernetes - connect to existing Pod, execute script).

Is this the only way to achieve getting new map data and refresh the data used by the osrm service? How exactly? Is there a better - easier way to achieve this?

1

There are 1 answers

1
Giulio Giannitrapani On

This is a tricky situation, I had the same problem in my cluster and I fixed dividing the job in more pods:

  • 1 wget in a volume mount ('volume A')
  • 2 extract, partition, customize in 'volume A'
  • 3 copy 'volume A' to volume mount B
  • 4 run osrm-routed with 'volume B'

In this way a set pod 1, 2, and 3 as a cronjob and each pod would do all operation without broke the service. This issue was due by a large amount of time for the first 3 operation (2 to 3 hours).