To extract the definition of an object into a YAML file, we can do the following.

kubectl get object-type <object-name> -o yaml > name-of-object-definition-file.yaml