Scaling Intelligence: Deploying a Lead Scoring Model with Kubernetes (kind)
Project Overview
This article documents the process of taking a trained Machine Learning model—a lead scoring classifier—and deploying it into a production-ready environment using Docker for containerization and Kubernetes (Kind) for orchestration. This project focuses on MLOps fundamentals, specifically deploying a Java-based microservice that runs the model.
Goal: Deploy a lead scoring prediction service to a local Kubernetes cluster and implement Horizontal Pod Autoscaling (HPA) to manage traffic spikes efficiently.
Key Technologies Used:
Java/Spring Boot: Backend application framework (within the container).
Docker: Containerization.
Kubernetes (kind): Local cluster orchestration.
kubectl: Kubernetes command-line tool.
Phase 1: Containerization and Local Verification
The first step is ensuring our model microservice is correctly packaged and running inside a Docker container.
1. Building the Model Image
We build the Docker image using a provided Dockerfile_full.
# 1. Navigate to the project directory
cd machine-learning-zoomcamp/cohorts/2025/05-deployment/homework
# 2. Build the image
docker build -f Dockerfile_full -t zoomcamp-model:3.13.10-hw10 .
2. Local Testing (Sanity Check)
Before touching Kubernetes, we test the image locally. The service runs on port 9696.
# Terminal 1: Run the container
docker run -it --rm -p 9696:9696 zoomcamp-model:3.13.10-hw10
(The container should start and listen for requests.)
# Terminal 2: Execute the test client
python q6_test.py
SNAPSHOT: Local Test Output
{'conversion_probability': 0.29, 'conversion': False}
Verification: The prediction service is correctly initialized and functional.
Phase 2: Kubernetes Setup
We use kind (Kubernetes in Docker) to quickly set up a local, lightweight cluster.
1. Cluster Creation
# Create the kind cluster
kind create cluster
# Verify cluster info
kubectl cluster-info
SNAPSHOT: Cluster Info Verification
Kubernetes control plane is running at [https://127.0.0.1:52123](https://127.0.0.1:52123)
KubeDNS is running at [https://127.0.0.1:52123/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy](https://127.0.0.1:52123/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy)
2. Loading the Docker Image into Kind
Kubernetes nodes cannot directly access the Docker images on your host machine. We must explicitly load the built image into the kind cluster's nodes.
kind load docker-image zoomcamp-model:3.13.10-hw10