liveBook · Manning

Chapter 3: Building applications on Kubernetes

What you will learn in chapter 3 of Machine Learning Platform Engineering

This chapter introduces the infrastructure tools and practices that support reliable ML systems, from packaging applications to deploying, automating, and monitoring them.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces the infrastructure tools and practices that support reliable ML systems, from packaging applications to deploying, automating, and monitoring them.

Key terms: ML platform, ML engineer, DevOps tools and practices, infrastructure, Docker, Kubernetes, continuous integration/continuous deployment (CI/CD), monitoring

3.1 Containers and tooling

The section introduces the tools and workflow for packaging, deploying, automating, and monitoring a sample application on Kubernetes.

Key terms: Docker, containerization, Kubernetes, resource management, scaling, cloud agnostic, continuous integration (CI), continuous deployment (CD), GitLab CI, Argo CD

3.2 Docker

This section introduces Docker containerization as a way to package an application with its dependencies so it can run consistently across local and production environments.

Key terms: Docker, containerization, container, dependencies, shipping containers, Docker containers, applications or services, configurations

3.2.1 Write the application code

This section creates a small FastAPI joke application, checks that it runs locally, and prepares to containerize it with Docker.

Key terms: FastAPI, main.py, requirements.txt, API, Uvicorn, ASGI server, port 8083, curl, Docker Desktop

3.2.2 Write a Dockerfile

This section explains how a Dockerfile builds the FastAPI application image and specifies the script that runs when the container starts.

Key terms: Dockerfile, FROM, base image, layer, WORKDIR, RUN, ARG, build argument, ENV, ENVIRONMENT

3.2.3 Building and pushing a Docker image

This section builds a Docker image from a Dockerfile, tests it as a local container, and pushes a tagged copy to a registry for deployment.

Key terms: Dockerfile, Docker image, repository, tag, image ID, docker run, container, -p, -it, localhost:8081

3.3 Kubernetes

This section introduces Kubernetes as the tool that schedules Docker containers on servers and brings them back up when they fail outside the development environment.

Key terms: Kubernetes, K8s, container orchestration, docker run, Out of Memory (OOM)

3.3.1 Kubernetes architecture overview

This section explains why Kubernetes uses a multi-node cluster and how master and worker services coordinate to run containers.

Key terms: cluster, master node, worker nodes, resilience, scaling, API server, etcd key-value store, scheduler, controller, CPU

3.3.2 Kubectl

Introduces kubectl as the command-line tool for inspecting and managing a Kubernetes cluster, with examples of node inspection, cluster information, and application deployment.

Key terms: kubectl, K8s cluster, nodes, status, role, node label, age, K8s version

3.3.3 Kubernetes objects

The section builds a FastAPI application on Kubernetes from a pod through a ReplicaSet to a Deployment, showing how to inspect, scale, update, and recover it.

Key terms: pod, apiVersion, kind, metadata, spec, container image, kubectl create, kubectl apply, kubectl get, READY

3.3.4 Networking and services

Kubernetes Services give changing pods stable ways to communicate within a cluster or receive traffic from outside it, using NodePort, ClusterIP, or LoadBalancer access.

Key terms: Service, pod IP address, kubectl port-forward, selector, labels, NodePort, port, targetPort, node IP, ClusterIP

3.3.5 Other objects

This section introduces namespaces, ConfigMaps, and Secrets as Kubernetes objects for organizing resources and supplying application configuration.

Key terms: namespace, default namespace, kubectl create namespace, -n, metadata, ClusterIP, DNS, ConfigMap, data, key-value pairs

3.3.6 Helm charts

This section introduces Helm charts as a way to package, configure, install, and manage applications made of multiple Kubernetes objects.

Key terms: Helm, chart, object templates, values.yaml, K8s objects, Artifact Hub, chart repository, helm repo update, helm install, release name

3.3.7 Conclusion

This conclusion recaps how Docker and Kubernetes provide a starting point for deploying applications and why Kubernetes suits resource-intensive ML workloads.

Key terms: Docker, K8s, container orchestrator, ML workloads, scalability, resource efficiency, training, inferring

3.4 Continuous integration and deployment

This section explains why Kubernetes application releases should be automated and how GitLab CI and Argo CD divide the work of building, deploying, and keeping a release current.

Key terms: Continuous Integration (CI), Continuous Deployment (CD), image tag, CI job, CD job, Helm chart, GitLab CI, Argo CD

3.4.1 GitLab CI

This section sets up GitLab CI to test a FastAPI application, publish a commit-tagged Docker image, and update a Helm chart for a separate CD tool to deploy.

Key terms: .gitlab-ci.yaml, stages, test_code, build_image, update_helm_chart, pytest, CI_COMMIT_SHA, Docker Hub, Helm chart, values.yaml

3.4.2 Argo CD

This section shows how Argo CD deploys a CI-updated Helm chart and keeps Kubernetes resources aligned with Git.

Key terms: Argo CD, source of truth, Git repository, manifests, sync, https, Applications, New App, Repository URL, target Revision

3.5 Prometheus and Grafana

This section shows how to expose application metrics, collect them with Prometheus, and visualize request activity in Grafana.

Key terms: logs, metrics, alerts, Prometheus, scraping, time series database, Grafana, Alertmanager, pull-based metrics system, /metrics

3.6 Summary

The chapter summary connects containerization, orchestration, CI/CD, and monitoring to reliable ML platforms while stressing that tools must serve organizational goals.

Where this is used later

Concepts explained in this chapter

← Chapter 2: What is MLOps? Chapter 4: Designing reliable ML systems →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.