Anton Patsev
Anton Patsev

Reputation: 639

Can change clusterip to nodeport command line without editor?

NodePort This way of accessing Dashboard is only recommended for development environments in a single node setup.

Edit kubernetes-dashboard service.

$ kubectl -n kube-system edit service kubernetes-dashboard You should see yaml representation of the service. Change type: ClusterIP to type: NodePort and save file.

Can change clusterip to nodeport command line without editor? Thanks!

Upvotes: 19

Views: 38371

Answers (5)

Gopi Palamalai
Gopi Palamalai

Reputation: 416

Here's the answer for the reverse scenario of converting from NodePort to ClusterIP.

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

Upvotes: 2

Fabrice Jammes
Fabrice Jammes

Reputation: 3205

To specify a given nodePort in addition:

kubectl patch svc my-service --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"},{"op":"replace","path":"/spec/ports/0/nodePort","value":30040}]'

Upvotes: 14

袁文涛
袁文涛

Reputation: 856

kubectl patch svc you-svc -p '{"spec": {"type": "NodePort"}}'

Upvotes: 16

sfgroups
sfgroups

Reputation: 19117

you can change it like this

kubectl patch svc kubernetes-dashboard --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'

Upvotes: 44

the_marcelo_r
the_marcelo_r

Reputation: 1856

You can just fetch the YAML for this given service:

kubectl -n kube-system get service kubernetes-dashboard -o yaml > kube-dash-svc.yaml

Make the changes you want (without using an editor). e.g.,

sed 's/ClusterIP/NodePort/' kube-dash-svc.yaml > new-kube-dash-svc.yaml

Delete the current service:

kubectl delete svc kubernetes-dashboard

And finally feed this yaml back to the Kubernetes control plane:

kubectl create -f new-kube-dash-svc.yaml

Upvotes: 1

Related Questions