0

I am trying to run mongodb via helm. I want to run 1 primary replica and 2 secondary replicas.

I would like to setup the following naming for the 3 mongodb pods once they are created: mongo-0 mongo-1 mongo-2 And lets say that mongo-0 would be primary.

When I run the following command

helm install --name mongo ~/charts/stable/mongodb --set replicaSet.enabled=true,fullnameOverride=mongo

The pods do not have require naming:

kubectl get pods
NAME                      READY   STATUS        RESTARTS   AGE
mongo-arbiter-0           1/1     Running       0          15s
mongo-primary-0           0/1     Running       0          15s
mongo-secondary-0         0/1     Running       0          15s

Please any advice how can I change that ? I tried it also via changing values-production.yml but the same output.

Palino1611
  • 11
  • 3

2 Answers2

0

You need to modify the mongoDB helm chart template.

To be more specific you need to change following files.

charts/stable/mongodb/templates/statefulset-arbiter-rs.yaml

edit lines:

name: {{ template "mongodb.fullname" . }}-arbiter

and

- name: {{ template "mongodb.name" . }}-arbiter

And replace arbiter with the name of ReplicaSet you want.

charts/stable/mongodb/templates/statefulset-primary-rs.yaml

edit lines:

name: {{ template "mongodb.fullname" . }}-primary

and

- name: {{ template "mongodb.name" . }}-primary

And replace primary with the name of ReplicaSet you want.

charts/stable/mongodb/templates/statefulset-secondary-rs.yaml

edit lines:

name: {{ template "mongodb.fullname" . }}-secondary

and

- name: {{ template "mongodb.name" . }}-secondary

And replace secondary with the name of ReplicaSet you want.

Crou
  • 714
  • 3
  • 9
  • it is a good idea but not 100% effective. I am running the pods in statefulset so kubectl get rs returns no output. Here is kubectl get ss: `kubectl get statefulsets NAME DESIRED CURRENT AGE mongo-0 1 1 93s mongo-1 1 1 93s mongo-2 1 1 93s` After changing the configs as Crou suggested I get pods like this: `kubectl get pods NAME READY STATUS RESTARTS AGE mongo-0-0 1/1 Running 0 39s mongo-1-0 1/1 Running 0 39s mongo-2-0 1/1 Running 0 39s` – Palino1611 Jul 28 '19 at 20:23
  • Check this SO [link](https://stackoverflow.com/questions/40274031/in-kubernetes-how-to-set-pods-names-when-using-replication-controllers) – Crou Jul 29 '19 at 10:53
0

as my comment does not show in very readable form I ma posting my comment also here:

it is a good idea but not 100% effective. I am running the pods in statefulset so kubectl get rs returns no output. Here is kubectl get ss:

kubectl get statefulsets
NAME      DESIRED   CURRENT   AGE
mongo-0   1         1         93s
mongo-1   1         1         93s
mongo-2   1         1         93s

After changing the configs as Crou suggested I get pods like this:

kubectl get pods
NAME        READY   STATUS    RESTARTS   AGE
mongo-0-0   1/1     Running   0          39s
mongo-1-0   1/1     Running   0          39s
mongo-2-0   1/1     Running   0          39s

Now I would like to delete the -0 in the end so I get:

kubectl get pods
NAME        READY   STATUS    RESTARTS   AGE
mongo-0   1/1     Running   0          39s
mongo-1   1/1     Running   0          39s
mongo-2   1/1     Running   0          39s
Palino1611
  • 11
  • 3