<p>I am creating a MongoDB cluster on Kubernetes using Stateful sets. I have 3 mongo replicas configured in my Stateful set. </p>

<p>Now I create Stateful set and service using just one command</p>

<blockquote>
  <p>kubectl create -f mongo-stateful.yaml</p>
</blockquote>

<p>Then I use the mongo client to initiate mongo replica set members.</p>

<pre><code>rs.initiate(
   {
      _id: "replicaset1",
      version: 1,
      members: [
         { _id: 0, host:port1 },
         { _id: 1, host : host:port1 },
         { _id: 2, host : host:port1  }
      ]
   }
)
</code></pre>

<p>All of this works except I would like to automate this step of configuring replica set members.</p>

<p>My questions is whether this step can be automated and if we can add this to the yaml file?</p>

<p>This might be what you're looking for: </p>

<p><a href="http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html" rel="nofollow noreferrer">http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html</a></p>
