Kubernetes seeding a mongo database

10/11/2018

I've got a docker compose file that looks like the below and trying to get started with a Kubernetes setup that can create mongo deployments that seed a new database when it starts. I am using kompose convert to create the yml files from this docker-compose but its failing to find the mongo seed.

I don't think this is quite correct when it comes to Kubernetes and a proper way to seed a database although this is working fine for a docker compose up setup. Would a seed like this for kubernetes be better off in an initContainer setup? I'm not finding alot of seeding examples for Kubernetes and databases.

Any help here would be appreciated

the docker-compose i'm running the kompose convert on looks like the below:

version: '3'
services:

  mongodb:
    image: mongo    
    ports:
      - "27017:27017"
    volumes:
      - mongodata:/data/db

  mongo_seed:
    image: mongo
    depends_on: 
      - mongodb    
    links:
      - mongodb
    volumes:
      - ./mongo-seed:/seed
    command:         
        /seed/database.sh &&
        /seed/users.sh

volumes:  
  mongodata:
    driver: local

networks:
  mongonetwork:
    external: true

the seeds .sh's are just lines like:

mongoimport --host mongodb --db test --collection testwidgets --type json --file /seed/widgets.json --jsonArray

The goal is to be able to spin these up in an environment. Would like to allow persistent scenarios and also just lifetime of the pods.

-- james
docker
kubernetes
mongodb

0 Answers