I found that creating a yaml object description using --dry-run=client and providing --command only works when the provided arguments are in a very specific order.
This works:
k run nginx --image=nginx --restart=Never --dry-run=client -o yaml --command -- env > nginx.yaml
This does NOT:
k run nginx --image=nginx --restart=Never --command -- env --dry-run=client -o yaml > nginx.yaml
I feel a bit confused because the version that does not work looks a lot more intuitive to me then the one that does work. Ideally both should work in my opinion. Is this intended behavior? I can't find any documentation about it.