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


























