Your first local Kubernetes deployment¶
Push an application to a local registry, run it as a real HTTP service, rotate its runtime without rebuilding it, and remove the installation normally.
In this tutorial, you'll install Brewlet in a local kind cluster, deploy a Python application, and update its node-supplied runtime. You'll see how a running Pod keeps its original runtime while a replacement Pod uses the update, without changing the application image.
The tutorial installs the latest Brewlet release. To use a specific release
instead, pass the same --version VERSION to the install script and to
helm install.
Prerequisites¶
- macOS or Linux, on amd64 or arm64
- Docker, running Linux containers
- kind v0.33.0, kubectl and Helm
- Network access to GitHub and public container registries
Run every step in the same terminal.
1. Install the Brewlet CLI¶
Install the brewlet CLI into ~/.local/bin:
# tutorial-step: cli
curl -fsSL https://brewlet.sh/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
brewlet version
The script downloads the latest release for your machine and verifies its checksum.
2. Create a work directory¶
The work directory holds the application and a separate kubeconfig, so the tutorial doesn't touch your existing clusters.
# tutorial-step: setup
WORK="$(mktemp -d)"
ARCH="$(docker info --format '{{.Architecture}}' | sed 's/x86_64/amd64/; s/aarch64/arm64/')"
export KUBECONFIG="$WORK/kubeconfig"
3. Create the cluster and local registry¶
Create a one-node kind cluster. kind's default node image runs containerd 2.x, which Brewlet requires. The configuration tells containerd to read per-registry host settings, which the local registry below needs:
# tutorial-step: create cluster
cat <<EOF | DOCKER_DEFAULT_PLATFORM="linux/$ARCH" kind create cluster --name brewlet --config -
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry]
config_path = "/etc/containerd/certs.d"
EOF
Setting DOCKER_DEFAULT_PLATFORM for this command runs the node with the same
architecture as the application image, even if your shell already sets the
variable. A node on another architecture, such as linux/amd64 on an Apple
silicon Mac, runs under emulation and never starts its control plane, so kind
fails with unable to create ClusterRoleBinding: context deadline exceeded.
Start a disposable OCI registry on the cluster's Docker network. Docker assigns an available host port, bound only to loopback:
# tutorial-step: registry
docker run -d --name brewlet-registry --network kind \
--platform "linux/$ARCH" --publish 127.0.0.1::5000 \
registry@sha256:ddf754342cfc8acc51a56d5d0ab6af06826461864460636d8bd5c546dab2a7b8
REGISTRY="$(docker port brewlet-registry 5000/tcp)"
curl -fsS --max-time 5 --retry 10 --retry-connrefused --retry-delay 1 "http://$REGISTRY/v2/"
for NODE in $(kind get nodes --name brewlet); do
docker exec "$NODE" mkdir -p "/etc/containerd/certs.d/$REGISTRY"
cat <<EOF | docker exec -i "$NODE" cp /dev/stdin "/etc/containerd/certs.d/$REGISTRY/hosts.toml"
[host."http://brewlet-registry:5000"]
capabilities = ["pull", "resolve"]
EOF
done
The CLI reaches the registry through $REGISTRY on your machine. Inside each
node, containerd maps that same image authority to brewlet-registry:5000 on
the Docker network; a node's loopback address is not your machine's loopback
address. This follows kind's local registry setup.
Configure every new or recreated node the same way.
This registry has no authentication or TLS. Use it only on a trusted local Docker network for this disposable tutorial, not for production. The public runtime images below still come directly from their registries.
4. Install Brewlet on the cluster¶
Install the latest released Helm chart. It includes the CRDs and digest-pinned component images:
# tutorial-step: install
helm install brewlet oci://ghcr.io/microsoft/charts/brewlet \
--namespace brewlet --create-namespace --wait
5. Offer a runtime¶
Now offer a runtime for Python:
# tutorial-step: offer a runtime
cat > "$WORK/python.yaml" <<'EOF'
apiVersion: node.brewlet.sh/v1alpha1
kind: RuntimeImage
metadata:
name: python
spec:
source:
image: gcr.io/distroless/python3-debian12@sha256:2fdb05402a2cf21cf78fdb3ba4c5db167241e9e498140f5bf689d7efb773731f
user: {uid: 65532, gid: 65532}
---
apiVersion: node.brewlet.sh/v1alpha1
kind: NodeProfile
metadata:
name: local
spec:
nodePool: {includeControlPlane: true}
runtimeImages:
- id: python
tolerations:
- {key: startup-taint.cluster-autoscaler.kubernetes.io/brewlet, operator: Equal, value: provisioning, effect: NoSchedule}
EOF
until kubectl apply -f "$WORK/python.yaml"; do sleep 2; done
kubectl wait --for=condition=Ready nodeprofile/local --timeout=5m
brewlet k8s runtime status python
The admission webhook can take a few seconds to start answering after the
install, so the until loop retries the apply until it succeeds.
The python RuntimeImage is the distroless Python 3.11 image, unchanged and
pinned by digest. The local profile tells Brewlet to install it on the cluster's node.
includeControlPlane allows that on this one-node cluster; leave it disabled
for control-plane nodes in a shared cluster.
6. Build and push the application image¶
The application is a small Python HTTP server. Its image contains only the application: Python itself will come from the node.
# tutorial-step: build
mkdir "$WORK/app"
cat > "$WORK/app/server.py" <<'EOF'
import json, os, signal, sys, threading
from http.server import BaseHTTPRequestHandler, HTTPServer
class Hello(BaseHTTPRequestHandler):
def do_GET(self):
body = json.dumps({"python": sys.version.split()[0], "uid": os.getuid()})
self.send_response(200)
self.end_headers()
self.wfile.write(body.encode() + b"\n")
server = HTTPServer(("", 8000), Hello)
signal.signal(signal.SIGTERM,
lambda *_: threading.Thread(target=server.shutdown, daemon=True).start())
try:
server.serve_forever()
finally:
server.server_close()
EOF
cat > "$WORK/launch.json" <<'EOF'
{"schemaVersion": 1, "process": {"entrypoint": ["/usr/bin/python3"],
"args": ["/app/server.py"], "workingDir": "/app"}}
EOF
brewlet build "$REGISTRY/brewlet/hello:v1" --platform "linux/$ARCH" \
--launch "$WORK/launch.json" --layer "$WORK/app:/app" --store "$WORK/image"
launch.json tells Brewlet how to start the application with the
node-supplied Python. ARCH is your Docker engine's architecture, which is
also the architecture of the kind node in step 3. brewlet build writes the
image to $WORK/image.
Push the OCI image to the local registry, then use the pushed digest for deployment:
# tutorial-step: push app
brewlet push "$REGISTRY/brewlet/hello:v1" --store "$WORK/image" \
--insecure --push-result "$WORK/push.json"
APP="$REGISTRY/brewlet/hello@$(grep -o 'sha256:[0-9a-f]*' "$WORK/push.json")"
echo "$APP"
--insecure explicitly selects HTTP for this local registry; it does not
disable certificate verification. The result file records the pushed digest,
so APP names immutable content rather than a mutable tag. Kubernetes pulls
the application normally, without importing or retagging it on individual
nodes. For authenticated registries and TLS, see
registry and trust configuration.
7. Deploy and call the application¶
The annotation asks for the python runtime, and runtimeClassName: brewlet
lets Brewlet supply it:
# tutorial-step: application
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
spec:
selector:
matchLabels: {app: hello}
template:
metadata:
labels: {app: hello}
annotations: {runtime-image.brewlet.sh/app: python}
spec:
runtimeClassName: brewlet
containers:
- name: app
image: $APP
imagePullPolicy: IfNotPresent
securityContext: {readOnlyRootFilesystem: true}
readinessProbe:
httpGet: {path: /, port: 8000}
EOF
kubectl expose deployment hello --port=8000
kubectl rollout status deployment/hello --timeout=5m
SERVICE_IP="$(kubectl get service hello -o jsonpath='{.spec.clusterIP}')"
docker exec brewlet-control-plane curl -fsS --max-time 5 --retry 5 --retry-connrefused "http://$SERVICE_IP:8000/"
The response shows Python 3.11.2, supplied by the node, and the runtime's UID, 65532.
8. Rotate the runtime, not the application¶
Point the RuntimeImage at Python 3.13.5, then wait for Brewlet to roll it out:
# tutorial-step: rotation
rotate_runtime() {
kubectl patch runtimeimage python --type=merge -p '{"spec":{"source":{"image":"gcr.io/distroless/python3-debian13@sha256:f47f5807043391605425f2bd162b25f50cebdc90640bacc804e0177608fe5c65"}}}' &&
kubectl wait runtimeimage/python --for=jsonpath='{.status.generation}'=2 --timeout=2m &&
kubectl wait runtimeimage/python --for=condition=RotationComplete --timeout=5m &&
test -z "$(kubectl get runtimeimage python -o jsonpath='{.status.rotation.excludedNodes[*].name}')" &&
kubectl wait runtimeimage/python --for=condition=OldGenerationTasks=true --timeout=2m
}
if rotate_runtime; then
brewlet k8s runtime status python
else
echo "Runtime rotation did not complete; do not restart the Deployment. Current status:" >&2
brewlet k8s runtime status python
false
fi
The provisioner retries failed pulls and cancels a registry response that makes
no download progress for 30 seconds. A healthy rotation usually finishes much
sooner; if a wait fails, this block prints the runtime status and stops before
the replacement step. Do not restart the Deployment until RotationComplete
is true and no nodes are excluded.
The RuntimeImage is now at generation 2, but the running Pod still answers with Python 3.11.2:
# tutorial-step: old-pod
docker exec brewlet-control-plane curl -s "http://$SERVICE_IP:8000/"
Now restart the Deployment. The replacement Pod uses the new runtime, with the same
application image. Waiting for OldGenerationTasks=false ensures the old Pod
has stopped before you call the Service:
# tutorial-step: replacement
if kubectl wait runtimeimage/python --for=condition=RotationComplete --timeout=1s &&
test -z "$(kubectl get runtimeimage python -o jsonpath='{.status.rotation.excludedNodes[*].name}')"; then
kubectl rollout restart deployment/hello &&
kubectl rollout status deployment/hello --timeout=5m &&
kubectl wait runtimeimage/python --for=condition=OldGenerationTasks=false --timeout=2m &&
docker exec brewlet-control-plane curl -fsS --max-time 5 --retry 5 --retry-connrefused "http://$SERVICE_IP:8000/"
else
echo "Runtime rotation is incomplete or has excluded nodes; refusing to restart. Current status:" >&2
brewlet k8s runtime status python
false
fi
The replacement Pod answers with Python 3.13.5. No Pod uses generation 1 anymore, and the application image digest is the same one you built in step 6.
9. Clean up¶
Delete the application, then let Brewlet remove the runtime and restore the node's configuration before deleting the cluster:
# tutorial-step: cleanup
kubectl delete deployment hello
kubectl delete nodeprofile local --timeout=10m
kubectl delete runtimeimage python
helm uninstall brewlet --namespace brewlet
kind delete cluster --name brewlet
docker rm -f brewlet-registry
rm -rf "$WORK"
To remove the CLI too, run rm ~/.local/bin/brewlet.
If a cleanup command fails, see troubleshooting and safe removal.
Explore runtime images and pools, or package and publish applications.