kubernetes: podAntiAffinity in a daemonset is not accepted , k8s versions > 1.27.0
What happened?
During one of our tests with daemonsets, we find new pods being scheduled despite having a podAntiAffinity rule set into the daemonset.
Here’s our test case;
- We installed older version of our app.
- We apply a finalizer to a pod( rlinux-xs84n in this case).
- We upgrade(rolling update) to latest version of the app.(no change in Kubernetes version).
- At this point, rlinux-xs84n pod gets stuck in ‘Terminating’.
- As a new daemonset spins up, it succeeds in scheduling new pods on the same node( xxx.194 in this case).
Actual output:
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES rlinux-8p5qt 2/2 Running 0 3h47m xxx.194 vm7002 <none> <none> rlinux-b6z99 2/2 Running 0 3h47m xxx.105 vm8001 <none> <none> rlinux-hjpj7 2/2 Running 0 3h47m xxx.42 vm7001 <none> <none> rlinux-xs84n 0/2 Terminating 0 3h52m xxx.194 vm7002 <none> <none>
This behaviour is observed in K8S; 1.27.0 - 1.28 versions This behaviour is not observed is K8S; 1.23, 1.24, 1.25 and 1.26 versions
What did you expect to happen?
Expected output(A pod scheduled by the new DS should have been ‘Pending’ on the same node ‘vm7002’):
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES rlinux-8p5qt 2/2 Pending 0 3h47m xxx.194 vm7002 <none> <none> rlinux-b6z99 2/2 Running 0 3h47m xxx.105 vm8001 <none> <none> rlinux-hjpj7 2/2 Running 0 3h47m xxx.42 vm7001 <none> <none> rlinux-xs84n 0/2 Terminating 0 3h52m xxx.194 vm7002 <none> <none>
Please share a workaround to make the pod scheduling (like above) and let us know if there were any similar field issues were noticed earlier.
How can we reproduce it (as minimally and precisely as possible)?
Steps could be similar to that of our test.
Anything else we need to know?
The daemonset has a podAntiAffinity like below:
"spec": {
...
"podAntiAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": [
{
"labelSelector": {
"matchExpressions": [
{
"key": "app",
"operator": "In",
"values": [
"node.rlinux.app.io"
]
}
]
},
"topologyKey": "kubernetes.io/hostname"
}
]
}
}
Also daemonset has a rollingUpdate strategy:
"updateStrategy": {
"rollingUpdate": {
"maxSurge": 0,
"maxUnavailable": 1
},
"type": "RollingUpdate"
}
Kubernetes version
$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.0", GitCommit:"xyz", GitTreeState:"clean", BuildDate:"2023-04-11T17:10:18Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.5", GitCommit:"xtz", GitTreeState:"clean", BuildDate:"2023-08-24T00:42:11Z", GoVersion:"go1.20.7", Compiler:"gc", Platform:"linux/amd64"}
Cloud provider
OS version
# On Linux:
$ cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="9.2 (Plow)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Red Hat Enterprise Linux 9.2 (Plow)"
ANSI_COLOR="0;31"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:redhat:enterprise_linux:9::baseos"
HOME_URL="https://www.redhat.com/"
DOCUMENTATION_URL="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 9"
REDHAT_BUGZILLA_PRODUCT_VERSION=9.2
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, …) and versions (if applicable)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (13 by maintainers)
Let me take an experiment, kube-scheduler should take terminating pods into consideration.
A pod with phase=Succeeded and a deletionTimestamp is not a “terminating” pod, it is a TERMINATED pod.
As such, it is as if it doesn’t exist.
@alculquicondor Shared the terminating pod status on a 1.27.4 cluster.
apiVersion: v1 kind: Pod metadata: creationTimestamp: “2023-08-29T16:27:33Z” deletionGracePeriodSeconds: 0 deletionTimestamp: “2023-08-29T16:28:36Z” finalizers:
Thanks @tksm for the detailed investing and Aldo pointed out the key point. So after https://github.com/kubernetes/kubernetes/commit/3d68f362c372ea2af5165198c0c60f19ebc60a3f, Pod will be marked as succeed finally, then scheduler will ignore the pod, that’s the phenomenon currently. But we should fix the https://github.com/kubernetes/kubectl/issues/1595 to prevent confusion.
However, since pod is protected by the finalizer, should we mark the pod succeeded directly rather than waiting for the finalizer being removed? But I have no real sense yet …