How correct change clusterIP to nodeport of kubespray?

7/4/2018

I try install kubernetes using kubespray

github repo

Change clusterip to nodeport command line without editor

kubectl -n kube-system get service kubernetes-dashboard -o yaml > kube-dash-svc.yaml
sed 's/ClusterIP/NodePort/' kube-dash-svc.yaml > new-kube-dash-svc.yaml
kubectl delete svc kubectl delete svc kubernetes-dashboard --namespace kube-system --namespace kube-system
kubectl create -f new-kube-dash-svc.yaml

After install and change clusterIP to nodeport i try install kubernetes again and get error:

err='The Service \"kubernetes-dashboard\" is invalid: \n* metadata.resourceVersion: Invalid value: \"\": must be specified for an update\n* spec.clusterIP: Invalid value: \"\": field is immutable\n* spec.ports[0].nodePort: Forbidden: may not be used when type is 'ClusterIP'\n'"}

How correct change clusterIP to nodeport of kubespray?

Thanks

-- Anton Patsev
kubernetes

1 Answer

7/5/2018

ClusterIP can't simply change to nodeport just by replace ClusterIP with NodePort, since the ClusterIP is the default, there is maybe no 'ClusterIP' in the definitions at all.

You should delete everthing involve 'clusterIP/ClusterIP', then insert 'type: NodePort' in the proper place, something like:

sed '/clusterIP/d;/ClusterIP/d;/^[ ]*ports:/i \  type: NodePort' 
-- Kun Li
Source: StackOverflow