postgresqlkubernetesopenshiftstolon

How can I deploy PostgreSQL using the Stolon operator on OpenShift?


Please provide detailed steps and explanations for each configuration file and command. Explanation of stolon operator's working would also be helpful along with code reference.

I have followed the steps from stolon github doc but not able to start the postgres server. Thank you for the help!


Solution

  • The stolon operator key components :

    The Stolon operator is a Kubernetes operator that manages PostgreSQL clusters using the Stolon framework. Stolon is a cloud-native PostgreSQL manager that provides high availability, automated failover, and replication. Here's an overview of how the Stolon operator works:

    Key Components

    1. Stolon Keeper:

      • Manages PostgreSQL instances.
      • Each keeper runs a PostgreSQL instance and is responsible for starting, stopping, and monitoring it.
      • Keeps the PostgreSQL data directory in sync with the cluster state.
    2. Stolon Sentinel:

      • Monitors the state of the PostgreSQL cluster.
      • Decides which keeper should be the master and which should be replicas.
      • Handles failover by promoting a replica to master if the current master fails.
    3. Stolon Proxy:

      • Provides a single endpoint for clients to connect to the PostgreSQL cluster.
      • Routes client connections to the current master.
      • Ensures that clients always connect to the correct master instance.
    4. Stolonctl:

      • Command-line tool for managing the Stolon cluster.
      • Used to initialize the cluster, perform manual failovers, and manage cluster configuration.

    Deploy postgres through stolon operator

    To deploy PostgreSQL using the Stolon operator on OpenShift, follow these detailed steps. I will explain each configuration file and the commands required to set up the deployment.

    Explanation of Deployment Files

    1. role.yaml:

      • Defines the permissions required by Stolon components (pods, services, configmaps, etc.) in the namespace.
    2. role-binding.yaml:

      • Binds the role defined in role.yaml to the service account used by Stolon.
    3. secret.yaml:

      • Stores sensitive information such as passwords for the Stolon components.
    4. stolon-keeper_new.yaml:

      • Defines the deployment for the Stolon Keeper, which manages the PostgreSQL instances.
    5. stolon-keeper-service.yaml:

      • Defines the service for the Stolon Keeper, exposing it within the cluster.
    6. stolon-proxy_new.yaml:

      • Defines the deployment for the Stolon Proxy, which routes client connections to the correct PostgreSQL instance.
    7. stolon-proxy-service.yaml:

      • Defines the service for the Stolon Proxy, exposing it within the cluster.
    8. stolon-sentinel-service.yaml:

      • Defines the service for the Stolon Sentinel, exposing it within the cluster.
    9. stolonctl-pod.yaml:

      • Defines a pod for running stolonctl commands to initialize and manage the Stolon cluster.

    Steps to Deploy Stolon on OpenShift

    1. Create a New Project:

      oc new-project <new-namespace>
      
    2. Create a Service Account:

      oc create sa stolon-sa -n <new-namespace>
      
      • Assign the anyuid Security Context Constraints (SCC) to the service account:
        oc adm policy add-scc-to-user anyuid -z stolon-sa -n <new-namespace>
        
    3. Assign Required Roles:

      • Update role.yaml and role-binding.yaml with the new namespace and service account name.
      • Apply the role and role binding:
        oc apply -f role.yaml -n <new-namespace>
        oc apply -f role-binding.yaml -n <new-namespace>
        
    4. Create Secrets:

      • Ensure secret.yaml is configured correctly for the new namespace.
      • Apply the secret:
        oc apply -f secret.yaml -n <new-namespace>
        
    5. Deploy Stolon Keeper:

      • Update stolon-keeper_new.yaml and stolon-keeper-service.yaml with the new namespace.
      • Apply the configurations:
        oc apply -f stolon-keeper_new.yaml -n <new-namespace>
        oc apply -f stolon-keeper-service.yaml -n <new-namespace>
        
    6. Deploy Stolon Proxy:

      • Update stolon-proxy_new.yaml and stolon-proxy-service.yaml with the new namespace.
      • Apply the configurations:
        oc apply -f stolon-proxy_new.yaml -n <new-namespace>
        oc apply -f stolon-proxy-service.yaml -n <new-namespace>
        
    7. Deploy Stolon Sentinel:

      • Update stolon-sentinel.yaml and stolon-sentinel-service.yaml with the new namespace.
      • Apply the configurations:
        oc apply -f stolon-sentinel.yaml -n <new-namespace>
        oc apply -f stolon-sentinel-service.yaml -n <new-namespace>
        
    8. Initialize Stolon Cluster:

      • Update stolonctl-pod.yaml with the new namespace.
      • Apply the configuration:
        oc apply -f stolonctl-pod.yaml -n <new-namespace>
        
    9. Verify Deployment:

      • Check the status of the pods and services:
        oc get pods -n <new-namespace>
        oc get services -n <new-namespace>
        
    10. Use the postgres instance:

      • Go to keeper pod and use psql command:
        oc exec -it stolon-keeper-0  -- psql -h stolon-proxy -U stolon -d postgres -W
        

        password : password1

    YAML files can be found in this github gist

    By following these steps, you should be able to deploy Stolon on OpenShift successfully. If you encounter any issues, please let me know!