Home Explore Blog CI



kubernetes

3rd chunk of `content/en/blog/_posts/2017-02-00-Postgresql-Clusters-Kubernetes-Statefulsets.md`
1f9c123b6c5fe5eb7594096374ba7d2b77646cede5194b1f0000000100000607
![](https://lh3.googleusercontent.com/5NthdAnA243jN_gXVlwZsg74jkGgCwQZh1yq78-8E0L7wuDgpdqH_AaeUvQd9RtXIlOV0cAWv1P0a_2oeVJN8fHstf9Iev1c-swGIqojIw0pXrVuqAqpCF3M5hw6sdTmx_1-Bg27)

In this deployment, there is a Service for the master and a separate Service for the replica.  The replica is connected to the master and replication of state has started.



The Crunchy PostgreSQL container supports other forms of cluster deployment, the style of deployment is dictated by setting the PG\_MODE environment variable for the container.  In the case of a StatefulSet deployment, that value is set to: PG\_MODE=set



This environment variable is a hint to the container initialization logic as to the style of deployment we intend.



**Step 7** - Testing the Example



The tests below assume that the psql client has been installed on the test system. If not, the psql client has been previously installed, it can be installed as follows:



```
sudo yum -y install postgresql
 ```



In addition, the tests below assume that the tested environment DNS resolves to the Kube DNS and that the tested environment DNS search path is specified to match the applicable Kube namespace and domain. The master service is named pgset-master and the replica service is named pgset-replica.



Test the master as follows (the password is password):



```
psql -h pgset-master -U postgres postgres -c 'table pg\_stat\_replication'
 ```



If things are working, the command above will return output indicating that a single replica is connecting to the master.

Title: Master/Replica Services, PG_MODE Environment Variable, and Testing the PostgreSQL Deployment
Summary
This section details that there are separate services for the PostgreSQL master and replica, with the replica connected and replicating state from the master. The `PG_MODE` environment variable is set to 'set' to indicate a StatefulSet deployment. It also provides instructions on how to test the deployment by using the `psql` client to check if the replica is connected to the master, assuming the necessary DNS configurations are in place.