无法通过 kubernetes 服务访问 Postgres

时间:2021-07-19 12:20:57

标签: postgresql kubernetes rancher kubernetes-service k3s

我正在尝试部署 postgres,但无法通过服务访问 postgres,使用以下域名testapp-postgres.default.svc.cluster.local

但是,我得到以下回复

<块引用>

django.db.utils.OperationalError:无法连接到服务器:连接被拒绝 服务器是否在主机“testapp-postgres.default.svc.cluster.local”(10.43.31.182)上运行并接受 端口 5432 上的 TCP/IP 连接?

地址与服务匹配

<块引用>

默认 testapp-postgres ClusterIP 10.43.31.182 5432/TCP 20m

我正在使用以下部署和服务

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: testapp-postgres
  labels:
    app: testapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testapp
  template:
    metadata:
      labels:
        app: testapp
    spec:

      containers:
        - name: testapp-postgres
          image: library/postgres:12-alpine
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_DB
              valueFrom:
                secretKeyRef:
                  key: DB_NAME
                  name: testapp-secret
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: DB_PASSWORD
                  name: testapp-secret
            - name: POSTGRES_USER
              valueFrom:
                secretKeyRef:
                  key: DB_USER
                  name: testapp-secret

          volumeMounts:
            - mountPath: /var/lib/postgresql/data/
              name: testapp-postgres-data

      volumes:
        - name: testapp-postgres-data
          persistentVolumeClaim:
            claimName: testapp-postgres-data

---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: testapp
  name: testapp-postgres
spec:
  selector:
    app: testapp
  ports:
    - protocol: TCP
      port: 5432
      targetPort: 5432
      name: postgres

0 个答案:

没有答案
相关问题