[kubernetes/kubectl] Unable to change service from type=NodePort to type=ClusterIP with kubectl (#221)

486 views
Skip to first unread message

Zihong Zheng

unread,
Jan 23, 2018, 1:30:32 PM1/23/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Is this a BUG REPORT or FEATURE REQUEST? (choose one):
/kind bug

Kubernetes version (use kubectl version):

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.6", GitCommit:"6260bb08c46c31eea6cb538b34a9ceb3e406689c", GitTreeState:"clean", BuildDate:"2017-12-21T06:34:11Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.0-alpha.1.930+0d1986ad8219bf-dirty", GitCommit:"0d1986ad8219bf1a64fc657eac407cc84d3ad647", GitTreeState:"dirty", BuildDate:"2018-01-17T03:10:36Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}

What happened:

  • Create a service with type=ClusterIP. Let's say kube-dns:
apiVersion: v1
kind: Service
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: KubeDNS
  name: kube-dns
  namespace: kube-system
spec:
  clusterIP: 10.0.0.10
  ports:
  - name: dns
    port: 53
    protocol: UDP
    targetPort: 53
  - name: dns-tcp
    port: 53
    protocol: TCP
    targetPort: 53
  selector:
    k8s-app: kube-dns
  type: ClusterIP
  • Edit type from ClusterIP to NodePort, and now we have:
apiVersion: v1
kind: Service
metadata:
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: KubeDNS
  name: kube-dns
  namespace: kube-system
spec:
  clusterIP: 10.0.0.10
  ports:
  - name: dns
    nodePort: 31716
    port: 53
    protocol: UDP
    targetPort: 53
  - name: dns-tcp
    nodePort: 30492
    port: 53
    protocol: TCP
    targetPort: 53
  selector:
    k8s-app: kube-dns
  type: NodePort
  • Edit type from NodePort to ClusterIP with all the auto-allocated nodePorts removed, and we hit this error:
# services "kube-dns" was not valid:
# * spec.ports[1].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'
  • Try to use kubectl apply -f with a similar kube-dns yaml (type=ClusterIP with all nodePorts removed) and hit the same error:
$ kubectl apply -f kube-dns.yaml 
The Service "kube-dns" is invalid: spec.ports[1].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'

What you expected to happen:
Users should be able to modify service type from NodePort to CluserIP.

