I'm trying to deploy mongodb on Kubernetes but I'm getting the error:
error parsing stateful.yaml: error converting YAML to JSON: yaml: line 35: mapping values are not allowed in this context
the line 35 is the container name: - name: uat-mongo-primary
I get this error when i try to create the pods but if i comment the lines :
mongo --eval rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "uat-mongo-primary-rc-0:27017" }]}); 53 mongo --eval "db.getSiblingDB('admin').createUser({user : \"$MONGO_USER\", pwd : \"$MONGO_PASSWORD\", roles: [ { role: 'root', db: 'admin' } ] })";
the pods being create normally but i need to initiate the cluster also create an user and password.
this is the full yaml file I'm using, i will appreciate any help:
apiVersion: v1
kind: Service
metadata:
name: uat-mongo-primary
labels:
name: uat-mongo-primary
spec:
type: NodePort
ports:
- port: 27017
targetPort: 27017
protocol: TCP
name: uat-mongo-primary
selector:
name: uat-mongo-primary
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: uat-mongo-primary-rc
labels:
name: uat-mongo-primary-rc
spec:
serviceName: uat-mongo-primary
replicas: 1
template:
metadata:
labels:
role: mongo
environment: test
spec:
containers:
- name: uat-mongo-primary
image: mongo
env:
- name: "MONGO_DATA_DIR"
value: "/data/db"
- name: "MONGO_LOG_DIR"
value: "/data/logs"
- name: MONGO_USER
value: "admin"
- name: MONGO_PASSWORD
value: "password"
command: ["/bin/sh", "-c"]
args:
- echo starting;
ulimit -a;
mongod --replSet rs0 --bind_ip_all;
mongo --eval rs.initiate({_id: "rs0", version: 1, members: [{ _id: 0, host : "uat-mongo-primary-rc-0:27017" }]});
mongo --eval "db.getSiblingDB('admin').createUser({user : \"$MONGO_USER\", pwd : \"$MONGO_PASSWORD\", roles: [ { role: 'root', db: 'admin' } ] })";
ports:
- containerPort: 27017
volumes:
- name: uat-mongo-primary-db
persistentVolumeClaim:
claimName: uat-mongo-primary-pvc