HostNotFound: error when connecting to Mongo pod in same namespace

I am trying to connect to a MongoDB deployment from another deployment which is in the same namespace but when I attempt to do so I am getting an error :

kubectl exec -it mongodb-0 -- sh
mongo mongodb://admin:abc123@mongodb-headless-service.svc.cluster.local/platforms?authSource=admin MongoDB shell version v5.0.9 connecting to: mongodb://mongodb-headless-service.svc.cluster.local:27017/platforms?authSource=admin&compressors=disabled&gssapiServiceName=mongodb Error: couldn't connect to server mongodb-headless-service.svc.cluster.local:27017, connection attempt failed: HostNotFound: Could not find address for mongodb-headless-service.svc.cluster.local:27017: SocketException: Host not found (authoritative) : connect@src/mongo/shell/mongo.js:372:17 @(connect):2:6 exception: connect failed exiting with code 1

However when I test the connection in the original pod it authenticates successfully

kubectl exec -it mongodb-deployment-c896cf876-djhvl -- sh
mongo "mongodb://admin:abc123@localhost/platforms?authSource=admin"
MongoDB shell version v4.4.6
connecting to: mongodb://localhost:27017/platforms?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("23c1e0ce-3369-4449-8895-1a6791246b67") }
MongoDB server version: 4.4.6
---
....
....

I have tried specifying namespace but still I get same error :

mongo mongodb://admin:abc123@mongodb-headless-service.labs.svc.cluster.local/platforms?authSource=admin

I have checked with kubectl describe deploment whether bind-ip is specified (is this even necessary ?) and I observe its not configured.
When I specify bind-ips in the yml definition for the container as below :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb-deployment
  namespace: labs
  labels:
    app: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: docker.io/bitnami/mongodb:4.4.6-debian-10-r0
        imagePullPolicy: "IfNotPresent"
        command:
          - "mongod"
          - "--bind_ip"
          - "0.0.0.0"
        securityContext:
            runAsNonRoot: true
            runAsUser: 1001
        ports:
          - containerPort: 27017
        env:
            - name: MONGO_INITDB_ROOT_USERNAME
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret-amended
                  key: mongo-root-username
            - name: MONGO_INITDB_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mongodb-secret-amended
                  key: mongo-root-password
        volumeMounts: 
            - mountPath: /data/db
              name: mongodb-vol
      volumes:
      - name: mongodb-vol
        persistentVolumeClaim:
          claimName: mongodb-claim
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-service
  namespace: labs
spec:
  type: NodePort
  selector:
    app: mongodb
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017 
---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-headless-service
  namespace: labs
spec:
  selector:
    app: mongodb
  ports:
    - protocol: TCP
      port: 27017
      targetPort: 27017 

I also get an error on container startup :

{"t":{"$date":"2022-06-12T10:23:14.337+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2022-06-12T10:23:14.339+00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2022-06-12T10:23:14.339+00:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2022-06-12T10:23:14.340+00:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"mongodb-deployment-c896cf876-djhvl"}}
{"t":{"$date":"2022-06-12T10:23:14.340+00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.6","gitVersion":"72e66213c2c3eab37d9358d5e78ad7f5c1d0d0d7","openSSLVersion":"OpenSSL 1.1.1d  10 Sep 2019","modules":[],"allocator":"tcmalloc","environment":{"distmod":"debian10","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2022-06-12T10:23:14.340+00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"PRETTY_NAME=\"Debian GNU/Linux 10 (buster)\"","version":"Kernel 5.8.0-43-generic"}}}
{"t":{"$date":"2022-06-12T10:23:14.340+00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"0.0.0.0"}}}}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db"}}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"REPL",     "id":4784900, "ctx":"initandlisten","msg":"Stepping down the ReplicationCoordinator for shutdown","attr":{"waitTimeMillis":10000}}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"COMMAND",  "id":4784901, "ctx":"initandlisten","msg":"Shutting down the MirrorMaestro"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"SHARDING", "id":4784902, "ctx":"initandlisten","msg":"Shutting down the WaitForMajorityService"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"NETWORK",  "id":4784905, "ctx":"initandlisten","msg":"Shutting down the global connection pool"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"STORAGE",  "id":4784906, "ctx":"initandlisten","msg":"Shutting down the FlowControlTicketholder"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"NETWORK",  "id":4784918, "ctx":"initandlisten","msg":"Shutting down the ReplicaSetMonitor"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"SHARDING", "id":4784921, "ctx":"initandlisten","msg":"Shutting down the MigrationUtilExecutor"}
{"t":{"$date":"2022-06-12T10:23:14.341+00:00"},"s":"I",  "c":"CONTROL",  "id":4784925, "ctx":"initandlisten","msg":"Shutting down free monitoring"}
{"t":{"$date":"2022-06-12T10:23:14.342+00:00"},"s":"I",  "c":"STORAGE",  "id":4784927, "ctx":"initandlisten","msg":"Shutting down the HealthLog"}
{"t":{"$date":"2022-06-12T10:23:14.342+00:00"},"s":"I",  "c":"STORAGE",  "id":4784929, "ctx":"initandlisten","msg":"Acquiring the global lock for shutdown"}
{"t":{"$date":"2022-06-12T10:23:14.342+00:00"},"s":"I",  "c":"-",        "id":4784931, "ctx":"initandlisten","msg":"Dropping the scope cache for shutdown"}
{"t":{"$date":"2022-06-12T10:23:14.342+00:00"},"s":"I",  "c":"FTDC",     "id":4784926, "ctx":"initandlisten","msg":"Shutting down full-time data capture"}
{"t":{"$date":"2022-06-12T10:23:14.342+00:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2022-06-12T10:23:14.342+00:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

What am I missing ?

Write permission for the directory /data/db.

@steevej is my issue about bind-ips really though. As it is I cannot assign bind-ips , those permissions are not there, bitnami mongo images run as non-root by default and overriding is not possible.

Is it not that the containers should discover each other by default (They are already in same namespace and I have used the recommened Mongo-URI pattern

You have to fix your write permission issue first

If mongod does not start it cannot bind to any address.