This issue occurs due to a known bug in the find_current_master() function in the /scripts/utils.sh file in the postgres pods.
Resolution
To resolve this issue:
Edit the postgres-scripts configmap in the prelude kubernetes namespaces through the kubectl edit configmap -n prelude postgres-scripts command.
Apply these changes:
In the find_current_master function definition in the file, replace the line:
local CLUSTER=$(ssh postgres@"${LINE}" repmgr cluster show --csv || true)
with this line, while observing and keeping the existing indentation.
local CLUSTER=$(ssh postgres@"${LINE}" repmgr cluster show --csv </dev/null 2>/dev/null || true)
This should resolve the issue live and postgres-0 and postgres-1 will be able to connect to postgres-2.
After this is confirmed, the fix should be made persistent by editing the content of /opt/charts/postgres/templates/scripts/configmap.yaml on each node, applying the same change.