<p>Here is my config of YAML (all PV, Statefulset, and Service get created fine no issues in that). Tried a bunch of solution for connection string of Kubernetes mongo but didn't work any.</p>
<p>Kubernetes version (minikube):
1.20.1</p>
<p>Storage for config:
NFS (working fine, tested)</p>
<p>OS:
Linux Mint 20</p>
<p>YAML CONFIG:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: auth-pv
spec:
  capacity:
    storage: 250Mi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  nfs:
    path: /nfs/auth
    server: 192.168.10.104
---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    name: mongo
spec:
  ports:
    - port: 27017
      targetPort: 27017
  selector:
    role: mongo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
spec:
  selector:
    matchLabels:
      app: mongo
  serviceName: mongo
  replicas: 1
  template:
    metadata:
      labels:
        app: mongo
    spec:
      terminationGracePeriodSeconds: 10
      containers:
        - name: mongo
          image: mongo
          ports:
            - containerPort: 27017
          volumeMounts:
            - name: mongo-persistent-storage
              mountPath: /data/db
  volumeClaimTemplates:
    - metadata:
        name: mongo-persistent-storage
      spec:
        storageClassName: manual
        accessModes: [&quot;ReadWriteMany&quot;]
        resources:
          requests:
            storage: 250Mi

</code></pre>

Meet Patel
<p>I have found few issues in your configuration file. In your service manifest file you use</p>
<pre><code>  selector:
    role: mongo
</code></pre>
<p>But in your statefull set pod template you are using</p>
<pre><code>labels:
        app: mongo
</code></pre>
<p>One more thing you should use <code>ClusterIP:None</code> to use the headless service which is recommended for statefull set, if you want to access the db using dns name.</p>
