Can change clusterip to nodeport command line without editor?

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}]'

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}]'

you can change it like this

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

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

Tags:

Kubernetes