zalando / postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
https://postgres-operator.readthedocs.io/
MIT License
4.29k stars 974 forks source link

Manual switchover via operator #1968

Open FactorT opened 2 years ago

FactorT commented 2 years ago

Please, answer some short questions which should help us to understand your problem / question better?

Does the operator support manual swithover? I know that I can enter in pod and run switchover via patronictl. But it may be convenient and useful to be able to do a switchover using an operator, for example, through an endpoint annotation.

FxKu commented 2 years ago

You can indeed add the annotation zalando-postgres-operator-rolling-update-required: true to the pods and the operator will discover it on next sync and think it has to do a rolling update.

FactorT commented 2 years ago

Thank you very much @FxKu! This workaround sounds good. But is there a way to force operator run sync operation early? For example via send a request to service postgres-operator.

FxKu commented 2 years ago

Only by deleting the operator pod you can force a sync of all clusters.

FactorT commented 2 years ago

Thank you very much @FxKu for your answers! Could you give me advise please.

I want to try make a PR with switchover functionality via operator. How do you think is it possible to realise it with the next approach?

  1. Add optional section in spec section of kind: postgresql manifest spec: patroni: switchover: enabled: true targetInstance: acid-test-cluster-1 This enable swithcover functionality via operator for our postgresql cluster and set target instance for promoting. Operator will be looking for the trigger in cluster's annotation to perform a switchover.
  2. When we need make swithover we need to add annotation for our postgresql cluster: kubectl annotate postgresql acid-test-cluster acid.zalan.do/swithcover="$(date)"
  3. After that we need to delete operator's pod for trigger sync operation.
  4. Pod make sync. Detect switchover annotation and make switchover via patroni api.
  5. After that we disable switchover section in cluster's spec.
ms3rgio commented 2 years ago

You can indeed add the annotation zalando-postgres-operator-rolling-update-required: true to the pods and the operator will discover it on next sync and think it has to do a rolling update.

Is it recommended to remove annotation after rollout? I noticed that when the annotation is removed, another rollout happens. I also saw that regardless of the true or false value, the rollout happens, is this expected?