The unbreakable, scalable elephant - Patroni automation with Ansible - - PowerPoint PPT Presentation

the unbreakable scalable elephant patroni automation with
SMART_READER_LITE
LIVE PREVIEW

The unbreakable, scalable elephant - Patroni automation with Ansible - - PowerPoint PPT Presentation

18.10.2019 The unbreakable, scalable elephant - Patroni automation with Ansible 18.10.2019 Who we are The Company > Founded in 2010 > More than 70 specialists > Specialized in the Middleware Infrastructure > The invisible part of IT


slide-1
SLIDE 1

18.10.2019

The unbreakable, scalable elephant - Patroni automation with Ansible

slide-2
SLIDE 2

18.10.2019

Who we are

18.10.2019 Page 2 The unbreakable, scalable elephant

The Company

>Founded in 2010 >More than 70 specialists >Specialized in the Middleware Infrastructure

> The invisible part of IT

>Customers in Switzerland and all over Europe

Our Offer

>Consulting >Service Level Agreements (SLA) >Trainings >License Management

slide-3
SLIDE 3

18.10.2019

About me

18.10.2019 Page 3 The unbreakable, scalable elephant

Julia Gugel

Consultant +41 78 320 43 07 julia.gugel[at]dbi-services.com

slide-4
SLIDE 4

18.10.2019

Agenda

  • 1. Ansible
  • 2. Patroni
  • 3. Little helpers
  • 4. Demo
  • 5. Conclusion

18.10.2019 Page 4 The unbreakable, scalable elephant

slide-5
SLIDE 5

18.10.2019

18.10.2019 Page 5 The unbreakable, scalable elephant

1 2 3 4 5

Ansible

> What is Ansible? > Playbooks, Modules & Co. > How to run a playbook

slide-6
SLIDE 6

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 6

Ansible

What is Ansible? Overview

> Simple IT automation engine > Designed for multi-tier deployments > Does not use agents > Pushing small programs "Ansible modules" to the nodes > Playbooks written in YAML

No need to know the commands to accomplish tasks

slide-7
SLIDE 7

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 7

Ansible

Playbooks, Modules & Co. Inventory

>Set of Hosts

Task

>Call to an Ansible module

Module

>Unit of code which is implemented by Ansible on the host

Play

>One or more tasks executed on a particular host

Playbooks

>One or more plays >Plays may be executed on similar or different hosts

slide-8
SLIDE 8

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 8

Ansible

Playbooks, Modules & Co. Roles

> Group the resources according to particular functionality > Directories for

Variables Templates Tasks …..

> Specify roles within playbooks to use them

Templates

> Transfers templated files to remote hosts > Templating happens on the Ansible controller before the task is sent > Stored in j2 format

slide-9
SLIDE 9

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 9

Ansible

How to run a playbook One simple command to run a playbook ……and all the magic starts……

[root@ansible]:/home/ansible/roles# ansible-playbook -i ../patroni patroni/site.yml PLAY [patroni-servers] *********************************************************** TASK [Gathering Facts] ***********************************************************

  • k: [192.168.22.112]
  • k: [192.168.22.113]
  • k: [192.168.22.111]
slide-10
SLIDE 10

18.10.2019

18.10.2019 Page 10 The unbreakable, scalable elephant

1 2 3 4 5

Patroni

> What is Patroni? > Requirements

slide-11
SLIDE 11

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 11

Patroni

What is Patroni? Zalando’s Python-based PostgreSQL controller Template to create high-availability solutions

> Far from being a one-size-fits-all or plug-and-play replication system

Fork of Governor with plenty of new features

> Support for Consul or Zookeeper > Dynamical reconfiguration of all cluster members at once > Support for watchdog on Linux

In active development and accepts contributions

slide-12
SLIDE 12

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 12

Patroni

What is Patroni? Components

>One writable node (primary/leader) >Multiple read-only replicas (secondary)

Supports manual and automatic failovers Problem:

>How to know who is leader? Is the leader present? Who gets the new leader?

slide-13
SLIDE 13

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 13

Patroni

Requirements Packages A distributed key value store (dcs)

> etcd, consul, zookeeper….. [root@patroni2 ~]# yum install etcd haproxy libyaml python [root@patroni2 ~]# yum install python-psycopg2 [root@patroni2 ~]# pip install psycopg2-binary [root@patroni2 ~]# pip install psycopg2>=2.5.4 [root@patroni2 ~]# pip install patroni[etcd]

slide-14
SLIDE 14

18.10.2019

18.10.2019 Page 14 The unbreakable, scalable elephant

1 2 3 4 5

Little helpers

> etcd > HAProxy > watchdog

slide-15
SLIDE 15

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 15

Little helpers

etcd What is etcd?

> Distributed Key value store to store data across distributed systems > Stores information about the Cluster status, available nodes and resources > Needs an uneven number of members > Leader is elected by the other members

What is it used for in combination with Patroni?

> Postgres nodes make use of etcd to keep the Postgres Cluster up and running

slide-16
SLIDE 16

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 16

Little helpers

HAProxy What is HAProxy?

> Solution for high availability, load balancing and proxying for TCP/HTTP-based applications > De-facto standard open source load balancer > Shipped with most mainstream Linux distributions > Often deployed by default in cloud platforms

