GIScience / openrouteservice

🌍 The open source route planner api with plenty of features.
https://openrouteservice.org
GNU General Public License v3.0
1.43k stars 391 forks source link

Contributing opsy code for k8s. #1606

Open itissid opened 10 months ago

itissid commented 10 months ago

Is there an existing issue for this?

Problem description

Hi, this project is amazing it helped me put together this project. It enabled distance calculation for walking to Event addresses that are reverse geocoded to lat longs from where you drop a pin on the home page.

In the process I deployed openroute service on k8s by editing the docker-compose.yml and used Persistent Open Volumes.

I am not sure though if these would be useful to anyone in this project? If not I suppose I could just leave the low down on the basic files in this issue for someone to use. But I have almost neo natal knowledge of k8s so apologies if the code has implementation gaps.

First I split the compose yaml into parts using kompose then heavily edited them.

Proposed solution

Here are some barebones files I eventually used and that worked:

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: "kompose convert -f docker-compose.yml"
    kompose.version: "1.31.2 (HEAD)"
  creationTimestamp: null
  labels:
    app: ors-app
  name: ors-app
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  selector:
    matchLabels:
      app: ors-app
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      annotations:
        kompose.cmd: "kompose convert -f docker-compose.yml"
        kompose.version: "1.31.2 (HEAD)"
      creationTimestamp: null
      labels:
        app: ors-app
        io.kompose.network/openrouteservice-default: "true"
        io.kompose.service: ors-app
    spec:
      initContainers:
      - name: volume-permissions
        image: '<URL_YOUR_REGISTRY>'
        command: ['sh', '-c', 'mkdir -p /home/ors/ors-core/data/graphs /home/ors/ors-core/data/elevation_cache /home/ors/ors-core/logs/ors /home/ors/tomcat/logs /home/ors/ors-conf /home/ors/ors-core/data']
        volumeMounts:
        - mountPath: /home/ors/ors-core/data/graphs
          name: ors-graphs-claim
        - mountPath: /home/ors/ors-core/data/elevation_cache
          name: ors-elevation-cache-claim
        - mountPath: /home/ors/ors-core/logs/ors
          name: ors-logs-claim
        - mountPath: /home/ors/tomcat/logs
          name: ors-tomcat-logs-claim
        - mountPath: /home/ors/ors-conf
          name: ors-conf-claim
        - mountPath: /home/ors/ors-core/data/
          name: ors-data-claim
      nodeSelector:
      nodeSelector:
        app: ors
      containers:
      - image: registry.digitalocean.com/herenowdemoregistry/openrouteservice
        imagePullPolicy: Always
        env:
          - name: BUILD_GRAPHS
            value: "True"
          - name: CATALINA_OPTS
            value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote.rmi.port=9001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost"
          - name: JAVA_OPTS
            value: "-Djava.awt.headless=true -server -XX:TargetSurvivorRatio=75 -XX:SurvivorRatio=64 -XX:MaxTenuringThreshold=3 -XX:+UseG1GC -XX:+ScavengeBeforeFullGC -XX:ParallelGCThreads=4 -Xms512m -Xmx1g"
        name: ors-app
        ports:
        - containerPort: 8080
          protocol: TCP
          hostPort: 8080
        - containerPort: 9001
          hostPort: 9001
          protocol: TCP
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        resources: {}
        volumeMounts:
          - mountPath: /home/ors/ors-core/data/graphs
            name: ors-graphs-claim
          - mountPath: /home/ors/ors-core/data/elevation_cache
            name: ors-elevation-cache-claim
          - mountPath: /home/ors/ors-core/logs/ors
            name: ors-logs-claim
          - mountPath: /home/ors/tomcat/logs
            name: ors-tomcat-logs-claim
          - mountPath: /home/ors/ors-conf
            name: ors-conf-claim
          - mountPath: /home/ors/ors-core/data/
            name: ors-data-claim
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - name: ors-graphs-claim
          persistentVolumeClaim:
            claimName: ors-graphs-claim
        - name: ors-elevation-cache-claim
          persistentVolumeClaim:
            claimName: ors-elevation-cache-claim
        - name: ors-logs-claim
          persistentVolumeClaim:
            claimName: ors-logs-claim
        - name: ors-tomcat-logs-claim
          persistentVolumeClaim:
            claimName: ors-tomcat-logs-claim
        - name: ors-conf-claim
          persistentVolumeClaim:
            claimName: ors-conf-claim
        - name: ors-data-claim
          persistentVolumeClaim:
            claimName: ors-data-claim
status: {}

PVC Claims for DO look like(e.g. for graphs):

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    io.kompose.service: ors-app-claim0
    app: ors
  name: ors-graphs-claim
spec:
  storageClassName: do-block-storage
    #selector:
    #  matchLabels:
    #    thing: graphs
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi

Pod deployment is like(Note that there are repeated commands for initContainer and volumeMounts), this is intentional but not needed. You can have those in deployment or this yaml depending on granularity of control, but Pod is smallest unit of control/abstraction in k8s:

