Namespace when exposing a service

Hi

I was creating a service with the command

kubectl -n mynamespace expose deploy .... --dry-run=client -o yaml > service.yaml

and it seems that the namespace is not taken into account in the yaml file.

Is it normal ?

Hello @stephane.hordoir
Please make sure that the namespace already exists.

Hello all,

If the namespace was not yet available, the error message will be thrown:

Error from server (NotFound): namespaces "mynamespace" not found

I give it a try on my end and it worked just fine, the namespace apear under metadata attribute, which kubectl version do you have on your machine @stephane.hordoir ?

Trung.

Hi @trung-kodekloud,

It was the version on the kubectl exercise, not on my local machine.

Try

kubectl create namespace test 
kubectl -n test create deployment nginx --image=nginx 
kubectl -n test expose deployment nginx --port 80 --dry-run=client -o yaml > service.yml

Also, you can check the steps in the attached gif
dry

Perfect,

Thanks for the review, it is perfectly clear, I must have made a mistake.