Postgres service was unable to connect

I am trying to deploy ‘voting-app’ service in minikube based on guide of ’ Demo – Deploying voting app on Kubernetes’ in course ‘Kubernetes for the Absolute Beginners - Hands-on’.

I have create pods with following yaml:

$ cat postgres-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: postgres-pod
  labels:
    name: postgres-pod
    app: demo-voting-app
spec:
  containers:
  - name: postgres
    image: postgres:9.4
    ports:
    - containerPort: 5432
    env:
    - name: POSTGRES_USER
      value: "postgres"
    - name: POSTGRES_PASSWORD
      value: "postgres"

postgres service yaml

$ cat postgres-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: db
  labels:
    name: postgres-service
    app: demo-voting-app
spec:
  ports:
  - port: 5432
    targetPort: 5432
  selector:
    name: postgres-pod
    app: demo-voting-app

worker pod was unable to start as following error was shown in kubectl logs worker-pod

$ kubectl logs pod/worker-pod
System.NotSupportedException: Authentication method not supported (Received: 10)
   at Npgsql.NpgsqlConnector.ParseServerMessage(ReadBuffer buf, BackendMessageCode code, Int32 len, DataRowLoadingMode dataRowLoadingMode, Boolean isPrependedMessage)
   at Npgsql.NpgsqlConnector.DoReadMessage(DataRowLoadingMode dataRowLoadingMode, Boolean isPrependedMessage)
   at Npgsql.NpgsqlConnector.ReadMessageWithPrepended(DataRowLoadingMode dataRowLoadingMode)
   at Npgsql.NpgsqlConnector.HandleAuthentication(String username, NpgsqlTimeout timeout)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
   at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)
   at Npgsql.NpgsqlConnection.OpenInternal()
   at Worker.Program.OpenDbConnection(String connectionString) in /code/src/Worker/Program.cs:line 78
   at Worker.Program.Main(String[] args) in /code/src/Worker/Program.cs:line 19

And I login to ‘postgres-pod’ to check with following cmd:

# /usr/bin/psql -h 10.111.80.17 -p 5432 -U postgres -W
Password for user postgres:
psql: could not connect to server: Connection timed out
        Is the server running on host "10.111.80.17" and accepting
        TCP/IP connections on port 5432?

ip of ‘10.111.80.17’ is svc ‘postgres-service’ .

 $ kubectl get svc -o wide
NAME             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE   SELECTOR
db               ClusterIP   10.111.80.17    <none>        5432/TCP       35m   app=demo-voting-app,name=postgres-pod
kubernetes       ClusterIP   10.96.0.1       <none>        443/TCP        81m   <none>
redis            ClusterIP   10.99.219.213   <none>        6379/TCP       35m   app=demo-voting-app,name=redis-pod
voting-service   NodePort    10.96.33.60     <none>        80:30004/TCP   37m   app=demo-voting-app,name=voting-app-pod

any guidance or tips would be appreciated?

Hello @Matrix-Zou,
Please follow these full steps to know what you have missed and try again :

Note: We will create deployments again so please before following the steps, Run kubectl delete deployment --all to delete old deployments and avoid any conflicts.

  1. Run git clone https://github.com/mmumshad/example-voting-app-kubernetes-v2.git

  2. Run cd example-voting-app-kubernetes-v2/

  3. Run vim postgres-deployment.yml and modify it’s content as below then save and exit.

Note: It’s a new update from Postgres.

apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: postgres-deployment
   labels:
     app: demo-voting-app
 spec:
   replicas: 1
   selector:
     matchLabels:
       name: postgres-pod
       app: demo-voting-app
   template:
     metadata:
       name: postgres-pod
       labels:
         name: postgres-pod
         app: demo-voting-app
     spec:
       containers:
       - name: postgres
         image: postgres:9.4
         env:
         - name: POSTGRES_USER
           value: postgres
         - name: POSTGRES_PASSWORD
           value: postgres
         - name: POSTGRES_HOST_AUTH_METHOD
           value: trust
         ports:
         - containerPort: 5432
  1. Run kubectl create -f . if you create deployments for the first time, if you created the same deployments before Run kubectl apply -f . .

  2. Run kubectl get service to get the exposed ports.

For example if the output of the command as above you can accces the voting app by hitting One_of_the_worker_nodes_IP:32733 on your browser and the same for the resulting app >> One_of_the_worker_nodes_IP:30013.

Check :

Note: The voting application only accepts one vote per client. It does not register votes if a vote has already been submitted from a client.

Hope this helps!

2 Likes

Hi, @Ayman

Thanks for your quick support. After update postgres pod creation file, it works for me.