Anything else we need to know:
Is this a regression? There was a similar bug before (kubernetes/kubernetes#42282), which was fixed.

@mengqiy @kubernetes/sig-cli-bugs


You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

Mengqi Yu

unread,
Jan 23, 2018, 2:17:14 PM1/23/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

This is caused by a known issue: mergeKey in ports is portNumber (both are 53) cannot uniquely identify an entry in this case.

Cristian Greco

unread,
Mar 16, 2018, 4:47:59 PM3/16/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

I've just run into this issue, is there a workaround?

Mengqi Yu

unread,
Mar 16, 2018, 6:11:20 PM3/16/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

kubectl replace can be the workaround.

Vikash082

unread,
Apr 20, 2018, 2:12:30 AM4/20/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Hitting similar issue. Any workaround which doesn't delete service ?

Mengqi Yu

unread,
Apr 24, 2018, 1:07:33 PM4/24/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

@Vikash082 Does kubectl replace work for you?

fejta-bot

unread,
Jul 23, 2018, 1:08:58 PM7/23/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

Daniel Holmes

unread,
Jul 31, 2018, 1:02:29 AM7/31/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Just came across this issue so definitely not stale.

Yifei Zhang

unread,
Jul 31, 2018, 7:25:28 PM7/31/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

kubectl replace worked for me

Note: it requires specifying the clusterIP field to be the same IP as the allocated ClusterIP of this service

fejta-bot

unread,
Aug 30, 2018, 8:09:51 PM8/30/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.

/lifecycle rotten

Michael Bushey

unread,
Sep 11, 2018, 1:35:24 PM9/11/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Not fixed:

$ kubectl replace -f grav-deployment.yml
deployment.apps/grav replaced
The Service "grav-service" is invalid: spec.clusterIP: Invalid value: "": field is immutable
$ kubectl delete -f grav-deployment.yml                                                                                                                                                                                                           
deployment.apps "grav" deleted
service "grav-service" deleted
$ kubectl apply -f grav-deployment.yml                                                                                                                                                                                                            
deployment.apps/grav created
service/grav-service created

Di Xu

unread,
Sep 16, 2018, 6:47:33 AM9/16/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Dup of kubernetes/kubernetes#66390, which has been fixed in kubernetes/kubernetes#66602.

Please try using kubectl apply -f test-service.yaml --force.

/close

Please reopen if needed.

k8s-ci-robot

unread,
Sep 16, 2018, 6:47:34 AM9/16/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Closed #221.

k8s-ci-robot

unread,
Sep 16, 2018, 6:47:34 AM9/16/18
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

@dixudx: Closing this issue.

In response to this:

Dup of kubernetes/kubernetes#66390, which has been fixed in kubernetes/kubernetes#66602.

Please try using kubectl apply -f test-service.yaml --force.

/close

Please reopen if needed.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

willgithub

unread,
Jan 6, 2019, 1:50:39 AM1/6/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

it workd for me


kubectl apply -f test-service.yaml --force.

Alan

unread,
Feb 12, 2019, 4:43:11 AM2/12/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention
The Service "ingress-nginx" is invalid:

* spec.ports[0].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'

* spec.ports[1].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'

Should we update the error message?
 

Michael Garate

unread,
Feb 19, 2019, 10:21:21 PM2/19/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

is there a workaround for this that does not require the use of --force?

Zihong Zheng

unread,
Feb 21, 2019, 1:08:23 PM2/21/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

@mpgarate Have you tried kubectl replace?

Ref #221 (comment).

Michael Garate

unread,
Feb 21, 2019, 1:54:48 PM2/21/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

I ran into this message with kubectl replace:
The Service ... is invalid: spec.clusterIP: Invalid value: "": field is immutable

I suspect this is because I do not have the ip address hard-coded as mentioned in comment 221. In my case is is not practical to do that for every service, and instead I am using a NodePort type as a workaround.

Zihong Zheng

unread,
Feb 21, 2019, 2:15:53 PM2/21/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

@mpgarate Agreed that hardcoding the IP for every service on creation is not practical. But it may be doable to simply copy over the randomly allocated clusterIP when you try to update the service (e.g. via kubectl replace)?

Huang Fuguo

unread,
Mar 12, 2019, 11:15:26 AM3/12/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

use edit service, and
comment out the # nodePort: 30492
change to ClusterIP
save it

Albert Serrallé Ríos

unread,
Jul 23, 2019, 7:40:14 AM7/23/19
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

I use helm and this help me fix the issue:

spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.externalPort }}
{{ if (eq .Values.service.type "ClusterIP") }}
      nodePort: null
{{ end }}
      targetPort: {{ .Values.service.internalPort }}
      protocol: TCP
      name: {{ .Values.service.name }}

Ufuk Hacıoğulları

unread,
Feb 17, 2020, 11:13:19 AM2/17/20
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

nodePort: null definitely works declaratively. Thanks @aserrallerios.


You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub, or unsubscribe.

gopiextrahop

unread,
Aug 5, 2020, 8:01:50 PM8/5/20
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

nodePort: null definitely works declaratively. Thanks @aserrallerios.

The following worked for me kubectl patch svc my-service --type='json' -p '[{"op":"replace","path":"/spec/type","value":"ClusterIP"},{"op":"replace","path":"/spec/ports/0/nodePort","value":null}]'.


You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub, or unsubscribe.

O-ll-O

unread,
Feb 1, 2021, 2:21:49 AM2/1/21
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

I encountered the same bug, is it a bug?has it been fixed?


You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub, or unsubscribe.

tarunkhannan

unread,
Feb 1, 2021, 9:52:25 PM2/1/21
to kubernetes/kubectl, k8s-mirror-cli-bugs, Team mention

Check for indentations too. In my case its the issue :p


You are receiving this because you are on a team that was mentioned.

Reply to this email directly, view it on GitHub, or unsubscribe.

Reply all
Reply to author
Forward
0 new messages