kubernetes: Unable to update the deployment containers ports name on redeployment
What happened:
managementPort is provided by default while applying the k8s manifest.
“mng-mytest” is the name alias for containerPort in deployment manifest. ports: - containerPort: 9095 name: mng-mytest
Recently we changed the value of default management port, however for existing deployments that are running when redeployed the changes of new default mgmt port while getting applied fails with this issue,
The Deployment “mytestservice-deployment” is invalid: spec.template.spec.containers[0].ports[2].name: Duplicate value: “mng-mytest”
“mng-mytest” is the name alias for containerPort in deployment manifest. ports: - containerPort: 9090 name: mng-mytest
What you expected to happen:
The new port value should get applied.
How to reproduce it (as minimally and precisely as possible):
First, add a port name and value to the containerPort section of the deployment manifest then deploy. Second, change the value of the containerPort but keep the name same then redeploy on top of above existing running deployment.
Anything else we need to know?:
NA
Environment:
- Kubernetes version (use
kubectl version): - Client Version: version.Info{Major:“1”, Minor:“20”, GitVersion:“v1.20.4”
- Server Version: version.Info{Major:“1”, Minor:“18+”,
- Cloud provider or hardware configuration: AWS
- OS (e.g:
cat /etc/os-release): - Kernel (e.g.
uname -a): - Install tools:
- Network plugin and version (if this is a network-related bug):
- Others: NA
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18 (6 by maintainers)
Hi @yashwanthkalva, I can recreate the same error now. Please check the doc In-place-updates-of-resources. If you are trying to update a deployment without
kubectl.kubernetes.io/last-applied-configurationannotation.kubectl applywill fall back to 2-way diff. That means thekubectl applywon’t generate delete options in the JSON patch. A 3-way JSON patch example like below:If your deployment was created by Helm or the annotation was deleted somehow, you will see the error.
Regards, Roland