What is it used for in combination with Patroni?

> Giving your application a single endpoint for connecting to the cluster's leader

slide-17
SLIDE 17

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 17

Little helpers

watchdog What is watchdog?

> Daemon/subsystem used to monitor the basic health of a machine > Device that triggers a system reboot if it detects

The system hangs No more free memory

> Can also trigger a script, before triggering a reboot

What is it used for in combination with Patroni?

> Automatic reboot when server gets unavailable due to failures

slide-18
SLIDE 18

18.10.2019

18.10.2019 Page 18 The unbreakable, scalable elephant

1 2 3 4 5

Demo

> Starting position > Adding a node > Removing a node

slide-19
SLIDE 19

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 19

Demo

Starting position

Ansible Patroni1 Patroni2 Patroni3

192.168.22.110 192.168.22.111 192.168.22.112 192.168.22.113

Patroni4

192.168.22.114

slide-20
SLIDE 20

18.10.2019

18.10.2019 Page 20 The unbreakable, scalable elephant

1 2 3 4 5

Conclusion

> Lessons learned > Advantages and drawbacks

slide-21
SLIDE 21

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 21

Conclusion

Lessons learned

Did you recognize this?

slide-22
SLIDE 22

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 22

Conclusion

Lessons learned

And that?

slide-23
SLIDE 23

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 23

Conclusion

Lessons learned

And now?

slide-24
SLIDE 24

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 24

Conclusion

Lessons learned

And now?

slide-25
SLIDE 25

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 25

Conclusion

Lessons learned

And now?

slide-26
SLIDE 26

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 26

Conclusion

Lessons learned To improve it:

>Correct the entry in the etcd.conf: >Add the new host to the etcd cluster: postgres@patroni1:/home/postgres/ [PG1]$ etcdctl member add patroni4 http://192.168.22.114:2380 name: patroni4 data-dir: /u02/pgdata/etcd initial-advertise-peer-urls: http://192.168.22.114:2380 listen-peer-urls: http://192.168.22.114:2380 listen-client-urls: http://192.168.22.114:2379,http://localhost:2379 advertise-client-urls: http://192.168.22.114:2379 initial-cluster: patroni1=http://192.168.22.111:2380,patroni2=http://192.168.22.112:2380,patr

  • ni3=http://192.168.22.113:2380,patroni4=http://192.168.22.114:2380
slide-27
SLIDE 27

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 27

Conclusion

Lessons learned To improve it:

>Correct the entry in the etcd.conf: >Add the new host to the etcd cluster: postgres@patroni1:/home/postgres/ [PG1]$ etcdctl member add patroni4 http://192.168.22.114:2380 name: patroni4 data-dir: /u02/pgdata/etcd initial-advertise-peer-urls: http://192.168.22.114:2380 listen-peer-urls: http://192.168.22.114:2380 listen-client-urls: http://192.168.22.114:2379,http://localhost:2379 advertise-client-urls: http://192.168.22.114:2379 initial-cluster: patroni1=http://192.168.22.111:2380,patroni2=http://192.168.22.112:2380,patr

  • ni3=http://192.168.22.113:2380,patroni4=http://192.168.22.114:2380

name: patroni4 data-dir: /u02/pgdata/etcd initial-advertise-peer-urls: http://192.168.22.114:2380 listen-peer-urls: http://192.168.22.114:2380 listen-client-urls: http://192.168.22.114:2379,http://localhost:2379 advertise-client-urls: http://192.168.22.114:2379 initial-cluster-state: 'existing' initial-cluster: patroni1=http://192.168.22.111:2380,patroni2=http://192.168.22.112:2380, \ patroni3=http://192.168.22.113:2380,patroni4=http://192.168.22.114:2380

slide-28
SLIDE 28

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 28

Conclusion

Lessons learned To make it better and High Available:

>Start etcd service >Change the patroni.yml on the new host >Start patroni service etcd: host: 127.0.0.1:2379 root@patroni4:/home/postgres/ [PG1]$ systemctl start etcd root@patroni4:/home/postgres/ [PG1]$ systemctl start patroni

slide-29
SLIDE 29

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 29

Conclusion

Lessons learned To make it better and High Available:

>Start etcd service >Change the patroni.yml on the new host >Start patroni service etcd: host: 127.0.0.1:2379 etcd: hosts: 192.168.22.111:2379,192.168.22.112:2379 \ ,192.168.22.113:2379,192.168.22.114:2379 root@patroni4:/home/postgres/ [PG1]$ systemctl start etcd root@patroni4:/home/postgres/ [PG1]$ systemctl start patroni

slide-30
SLIDE 30

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 30

Conclusion

Advantages and drawbacks

Pre work tasks take a lot of time. It is not unbreakable, but close to. Time mismatch is critical. Scale up and down is easy and fast. Ansible playbooks make an admins life easier / reduce human errors. Ability to reduce common risks.

slide-31
SLIDE 31

18.10.2019

18.10.2019 The unbreakable, scalable elephant Page 31

Conclusion

Advantages and Drawbacks

slide-32
SLIDE 32

18.10.2019

18.10.2019 Page 32