/

Ambitwin · source-available, not open source · © 2026 Nicolò Ghignatti

Deployment & Kubernetes

Keywords on this page
WordMeaningExample
PodOne running copy of a servicetelemetry-5d8...
DeploymentKeeps stateless pods runningk8s/deployments/chat.yml
StatefulSetSame, for pods with their own disktwin-db-0
PVCA disk claimed by a podtwin-data-twin-db-0
Init containerRuns first, must finish before the service startswait-for-db
k3dKubernetes in Docker, for local usejust k8s create

How the cluster is built. Commands and setup: Kubernetes & Istio.


What is in k8s/

k8s/
├── namespace.yml                     # ambitwin, enrolled in ambient mode
├── istio-gateway.yml                 # the gateway and one route per service
├── istio-peer-authentication.yml     # STRICT mTLS
├── istio-request-authentication.yml  # JWT check at the edge
├── istio-agent-authz.yml             # who may call agent
├── configmaps/common.yml             # shared settings that are not secret
├── deployments/                      # 12 stateless services
├── stateful/                         # 8 databases, Redis, Kafka
└── monitoring/                       # Prometheus, Grafana

Stateless or stateful

KindWhatIf a pod dies
DeploymentThe 12 servicesA new one starts anywhere
StatefulSet4 MongoDB, 4 PostgreSQL, Redis, KafkaSame name, same disk
flowchart LR
    S["Headless Service: twin-db"] --> P["Pod: twin-db-0"]
    P --> V["PVC: twin-data-twin-db-0"]

Starting order

A service must not start before its database. Each pod waits in an init container:

initContainers:
  - name: wait-for-db
    image: busybox:1.38.0
    command: [sh, -c, "until nc -z twin-db 27017; do sleep 2; done"]

Settings and secrets

Warning

A Kubernetes secret is base64, not encryption. RBAC is the real guard. For production, prefer an external manager.


Hardening on every service


Updates

kubectl rollout restart deployment/digital-twin -n ambitwin
kubectl rollout status  deployment/digital-twin -n ambitwin
kubectl rollout undo    deployment/digital-twin -n ambitwin

The old pod serves until the new one is ready.

Application images use IfNotPresent, so just k8s load works on k3d without a registry. For a real cluster see Trust & Service Mesh.


Known gaps


When something is wrong

# why is the pod not ready? read Events at the bottom
kubectl describe pod <pod> -n ambitwin

# logs: current, previous crash, init container
kubectl logs deployment/digital-twin -n ambitwin
kubectl logs <pod> -n ambitwin --previous
kubectl logs <pod> -n ambitwin -c wait-for-db

# shell inside
kubectl exec -it <pod> -n ambitwin -- sh

# recent events
kubectl get events -n ambitwin --sort-by=.lastTimestamp

# which image is really running
kubectl get pod <pod> -n ambitwin -o jsonpath='{.spec.containers[0].image}'

k3d refuses connections after a restart? Find the port mapped to 6443:

docker ps --filter name=k3d-ambitwin-serverlb
kubectl config set-cluster k3d-ambitwin --server=https://127.0.0.1:<PORT>