Expose Deployment in Nodeport, with imperative commands

Hello, a question, if I have a Deployment already created and I would like to expose it in a Service with the NodePort parameter, I know that I can do it directly in a YAML file, but how could I do it with imperative commands, can I?

$ kubectl create deployment dummy-micro-01 --image=maktup/dummy-micro-01:latest

//Service: Without the param NodePort .
$ kubectl expose deployment dummy-micro-01 --name=dummy-micro-01-service --port=8080 --type=NodePort

¿How could be?

Hello @maktup,

Can clarify your question? you already wrote the answer as you can create a service with kubectl expose:

 kubectl expose deployment hello-world --type=NodePort --port=8080 --name=my-service

Hi, thanks for answering, but they didn’t refer me to the parameter:
–type=NodePort, since this is for the Service created to be of type:NodePort (I do know that), but what I want is the way to use Imperative commands, I can set the field: nodePort:32484


I understand that when editing said field, I can make ** Fixed ** the Service Port of type ** NodePort **. Because of this, I wanted to know how to Set this field Imperatively with commands.

Thank you.

Hello, @maktup
kubectl create service nodeport xyz-service-name --tcp port:targetPort --node-port=30000-32767
In this case, you had to change manually the selector with the correct one.

Add correct selector in the single command:
kubectl create service nodeport <service-name> --tcp port:targetPort --node-port <node-port> -o yaml --dry-run=client | kubectl set selector --local -f - ' key=value' -o yaml | kubectl create -f -