PostgreSQL auf K8s bei Zalando: zwei Jahre im Kampf. Alexander Kukushkin (Zalando)



Wir alle wissen, dass die meisten Datenbankadministratoren sehr konservativ sind und es vorziehen, dass ihre Datenbanken ausschlieƟlich auf dedizierten Servern gespeichert sind. In der modernen Welt mit Microservices, Kafka und Kubernetes beginnt die Anzahl der Basen direkt proportional zur GrĆ¶ĆŸe des Unternehmens zu wachsen und geht sehr schnell Ć¼ber das komfortable manuelle oder halbautomatische Management hinaus.







Ich arbeite jetzt seit fast 7 Jahren bei Zalando. Wie viele haben von Zalando gehƶrt?





  • FĆ¼r diejenigen, die nicht gehƶrt haben, ist dies eine Firma Ƥhnlich der russischen Lamoda.



  • Wir verkaufen Kleidung und Schuhe, aber wir machen das in Europa, in 17 LƤndern.



  • Wir haben 7 eigene Logistikzentren und Lager.



  • Zalando beschƤftigt Ć¼ber 15.000 Mitarbeiter.



  • Und davon arbeiten rund 2.000 in der Technik. Die Mitarbeiter der Technologie verteilen sich auf rund 200 Teams, die Anwendungen schreiben.



  • In letzter Zeit haben wir viele Dinge auf Kubernetes bereitgestellt und viel mit Kubernetes gearbeitet.







?



  • , Kubernetes, , .
  • , Postgres Kubernetes Spilo Patroni.
  • , Postgres-Operator Kubernetes.
  • ā€“ , , .




  • Kubernetes . 140 . 50/50 production/test environment. . . cost unit 2 Kubernetes-. , . .
  • production deployment CI/CD. docker image, , CI/CD.
  • production Kubernetes- , . request, 4- , - , . -.




Postgres Kubernetes? . 10 Postgres- Kubernetes-.



Postgres-Operator Postgres Kubernetes , 140, .





Kubernetes, Postgres? . , , Kubernetes.



, , - .



  • Kubernetes . tools.
  • Kubernetes . .




. -. worker-, , Kubernetes , kubelet, docker, fluentd, kube-proxy . .



. , .





?



- . docker . Kubernetes . , PersistentVolumes PersistentVolumeClaim.



ā€“ StatefulSets, , -, , . . . , -, StatefulSets PersistentVolumeClaim PersistentVolumeClaim templates volume, volume , .





Postgres Kubernetes, . , Kubernetes docker. , - .



  • docker image. Spilo. Spilo ā€“ . image Postgres, . . , 9.3 12.
  • postgresā€™ extensions , pg_partman, pg_cron, postgis, etc, timescaledb.
  • tools , pgq, pgbouncer, wal-e/wal-g. , , docker Kubernetes, , image Kubernetes EC2 instance Amazon.
  • HA Patroni,
  • .




Patroni? , , . Postgres, HA.



Patroni Python. Kubernetes. Postgres first class citizen Kubernetes, . . Postgres .



Patroni Postgres Kubernetes supervisor , . . .



Patroni ā€“ , , failover . Patroni , . . InitDB Postgres, Patroni point in time recovery, .



, , Patroni .



, Patroni, Postgres. - Postgres, Patroni: Ā« Ā». .





? StatefulSet. . . PersistentVolume. StatefulSet, demo-0 demo-1.



, ā€“ Patroni. Patroni kubernetesā€™ endpoint. . . , Patroni , . , , , endpoint, IP.



-. , .



demo ā€” repl. , labelSelector: role = replica. , labelSelector.





?



, , YAML manifests. . , YAML. , .





Helm, . . CI/CD deployment. . rolling upgrade. minor Postgres, docker image, ? StatefulSet , StatefulSet, . . .



, , rolling upgrade. rolling upgrade Kubernetes-.





? , : 1, 2, 3. availability , . . -. , volumes .



Kubernetes upgrade, workers, . . . cloud environment AWS, - EC2 instance, . .



? , 3 , 3- . 2 availability .



Kubernetes , . Patroni . enter option , . . connections , . , .





.





Kubernetes rolling upgrade .





. . . .



, .





.





? ā€“ .





, 3 failover , . . 3 3 failover. B ā€“ 2, C ā€“ 2.





- , .





.





, , . . , : Ā« PostgresĀ». , pull request Git. kubectl Amazon. .



, - instance, .



.



, .





?



:



  • Deployments. . .
  • Upgrades clusters. rolling upgrade Postgres. rolling upgrade Kubernetes .
  • : , , .
  • failovers maintenance.




Postgres-Operator. Kubernetes, , . . , , . ā€“ , .





Postgres, YAML-. .



-, , ID , . . . Team, , ACID. ? , . . Atomicity, Consistency, Isolation, Durability.



-, volume. ā€“ 1 . ā€“ 2. Postgres. . : Ā«, , . owner Ā».



?





DB deployer. , CI/CD. YAML- CRD-, . Postgres-operator event . StatefulSet - . endpoint, . Postgres, . . superuser , .



Kubernetes , .





rolling upgrade Kubernetes?



.





3 , 3 . , 3 , .





, . Kubernetes , .





. , , .