apiVersion: v1
items:
- apiVersion: v1
  kind: Pod
  metadata:
    annotations:
      kompose.cmd: kompose convert -f docker-compose.yml
      kompose.version: 1.31.2 (HEAD)
    creationTimestamp: "2023-11-09T16:29:10Z"
    generateName: ors-app-576cccb994-
    labels:
      app: ors-app
      io.kompose.network/openrouteservice-default: "true"
      io.kompose.service: ors-app
      pod-template-hash: 576cccb994
    name: ors-app-576cccb994-98689
    namespace: default
    ownerReferences:
    - apiVersion: apps/v1
      blockOwnerDeletion: true
      controller: true
      kind: ReplicaSet
      name: ors-app-576cccb994
      uid: 82c3b61c-a744-4cf1-a9f3-a2773080ff67
    resourceVersion: "564185"
    uid: aef68ec4-3f97-43f9-b83a-b3bd420617dd
  spec:
    containers:
    - env:
      - name: BUILD_GRAPHS
        value: "True"
      - name: CATALINA_OPTS
        value: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001
          -Dcom.sun.management.jmxremote.rmi.port=9001 -Dcom.sun.management.jmxremote.authenticate=false
          -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost
      - name: JAVA_OPTS
        value: -Djava.awt.headless=true -server -XX:TargetSurvivorRatio=75 -XX:SurvivorRatio=64
          -XX:MaxTenuringThreshold=3 -XX:+UseG1GC -XX:+ScavengeBeforeFullGC -XX:ParallelGCThreads=4
          -Xms512m -Xmx1g
      image: registry.digitalocean.com/herenowdemoregistry/openrouteservice
      imagePullPolicy: Always
      name: ors-app
      ports:
      - containerPort: 8080
        hostPort: 8080
        protocol: TCP
      - containerPort: 9001
        hostPort: 9001
        protocol: TCP
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
      - mountPath: /home/ors/ors-core/data/graphs
        name: ors-graphs-claim
      - mountPath: /home/ors/ors-core/data/elevation_cache
        name: ors-elevation-cache-claim
      - mountPath: /home/ors/ors-core/logs/ors
        name: ors-logs-claim
      - mountPath: /home/ors/tomcat/logs
        name: ors-tomcat-logs-claim
      - mountPath: /home/ors/ors-conf
        name: ors-conf-claim
      - mountPath: /home/ors/ors-core/data/
        name: ors-data-claim
      - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
        name: kube-api-access-6kpmr
        readOnly: true
    dnsPolicy: ClusterFirst
    enableServiceLinks: true
    imagePullSecrets:
    - name: registry-herenowdemoregistry
    - name: herenowdemoregistry
    initContainers:
    - command:
      - sh
      - -c
      - mkdir -p /home/ors/ors-core/data/graphs /home/ors/ors-core/data/elevation_cache
        /home/ors/ors-core/logs/ors /home/ors/tomcat/logs /home/ors/ors-conf /home/ors/ors-core/data
      image: registry.digitalocean.com/herenowdemoregistry/openrouteservice
      imagePullPolicy: Always
      name: volume-permissions
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
      - mountPath: /home/ors/ors-core/data/graphs
        name: ors-graphs-claim
      - mountPath: /home/ors/ors-core/data/elevation_cache
        name: ors-elevation-cache-claim
      - mountPath: /home/ors/ors-core/logs/ors
        name: ors-logs-claim
      - mountPath: /home/ors/tomcat/logs
        name: ors-tomcat-logs-claim
      - mountPath: /home/ors/ors-conf
        name: ors-conf-claim
      - mountPath: /home/ors/ors-core/data/
        name: ors-data-claim
      - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
        name: kube-api-access-6kpmr
        readOnly: true
    nodeName: pool-rvh7q9cqa-xup5t
    nodeSelector:
      app: ors
    preemptionPolicy: PreemptLowerPriority
    priority: 0
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    serviceAccount: default
    serviceAccountName: default
    terminationGracePeriodSeconds: 30
    tolerations:
    - effect: NoExecute
      key: node.kubernetes.io/not-ready
      operator: Exists
      tolerationSeconds: 300
    - effect: NoExecute
      key: node.kubernetes.io/unreachable
      operator: Exists
      tolerationSeconds: 300
    volumes:
    - name: ors-graphs-claim
      persistentVolumeClaim:
        claimName: ors-graphs-claim
    - name: ors-elevation-cache-claim
      persistentVolumeClaim:
        claimName: ors-elevation-cache-claim
    - name: ors-logs-claim
      persistentVolumeClaim:
        claimName: ors-logs-claim
    - name: ors-tomcat-logs-claim
      persistentVolumeClaim:
        claimName: ors-tomcat-logs-claim
    - name: ors-conf-claim
      persistentVolumeClaim:
        claimName: ors-conf-claim
    - name: ors-data-claim
      persistentVolumeClaim:
        claimName: ors-data-claim
    - name: kube-api-access-6kpmr
      projected:
        defaultMode: 420
        sources:
        - serviceAccountToken:
            expirationSeconds: 3607
            path: token
        - configMap:
            items:
            - key: ca.crt
              path: ca.crt
            name: kube-root-ca.crt
        - downwardAPI:
            items:
            - fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
              path: namespace
kind: List
metadata:
  resourceVersion: ""

Additional context

No response

Forum Topic Link

No response

MichaelsJP commented 9 months ago

@itissid We're happy you could achieve your projects goals with ORS!

Thank you so much for your setup scripts! This will definitely be a good start for many to deploy on k8s.

If you would like to contribute this to our documentation, it is more than welcome.

It is as simple as doing a pull request into the docs' folder: https://github.com/GIScience/openrouteservice/tree/master/docs