Kubernetes Quick Start#

This guide covers Kubernetes-specific deployment of FleetMesh meshnode: persistent identity storage (ReadWriteOnce), non-root hardening, automated initialization and probes, TLS WebSocket routing (Gateway API or Ingress), NetworkPolicy isolation, and cluster rollouts.

For general production operations that apply across every runtime—fleet enrollment, meshctl watch monitoring, key hygiene, canary upgrade checklists, and node retirement—see the Operator Guide.

Prerequisites#

  • A Kubernetes 1.28+ cluster (kind, k3s, minikube, or managed cloud) with a default StorageClass supporting ReadWriteOnce volumes

  • kubectl configured for your cluster

  • Outbound access to docker.io/fleetmesh/meshnode:0.5.0a1 (or :0.5.0a1-postgres for PostgreSQL; see Podman Quick Start to mirror or build custom extras)

  • Optional: meshctl on your operator workstation (Install)

Key Kubernetes Invariants#

  Clients & Peer Nodes (wss://node-1.example.org)
                        │
             Gateway API / Ingress (TLS)
                        │  HTTP/1.1 Upgrade (WebSocket)
                        ▼
             Service: meshnode-1 (ClusterIP :7777)
                        │
                        ▼
       ┌─────────────────────────────────────────┐
       │  Pod: meshnode-1  (replicas: 1)         │
       │  ├─ initContainer: idempotent init/check│
       │  └─ container: meshnode run             │
       │        ├─ /var/lib/meshnode  (RWO PVC)  │
       │        └─ /tmp               (emptyDir) │
       └─────────────────────────────────────────┘
  1. Always run replicas: 1 per node identity (strategy.type: Recreate or a 1-replica StatefulSet). Each node owns a unique keypair (keys.json) and embedded SQLite WAL databases; two pods must never mount the same PVC concurrently. To scale out, deploy multiple distinct node identities (each with its own PVC).

  2. Persist /var/lib/meshnode on a ReadWriteOnce PVC. Losing keys.json creates a new identity and forfeits existing enrollment and peering grants.

  3. Configure long WebSocket idle timeouts at your Gateway or Ingress. Short defaults (such as 60s) unnecessarily churn persistent peer streams.


1. Create the Namespace and Persistent Volume#

# 01-namespace-pvc.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: fleetmesh
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: meshnode-1-data
  namespace: fleetmesh
  labels:
    app.kubernetes.io/name: meshnode
    app.kubernetes.io/instance: meshnode-1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
kubectl apply -f 01-namespace-pvc.yaml

2. Deploy meshnode with Automated Init and Probes#

The manifest below pairs strategy.type: Recreate, an idempotent initContainer (init once + check on every start), a hardened non-root securityContext, and CLI probes backed by meshnode whoami --json. Replace node-1.example.org with your public domain (or swap the image tag to :0.5.0a1-postgres for PostgreSQL):

# 02-meshnode.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: meshnode-1
  namespace: fleetmesh
  labels:
    app.kubernetes.io/name: meshnode
    app.kubernetes.io/instance: meshnode-1
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: meshnode
      app.kubernetes.io/instance: meshnode-1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: meshnode
        app.kubernetes.io/instance: meshnode-1
    spec:
      terminationGracePeriodSeconds: 30
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        runAsGroup: 1000
        fsGroup: 1000
        fsGroupChangePolicy: OnRootMismatch
        seccompProfile:
          type: RuntimeDefault
      initContainers:
        - name: init-meshnode
          image: docker.io/fleetmesh/meshnode:0.5.0a1
          imagePullPolicy: IfNotPresent
          command: ["/bin/sh", "-eu", "-c"]
          args:
            - |
              if [ ! -f /var/lib/meshnode/keys.json ]; then
                python3 -m fleetmesh_node.meshnode init /var/lib/meshnode \
                  --name meshnode-1 \
                  --class edge \
                  --face-host 0.0.0.0 \
                  --face-port 7777 \
                  --relay wss://relay.fleetmesh.org \
                  --endpoint wss=wss://node-1.example.org
              fi
              python3 -m fleetmesh_node.meshnode check /var/lib/meshnode
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          volumeMounts:
            - name: data
              mountPath: /var/lib/meshnode
            - name: tmp
              mountPath: /tmp
      containers:
        - name: meshnode
          image: docker.io/fleetmesh/meshnode:0.5.0a1
          imagePullPolicy: IfNotPresent
          args: ["run", "/var/lib/meshnode"]
          ports:
            - name: ws-face
              containerPort: 7777
              protocol: TCP
          resources:
            requests:
              cpu: 100m
              memory: 192Mi
            limits:
              cpu: "1"
              memory: 512Mi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          startupProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - python3 -m fleetmesh_node.meshnode whoami /var/lib/meshnode --json | grep -q '"running": true'
            initialDelaySeconds: 5
            periodSeconds: 5
            failureThreshold: 18
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - python3 -m fleetmesh_node.meshnode whoami /var/lib/meshnode --json | grep -q '"running": true'
            periodSeconds: 15
            timeoutSeconds: 5
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - python3 -m fleetmesh_node.meshnode whoami /var/lib/meshnode --json | grep -q '"running": true'
            periodSeconds: 30
            timeoutSeconds: 5
            failureThreshold: 3
          volumeMounts:
            - name: data
              mountPath: /var/lib/meshnode
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: meshnode-1-data
        - name: tmp
          emptyDir:
            sizeLimit: 64Mi
---
apiVersion: v1
kind: Service
metadata:
  name: meshnode-1
  namespace: fleetmesh
  labels:
    app.kubernetes.io/name: meshnode
    app.kubernetes.io/instance: meshnode-1
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: meshnode
    app.kubernetes.io/instance: meshnode-1
  ports:
    - name: ws-face
      port: 7777
      targetPort: ws-face
      protocol: TCP

Apply and verify health:

kubectl apply -f 02-meshnode.yaml
kubectl -n fleetmesh rollout status deployment/meshnode-1
kubectl -n fleetmesh exec deployment/meshnode-1 -- \
  python3 -m fleetmesh_node.meshnode health /var/lib/meshnode

Declarative export (experimental): meshctl export --target k8s can generate baseline Deployment, Service, and ConfigMap YAML from a MeshNode manifest; see Manifests: export.


3. Expose Over TLS & Configure Cluster Proxy Trust#

Choose either Gateway API (HTTPRoute) or traditional Ingress.

Option A: Gateway API (HTTPRoute)#

# 03-httproute.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: meshnode-1
  namespace: fleetmesh
spec:
  parentRefs:
    - name: platform
      namespace: gateway
      sectionName: https
  hostnames:
    - node-1.example.org
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: meshnode-1
          port: 7777

Option B: Standard Ingress (ingress-nginx + cert-manager)#

# 03-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: meshnode-1
  namespace: fleetmesh
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - node-1.example.org
      secretName: meshnode-1-tls
  rules:
    - host: node-1.example.org
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: meshnode-1
                port:
                  number: 7777

Cluster Proxy CIDRs#

Because ingress traffic arrives from your cluster pod/gateway CIDR rather than 127.0.0.1, add your cluster proxy subnet to --trusted-proxy (see Relay Face Limits):

kubectl -n fleetmesh exec deployment/meshnode-1 -- \
  python3 -m fleetmesh_node.meshnode relay-limits /var/lib/meshnode \
    --trusted-proxy 10.244.0.0/16 \
    --trusted-proxy 10.0.0.0/8

4. Restrict Traffic (NetworkPolicy)#

If your CNI enforces NetworkPolicy (Cilium, Calico, etc.), permit ingress to port 7777 only from your gateway/ingress namespace and outbound DNS (53) + relay TLS (443):

# 04-networkpolicy.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: meshnode-1
  namespace: fleetmesh
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/instance: meshnode-1
  policyTypes:
    - Ingress
    - Egress
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: gateway
      ports:
        - protocol: TCP
          port: 7777
  egress:
    - to:
        - namespaceSelector: {}
      ports:
        - protocol: UDP
          port: 53
        - protocol: TCP
          port: 53
    - ports:
        - protocol: TCP
          port: 443

5. Enrollment, Rollouts, Scaling & Backups#

Fleet Enrollment via kubectl exec#

Follow the enrollment and roster workflow in Keys, Fleets & Access, running the two node-side steps via kubectl exec:

# 1. Read the pod's pubkey, then mint TOKEN on your operator workstation
kubectl -n fleetmesh exec deployment/meshnode-1 -- \
  python3 -m fleetmesh_node.meshnode whoami /var/lib/meshnode

# 2. Apply the node-bound enrollment token to the running pod
kubectl -n fleetmesh exec deployment/meshnode-1 -- \
  python3 -m fleetmesh_node.meshnode enrol /var/lib/meshnode "$TOKEN"

Upgrades, Multi-Node Scaling & Backups#

  • Upgrades: Update the image tag in both initContainers and containers of 02-meshnode.yaml and run kubectl apply -f 02-meshnode.yaml. strategy.type: Recreate cleanly terminates the old pod (SIGTERM) and unmounts the PVC before starting the new pod with the same identity. Follow the canary-first checklist in Upgrades, Backups & Retirement.

  • Multiple nodes: Duplicate 01-namespace-pvc.yaml and 02-meshnode.yaml with distinct metadata.name values (meshnode-1, meshnode-2, …) or use a StatefulSet with volumeClaimTemplates and --name "$HOSTNAME" in initContainers.

  • Backups: Enable scheduled CSI VolumeSnapshots on meshnode-1-data, and copy keys.json to an encrypted off-cluster vault:

    kubectl -n fleetmesh cp \
      "$(kubectl -n fleetmesh get pod -l app.kubernetes.io/instance=meshnode-1 -o jsonpath='{.items[0].metadata.name}'):/var/lib/meshnode/keys.json" \
      ./meshnode-1.keys.json && chmod 600 ./meshnode-1.keys.json
    

6. Kubernetes Troubleshooting#

Symptom

Likely Cause

Fix

Pod stuck in CrashLoopBackOff on init-meshnode

PVC permissions or unsupported fsGroup

Ensure securityContext.fsGroup: 1000 matches runAsUser: 1000 and the StorageClass supports fsGroup.

Multi-Attach error for volume during rollout

Deployment used RollingUpdate instead of Recreate

Set spec.strategy.type: Recreate so the old pod detaches the RWO PVC first.

Readiness probe fails on first start

Descriptor proof-of-work mining takes a few seconds

Increase startupProbe.failureThreshold on CPU-throttled nodes.

Peers disconnect every 60 seconds

Ingress/Gateway WebSocket idle timeout is too low

Raise proxy read/send timeouts to 3600s.

For protocol, relay, enrollment, and digest troubleshooting, see Troubleshooting & Opt-In Features.