kubernetes Minikube上的Postgis部署提供了一个看起来正在运行的pod,但拒绝psql命令,并且内部只有很少的日志

cedebl8k  于 2023-03-22  发布在  Kubernetes
关注(0)|答案(1)|浏览(112)

Debian 11 上,我尝试使用 Kubernetes 进行部署,从我使用 Docker compose 到现在,安装 PostGIS 示例。
我的集群是一个带有 CRIOMinikube。我基本上是按照我在互联网上找到的。

最后,一切看起来都在运行,但使用psql测试Pod的连接失败。

以下是我的部署者描述符:

  • 命名空间:
apiVersion: v1
kind: Namespace
metadata:
  name: ecoemploi
  • 配置Map:
apiVersion: v1
kind: ConfigMap

metadata:
  name: postgres-config
  namespace: ecoemploi

  labels:
    app: sources

data:
  POSTGRES_DB: postgresdb
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres
  • 持久卷和持久卷声明:
kind: PersistentVolume
apiVersion: v1

metadata:
  name: postgres-pv-volume
  namespace: ecoemploi

  labels:
    type: local
    app: sources

spec:
  storageClassName: manual

  capacity:
    storage: 50Gi

  accessModes:
    - ReadWriteMany

  hostPath:
    path: "/mnt/data"

---

kind: PersistentVolumeClaim
apiVersion: v1

metadata:
  name: postgres-pv-claim
  namespace: ecoemploi

  labels:
    app: sources

spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany

  resources:
    requests:
      storage: 50Gi
  • PostGIS sgbd:

使用的镜像postgis/postgis:14-3.3是我在Dockerfile上使用的镜像。

apiVersion: apps/v1
kind: Deployment

metadata:
  name: postgres
  namespace: ecoemploi

spec:
  replicas: 1

  selector:
    matchLabels:
      app: sources

  template:
    metadata:
      labels:
        app: sources

    spec:
      containers:
        - name: sources
          image: postgis/postgis:14-3.3

          imagePullPolicy: "IfNotPresent"

          ports:
            - containerPort: 5435

          envFrom:
            - configMapRef:
                name: postgres-config

          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              name: ecoemploigis

      volumes:
        - name: ecoemploigis

          persistentVolumeClaim:
            claimName: postgres-pv-claim
  • 服务:
apiVersion: v1
kind: Service

metadata:
  name: postgres
  namespace: ecoemploi

  labels:
    app: sources

spec:
  type: NodePort

  ports:
    - port: 5435

  selector:
    app: sources

以下是 Minikubekubectl get all --namespace=ecoemploi的响应:

kubectl get all --namespace=ecoemploi
NAME                            READY   STATUS    RESTARTS      AGE
pod/postgres-687c6f59f6-8fkb4   1/1     Running   2 (10h ago)   15h

NAME               TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
service/postgres   NodePort   10.98.16.113   <none>        5435:31956/TCP   15h

NAME                       READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/postgres   1/1     1            1           15h

NAME                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/postgres-687c6f59f6   1         1         1       15h

根据我在互联网上的示例,我应该可以在运行的pod中执行psql命令,并使用:

kubectl exec -it pod/postgres-687c6f59f6-8fkb4 --namespace ecoemploi -- psql -h localhost -U postgres --password -p 5435 ecoemploigis

psql失败,显示如下信息:

psql: error: connection to server at "localhost" (127.0.0.1), port 5435 failed: Connection refused
    Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5435 failed: Cannot assign requested address
    Is the server running on that host and accepting TCP/IP connections?
command terminated with exit code 2

执行一个kubectl exec -it pod/postgres-687c6f59f6-8fkb4 --namespace ecoemploi -- bash,会将我带到pod的内部,其中存在以下文件夹:

bin  boot  dev  docker-entrypoint-initdb.d  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

但是/var/log内容并没有解释任何事情:

-rw-r--r-- 1 root root       8436 Mar 18 16:59 alternatives.log
drwxr-xr-x 1 root root       4096 Mar 18 16:59 apt
-rw-rw---- 1 root utmp          0 Feb 27 00:00 btmp
-rw-r--r-- 1 root root      70686 Mar 18 16:59 dpkg.log
-rw-r--r-- 1 root root      32000 Mar  1 13:53 faillog
-rw-rw-r-- 1 root utmp     292000 Mar  1 13:53 lastlog
drwxrwxr-t 2 root postgres   4096 Feb  9 10:28 postgresql
-rw-rw-r-- 1 root utmp          0 Feb 27 00:00 wtmp

(only dpkg.logalternatives.log确实发生了变化)
我有:

ls -l /var/log/postgresql/
total 0

看起来 Kubernetes 并没有真正尝试运行我的ecoemploi“子系统”。
这是我第一次部署Kubernetes。我错过了什么重要的东西吗?

7d7tgy0s

7d7tgy0s1#

该错误可能是由于您的系统意外关闭。
尝试运行下面的命令:

postgres -D /usr/local/var/postgres

您将得到以下输出:

FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 449) running in data directory "/usr/local/var/postgres"?

然后是kill -9 PID,它应该正常启动postgres。
另一个解决方法是下载官方的postgresqlapp并启动它。它将强制服务器启动。

相关问题