diff --git a/docker-orchestration/README.md b/docker-orchestration/README.md index 6003bedeb..3a3d65403 100644 --- a/docker-orchestration/README.md +++ b/docker-orchestration/README.md @@ -14,3 +14,7 @@ Image contains web tool to check routing and guidance result. It uses MapBox GL JS and apply routing response on top of Mapbox vector tiles. See details in [osrm-frontend-docker](./osrm-frontend-docker/README.md) +## Kubernetes Deployment +### k8s-rolling-update +Use kubernetes rolling update deployment strategy for timed replace container with new one. Latest traffic will be used during container startup. +See details in [k8s rolling update](./k8s-rolling-update/) diff --git a/docker-orchestration/k8s-rolling-update/README.md b/docker-orchestration/k8s-rolling-update/README.md new file mode 100644 index 000000000..be00d8750 --- /dev/null +++ b/docker-orchestration/k8s-rolling-update/README.md @@ -0,0 +1,48 @@ +# Kubernetes Rolling Update Deployment +Use kubernetes rolling update deployment strategy for timed replace container with new one. Latest traffic will be used during container startup. + +## Usage +```bash + +# NOTE: prepare your image and fill into osrm.yaml +$ sed -i "s#TELENAV_OSRM_BACKEND_DOCKER_IMAGE##g" ./osrm.yaml + +# create deployment +$ kubectl create -f osrm.yaml +deployment.extensions/osrm created + +# create loadbalancer +$ kubectl create -f osrm_svc.yaml +service/routing-osrm-service created + +# OPTIONAL: checking deployment status, wait READY +$ kubectl get deployments -n routing-osrm +NAME READY UP-TO-DATE AVAILABLE AGE +osrm 0/1 1 0 20s +$ kubectl get pods -n routing-osrm +NAME READY STATUS RESTARTS AGE +osrm-67b55f46c9-tpfgs 0/1 Running 0 22s + +# OPTIONAL: check deployment details for troubleshooting +$ kubectl describe deployments -n routing-osrm +... +$ kubectl describe pods -n routing-osrm +... + +# OPTIONAL: check container running log for troubleshooting +$ kubectl logs -f --timestamps=true -n routing-osrm osrm-67b55f46c9-tpfgs +... + +# start timed rolling update for traffic updating +$ crontab osrm_cron +$ crontab -l +*/30 * * * * export PATH=$HOME/bin:$PATH && kubectl set env --env="LAST_MANUAL_RESTART=$(date -u +\%Y\%m\%dT\%H\%M\%S)" deploy/osrm -n routing-osrm >> ${HOME}/osrm_cron.log 2>&1 + +# OPTIONAL: if want to stop +$ crontab -r +$ kubectl delete deployment osrm -n routing-osrm +deployment.extensions "osrm" deleted +$ kubectl delete routing-osrm-service -n routing-osrm +service "routing-osrm-service" deleted + +``` \ No newline at end of file diff --git a/docker-orchestration/k8s-rolling-update/osrm.yaml b/docker-orchestration/k8s-rolling-update/osrm.yaml new file mode 100644 index 000000000..ee4cc71d2 --- /dev/null +++ b/docker-orchestration/k8s-rolling-update/osrm.yaml @@ -0,0 +1,33 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: osrm + namespace: routing-osrm +spec: + replicas: 1 + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + template: + metadata: + labels: + app: routing + spec: + nodeSelector: + routing-osrm/role: routing-osrm + containers: + - name: osrm-backend + image: TELENAV_OSRM_BACKEND_DOCKER_IMAGE + imagePullPolicy: IfNotPresent + args: ["routed_startup"] + ports: + - containerPort: 5000 + protocol: TCP + readinessProbe: + tcpSocket: + port: 5000 + initialDelaySeconds: 10 + periodSeconds: 5 + failureThreshold: 1000 diff --git a/docker-orchestration/k8s-rolling-update/osrm_cron b/docker-orchestration/k8s-rolling-update/osrm_cron new file mode 100644 index 000000000..06f91e690 --- /dev/null +++ b/docker-orchestration/k8s-rolling-update/osrm_cron @@ -0,0 +1 @@ +*/20 * * * * export PATH=$HOME/bin:$PATH && kubectl set env --env="LAST_MANUAL_RESTART=$(date -u +\%Y\%m\%dT\%H\%M\%S)" deploy/osrm -n routing-osrm >> ${HOME}/osrm_cron.log 2>&1 diff --git a/docker-orchestration/k8s-rolling-update/osrm_svc.yaml b/docker-orchestration/k8s-rolling-update/osrm_svc.yaml new file mode 100644 index 000000000..513fb96a7 --- /dev/null +++ b/docker-orchestration/k8s-rolling-update/osrm_svc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: routing-osrm-service + namespace: routing-osrm + annotations: + service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0 +spec: + selector: + app: routing + ports: + - port: 5001 + protocol: TCP + targetPort: 5000 + type: LoadBalancer