liveBook · Manning

Dependency

As explained in Kubernetes for Developers

An external dependency is a separately running service or resource that an application requires to perform some operations.

A dependency is something an application needs to perform an operation. In a container, dependencies can be installed into the image during the build so deployment is repeatable. A separate service, such as a database, is an external dependency that the running application must reach. section 2.1.3 section 2.1.6

Treat dependencies according to where they run:

  • Package operating-system and language requirements into the container image, including Python, Ruby, database clients, fonts, TLS certificates, and extraction tools. section 2.1.3 section 2.1.6
  • Keep external services outside the container and account for their availability when deciding whether an application replica is ready. section 4.1.4
  • Avoid checking external services in liveness probes by default; restarting a healthy container because another service is unavailable can create churn and cascading failures. section 4.1.4

Database dependency and readiness

An application using MariaDB can install a MariaDB client while building its Python image. At runtime, its readiness endpoint can query one database row and return 200 when the connection works or 503 when it does not. Kubernetes can then keep unavailable replicas out of load-balancer rotation without restarting containers that are otherwise alive. section 2.1.6 section 4.1.4

Listing 2.9 Chapter02/2.1.6_Dependencies/Dockerfile
FROM python:3
RUN apt-get update                      #1
RUN apt-get install -y mariadb-client   #1
COPY . /app
WORKDIR /app 
CMD python3 hello.py
#1 Use apt-get to configure your Linux container with everything your app needs.

Use the Dockerfile listing to see an application dependency installed into a Python container image. section 2.1.6

result = sql.execute("SELECT id FROM users LIMIT 1;")
if result:
 http_response(200, "Ready")
else:
 http_response(503, "Not Ready")

Use the readiness pseudocode to see an external database dependency determine whether a replica reports Ready. section 4.1.4

How Kubernetes for Developers covers it

How deep it goes
Defines dependency installation and probe behavior with examples, but stops short of detailing dependency management beyond Docker builds and health checks.
Examples
Uses Python and Ruby images, a MariaDB client, Unicode fonts, and a database-backed readiness query.
What it assumes
Assumes basic application and container concepts while teaching dependency installation and liveness-versus-readiness decisions through concrete examples.
What you can do after
Build it from scratch by installing required packages into an image and designing readiness checks that reflect external-service availability.
How it connects
Connects dependencies to container images, Dockerfiles, base images, database connections, readiness probes, and liveness probes.

Also explained in

Compare how 27 books explain dependency →

Related concepts

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