Giter Site home page Giter Site logo

postgres-statefulset's Introduction

postgres-statefulset

This is an example of using Kubernetes StatefulSets to get a Postgres instance running with replication enabled. This also uses the standard Postgres container. Blog article here

The work here is based off the official documentation here https://wiki.postgresql.org/wiki/Streaming_Replication

Configuration

  1. Edit config/secret.yml with the Postgres database password and the replication password
  2. Run kubectl apply -f config/secret.yml and then cd config && ./create_configmap.sh

Note, replication password is used to connect to the master and stream updates to the replica. It just needs to be a random password.

Running

Running this example is easy!

Start Master servers

Run kubectl apply -f statefulset-master.yml and wait for Master to be running

Start Master service (IMPORTANT or replica cannot find the master)

Run kubectl apply -f service.yml

Start Replica server

Run kubectl apply -f statefulset-replica.yml and wait for Replica to be running

If you run kubectl logs -f postgres-replica-0, you can see in the logs that it starts replication:

2019-01-08 05:07:01.035 UTC [24] LOG:  started streaming WAL from primary at 0/6000000 on timeline 1

That's it, you have a full Postgres master + replicating server that's ready to use in production.

Multiple Replicas

You can also set replicas to more than 1 if you want N replicas.

Motivation

I was using Helm to manage Postgres, but they switched to bitnami/postgresql instead of the standard postgres. Also, upon upgrading, I could not use my existing helm setup to get replication working.

Lately I've realized it's just easier to write my own definitions instead of messing around with Helm charts.

postgres-statefulset's People

Contributors

arianitu 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.