<p>I'm trying to deploy mongodb on Kubernetes but I'm getting the error: </p>

<blockquote>
  <p>error parsing stateful.yaml: error converting YAML to JSON: yaml: line
  35: mapping values are not allowed in this context</p>
</blockquote>

<p>the line 35 is the container name: - name: <strong>uat-mongo-primary</strong></p>

<p>I get this error when i try to create the pods but if i comment the lines :</p>

<blockquote>
  <p>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' } ]
  })";</p>
</blockquote>

<p>the pods being create normally but i need to initiate the cluster also create an user and password.</p>

<p>this is the full yaml file I'm using, i will appreciate any help:</p>

<pre><code>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
</code></pre>

<p>It is not possible to use YAML strings containing colons (at least with kubectl). You should convert your YAML to JSON (using <a href="https://codebeautify.org/yaml-to-json-xml-csv" rel="nofollow noreferrer">this</a> tool for example) and apply that JSON with kubectl.</p>
