Problem scenario
You run a kubectl command on a YAML (.yml) file. But you get "Expected X selector labels". What do you do?
Solution
Go to the "labels" and "matchlabels" sections of corresponding YAML files. Do you see "app:" or "environment:" stanzas? Are these consistently used in your YAML files? This error can happen if the YAML files are inconsistent with their "app:" and "environment:" stanzas. Was one line commented out of one file? Could you have placed the stanza in an incorrect location in the YAML file?
Search the YAML file for "env" and "envFrom". Could the user running the command have fewer permissions than normal? Could some files be missing where the "kubectl" command was run from?
To learn more, see these postings:
https://medium.com/@zwhitchcox/matchlabels-labels-and-selectors-explained-in-detail-for-beginners-d421bdd05362
https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
If you are using OpenShift, or you want more information in general, this RedHat posting could help you: https://learn.redhat.com/t5/DO280-Red-Hat-OpenShift/Labels-and-Selectors/td-p/38276