Skip to content

Commit 8a093d1

Browse files
committed
Add the deployment
1 parent be65b84 commit 8a093d1

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

docs/docs/kubernetes/index.mdx

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,26 @@ python_format_string(
185185
k8s_bundle(
186186
name="webpages",
187187
context="kind-kind",
188-
**parametrize("default", sources=("src/k8s:webpages-template@parametrize=web",)),
188+
**parametrize("default", sources=("src/k8s:webpages-template@parametrize=default",)),
189189
**parametrize("web", sources=("src/k8s:webpages-template@parametrize=web",)),
190190
)
191191
```
192192

193193
## Docker images
194194

195+
Before we continue, add the docker backend:
196+
197+
```toml title="pants.toml"
198+
[GLOBAL]
199+
backend_packages = [
200+
...
201+
"pants.backend.docker",
202+
]
203+
204+
[dockerfile-parser]
205+
use_rust_parser = true
206+
```
207+
195208
To use docker images you most likely will need some templating. This is because
196209
your docker image tags will be probably versioned.
197210

@@ -210,11 +223,60 @@ This script will run before every pants command, so you can now use the
210223
`VERSION` env var in the BUILD file:
211224

212225
```python title="src/k8s/BUILD"
226+
...
213227
docker_image(
214-
name="nginx",
228+
name="custom-nginx",
215229
instructions=["FROM nginx"],
216230
image_tags=[env("VERSION")],
217231
)
218-
# TODO
232+
python_format_string(
233+
name="webserver-template",
234+
source="deployment.yaml",
235+
values={"VERSION": env("VERSION")},
236+
)
237+
k8s_bundle(
238+
name="webserver",
239+
context="kind-kind",
240+
sources=("src/k8s:webserver-template",),
241+
dependencies=(":custom-nginx",),
242+
)
219243
```
220244

245+
Create the deployment:
246+
247+
```yaml title="src/k8s/deployment.yaml"
248+
---
249+
apiVersion: apps/v1
250+
kind: Deployment
251+
metadata:
252+
name: webserver
253+
namespace: web
254+
spec:
255+
replicas: 1
256+
selector:
257+
matchLabels:
258+
app: webserver
259+
template:
260+
metadata:
261+
labels:
262+
app: webserver
263+
spec:
264+
containers:
265+
- name: nginx
266+
image: custom-nginx:{VERSION}
267+
```
268+
269+
Now deploy the bundle:
270+
271+
```bash
272+
pants experimental-deploy src/k8s:webserver
273+
```
274+
275+
Notice, that pants will automatically publish the image. This happens because
276+
we've configured `dependencies=(":custom-nginx",)` field on `k8s_bundle`
277+
target. You can disable this behaviour and publish the image manually:
278+
279+
```bash
280+
pants publish src/k8s:custom-nginx
281+
pants experimental-deploy --no-publish-dependencies src/k8s:webserver
282+
```

0 commit comments

Comments
 (0)