As of 2025 using option -n namespace or specifying namespace in the yaml file don't work.
I had to run two commands:
kubectl create ns namespace
kubectl apply -f deployment.yaml