Home Explore Blog CI



kubernetes

4th chunk of `content/en/blog/_posts/2017-02-00-Postgresql-Clusters-Kubernetes-Statefulsets.md`
aebb380ba82acea18b0f9381f368026b836aaf041137729000000001000006fa
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.



Next, test the replica as follows:



```
psql -h pgset-replica -U postgres postgres  -c 'create table foo (id int)'
 ```



The command above should fail as the replica is **read-only** within a PostgreSQL cluster.



Next, scale up the set as follows:



```
kubectl scale statefulset pgset --replicas=3
 ```



The command above should successfully create a new replica pod called **pgset-2** as depicted below:

 ![](https://lh5.googleusercontent.com/w82XRPd9LqwgcoY3wJrilJEULxZyub6HLcFk332--1fd94-Vte4YlDFvspLM9syNCdT47PISJlEDo7jSPmiflFv-ZZKmrY6Jm6sJWMki0RfJigf6a6IEPNeyy1PJ_5Mhd4NW4rHm)

Title: Testing PostgreSQL Replication and Scaling the StatefulSet
Summary
This section describes testing the PostgreSQL deployment by first verifying that the replica is read-only, then scaling up the StatefulSet to create a new replica pod. The read-only test involves attempting to create a table on the replica, which should fail. Scaling up the StatefulSet increases the number of replicas, in this case, creating a new pod named 'pgset-2'.