Unable to connect to Postgres StatefulSet in kubernetes cluster from go web server

I have a web server in Golang that connects to Postgres as a StatefulSet. However, I am getting an error with the connection where there is no such host found. The web server was created using ClusterIP as a service for networking and Deployment for creating the pods. Postgres was created using a Headless Service and StatefulSet. The following are my k8s configuration files and also the error message:

# headless-service.yml
apiVersion: v1
kind: Service
metadata:
  name: authentication-headless-service
  labels:
    ims: authentication
spec:
  clusterIP: None # headless service
  selector:
    ims: authentication-postgres
  ports:
    - name: authentication-postgres-h
      port: 5432
      targetPort: 5432

# statefulset.yml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: authentication-postgres-statefulset
spec:
  serviceName: authentication-headless-service
  replicas: 1
  selector:
    matchLabels:
      ims: authentication-postgres
  template:
    metadata:
      labels:
        ims: authentication-postgres
    spec:
      containers:
        - name: postgres
          image: postgres:14.2
          env:
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: authentication-secret
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: authentication-secret
                  key: POSTGRES_PASSWORD
            - name: POSTGRES_HOST
              valueFrom:
                secretKeyRef:
                  name: authentication-secret
                  key: POSTGRES_HOST
          ports:
            - containerPort: 5432
              name: postgres
          volumeMounts:
            - name: postgres-authentication-data
              mountPath: /var/lib/postgresql/data
              subPath: postgres # specific to postgres
          livenessProbe:
            tcpSocket:
              port: 5432
            initialDelaySeconds: 60
            periodSeconds: 30
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 5432
            initialDelaySeconds: 60
            periodSeconds: 30
            failureThreshold: 3
  volumeClaimTemplates:
    - metadata:
        name: postgres-authentication-data
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: 500Mi
        storageClassName: ims-storage-class
apiVersion: v1
kind: Secret
metadata:
  name: authentication-secret
type: Opaque
data:
  POSTGRES_USER: YXV0aGVudGljYXRpb24tcG9zdGdyZXM=
  POSTGRES_PASSWORD: cGFzc3dvcmQ=

  # base64 encoded 'authentication-postgres-0.authentication-headless-service.default.svc.cluster.local'
  POSTGRES_HOST: YXV0aGVudGljYXRpb24tcG9zdGdyZXMtMC5hdXRoZW50aWNhdGlvbi1oZWFkbGVzcy1zZXJ2aWNlLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWw=

---
apiVersion: v1
kind: Service
metadata:
  name: authentication-clusterip
spec:
  type: ClusterIP
  ports:
    - targetPort: 8001
      port: 8001
  selector:
    ims: authentication

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: authentication-deployment
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      ims: authentication
  template:
    metadata:
      labels:
        ims: authentication
    spec:
      containers:
        - name: authentication
          image: localhost:5050/ims-authentication:latest
          ports:
            - containerPort: 8001
          env:
            - name: MODE
              value: docker
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  name: authentication-secret
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: authentication-secret
                  key: POSTGRES_PASSWORD
            - name: POSTGRES_HOST
              valueFrom:
                secretKeyRef:
                  name: authentication-secret
                  key: POSTGRES_HOST
            - name: POSTGRES_PORT
              valueFrom:
                configMapKeyRef:
                  name: authentication-configmap
                  key: POSTGRES_PORT
            - name: POSTGRES_DB
              valueFrom:
                configMapKeyRef:
                  name: authentication-configmap
                  key: POSTGRES_DB
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

This is the error message:

kubectl logs authentication-deployment-99c845645-vr48p

2024/09/18 17:16:10 failed to connect to postgres db: failed to connect to `user=authentication-postgres database=imsdb`: hostname resolving error: lookup authentication-postgres-0.authentication-headless-service.default.svc.cluster.local on 10.96.0.10:53: no such host

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật