Automating MongoDB Replica set configuration on Kubernetes
This might be what you're looking for:
http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html
Yes, it is possible, you have several choices:
- Use the sidecar approach as specified by @tzik, then you don't need to do much in your code
- Use the kubernetes
lifecycle.postInstall
feature to implement the clustering on your own (this is a bit tricky, because postInstall runs on each statefulset member) - Use if you decide to use helm to manage your k8s deployments, then you can use helm post-install hooks to initiate your mongodb cluster.