Today I Learned (May 15, 2024)

How to select a Pod deployed by DevSpace via labels

In your dev configuration in devspace.yaml, add a labelSelector

dev:
  the-dev-container:
    labelSelector: 
      <the-label-key>: <the-label-value>

This is helpful if you have to deploy multiple dev container Pods in a single namespace. You could for example add a user identifier (such as the email from the Git config) as a label selector to be able to distinguish between Pods for multiple users that are deployed to the same namespace.

dev:
  the-dev-container: 
    labelSelector:
      devspace.sh/user: "${USER}"

vars:
  USER: $(git config user.email | tr '@' '_')

:bulb: Note that unlike stated in the DevSpace documentation, .dev.imageSelector and .dev.labelSelector may not be used together (at least in version 6.3.12). DevSpace CLI returns the following error if both selectors are specified simultaneously:

fatal dev.the-dev-container: image selector and label selector cannot be used together

:bulb: We have to replace @ with a legal symbol for label values. I’m replacing it with _. Hence the ... | tr '@' '_' part of the USER variable assignment.