the origin of this registry is https://hub.docker.com/r/tarosky/k8s-mongo-ha/ . This is clone .
252
Sample of Kubernetes MongoDB and a utility Image implemented using StatefulSet.
If you already have a Kubernetes cluster, you can deploy High Availability MongoDB using the following command:
$ kubectl create -f example/
pod "console" created
service "mongo" created
deployment "mongo-supervisor" created
statefulset "mongo" created
You can access MongoDB using console pod:
$ kubectl exec -ti console -- /bin/bash
root@console:# export TARGET='mongo-0.mongo.default.svc.cluster.local:27017'
root@console:# mongo "${TARGET}" --quiet --eval 'db.test_col.insert({"foo": "bar"})'
WriteResult({ "nInserted" : 1 })
root@console:/# mongo $TARGET --quiet --eval 'db.test_col.find({"foo": "bar"})'
{ "_id" : ObjectId("59210a0dc566ec973e149251"), "foo" : "bar" }
root@console:/# mongo 'mongo-1.mongo.oshita.svc.cluster.local:27017' --quiet --eval 'rs.slaveOk();db.test_col.find({"foo": "bar"})' # access slave
{ "_id" : ObjectId("59210a0dc566ec973e149251"), "foo" : "bar" }
root@console:/# mongo $TARGET --quiet --eval 'db.test_col.remove({"foo": "bar"})'
WriteResult({ "nRemoved" : 1 })
With tarosky/k8s-mongo-ha, you can scale up/down MongoDB like the normal Deployment resources:
$ kubectl scale --replicas=5 statefulset/redis-mongo
statefulset "mongo" scaled
$ kubectl exec -ti console -- ipython
In [1]: from redis import StrictRedis
In [2]: from redis.sentinel import Sentinel
In [3]: sentinel = Sentinel([
...: ('redis-sentinel-0.redis-sentinel.default.svc.cluster.local', 26379),
...: ('redis-sentinel-1.redis-sentinel.default.svc.cluster.local', 26379),
...: ('redis-sentinel-2.redis-sentinel.default.svc.cluster.local', 26379)
...: ], socket_timeout=0.1
...: )
In [4]: master = sentinel.master_for(
...: 'mymaster',
...: password='_redis-server._tcp.redis-server.default.svc.cluster.local',
...: socket_timeout=0.1
...: )
In [5]: slave = sentinel.slave_for(
...: 'mymaster',
...: password='_redis-server._tcp.redis-server.default.svc.cluster.local',
...: socket_timeout=0.1
...: )
In [6]: master.set('foo', 'bar')
Out[6]: True
In [7]: slave.get('foo')
Out[7]: b'bar'
$ pyvenv .venv
$ source .venv/bin/activate
$ pip install -r test/requirements.txt
You can run the test command using the following command:
$ KUBE_NAMESPACE='{{Your name space}}' nosetests test/test.py
Content type
Image
Digest
Size
325.1 MB
Last updated
over 9 years ago
docker pull ilil/k8s-mongo-ha:console-2.0.0