Error: spec.ports[0].nodePort: Forbidden: may not be used when `type` is 'ClusterIP'
Quote from moshe on 29/12/2021, 5:51 pmProblem
User tries to change the type of the service from LoadBalancer to ClusterIP and getting the following error
The Service “kibana-kibana” is invalid: spec.ports[0].nodePort: Forbidden: may not be used when `type` is ‘ClusterIP’
Solution
Patch the service to NodePort
kubectl patch svc kibana-kibana -p ‘{“spec”: {“type”: “NodePort”}}’
and then patch to ClusterIP
kubectl patch svc kibana-kibana -p ‘{“spec”: {“type”: “ClusterIP”}}’
Note: if you still getting errors edit the service
kubectl edit svc kibana-kibana
Change this section from This
spec:
clusterIP: 10.100.144.140
externalTrafficPolicy: Cluster
ports:
– name: http
port: 5601
protocol: TCP
targetPort: 5601
selector:
app: kibana
release: kibana
sessionAffinity: None
type: CluserIP
status:
loadBalancer: {}To This
spec:
clusterIP: 10.100.144.140
ports:
– name: http
port: 5601
protocol: TCP
targetPort: 5601
selector:
app: kibana
release: kibana
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Problem
User tries to change the type of the service from LoadBalancer to ClusterIP and getting the following error
The Service “kibana-kibana” is invalid: spec.ports[0].nodePort: Forbidden: may not be used when `type` is ‘ClusterIP’
Solution
Patch the service to NodePort
kubectl patch svc kibana-kibana -p ‘{“spec”: {“type”: “NodePort”}}’
and then patch to ClusterIP
kubectl patch svc kibana-kibana -p ‘{“spec”: {“type”: “ClusterIP”}}’
Note: if you still getting errors edit the service
kubectl edit svc kibana-kibana
Change this section from This
spec:
clusterIP: 10.100.144.140
externalTrafficPolicy: Cluster
ports:
– name: http
port: 5601
protocol: TCP
targetPort: 5601
selector:
app: kibana
release: kibana
sessionAffinity: None
type: CluserIP
status:
loadBalancer: {}
To This
spec:
clusterIP: 10.100.144.140
ports:
– name: http
port: 5601
protocol: TCP
targetPort: 5601
selector:
app: kibana
release: kibana
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
Uploaded files: