0

On Debian 11, I'm trying to do a deployment with Kubernetes from one I did with Docker compose until now, to install a PostGIS instance.
My cluster is a Minikube with CRIO. And I essentially followed what I found over the Internet.

Eventually, everything look running, but a connection test to the pod with psql fails.
Here are my deployers descriptors:

  • Namespace:
apiVersion: v1
kind: Namespace
metadata:
  name: ecoemploi
  • ConfigMap:
apiVersion: v1
kind: ConfigMap

metadata:
  name: postgres-config
  namespace: ecoemploi

  labels:
    app: sources

data:
  POSTGRES_DB: postgresdb
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: postgres
  • Persistent Volume and Persistent Volume Claim:
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:

The image used, postgis/postgis:14-3.3, is the one I was using on the 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
  • Service:
apiVersion: v1
kind: Service

metadata:
  name: postgres
  namespace: ecoemploi

  labels:
    app: sources

spec:
  type: NodePort

  ports:
    - port: 5435

  selector:
    app: sources

Here's what Minikube responds to a kubectl 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

According to the example I followed on the Internet, what I have should allow me to execute a psql command into that running pod, with a:

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

But psql fails, with this message:

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

Executing a kubectl exec -it pod/postgres-687c6f59f6-8fkb4 --namespace ecoemploi -- bash instead, leads me to the pod's internal, where these folders are present:

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

but /var/log content doesn't explain anything:

-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.log and alternatives.log really changed)

and I have:

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

Things look like Kubernetes didn't really attempted to run my ecoemploi "sub-system".

It's my first Kubernetes deployment. Am I missing something important?

Marc Le Bihan
  • 2,308
  • 2
  • 23
  • 41

1 Answers1

0

The error might be due to your system have shutdown unexpectedly.

Try running below command:

postgres -D /usr/local/var/postgres

You will get the below output:

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

Then kill -9 PID , and it should start postgres normally.

Another workaround is to download the official postgresqlapp and launch it. It will force the server to start.

Fariya Rahmat
  • 2,123
  • 3
  • 11
  • I've attempted a `postgres -D /usr/local/var/postgres` from the bash command line that led me into the pod. It responds: `"root" execution of the PostgreSQL server is not permitted.`. I did a `su - postgres` (I have no `sudo` under that pod) but then I received: `postgres: command not found`. – Marc Le Bihan Mar 22 '23 at 03:06
  • Refer to this [link](https://stackoverflow.com/questions/37307346/is-the-server-running-on-host-localhost-1-and-accepting-tcp-ip-connections). Let me know if it helps. – Fariya Rahmat Mar 22 '23 at 10:41
  • I hope the shared information was helpful to you in overcoming the issue. If you have any further queries, I am happy to offer further assistance. – Fariya Rahmat Apr 03 '23 at 08:57