Skip to the workspace
Pebellslearn by building
Cloud and Containers for ML  ›  Capstone Project

Kubernetes for Training and Serving

Kubernetes 14 minOn Kubernetes, training runs as a Job that finishes and exits, while serving runs as a Deployment that keeps replicas alive, and both declare the CPU, memory or GPU they need.

mlops / Kubernetes for Training and Serving

Explore each scene at your own pace.

01 · The rule

The rule

Kubernetes for Training and Serving

The churn project now has two images: one that trains the model and one that serves it. On a Kubernetes cluster they need very different care. Training should run, finish and free its machine. Serving should never stop. Kubernetes has a different object for each, and picking the wrong one causes strange failures.

The rule

Work that ends is a Job; work that stays is a Deployment.

Training is a Job. A Job runs a container until it exits successfully, retries it if it fails, and then is done. A CronJob creates a Job on a schedule — here, every Sunday at 02:00:

apiVersion: batch/v1
kind: CronJob
metadata:
  name: churn-train
spec:
  schedule: "0 2 * * 0"
  jobTemplate:
    spec:
      backoffLimit: 2
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: train
              image: tunebox/churn-train:2026-09
              resources:
                requests: { cpu: "8", memory: 32Gi }

Serving is a Deployment. A Deployment keeps a set number of identical pods running, replaces any that crash, and rolls out new image versions gradually:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: churn-api
spec:
  replicas: 3
  selector:
    matchLabels: { app: churn-api }
  template:
    metadata:
      labels: { app: churn-api }
    spec:
      containers:
        - name: api
          image: tunebox/churn-api:7
          ports: [{ containerPort: 8000 }]
          resources:
            requests: { cpu: 500m, memory: 1Gi }
          readinessProbe:
            httpGet: { path: /health, port: 8000 }

A Service in front of the Deployment spreads requests across the three pods.

Both declare resources, so the scheduler places them on nodes with room. A neural network would add a GPU under limits, such as nvidia.com/gpu: 1, which also requires nodes with GPUs and their device plugin. The readiness probe matters for models: loading a large model takes time, and traffic should only arrive once /health says the model is loaded.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.