Skip to content

Commit

Permalink
Add the deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
grihabor committed Mar 4, 2025
1 parent be65b84 commit 8a093d1
Showing 1 changed file with 65 additions and 3 deletions.
68 changes: 65 additions & 3 deletions docs/docs/kubernetes/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,26 @@ python_format_string(
k8s_bundle(
name="webpages",
context="kind-kind",
**parametrize("default", sources=("src/k8s:webpages-template@parametrize=web",)),
**parametrize("default", sources=("src/k8s:webpages-template@parametrize=default",)),
**parametrize("web", sources=("src/k8s:webpages-template@parametrize=web",)),
)
```

## Docker images

Before we continue, add the docker backend:

```toml title="pants.toml"
[GLOBAL]
backend_packages = [
...
"pants.backend.docker",
]
[dockerfile-parser]
use_rust_parser = true
```

To use docker images you most likely will need some templating. This is because
your docker image tags will be probably versioned.

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

```python title="src/k8s/BUILD"
...
docker_image(
name="nginx",
name="custom-nginx",
instructions=["FROM nginx"],
image_tags=[env("VERSION")],
)
# TODO
python_format_string(
name="webserver-template",
source="deployment.yaml",
values={"VERSION": env("VERSION")},
)
k8s_bundle(
name="webserver",
context="kind-kind",
sources=("src/k8s:webserver-template",),
dependencies=(":custom-nginx",),
)
```

Create the deployment:

```yaml title="src/k8s/deployment.yaml"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: webserver
namespace: web
spec:
replicas: 1
selector:
matchLabels:
app: webserver
template:
metadata:
labels:
app: webserver
spec:
containers:
- name: nginx
image: custom-nginx:{VERSION}
```

Now deploy the bundle:

```bash
pants experimental-deploy src/k8s:webserver
```

Notice, that pants will automatically publish the image. This happens because
we've configured `dependencies=(":custom-nginx",)` field on `k8s_bundle`
target. You can disable this behaviour and publish the image manually:

```bash
pants publish src/k8s:custom-nginx
pants experimental-deploy --no-publish-dependencies src/k8s:webserver
```

0 comments on commit 8a093d1

Please sign in to comment.