3

So I am trying to configure postgresql with pgadmin access, I have managed to get postgresql and pgadmin deployed but issues appears when I try to login into pgadmin UI.

My k8s cluster is on google cloud platform.

Cluster info.

Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.4", GitCommit:"c96aede7b5205121079932896c4ad89bb93260af", GitTreeState:"clean", BuildDate:"2020-06-18T17:02:08Z", GoVersion:"go1.13.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.10-gke.36", GitCommit:"34a615f32e9a0c9e97cdb9f749adb392758349a6", GitTreeState:"clean", BuildDate:"2020-04-06T16:33:17Z", GoVersion:"go1.12.12b4", Compiler:"gc", Platform:"linux/amd64"}

This is pgadmin-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: pgadmin
spec:
  selector:
    matchLabels:
      frontend: pgadmin
  replicas: 1
  template:
    metadata:
      labels:
        frontend: pgadmin
    spec:
     containers:
     - name: pgadmin
       image: dpage/pgadmin4
       imagePullPolicy: "IfNotPresent"
       env:
       - name: PGADMIN_DEFAULT_EMAIL
         value: "[email protected]"
       - name: PGADMIN_DEFAULT_PASSWORD
         value: "test!"
       - name: PGADMIN_LISTEN_PORT
         value: "443"
       ports:
       - containerPort: 443

Here is mine pgadmin-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: pgadmin-service
spec:
  type: ClusterIP
  selector:
    frontend: pgadmin
  ports:
    - port: 9210
      targetPort: 443
      protocol: TCP

Also I have certmanager and nginx ingress installed on the cluster.

Nginx installation steps:

helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm install my-ingress stable/nginx-ingress --set rbac.create=true

Cert-Manager install steps:

kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.15.1/cert-manager-legacy.crds.yaml
kubectl create namespace cert-manager
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install \
  cert-manager jetstack/cert-manager \
  --namespace cert-manager \
  --version v0.15.1 \
  # --set installCRDs=true

My issuer.yaml

apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: "[email protected]"
    privateKeySecretRef:
      name: letsencrypt-prod
    solvers:
      - http01:
          ingress:
            class: nginx

My certificate.yaml

apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
  name: mydomain.com
spec:
  secretName: cert
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
  commonName: mydomain.com
  dnsNames:
    - pgadmin.mydomain.com
  acme:
    config:
      - http01:
          ingressClass: nginx
        domains:
          - pgadmin.mydomain.com

And finally ingress-service.yaml

 apiVersion: networking.k8s.io/v1beta1 #networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
 kind: Ingress
 metadata:
   name: example-ingress
   namespace: default
   annotations:
     kubernetes.io/ingress.class: nginx
     nginx.ingress.kubernetes.io/rewrite-target: /
     cert-manager.io/cluster-issuer: "letsencrypt-prod"
     nginx.ingress.kubernetes.io/ssl-redirect: 'true'
     nginx.ingress.kubernetes.io/use-regex: 'true'
 spec:
   tls:
    - hosts:
        - pgadmin.mydomain.com
      secretName: cert
   rules:
     - host: pgadmin.mydomain.com
       http:
         paths:
         - path: /
           backend:
             serviceName: pgadmin-service
             servicePort: 9210

Currently my issue is when I try to login into my pgadmin UI, I get the following error: error

Container logs: logs

My domain is located behind CloudFlare. tls settings

If anything else is needed please let me know.

2 Answers 2

1

Don't use port 443 .. use 80 and don't use ssl in pod.Terminate pls on ingress

1
  • I've tried with it but no luck. Same error appears.
    – Vuzimir
    Commented Jul 1, 2020 at 10:07
0

It's is because you aren't passing the TLS certificate to pgadmin pods.

As mentioned in documentation, you need to provide the certificate and key:

PGADMIN_ENABLE_TLS

Default:

If left un-set, the container will listen on port 80 for connections in plain text. If set to any value, the container will listen on port 443 for TLS connections.

When TLS is enabled, a certificate and key must be provided. Typically these should be stored on the host file system and mounted from the container. The expected paths are /certs/server.crt and /certs/server.key

You have 2 options:

  1. Provide the key using the volumes on your deployment as mentioned here
  2. Use port 80 on deployment and configure the SSL in the Ingress.

From the specs you have provided, you should change the deployment file to:

..
      env:
       - name: PGADMIN_DEFAULT_EMAIL
         value: "[email protected]"
       - name: PGADMIN_DEFAULT_PASSWORD
         value: "test!"
       ports:
       - containerPort: 80

Change the service spec to point to the correct port:

apiVersion: v1
kind: Service
metadata:
  name: pgadmin-service
spec:
  selector:
    frontend: pgadmin
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP

And then, change the ingress to the correct port:

 spec:
   tls:
    - hosts:
        - pgadmin.mydomain.com
      secretName: cert
   rules:
     - host: pgadmin.mydomain.com
       http:
         paths:
         - path: /
           backend:
             serviceName: pgadmin-service
             servicePort: 80

The ingress will redirect all request from port 80 to 443 since you are using the nginx.ingress.kubernetes.io/ssl-redirect annotation

6
  • Hi, so I have tried that method but result is same. Console logs: https://imgur.com/a/6zvDnRE Cookie: https://imgur.com/a/Sy0CSIC Payload: next=%2Fbrowser%2F&csrf_token=Ijk0NDU3ZjQ3ODYwNDEzMmIxODIwYTk4OGFmZjJkZjg3M2M3M2VjMTMi.XvxbGg.habrY5SqFPWmvBS99BEvLei_aLg&email=test%test.com&password=mypass%21&language=en Response is error code 400 BAD REQUEST @KoopaKiller
    – Vuzimir
    Commented Jul 1, 2020 at 10:06
  • 1
    You can make sure the service is working properly using kubectl port-forward svc pgadmin-service 8080:80 this command will map the port 8080 from your machine to service port, them you can access using localhost:8080. Just to eliminate the Ingress misconfiguration. Could you confirm if everything is ok? Commented Jul 1, 2020 at 10:14
  • Hi, I have tried it and its working as intended. I was able to login without any issues.
    – Vuzimir
    Commented Jul 1, 2020 at 10:26
  • Ok, after make sure the application is worling, let's put our efforts on ingress. Can you test the domain ingress without Cloudflare? Also, make sure the certificate was issued with the command kubectl describe certificate. Please share the results Commented Jul 2, 2020 at 8:39
  • 1
    Ok, i don't have much experience with how Cloudflare works with TLS mode, maybe you can open a ticker in Cloudflare support. But now you have sure the problem is not in your kubernetes deployment. =) Commented Jul 3, 2020 at 8:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.