Todos nĂłs sabemos que a maioria dos DBAs Ă© muito conservadora e prefere que seus bancos de dados residam exclusivamente em servidores dedicados. No mundo moderno com microsserviços, Kafka e Kubernetes, o nĂșmero de bases começa a crescer em proporção direta ao tamanho da organização e muito rapidamente vai alĂ©m do confortĂĄvel gerenciamento manual ou semiautomĂĄtico.
Trabalho na Zalando hĂĄ quase 7 anos. Quantos jĂĄ ouviram falar de Zalando?
Para quem ainda nĂŁo ouviu, trata-se de uma empresa parecida com a russa Lamoda.
Vendemos roupas e calçados, mas fazemos isso na Europa, em 17 paĂses.
Temos 7 centros de logĂstica prĂłprios e armazĂ©ns.
Zalando emprega mais de 15.000 pessoas.
E desses, cerca de 2.000 trabalham com tecnologia. O pessoal da tecnologia estĂĄ espalhado por cerca de 200 equipes que escrevem aplicativos.
Recentemente, implantamos muitas coisas no Kubernetes e trabalhamos muito com o Kubernetes.
?
- , 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. . . , .
, .
Os dados sĂŁo perdidos, via de regra, 1-2 segmentos do Ășltimo, se de todo ruins. A replicação nĂŁo fica atrĂĄs de nĂłs, como regra.
De 1 a 2 segmentos, se a carga for pequena, pode levar meio dia.
Sim, se não houver carga, os segmentos não podem ser girados de forma alguma, ou seja, se não houver transaçÔes mesmo após um tempo limite.
Posso colocĂĄ-lo lĂĄ automaticamente?
Deve atingir o tempo limite, mas se não houver transaçÔes, elas não serão giradas. Recentemente, lidei com isso.