Developers

Kubernetes and Helm

Plain manifests or the official Helm chart, with or without a GPU.

Updated:

StatefulSet or Deployment

KindWhen to use it
StatefulSet (recommended)Each pod has its own volume: after restarts, upgrades or node changes it comes back as the same computer, with its models already downloaded and its reputation.
DeploymentEphemeral pods without a persistent volume: each pod is a new computer that downloads its models on start and removes itself from My computers on shutdown (PIAP_REMOVE_ON_EXIT=true). Useful for temporary capacity, for example spot nodes.

Secrets

The same token works for the Secret the container reads and for the image pull Secret (docker-registry):

bash
kubectl create namespace piap
kubectl -n piap create secret generic piap-token --from-literal=token="$PIAP_TOKEN"
kubectl -n piap create secret docker-registry piap-registry \
  --docker-server=registry.piap.io \
  --docker-username=token \
  --docker-password="$PIAP_TOKEN"

Plain manifests

Namespace, headless Service (for metrics), StatefulSet with a 60 Gi volume on /data, restricted security context and PodDisruptionBudget:

yaml
apiVersion: v1
kind: Namespace
metadata:
  name: piap
---
apiVersion: v1
kind: Service
metadata:
  name: piap-node
  namespace: piap
  labels:
    app.kubernetes.io/name: piap-node
spec:
  clusterIP: None
  selector:
    app.kubernetes.io/name: piap-node
  ports:
    - name: http
      port: 9090
      targetPort: http
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: piap-node
  namespace: piap
spec:
  serviceName: piap-node
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: piap-node
  template:
    metadata:
      labels:
        app.kubernetes.io/name: piap-node
    spec:
      terminationGracePeriodSeconds: 90
      automountServiceAccountToken: false
      imagePullSecrets:
        - name: piap-registry
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
        runAsGroup: 65532
        fsGroup: 65532
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: node
          image: registry.piap.io/piap/node:0.1.0-cpu
          env:
            - name: PIAP_TOKEN
              valueFrom:
                secretKeyRef:
                  name: piap-token
                  key: token
            - name: PIAP_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: PIAP_GRACE_SECONDS
              value: "60"
          ports:
            - name: http
              containerPort: 9090
          resources:
            requests:
              cpu: "2"
              memory: 8Gi
            limits:
              memory: 16Gi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            periodSeconds: 20
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /readyz
              port: http
            periodSeconds: 10
            failureThreshold: 3
          volumeMounts:
            - name: data
              mountPath: /data
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: tmp
          emptyDir: {}
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 60Gi
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: piap-node
  namespace: piap
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: piap-node
bash
kubectl apply -f piap-node.yaml
kubectl -n piap get pods -w
kubectl -n piap logs -f piap-node-0
  • terminationGracePeriodSeconds: 90 is the container grace (PIAP_GRACE_SECONDS, 60 by default) plus 30 seconds.
  • /healthz answers while the process is alive (liveness); /readyz once it is connected to the network and the engine is ready (readiness).
  • The pod runs as user 65532, non-root, with a read-only file system, no capabilities and the RuntimeDefault seccomp profile.
  • The memory limit must leave headroom above what the model uses (PIAP_MAX_MEMORY_PERCENT is computed on the memory the container sees).

If you prefer the token as a file instead of an environment variable, mount the Secret and use PIAP_TOKEN_FILE:

yaml
          env:
            - name: PIAP_TOKEN_FILE
              value: /run/secrets/piap/token
          volumeMounts:
            - name: token
              mountPath: /run/secrets/piap
              readOnly: true
      volumes:
        - name: token
          secret:
            secretName: piap-token
            defaultMode: 0440

GPU variant

Switch the image to the cuda variant, request nvidia.com/gpu in the limits and schedule the pod on GPU nodes. The nodeSelector and tolerations are examples: use your cluster labels and taints. If your cluster uses a RuntimeClass for NVIDIA, add runtimeClassName.

yaml
    spec:
      nodeSelector:
        nvidia.com/gpu.present: "true"
      tolerations:
        - key: nvidia.com/gpu
          operator: Exists
          effect: NoSchedule
      containers:
        - name: node
          image: registry.piap.io/piap/node:0.1.0-cuda
          resources:
            requests:
              cpu: "2"
              memory: 8Gi
            limits:
              memory: 16Gi
              nvidia.com/gpu: 1

Official Helm chart

The chart lives in the piap registry and has the same version as the image. Sign in with a token that has the pull scope and install using the Secrets you already created:

