Select Container as Dev Container
To use standard Kubernetes label selectors to select a dev container, specify the labelSelector
field which first selects a Kubernetes pod and then the appropriate container inside of it.
dev:
backend:
labelSelector:
app.kubernetes.io/name: payment-service
app.kubernetes.io/component: rest-api
Because Kubernetes does not provide labels for container, DevSpace will select a pod if you specify the labelSelector
field. If the pod has only one container, DevSpace will use that container. If the pod has multiple containers, make sure to also specify the container
field.
Common Scenarios
It is key to make sure that your combination of selectors clearly selects one single container. If there is ambiguity because multiple pod and/or containers could be selected, DevSpace will require that you increase the specificity of your selectors. Here are a few common cases that may require you to combine multiple selectors:
Pods with Multiple Containers
If you are using the labelSelector
and DevSpace selects a pod with multiple containers, make sure you add the container name using the container
field to tell DevSpace which of the containers to select as dev container.
If a pod has multiple containers but each container has a different image, you could use the imageSelector
instead of setting labelSelector + container
.
Multiple Dev Containers Per Pod
If you want to make modifications for development for multiple containers in the same pod, you need to use the containers
field because some of the modifications you can define for dev containers actually apply to the pod itself and you want to reduce issues with conflicting modifications.
dev:
backend:
# Select the pod via labelSelector:
labelSelector:
app.kubernetes.io/name: payment-service
app.kubernetes.io/component: rest-api
# Specify ports (not reversePorts) for the entire pod, not per container
ports:
- port: 3000
# Make modifications for each container separately
containers:
api:
devImage: ghcr.io/org/project/image
reversePorts:
- port: 3306
redis:
env:
DEBUG: true
containers
+ Dev ConnectionsWhen using the containers
option, you should also specify the sections files
, persistPaths
, reversePorts
, etc. for each individual container.
However, since pods share the same network stack, the ports
option needs to be on the top-level instead of for each container individually.
Config Reference
imageSelector
required string
ImageSelector to select a pod
imageSelector
required string labelSelector
required <labelSelector_name>:string
LabelSelector to select a pod
labelSelector
required <labelSelector_name>:string namespace
required string
Namespace where to select the pod
namespace
required string container
required string
Container is the container name these services should get started.
container
required string arch
required string
Target Container architecture to use for the devspacehelper (currently amd64 or arm64). Defaults to amd64, but
devspace tries to find out the architecture by itself by looking at the node this container runs on.
arch
required string containers
required <container_name>:object
containers
required <container_name>:object