liveBook · Manning

Python

As explained in Road to Kubernetes

Python is a general-purpose, high-level programming language known for readable syntax and broad application support.

Python is a programming language used here to build a small web application. Alongside a JavaScript/Node.js application, it provides a concrete way to compare deployment methods: the application stays recognizable while its packaging and runtime change. section 2.0 section 1.2

A deployable Python application needs more than its source code:

  • FastAPI handles web requests and responses; functions can map URLs and HTTP methods to behavior. section 2.5
  • A requirements.txt file records third-party packages so the application’s environment can be recreated. section 2.5
  • A virtual environment gives the server a designated place to install and run those packages. section 3.4.1

Set up Python on an Ubuntu server

Check the installed version with python3 --version. Install python3, python3-venv, python3-pip, and build-essential with apt; Ubuntu may need these additional packages even when Python 3 is already present. Create an environment with python3 -m venv /opt/venv/, then use its Python executable to install the application’s requirements. The example server runs the app with Gunicorn and a Uvicorn worker on port 8888. section 3.4.1

Listing 3.18 Installing Python packages with absolute paths
/opt/venv/bin/python -m pip install -r \
    /opt/venv/roadtok8s/py/src/requirements.txt

The command installs packages from requirements.txt using the virtual environment’s Python executable, making both the installer and dependency list explicit. section 3.4.1

A container offers another way to select the Python runtime. Rather than relying on the server’s default version, choose a version-tagged Python image from Docker Hub. For example, docker run -it python:3.11.4 starts an interactive Python shell in that image; the same tag can identify the base image in a Dockerfile. section 5.3.1

How Road to Kubernetes covers it

How deep it goes
Works through application dependencies, Ubuntu setup, and runtime selection rather than comprehensive Python programming.
Examples
Uses a FastAPI application, Ubuntu setup commands, and a version-tagged Python container image.
What it assumes
Introduces basic web applications before containers and does not require prior Docker or Kubernetes knowledge.
What you can do after
Operate/configure a Python web app on Ubuntu with a virtual environment, or select and run a version-tagged Docker image.
How it connects
Connects Python to FastAPI, virtual environments, pip, Git, Docker containers, and Kubernetes deployment.

Also explained in

Compare how 26 books explain Python →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.