This proyect is aimed to create a empty OpenStreetMap PNG tile server for rendering layers over it, with Leaflet or OpenLayer
It is based on the latest Ubuntu 18.04 LTS guide from switch2osm.org and openstreetmap-tile-server
This server is ready to be deployed in docker or kubernetes
- Standalone Docker image
- Standalone Kuebernete Pod
- Simple default frontend
- Peristent Volumes in Docker
- Persistent Volumes in Kubernetes
- Import custom
osm
andosm.pbf
files throught volumes - Custom styles rendering map
- Use remote database (far away...)
- Remove tash (backup files and directories)
$docker build -t osm-tile-server .
Tiles that have already been rendered will be stored in /var/lib/mod_tile
. To make sure that this data survives container restarts, you should create another volume for it
$docker volume create osm-data
$docker volume create osm-rendered-tiles
$docker run -p 80:80 -v osm-data:/var/lib/postgresql/10/main \
-v osm-rendered-tiles:/var/lib/mod_tile \
-d scaamanho/osm-tile-server run
The import and tile serving processes use 4 threads by default, but this number can be changed by setting the THREADS
environment variable.
$docker run -p 80:80 -e THREADS=24 -v osm-data:/var/lib/postgresql/10/main -d scaamanho/osm-tile-server run
$docker-compose up [-d]
Login to docker hub:
$docker login --username=yourhubusername [email protected]
WARNING: login credentials saved in /home/username/.docker/config.json
Login Succeeded
Check the image id
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
osm-tile-server latest 023ab91c6291 3 minutes ago 3.750 GB
...
add your tag image
$docker tag bb38976d03cf yourhubusername/osm-tile-server:latest
Push your image to the repository you created
$docker push yourhubusername/osm-tile-server
Pushing to Docker Hub is great, but it does have some disadvantages:
- It take a lot of bandwidht uploading and downloading images
- When working on some clusters, each time you launch a job that uses a Docker container it pulls the container from Docker Hub, and if you are running many jobs, this can be really slow.
Solutions to these problems can be to save the Docker container locally as a a tar archive, and then you can easily load that to an image when needed.
To save a Docker image after you have pulled, committed or built it you use the docker save command. For example, lets save a local copy of the osm-tile-server
docker image we made:
$docker save osm-tile-server > osm-tile-server.tar
If we want to load that Docker container from the archived tar file in the future, we can use the docker load command:
$docker load --input osm-tile-server.tar
[TODO]
This step is not needed, but allow you deploy custom images and push them into Kubernetes registry, instead push to Docker registry or push it to custom registry and deal with security and certificates.
This osm-tile-server image takes its time in create, push and pull from Docker Hub, so unless u have a great machine and a great connection speed, use this method to speed up the process
Based on Sharing a local registry for minikube
$kubectl create -f kube-registry.yaml
$eval $(minikube docker-env)
this command exports the followin enviroment variables
$minikube docker-env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.39.36:2376"
export DOCKER_CERT_PATH="/home/scaamano/.minikube/certs"
export DOCKER_API_VERSION="1.35"
# Run this command to configure your shell:
# eval $(minikube docker-env)
[TODO]
Now you can build a push your docker images to Kubernetes registry
docker login <REGISTRY_HOST>:<REGISTRY_PORT>
docker tag <IMAGE_ID> <REGISTRY_HOST>:<REGISTRY_PORT>/:
docker push <REGISTRY_HOST>:<REGISTRY_PORT>/:
$docker build -t osm-tile-server .
$docker login repo.company.com:3456
$docker tag 19fcc4aa71ba repo.company.com:3456/myapp:0.1
$docker push repo.company.com:3456/myapp:0.1
NOTE: Is needed set permisions in mount directories due they are not writen by root user
$minikube ssh
$sudo mkdir -p /data/osm-db
$sudo mkdir -p /data/osm-tile
$sudo chmod 755 /dat /osm*
$kubectl create -f osm-k8s-full.yaml
You can now test your server with:
$curl http://$(minukube ip)/osm/tile/{z}/{x}/{y}.png
$curl http://$(minukube ip)/osm/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.