Open
Description
What happened?
When running two pods that both use hostNetwork and have sidecar initContainers (restartPolicy: Always) using the same port, kube-scheduler allows the pods to be scheduled on the same node.
What did you expect to happen?
kube-scheduler does not schedule these two pods on the same node, following the behavior for pods using hostNetwork ports via a main container.
How can we reproduce it (as minimally and precisely as possible)?
- Create a kind cluster:
kind create cluster
. The cluster only has one node. - Apply p1:
apiVersion: v1 kind: Pod metadata: name: p1 spec: hostNetwork: true dnsPolicy: ClusterFirstWithHostNet initContainers: - name: init restartPolicy: Always image: python:3.12 command: - /bin/bash - -c - python -m http.server 8081 ports: - containerPort: 8081 containers: - name: main image: python:3.12 command: - /bin/bash - -c - sleep 10000
- Apply p2:
apiVersion: v1 kind: Pod metadata: name: p2 spec: hostNetwork: true dnsPolicy: ClusterFirstWithHostNet initContainers: - name: init restartPolicy: Always image: python:3.12 command: - /bin/bash - -c - python -m http.server 8081 ports: - containerPort: 8081 containers: - name: main image: python:3.12 command: - /bin/bash - -c - sleep 10000
- p2 is scheduled (and crashing because p1 is already using the port).
Anything else we need to know?
kube-scheduler already accounts for hostNetwork ports used by main containers. For example:
- Create a kind cluster:
kind create cluster
. The cluster only has one node. - Apply p1:
apiVersion: v1 kind: Pod metadata: name: p1 spec: hostNetwork: true dnsPolicy: ClusterFirstWithHostNet containers: - name: main image: python:3.12 command: - /bin/bash - -c - python -m http.server 8081 ports: - containerPort: 8081
- Apply p2:
apiVersion: v1 kind: Pod metadata: name: p2 spec: hostNetwork: true dnsPolicy: ClusterFirstWithHostNet containers: - name: main image: python:3.12 command: - /bin/bash - -c - python -m http.server 8081 ports: - containerPort: 8081
- p2 is not scheduled:
Warning FailedScheduling 3m7s default-scheduler 0/1 nodes are available: 1 node(s) didn't have free ports for the requested pod ports. preemption: 0/1 nodes are available: 1 No preemption victims found for incoming pod.
Kubernetes version
$ kubectl version
Client Version: v1.31.9
Kustomize Version: v5.4.2
Server Version: v1.31.1
Cloud provider
local kind cluster
OS version
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here
# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
Install tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, ...) and versions (if applicable)
Metadata
Metadata
Assignees
Labels
Categorizes issue or PR as related to a bug.Must be staffed and worked on either currently, or very soon, ideally in time for the next release.Categorizes an issue or PR as relevant to SIG Node.Categorizes an issue or PR as relevant to SIG Scheduling.Indicates an issue or PR is ready to be actively worked on.
Type
Projects
Status
Triage