You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/configuration/dev/container/selector.mdx
+81-55Lines changed: 81 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,68 +5,96 @@ sidebar_label: selector
5
5
6
6
7
7
## 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
9
9
-[`imageSelector`](#imageselector)
10
10
-[`labelSelector`](#labelselector)
11
-
-[`containerName`](#containername)
11
+
-[`container`](#container)
12
12
-[`namespace`](#namespace)
13
13
14
14
:::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.
16
16
:::
17
17
18
18
### `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
- The above example defines two images that can be used as `imageSelector`: `john/devbackend` or `john/debugger`
55
87
- 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.
60
90
61
91
In consequence, the following sync processes would be started when using the above config example assuming the local project root directoy `/my/project/`:
62
92
63
93
1. `localhost:/my/project/` forwards to `container-0:$WORKDIR` **\***
64
94
2. `localhost:/my/project/debug-logs/` forwards to `container-1:/logs`
65
95
66
-
**\* Changes on either side (local and container filesystem) that occur within the sub-folders `node_modules/` and `logs/` would be ingored.**
67
-
68
96
### `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.
70
98
71
99
#### Example: Select Container by Label
72
100
```yaml {18-21}
@@ -75,36 +103,37 @@ images:
75
103
image: john/devbackend
76
104
backend-debugger:
77
105
image: john/debugger
106
+
78
107
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
+
88
117
dev:
89
-
sync:
90
-
- labelSelector:
118
+
my-dev:
119
+
labelSelector:
91
120
app.kubernetes.io/name: devspace-app
92
121
app.kubernetes.io/component: app-backend
93
122
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
97
126
```
98
127
**Explanation:**
99
128
- 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.
101
130
102
131
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.
105
134
106
135
:::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.
108
137
:::
109
138
110
139
#### Example
@@ -117,6 +146,3 @@ The `namespace` option expects a string with a Kubernetes namespace used to sele
117
146
:::warning
118
147
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.
0 commit comments