Skip to content

Commit 54b8234

Browse files
committed
docs: add dev selector
1 parent f9d7577 commit 54b8234

1 file changed

Lines changed: 81 additions & 55 deletions

File tree

docs/pages/configuration/dev/container/selector.mdx

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,96 @@ sidebar_label: selector
55

66

77
## Pod/Container Selection
8-
The following config options are needed to determine the container which the file synchronization should be established to:
8+
The following config options are needed to determine the pod which DevSpace should select
99
- [`imageSelector`](#imageselector)
1010
- [`labelSelector`](#labelselector)
11-
- [`containerName`](#containername)
11+
- [`container`](#container)
1212
- [`namespace`](#namespace)
1313

1414
:::info Auto Reconnect
15-
If the sync is unable to establish a connection to the selected container or loses it after starting the sync, DevSpace will try to restart the sync several times.
15+
If one of the services is unable to establish a connection to the selected container or loses it after starting the sync, DevSpace will try to restart the dev services.
1616
:::
1717

1818
### `imageSelector`
19-
<FragmentImageSelector />
19+
The `imageSelector` option expects a string that specifies an image (e.g. `my-registry.com/lib/my-image:tag`, `alpine:latest` or `nginx`) to select a target pod and container with it. The newest running pod that has a container which matches this image will be selected by DevSpace.
20+
21+
In addition, you can also reference images from the `images` section in the `imageSelector` with:
22+
- If the image in `imageSelector` matches a `images.*.image`, DevSpace will automatically append the latest built tag during runtime to the `imageSelector`.
23+
- You can also let DevSpace resolve the target image and tag by using runtime variables `${runtime.images.IMAGE_NAME}`, `${runtime.images.IMAGE_NAME.image}` or `${runtime.images.IMAGE_NAME.tag}`
24+
25+
For example:
26+
```yaml
27+
images:
28+
app:
29+
image: my-registry.com/lib/my-image
30+
31+
dev:
32+
...
33+
# DevSpace will search for the newest pod with a container that
34+
# uses my-registry.com/lib/other-image:latest
35+
imageSelector: my-registry.com/lib/other-image:latest
36+
# DevSpace will search for the newest pod with a container that
37+
# uses my-registry.com/lib/my-image:xxxxx (latest built tag by DevSpace)
38+
imageSelector: my-registry.com/lib/my-image
39+
# DevSpace will search for the newest pod with a container that
40+
# uses my-registry.com/lib/my-image:xxxxx (latest built tag by DevSpace)
41+
imageSelector: ${runtime.images.app}
42+
# DevSpace will search for the newest pod with a container that
43+
# uses my-registry.com/lib/my-image:custom-tag
44+
imageSelector: ${runtime.images.app.image}:custom-tag
45+
# DevSpace will search for the newest pod with a container that
46+
# uses my-registry.com/lib/my-image:xxxxx (latest built tag by DevSpace)
47+
imageSelector: ${runtime.images.app.image}:${runtime.images.app.tag}
48+
# DevSpace will search for the newest pod with a container that
49+
# uses the image of app of dependency dep1 with the latest built tag by DevSpace
50+
imageSelector: ${runtime.dependencies.dep1.images.app.image}:${runtime.dependencies.dep1.images.app.tag}
51+
```
2052
2153
#### Example: Select Container by Image
2254
```yaml
2355
vars:
24-
- name: backend-image
25-
value: john/devbackend
26-
- name: backend-debugger-image
27-
value: john/debugger
56+
BACKEND_IMAGE: john/devbackend
57+
BACKEND_DEBUGGER_IMAGE: john/debugger
58+
2859
images:
2960
backend:
30-
image: ${backend-image}
61+
image: ${BACKEND_IMAGE}
3162
backend-debugger:
32-
image: ${backend-debugger-image}
63+
image: ${BACKEND_DEBUGGER_IMAGE}
64+
3365
deployments:
34-
- name: app-backend
35-
helm:
36-
componentChart: true
37-
values:
38-
containers:
39-
- name: container-0
40-
image: ${backend-image}
41-
- name: container-1
42-
image: ${backend-debugger-image}
66+
app-backend:
67+
helm:
68+
values:
69+
containers:
70+
- name: container-0
71+
image: ${BACKEND_IMAGE}
72+
- name: container-1
73+
image: ${BACKEND_DEBUGGER_IMAGE}
74+
4375
dev:
44-
sync:
45-
- imageSelector: ${backend-image}
46-
excludePaths:
47-
- node_modules/
48-
- logs/
49-
- imageSelector: ${backend-debugger-image}
50-
localSubPath: ./debug-logs
51-
containerPath: /logs
76+
my-dev-1:
77+
imageSelector: ${BACKEND_IMAGE}
78+
sync:
79+
- path: ./
80+
my-dev-2:
81+
imageSelector: ${BACKEND_DEBUGGER_IMAGE}
82+
sync:
83+
- path: ./debug-logs:/logs
5284
```
5385
**Explanation:**
5486
- The above example defines two images that can be used as `imageSelector`: `john/devbackend` or `john/debugger`
5587
- The deployment starts two containers and each of them uses an image from the `images` section.
56-
- The `imageSelector` option of the first sync configuration in the `dev.sync` section references the same image as `images.backend`. That means DevSpace would select the first container for file synchronization, that would match `john/devbackend:tag(backend)`, where `tag(backend)` is the last built tag of `images.backend`
57-
- The first sync configuration does not define `localSubPath`, so it defaults to the project's root directory (location of `devspace.yaml`).
58-
- The first sync configuration does not define `containerPath`, so it defaults to the container's working directory (i.e. `WORKDIR`).
59-
- The `imageSelector` option of the second sync configuration in the `dev.sync` section references the same image as `images.backend-debugger`. That means DevSpace would select the second container for file synchronization, as this container uses the `image: john/debugger` which belongs to the `backend-debugger` image as defined in the `images` section.
88+
- The `imageSelector` option of the first sync configuration in the `dev.*.sync` section references the same image as `images.backend`. That means DevSpace would select the first container for file synchronization, that would match `john/devbackend:tag(backend)`, where `tag(backend)` is the last built tag of `images.backend`
89+
- The `imageSelector` option of the second sync configuration in the `dev.*.sync` section references the same image as `images.backend-debugger`. That means DevSpace would select the second container for file synchronization, as this container uses the `image: john/debugger` which belongs to the `backend-debugger` image as defined in the `images` section.
6090

6191
In consequence, the following sync processes would be started when using the above config example assuming the local project root directoy `/my/project/`:
6292

6393
1. `localhost:/my/project/` forwards to `container-0:$WORKDIR` **\***
6494
2. `localhost:/my/project/debug-logs/` forwards to `container-1:/logs`
6595

66-
**\* Changes on either side (local and container filesystem) that occur within the sub-folders `node_modules/` and `logs/` would be ingored.**
67-
6896
### `labelSelector`
69-
<FragmentLabelSelector />
97+
The `labelSelector` option expects a key-value map of strings with Kubernetes labels. This can be used to select the correct target pod with labels instead of the image name like `imageSelector` or `imageName`. If the pod you want to select has multiple containers, make sure to use `container` as well.
7098

7199
#### Example: Select Container by Label
72100
```yaml {18-21}
@@ -75,36 +103,37 @@ images:
75103
image: john/devbackend
76104
backend-debugger:
77105
image: john/debugger
106+
78107
deployments:
79-
- name: app-backend
80-
helm:
81-
componentChart: true
82-
values:
83-
containers:
84-
- name: container-0
85-
image: john/devbackend
86-
- name: container-1
87-
image: john/debugger
108+
app-backend:
109+
helm:
110+
values:
111+
containers:
112+
- name: container-0
113+
image: john/devbackend
114+
- name: container-1
115+
image: john/debugger
116+
88117
dev:
89-
sync:
90-
- labelSelector:
118+
my-dev:
119+
labelSelector:
91120
app.kubernetes.io/name: devspace-app
92121
app.kubernetes.io/component: app-backend
93122
custom-label: custom-label-value
94-
containerName: container-0
95-
localSubPath: ./src
96-
containerPath: /app/src
123+
container: container-0
124+
sync:
125+
- path: ./src:/app/src
97126
```
98127
**Explanation:**
99128
- The `labelSelector` would select the pod created for the component deployment `app-backend`.
100-
- Because the selected pod has two containers, we also need to specify the `containerName` option which defines the container that should be used for the file synchronization.
129+
- Because the selected pod has two containers, we also need to specify the `container` option which defines the container that should be used for the file synchronization.
101130

102131

103-
### `containerName`
104-
The `containerName` option expects a string with a container name. This option is used to decide which container should be selected when using the `labelSelector` option because `labelSelector` selects a pod and a pod can have multiple containers.
132+
### `container`
133+
The `container` option expects a string with a container name. This option is used to decide which container should be selected when using the `labelSelector` option because `labelSelector` selects a pod and a pod can have multiple containers.
105134

106135
:::info
107-
The `containerName` option is not required if the pod you are selecting using `imageName` or `labelSelector` has only one container.
136+
The `container` option is not required if the pod you are selecting using `imageSelector` or `labelSelector` has only one container.
108137
:::
109138

110139
#### Example
@@ -117,6 +146,3 @@ The `namespace` option expects a string with a Kubernetes namespace used to sele
117146
:::warning
118147
It is generally **not** needed (nor recommended) to specify the `namespace` option because by default, DevSpace uses the default namespace of your current kube-context which is usually the one that has been used to deploy your containers to.
119148
:::
120-
121-
122-
<br/>

0 commit comments

Comments
 (0)