Description
What happened:
If you update a deployment with duplicate ports, there's no deterministic behaviour for which ports kubernetes will preserve in the deployment. It may remove all duplicate ports, keep the last one, or the first one. The behaviour gets even more unpredictable as the number of ports increase.
What you expected to happen:
Duplicate ports should be left untouched, exactly as they were specified in the applied YAML
How to reproduce it (as minimally and precisely as possible):
-
Apply this Deployment which contains duplicate ports. [Expect: created deployment contains all ports in the YAML. Actual: created deployment contains all ports]
-
Now, remove the port named 'five'. [Expect: all ports excluding 'five' should be present. Actual: a non-deterministic list of ports get deleted]
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-test
namespace: sre
labels:
app: nginx-test
env: staging
owner: sre
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- name: one
containerPort: 8000
- name: two
containerPort: 8000
- name: three
containerPort: 9000
- name: four
containerPort: 8000
- name: five
containerPort: 8000
- name: six
containerPort: 7000
- name: seven
containerPort: 7000
resources:
limits:
cpu: 100m
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
Anything else we need to know?: n/a
Environment: GKE
- Kubernetes version (use
kubectl version
): 2 versions tested.
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T23:40:44Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"17+", GitVersion:"v1.17.9-gke.600", GitCommit:"0bd89e105de2e1718e7418e73db3312050551a2b", GitTreeState:"clean", BuildDate:"2020-07-20T18:10:21Z", GoVersion:"go1.13.9b4", Compiler:"gc", Platform:"linux/amd64"}
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T23:40:44Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.11-gke.5", GitCommit:"baccd25d44f1a0d06ad3190eb508784efbb990a5", GitTreeState:"clean", BuildDate:"2020-06-25T22:55:26Z", GoVersion:"go1.13.9b4", Compiler:"gc", Platform:"linux/amd64"}
- Cloud provider or hardware configuration: Google Kubernetes Engine
- OS (e.g:
cat /etc/os-release
): n/a - Kernel (e.g.
uname -a
): n/a - Install tools: n/a
- Network plugin and version (if this is a network-related bug): n/a
- Others: n/a