You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use Case: We want to allow eviction of the primary DB instance in order to perform upgrades on the underlying infrastructure automatically, for example updating a kubernetes node. While that will cause degraded performance during the failover, that is aligned with our SLOs for our uses of a majority of the clusters.
Problem: The current operator sets up a PDB that never allows the primary to be evicted. No configuration parameters are exposed to override this default behavior.
Edit:
I have expanded on additional use cases and reasons why this is critically important in a follow-up comment.
Reacted by Alfred Tovsen Mo, Matt M., Mathieu Massé, Tomasz Krzyżanowski, Marco Orovecchia, Sebastian Plattner, Till!, Christian-Probst-DATEV, Gerrit, stijn-kramer and 3 more
The operator is watching over nodes.
When the node where the primary Pod is running is being cordoned, it will automatically switchover to the most advanced replica running on a node which is not cordoned.
This will allow you to evict the Pods that are running on the node you drained, even if the PDB is still there.
Is this enough for you?
Thanks for the response. That is helpful info and confirmed that cordoning works for failovers to a running replica. However, there are a handful of scenarios that we encounter that don't work.
EKS node upgrades (docs): The cordoning happens after the eviction and causes a PodEvictionFailure due to not being able to evict the pg instances. We would like to avoid enabling the force parameter globally here as we have other cases where we would want PDBs for other resources to stop a node upgrade.
Clusters that do not have any replicas still get this PDB. The cordoning strategy does not work in this case. We run some ephemeral DB clusters without replicas or backups as they are meant to just be temporary. In this case, the clusters do not need to be highly available and we don't want PDBs at all.
It would be nice to just have a simple boolean parameter on Cluster that disables the PDB management behavior in the operator for that particular cluster.
Reacted by Christian-Probst-DATEV, Gerrit and Gabriele Bartolini
Unfortunately not. We don't want to disable the self-healing features. We want to be able to evict the primary and have the controller self-heal as it is able to.
For our ephemeral clusters, we want to avoid adding another control loop that has to toggle flags on the Cluster resource just to use the eviction API in our automations.
For our use case, we specifically want to allow disruptions of the primary. The PDB prevents that. That's a great default, but we specifically want to opt-out on a per-cluster basis.
Reacted by Vladimir Konkov, Matt M., Alfred Tovsen Mo, Till!, Christian-Probst-DATEV and cod-r
Similar situation here. We have many DBs without replicas (only backups) that is ok to shutdown on cluster upgrades. Ability to just disable PDB on cluster basis help us too.
Same here, we don't have control over the clusters where the CNPG is running, and its PDB is breaking the K8s cluster upgrades. It's not possible to switch the clusters to maintenance mode – the support is not informing us about K8s upgrades, and we don't have control over infra.
@leonardoce Does this use case here make sense to add this capability to disable the PDB as a non-default option? We would like to use this project, but this is a blocker.
For anyone curious for a workaround, we settled on running this in a periodic cronjob in the interim. Unfortunately, this is necessary as the operator will restore the PDB on every cluster update or when the operator pods restart. Additionally, the operator does not respect field managers so field edits such as manually adjusting minAvailable get overwritten.
The saga continues. Apparently, the script above does not work in later versions as the operator is in a realtime watch mode for changes or deletions of the pdb and will restore the pdb immediately after you try to remove them. The only way to buy yourself a bit of breathing room is to keep the pdb, remove the ownerReferences, and the change the minAvailable to 0.
#!/usr/bin/env bash# This script will patch all pdbs managed by the cnpg operator to allow primary disruptionset -eo pipefail
kubectl get pdb --all-namespaces -o json | jq -r \
'.items[] | select(.metadata.annotations["cnpg.io/operatorVersion"]? != null) | "\(.metadata.namespace) \(.metadata.name) \(.metadata.ownerReferences? != null)"'| \
whileread -r namespace name has_owner_references;do# Delete owner references if they existif [ "$has_owner_references"="true" ];then
kubectl patch pdb "$name" -n "$namespace" --type='json' -p='[{"op": "remove", "path": "/metadata/ownerReferences"}]'fi# Set minAvailable to 0
kubectl patch pdb "$name" -n "$namespace" --type='json' -p='[{"op": "replace", "path": "/spec/minAvailable", "value":0}]'done
Granted it will still restore itself occasionally like when the operator restarts, so you have to run this in a cronjob.
These settings will automatically remove the PodDisruptionBudget blocker to allow pod eviction when node drain is requested.
Basically, when you run a single node cluster you accept the downtime while upgrading the Kubernetes node.
The primary pod will get back up and running once the node is ready to schedule workloads again. The primary then reattaches itself to the PVC and starts Postgres.
We have a team doing the maintenance for k8s and our Team is running the database operator. 3 Nodes, 1 Primary, 2 Standbys. Our Team doesn't know when maintenance is taking place and is not involved with it. We need a way to remove, better avoid, all PDB's by declaration.
We have a team doing the maintenance for k8s and our Team is running the database operator. 3 Nodes, 1 Primary, 2 Standbys. Our Team doesn't know when maintenance is taking place and is not involved with it. We need a way to remove, better avoid, all PDB's by declaration.
You don't need to remove PDB when a cluster has at least one replica. In this case the PDB does not prevent the drain.
Indeed, the Operator will ensure the primary is always running on a schedulable node. That means, when the node drain kicks in against the node where the primary is running, the Operator will promote the most aligned replica before allowing the eviction of the primary pod.
I just did this test in a kind cluster with three (virtual) K8S nodes. I created a CNPG cluster with 2 nodes, one primary and one standby. I have not set the nodeMaintenanceWindow, so the default was set to false. I did execute kubectl cordon against the node where the primary was running. The result was the Operator performed the switchover to promote the standby as the new primary, on the K8S node that was still schedulable.
CNPG version: compiled from main, using the hack/setup-cluster.sh script.
So, my questions now are:
did you face any other blockers? Or
the Operator did not behave as expected in your specific case?
Please, elaborate more on the issue so we can help you resolve any blockers.
Can we please ask to backport this into 1.22 which is the current LTS version?
I think it was supposed to be included in 1.22 as per @gbartolini 's comment PR comment, but I don't see it in 1.22.
Can we please ask to backport this into 1.22 which is the current LTS version? I think it was supposed to be included in 1.22 as per @gbartolini 's comment PR comment, but I don't see it in 1.22.
Activity
leonardoce commentedon Aug 12, 2023
Hello.
The operator is watching over nodes.
When the node where the primary Pod is running is being cordoned, it will automatically switchover to the most advanced replica running on a node which is not cordoned.
This will allow you to evict the Pods that are running on the node you drained, even if the PDB is still there.
Is this enough for you?
fullykubed commentedon Aug 12, 2023
Thanks for the response. That is helpful info and confirmed that cordoning works for failovers to a running replica. However, there are a handful of scenarios that we encounter that don't work.
EKS node upgrades (docs): The cordoning happens after the eviction and causes a
PodEvictionFailuredue to not being able to evict the pg instances. We would like to avoid enabling theforceparameter globally here as we have other cases where we would want PDBs for other resources to stop a node upgrade.Clusters that do not have any replicas still get this PDB. The cordoning strategy does not work in this case. We run some ephemeral DB clusters without replicas or backups as they are meant to just be temporary. In this case, the clusters do not need to be highly available and we don't want PDBs at all.
fullykubed commentedon Aug 12, 2023
It would be nice to just have a simple boolean parameter on
Clusterthat disables the PDB management behavior in the operator for that particular cluster.leonardoce commentedon Aug 14, 2023
I think I got it now.
You can set the cluster in maintenance mode, and that will remove the PDB while the maintenance mode is set.
More info:
https://cloudnative-pg.io/documentation/1.20/kubernetes_upgrade/#kubernetes-upgrade
Would this help?
fullykubed commentedon Aug 14, 2023
Unfortunately not. We don't want to disable the self-healing features. We want to be able to evict the primary and have the controller self-heal as it is able to.
For our ephemeral clusters, we want to avoid adding another control loop that has to toggle flags on the Cluster resource just to use the eviction API in our automations.
For our use case, we specifically want to allow disruptions of the primary. The PDB prevents that. That's a great default, but we specifically want to opt-out on a per-cluster basis.
vladimirfx commentedon Aug 27, 2023
Similar situation here. We have many DBs without replicas (only backups) that is ok to shutdown on cluster upgrades. Ability to just disable PDB on cluster basis help us too.
tomaszkrzyzanowski commentedon Sep 4, 2023
Same here, we don't have control over the clusters where the CNPG is running, and its PDB is breaking the K8s cluster upgrades. It's not possible to switch the clusters to maintenance mode – the support is not informing us about K8s upgrades, and we don't have control over infra.
PDB toggle would be much appreciated :)
alfredtm commentedon Sep 6, 2023
Same here, we are using AKS with Autoupgrade and the PDB stops the upgrade. Need to evict the pod manually for the node to restart.
fullykubed commentedon Oct 27, 2023
@leonardoce Does this use case here make sense to add this capability to disable the PDB as a non-default option? We would like to use this project, but this is a blocker.
fullykubed commentedon Oct 27, 2023
For anyone curious for a workaround, we settled on running this in a periodic cronjob in the interim. Unfortunately, this is necessary as the operator will restore the PDB on every cluster update or when the operator pods restart. Additionally, the operator does not respect field managers so field edits such as manually adjusting
minAvailableget overwritten.fullykubed commentedon Oct 29, 2023
The saga continues. Apparently, the script above does not work in later versions as the operator is in a realtime watch mode for changes or deletions of the pdb and will restore the pdb immediately after you try to remove them. The only way to buy yourself a bit of breathing room is to keep the pdb, remove the ownerReferences, and the change the
minAvailableto0.Granted it will still restore itself occasionally like when the operator restarts, so you have to run this in a cronjob.
Christian-Probst-DATEV commentedon Nov 21, 2023
We need that feature too! Please.
jbattiato commentedon Dec 12, 2023
Hi @jclangst
Could you please elaborate more on how the self healing in a single node cluster would help you while you are evicting the only primary pod?
What are you trying to achieve?
This is how CNPG allows you to upgrade K8S node in case of a single node cluster:
as explained by Leonardo a few posts above:
https://cloudnative-pg.io/documentation/1.21/kubernetes_upgrade/
These settings will automatically remove the
PodDisruptionBudgetblocker to allow pod eviction when node drain is requested.Basically, when you run a single node cluster you accept the downtime while upgrading the Kubernetes node.
The primary pod will get back up and running once the node is ready to schedule workloads again. The primary then reattaches itself to the PVC and starts Postgres.
Would that be enough for you?
Christian-Probst-DATEV commentedon Dec 13, 2023
We have a team doing the maintenance for k8s and our Team is running the database operator. 3 Nodes, 1 Primary, 2 Standbys. Our Team doesn't know when maintenance is taking place and is not involved with it. We need a way to remove, better avoid, all PDB's by declaration.
jbattiato commentedon Dec 13, 2023
Hi @Christian-Probst-DATEV
You don't need to remove PDB when a cluster has at least one replica. In this case the PDB does not prevent the drain.
Indeed, the Operator will ensure the primary is always running on a schedulable node. That means, when the node drain kicks in against the node where the primary is running, the Operator will promote the most aligned replica before allowing the eviction of the primary pod.
I just did this test in a
kindcluster with three (virtual) K8S nodes. I created a CNPG cluster with 2 nodes, one primary and one standby. I have not set thenodeMaintenanceWindow, so the default was set tofalse. I did executekubectl cordonagainst the node where the primary was running. The result was the Operator performed the switchover to promote the standby as the new primary, on the K8S node that was still schedulable.CNPG version: compiled from main, using the
hack/setup-cluster.shscript.So, my questions now are:
Please, elaborate more on the issue so we can help you resolve any blockers.
17 remaining items
feat: add an option to drop PDBs
feat: make PDB configurable (#3837)
jsilvela commentedon Mar 12, 2024
Closing with the merge of #3837
jsilvela commentedon Mar 12, 2024
#3837
fix: webhook only warns about nodeMaintenance window if used in PDB-d…
pgodowski commentedon Aug 23, 2024
Can we please ask to backport this into 1.22 which is the current LTS version?
I think it was supposed to be included in 1.22 as per @gbartolini 's comment PR comment, but I don't see it in 1.22.
gbartolini commentedon Aug 23, 2024
Doing.
feat: make PDB configurable (#3837)
fix(cnpg): fall through to a fast shutdown after 15s (#581)