Skip to content

Instantly share code, notes, and snippets.

@pjvds
Created February 1, 2017 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjvds/5e290ecb4d4e1c2afbe5ac4fc6826d4a to your computer and use it in GitHub Desktop.
Save pjvds/5e290ecb4d4e1c2afbe5ac4fc6826d4a to your computer and use it in GitHub Desktop.
$ helm install -n mongo .
NAME:   mongo
LAST DEPLOYED: Wed Feb  1 17:23:36 2017
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/Service
NAME                       CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
mongo-mongodb-replicaset   None         <none>        27017/TCP   1s

==> v1/ConfigMap
NAME                 DATA      AGE
mongo-mongo-config   1         1s

==> apps/StatefulSet
NAME                       DESIRED   CURRENT   AGE
mongo-mongodb-replicaset   3         1         1s


NOTES:
1. After the petset is created completely, one can check which instance is primary by running:
	$ for i in `seq 0 2`; do kubectl exec  mongo-mongodb-replicaset-$i -- sh -c '/usr/bin/mongo --eval="printjson(rs.isMaster())"'; done.
	This assumes 3 replicas, 0 through 2. It should be modified to reflect the actual number of replicas specified.

2. One can insert a key into the primary instance of the mongodb replica set by running the following:
	$ kubectl exec MASTER_POD_NAME -- /usr/bin/mongo --eval="printjson(db.test.insert({key1: 'value1'}))"
	MASTER_POD_NAME must be replaced with the name of the master found from the previous step.

3. One can fetch the keys stored in the primary or any of the slave nodes in the following manner.
	$ kubectl exec POD_NAME -- /usr/bin/mongo --eval="rs.slaveOk(); db.test.find().forEach(printjson)"
	POD_NAME must be replaced by the name of the pod being queried.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment