kubernetes: applying a service twice with clusterIP set to blank returns an error
Is this a BUG REPORT or FEATURE REQUEST?: BUG REPORT
Uncomment only one, leave it on its own line:
/kind bug
/kind feature
What happened:
- Create a small file
service.ymlwith a Service in it, andclusterIP: "" kubectl apply -f service.yml- the service is createdkubectl apply -f service.yml- get an error
Then error is the classic:
F0906 19:32:48.426166 87883 helpers.go:119] The Service "myservice" is invalid: spec.clusterIP: Invalid value: "": field is immutable
I did check the annotation kubectl.kubernetes.io/last-applied-configuration to see that it has the clusterIP: "", which it does. Nonetheless, it treats it as mutated.
In short: kubectl apply -f service.yml done twice should always work, since the file has not changed.
What you expected to happen:
The service to be unchanged.
How to reproduce it (as minimally and precisely as possible):
See steps above.
Anything else we need to know?:
It also occurs when the first apply does not set clusterIP and the second one sets it to "" or vice-versa, see #65272 . This is more basic, though.
Environment:
- Kubernetes version (use
kubectl version): tried with client 1.9.x through 1.11.x, server 1.9.x through 1.10.x - Cloud provider or hardware configuration: tried bare metal, on EC2, and docker for mac
- OS (e.g. from /etc/os-release): linuxkit (docker for Mac), CoreOS on bare metal and EC2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 20 (15 by maintainers)
Understood from the technical perspective.
From a usage perspective (the important part), it creates hurdles and makes automation difficult. At the least, I think we should deprecate the
clusterIP: ""if you cannot use it twice.This also creates a problem using the Kubernetes API with something like Google Cloud Deployment Manager (GCDM). Minimum steps to demonstrate the problem:
Create a minimal type provider for the GKE API
Create the file '/type-provider-minimal.jinja`:
and deploy it with GCDM:
(here XXX.XXX.XXX.XXX is the IP address of our Kubernetes master).
Create a service
Create the file
test-svc:and deploy it:
Run
kubectl exec -ti <pod-name> /bin/bashto log into a container in the default namespace and then runcurl http://test-svc:8090/to check thatHello Worldis displayed. So far, so good.Updating the service
Now modify the service, e.g. copy the file
test.jinjatotest-modified.jinjaand add an extra port totest-svc:Now update the service:
This was tested against 1.11.6-gke.2 on the Kubernetes master.
@liggitt ‘s suggestion to omit clusterIP from the manifest doesn’t directly apply here, since the null clusterIP is presumably being inserted by GCDM, presumably in response to how it interprets Kubernetes’ Swagger API definition?