switchover.





, . . switchover = 1.





, .





Switchover . , , , , . . , downtime .



? issues ?







-, Kubernetes- AWS. .



AWS API , API. , - , AWS .



? Kubernetes AWS API , volumes, , , volumes , postgresā€™ . , . .



, deployment , . , .



EC2 instance Amazon. , , , , . Amazon, EBS volumes instances. ? , . . - , instances. , instance Amazon, volumes . . . 30 , . , .





Kubernetes, , Postgres, , . Postgres . Patroni . Postgres , Patroni . ā€“ crash loop. , .



partitions , -. volume . . volume, , throughput IOPS. volume .





auto-extend volumes? Amazon . API. volume 100 , .



, , , , , auto-extend. , , . . .



volumes , .



. , - jobs . .





? HA , Disaster Recovery , wal-e continuous archiving , basebackup.



wal-e ā€“ , - . pg_stat_statements 2- . , . , : APDATE WHERE id IN 150 . . . Postgres ā€“ .



Pg_stat_statements 2- . pg_stat_statements , . Kubernetes , , , . .





wal-e , . , , postgresā€™ - label- . - reinitializing.



ā€“ - tools, , , wal-g, pgBackRest. . -, , Postgres 9.6, 9.5 . -, , , .



. wal-e, , basebackup wal-e.





. Out-Of-Memory? docker Kubernetes ā€“ . Postgres, , 9. , . production .



. dmesg. , Memory cgroup out of memory Postgres. , ?





? process ID, .



, , . dmesg -T -. OOM system control Ā«oom_score_adjĀ», . Patroni Postgres, . . , .



memory limit 8 , cgroup , 6 + postgresā€™ shared buffers 2 . 6 . postgresā€™ , , , .





. . , cgroup shared memory , - .



, shared buffers 25 % 20 %. , , . . .





Postgres 11- . production minor releases, . , , .



. , ā€“ , - , shared memory. docker shared memory 64 .



Postgres 11? Postgres 11 parallel hash join. ? worker hash, shared memory. 64 , hash .



? docker dev/shm, .



Kubernetes . . . ā€“ tmpfs volume dshm.



, . . volume ā€“ enableShmVolume. , , volume. , .





Postgres . -, failover , . . Patroni, - events. Patroni failover , .



, , FATAL too many connections. . . 12- Postgres . max_wal_senders max_connections. wal_senders Postgres. .



Postgres ā€“ Built-in connection pooler.





ā€“ :



  • , cluster manifest, , . , : 100 . , , . , . OOM-Killer . , .



    . , : 4 , 32 . , 5 64 , , Kubernetesā€™ . , - .



  • ? production - ServiceAccout, Spilo. , , Postgres real only. ServiceAccount , , - , . .



  • YAML-.





.





, , , , array . .





tools, , Postgres , , 10.10, . 10. volume . .



tools . , , Git .



environment Ā«Ā». .





1 500 postgresā€™ . 100 Kubernetes-. . , on-Call , , , , . . - .



, . , , Patroni, Spilo, .





, open source. . Patroni Spilo .





! , .



Questions



availability ?



?



.



, anti-affinity, . . .



! . : production?*



, . 600 1 400 production. . . 600 . , . , , environment . , . , production 2- .



, external volume, . . Host Path , . . - ?



, . . . i3-volume Amazon . ? EBS , . , . . , . , .



, IO-bound , ?



, . Amazon i3-instances. NVMe . instance , . , , . Kubernetes team , , , rolling upgrade , . . 1-2 . 1-2 - .



! ?



wal-e. docker crone, basebackup. archive_command, . . wal, , S3 Amazon. , basebackup + wal . retention ā€“ 5 , . . 5 .



! . 1 400? ? 2?



200 . , , , , . . Kafka. , . , . . , . , , . . . 80, . . .



, , Postgres ?



7 . . , . pets world cattle. Pet ā€“ , -, . ā€“ , . . - , .



?



, .



, ! EBS volumes ?



gp2 , . Io1 ā€“ . 3 000 IOPS, io1 , , .



EBS gp2, 250 ?



. Kubernetes. ā€“ volumes, RAID. . Kubernetes . Kubernetes , ES2 i3-instance c nvme, instance, EBS , stripe.



Kubernetes + AWS?



, . . . . CPU, memory limit request 100 millicore, 100, 10 . . . . , 101, ā€“ . . .



RPO, RTO Postgres ?



, Kafka. . . , .



, .



Daten gehen in der Regel 1-2 Wal-Segmente der letzteren verloren, wenn Ć¼berhaupt schlecht. Die Replikation bleibt in der Regel nicht hinter uns zurĆ¼ck.



1-2 Segmente, wenn die Last klein ist, kann es einen halben Tag sein.



Ja, wenn keine Last vorhanden ist, werden die Segmente mƶglicherweise Ć¼berhaupt nicht gedreht, dh wenn auch nach einer ZeitĆ¼berschreitung keine Transaktionen vorhanden sind.



Kann ich es dort automatisch ablegen?



Es sollte eine ZeitĆ¼berschreitung auftreten, aber wenn keine Transaktionen vorhanden sind, werden sie nicht gedreht. Ich habe mich kĆ¼rzlich damit befasst.




All Articles