Anatomy of a Connection String
Understanding the structure of basic authentication, where credentials are included directly in the URI, will be valuable in our upcoming lessons. This URI is composed of three main parts: Scheme, Auth Credentials, and Service Location.
When a client (grade-submission-api) uses this URI to connect to MongoDB, here's what happens:
Kubernetes routing is based solely on the Service Location (
mongodb-service:27017), regardless of the Scheme used (mongodb://,http://,https://, etc.), or the existence of credentials.The ClusterIP Service
mongodb-servicereceives the request at its service port27017.The Service selects one of the MongoDB pods based on a label selector, and forwards the entire original URI to the selected pod, preserving all parts (Scheme, Auth Credentials, and Service Location).
MongoDB receives the full URI at its container port
27017, and authenticates the connection using the provided credentials.
It's worth noting that this process is consistent across different types of services in Kubernetes. For example:
Elasticsearch
MySQL
In each case, Kubernetes focuses on the Service Location for routing, while the application (MySQL or Elasticsearch) handles the Scheme and Auth Credentials as needed.