Kubernetes Service Setup
Relevant source files
The following files were used as context for generating this wiki page:
The Kubernetes Service setup in the OdooConnectorAPI project provides a stable network endpoint for accessing the FastAPI application within a cluster environment. This setup is managed through Helm charts, which define the infrastructure-as-code required to route external or internal traffic to the application containers.
The primary role of the Service is to abstract the underlying pod instances created by the Deployment, ensuring that even as pods are replaced or scaled, the connection to the OdooConnectorAPI remains consistent.
Sources: README.md:5-9, charts/odooconnectorapi/templates/service.yaml:1-11
Service Architecture and Routing
The networking architecture uses a Kubernetes Service object to act as a load balancer for the OdooConnectorAPI pods. The Service uses a label selector to identify the pods it should manage, specifically matching the app label defined in the deployment template.
The diagram above illustrates how the Service routes traffic from its exposed port to the container port of the backend pods.
Sources: charts/odooconnectorapi/templates/service.yaml:8-11, charts/odooconnectorapi/templates/deployment.yaml:20-22, app/main.py:27-31
Service Configuration Details
The Service is configured using template values to allow flexibility across different environments (e.g., staging vs. production). It defaults to a ClusterIP type, but this can be overridden in the configuration.
| Parameter | Type | Default | Description |
|---|---|---|---|
service.type | String | ClusterIP | The type of Kubernetes Service (e.g., ClusterIP, NodePort, LoadBalancer) |
service.port | Integer | 80 | The port number exposed by the Service |
targetPort | Integer | 8000 | The port on the container where the application listens |
Sources: charts/odooconnectorapi/values.yaml:12-14, charts/odooconnectorapi/templates/service.yaml:6-9
Integration with Deployment
The Service setup is tightly coupled with the deployment.yaml template. The Service relies on the labels and ports defined in the Deployment to correctly route traffic to the FastAPI application.
Label Selection Mechanism
The Service uses a selector to find target pods:
selector:
app: {{ include "odooconnectorapi.name" . }}
This matches the labels applied to the pod template in the Deployment configuration.
Sources: charts/odooconnectorapi/templates/service.yaml:10-11, charts/odooconnectorapi/templates/deployment.yaml:1-22
Application Traffic Flow
When a request hits the Service, it is forwarded to the application running inside the container. The FastAPI application is configured to listen on port 8000.
This sequence shows the lifecycle of a request from the initial Service entry point to the backend Odoo integration.
Sources: app/main.py:27-44, charts/odooconnectorapi/templates/service.yaml:7-9, charts/odooconnectorapi/templates/deployment.yaml:22
Helm Deployment Workflow
Deploying the service involves packaging the Helm chart and applying it to a cluster. The Chart.yaml defines the metadata for this deployment package.
- Package Chart: Use
helm package .to create a.tgzarchive. - Install/Upgrade: Use
helm installwith thevalues.yamlfile to provision the Service and Deployment resources.
Sources: README.md:46-60, charts/odooconnectorapi/Chart.yaml:1-4
Summary
The Kubernetes Service setup for OdooConnectorAPI ensures a scalable and reliable entry point for the API. By utilizing Helm templates, the project allows for configurable service types and ports while maintaining a strict link to the containerized FastAPI application via label selectors and port mapping. This architecture facilitates easy integration with Odoo ERP systems in a cloud-native environment.
Sources: charts/odooconnectorapi/templates/service.yaml:1-11, charts/odooconnectorapi/values.yaml:12-14, README.md:5-9