GithubHelp home page GithubHelp logo

isabella232 / postgresql-patroni-container Goto Github PK

View Code? Open in Web Editor NEW

This project forked from canonical/postgresql-patroni-container

0.0 0.0 0.0 14 KB

License: Apache License 2.0

Dockerfile 61.24% Shell 38.76%

postgresql-patroni-container's Introduction

PostgreSQL + Patroni Container

This docker container image bundles PostgreSQL database and Patroni (a template for PostgreSQL HA).

Built for use in the PostgreSQL k8s charm.

Currently it uses Postgres 12.4 on Ubuntu 20.04 LTS as the base image and adds Patroni v2.1.2 on top of it.

Usage

This container image requires a configuration file for Patroni and also some environment variables. They are explained in the following subsections.

Once they are all set and the image is present in a registry accessible on your cluster or published along with the charm, the charm can execute the following command to start Patroni (which starts and manages PostgreSQL process lifecycle):

/usr/bin/python3 /usr/local/bin/patroni /var/lib/postgresql/data/patroni.yml # use the path where the charm pushed the configuration file

Patroni configuration file

The k8s charm using this container image should push a Patroni configuration file with the following layout (replacing the {{ pod_ip }} variable with the pod IP address):

bootstrap:
  dcs:
    postgresql:
      use_pg_rewind: true
  initdb:
  - auth-host: md5
  - auth-local: trust
  - encoding: UTF8
  - locale: en_US.UTF-8
  - data-checksums
  pg_hba:
  - host all all 0.0.0.0/0 md5
  - host replication replication {{ pod_ip }}/16 md5
bypass_api_service: true
log:
  dir: /var/log/postgresql
restapi:
  connect_address: '{{ pod_ip }}:8008'
  listen: 0.0.0.0:8008
pod_ip: '{{ pod_ip }}'
postgresql:
  connect_address: '{{ pod_ip }}:5432'
  custom_conf: /var/lib/postgresql/data/postgresql-k8s-operator.conf
  data_dir: /var/lib/postgresql/data/pgdata
  listen: 0.0.0.0:5432
  pgpass: /tmp/pgpass
use_endpoints: true

The charm can also change the values of these settings (but these ones are good defaults based on Patroni k8s example) or choose different paths for the logs directory, data directory and custom postgresql.conf file based on how it's setting the paths in its code.

Environment variables

Some additional environment variables are required to properly start and run both Patroni and PostgreSQL:

  • PATRONI_KUBERNETES_LABELS
    • Labels applied to the created pods and which are used by Patroni to find the members of a cluster and replicate the data.
  • PATRONI_KUBERNETES_NAMESPACE
    • Namespace where the pods are created.
  • PATRONI_KUBERNETES_POD_IP
    • IP of the current pod (this variable is required only when deploying the image directly to a cluster i.e. not in a charm which replaces the pod IP in the patroni.yml file).
  • PATRONI_NAME
    • Name of the member in the cluster (for example, the pod name, such as postgresql-k8s-0).
  • PATRONI_SCOPE
    • Cluster name (can be the name of the juju deployment).
  • PATRONI_REPLICATION_USERNAME
    • Username Patroni will use to manage PostgreSQL replication.
    • Default = replication
  • PATRONI_REPLICATION_PASSWORD
    • Password for Patroni replication user.
  • PATRONI_SUPERUSER_USERNAME
    • Username that is used to run init db in the PostgreSQL bootstrap process.
    • Default = postgres
  • PATRONI_SUPERUSER_PASSWORD
    • Password for PostgreSQL superuser.

These variables can also be informed in the configuration file. They are listed separately from the configuration file in this README because it makes it easier to unit test the current PostgreSQL k8s charm.

postgresql-patroni-container's People

Contributors

marceloneppel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.