bash
echo "$PIAP_TOKEN" | helm registry login registry.piap.io -u token --password-stdin
bash
helm install piap-node oci://registry.piap.io/piap/charts/node --version 0.1.0 \
  -n piap --create-namespace \
  --set token.existingSecret=piap-token \
  --set registry.pullSecret.name=piap-registry

Or let the chart create both Secrets from the token. It is simpler, but the token is stored in the Helm release values:

bash
helm install piap-node oci://registry.piap.io/piap/charts/node --version 0.1.0 \
  -n piap --create-namespace \
  --set token.value="$PIAP_TOKEN"

For a GPU fleet, a values file:

yaml
image:
  variant: cuda
kind: StatefulSet
replicas: 2
name: gpu-pool
token:
  existingSecret: piap-token
registry:
  pullSecret:
    create: false
    name: piap-registry
policy:
  models: []
  maxMemoryPercent: 70
  diskGB: 80
  maxConcurrent: 1
  dailyTokens: 0
  hours: "20:00-08:00"
  days: "1-5"
  timezone: UTC
  ownUse: true
persistence:
  enabled: true
  size: 120Gi
gpu:
  enabled: true
  count: 1
nodeSelector:
  nvidia.com/gpu.present: "true"
networkPolicy:
  enabled: true
metrics:
  serviceMonitor:
    enabled: true
    interval: 30s
bash
helm upgrade --install piap-node oci://registry.piap.io/piap/charts/node --version 0.1.0 \
  -n piap --create-namespace -f values-gpu.yaml

To see every value with its default:

bash
helm show values oci://registry.piap.io/piap/charts/node --version 0.1.0

Chart values

ValueDefaultWhat it does
image.repositoryregistry.piap.io/piap/nodeImage repository.
image.tag(empty)Empty = chart version plus variant (for example 0.1.0-cpu).
image.variantcpucpu or cuda.
kindStatefulSetStatefulSet or Deployment.
replicas1Number of computers.
token.value(empty)Server token; the chart creates the Secret.
token.existingSecret(empty)Existing Secret holding the token.
token.keytokenKey of the token inside the Secret.
registry.pullSecret.createtrueCreates the pull Secret with the same token (only with token.value).
registry.pullSecret.name(empty)Name of the pull Secret, created or existing.
networkprodprod or lab.
name(empty)Name in My computers (PIAP_NAME); empty = pod name.
policy.models[]Allowed models (PIAP_MODELS); empty = any that fits.
policy.maxMemoryPercent70Memory (or GPU memory) a model may use, 10 to 90.
policy.diskGB40Space for models.
policy.maxConcurrent1Requests at a time.
policy.dailyTokens0Daily cap on network tokens; 0 = no cap.
policy.hours(always)Window HH:MM-HH:MM.
policy.days(always)Days, for example 1-5 or 0,6 (0 = Sunday).
policy.timezoneUTCTime zone of the window.
policy.yieldToOthersfalseYields to other programs on the node (PIAP_YIELD).
policy.ownUsetrueYour own requests without credits (PIAP_OWN_USE).
policy.networks[]Private networks in priority order, and global.
policy.locationcountryPrecision on the map: city, country or off.
policy.region(empty)Declared region.
graceSeconds60Graceful shutdown grace.
removeOnExit(empty)Empty = true with Deployment and false with StatefulSet.
persistence.enabledtruePersistent volume for /data.
persistence.size60GiVolume size.
persistence.storageClass(empty)StorageClass; empty = the cluster default.
resources(see helm show values)Container requests and limits.
gpu.enabledfalseRequests a GPU and uses the cuda variant.
gpu.count1GPUs per pod.
gpu.resourceNamenvidia.com/gpuGPU resource name.
gpu.runtimeClassName(empty)NVIDIA RuntimeClass, if your cluster uses one.
nodeSelector{}Node selector.
tolerations[]With gpu.enabled and no tolerations, adds the nvidia.com/gpu one.
affinity{}Pod affinity.
podDisruptionBudget.enabledtrueCreates the PodDisruptionBudget.
podDisruptionBudget.maxUnavailable1Pods that may be down at once.
networkPolicy.enabledfalseNetworkPolicy that only allows egress on 443 and DNS.
metrics.serviceMonitor.enabledfalseCreates a ServiceMonitor for Prometheus Operator.
metrics.serviceMonitor.interval30sMetrics scrape interval.
extraEnv[]Extra environment variables.