Kubernetes Deployment
Relevant source files
The following files were used as context for generating this wiki page:Traduora provides Kubernetes configuration files for a quick setup. The provided manifests are designed for a "preview" environment, bundling the application and its database into a single deployment. This setup is ideal for testing, demonstration, or development purposes. For production environments, it is recommended to adapt these configurations, for instance by using a managed database service and more robust secret management.
The core deployment manifest sets up all necessary resources within a dedicated namespace, including the application deployment, a service to expose it, and configuration objects. Additional files provide example Ingress configurations for exposing the application to external traffic using either GCP or an NGINX Ingress Controller.
Sources: README.md:31, deploy/k8s/traduora-preview.yaml
Architecture Overview
The Kubernetes deployment for Traduora is self-contained within the traduora-preview namespace. It consists of a single Deployment that manages a Pod with two containers: the api application and a mysql database. A Service of type NodePort exposes the application, and this service is the target for Ingress resources to manage external access. Configuration and secrets are managed by a ConfigMap and a Secret object, respectively.
The following diagram illustrates the high-level architecture of the preview deployment.
Kubernetes Resources
The main deployment file traduora-preview.yaml defines several key Kubernetes resources.
| Kind | Name | Namespace | Purpose |
|---|---|---|---|
Namespace | traduora-preview | - | Isolates all Traduora preview resources. |
Service | traduora | traduora-preview | Exposes the api container via a NodePort. |
Deployment | traduora | traduora-preview | Manages the Pod containing the api and mysql containers. |
ConfigMap | traduora | traduora-preview | Stores non-sensitive configuration data. |
Secret | traduora | traduora-preview | Stores sensitive data like passwords and application secrets. |
Sources: deploy/k8s/traduora-preview.yaml
Namespace
A dedicated namespace traduora-preview is created to logically group and isolate all the resources for this deployment.
---
apiVersion: v1
kind: Namespace
metadata:
name: traduora-preview
Sources: deploy/k8s/traduora-preview.yaml:2-5
Deployment
The traduora Deployment manages a single replica of a Pod. This Pod contains the two essential containers for the application to run.
Containers
The Pod specification includes two containers: api and mysql.
| Container Name | Image | Ports | Resource Limits | Resource Requests |
|---|---|---|---|---|
api | everco/ever-traduora:latest | 8080/TCP (http) | CPU: 500m, Memory: 256Mi | CPU: 50m, Memory: 64Mi |
mysql | mysql:5.7 | 3306/TCP (mysql) | CPU: 500m, Memory: 256Mi | CPU: 50m, Memory: 64Mi |
Sources: deploy/k8s/traduora-preview.yaml:38-85
Health Probes
The api container is configured with liveness and readiness probes to ensure container health. Both probes perform an HTTP GET request to the /health endpoint on port 8080 after an initial delay of 10 seconds.
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: /health
port: http
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: /health
port: http
Sources: deploy/k8s/traduora-preview.yaml:48-58
Service
A Service named traduora is created to provide a stable endpoint for the application. It is of type NodePort and maps port 80 to the api container's targetPort (http/8080).
apiVersion: v1
kind: Service
metadata:
name: traduora
namespace: traduora-preview
spec:
type: NodePort
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: traduora
Sources: deploy/k8s/traduora-preview.yaml:8-20
Configuration
Environment variables for the containers are supplied by a ConfigMap for non-sensitive data and a Secret for sensitive data.
ConfigMap
The traduora ConfigMap provides configuration for the API port, database connection, and mail settings.
| Key | Value | Description |
|---|---|---|
TR_PORT | '8080' | The port on which the API container listens. |
TR_AUTH_TOKEN_EXPIRE | '8600' | Authentication token expiration time in seconds. |
TR_DB_DATABASE | 'traduora_preview' | The name of the database. |
TR_DB_HOST | 'traduora-mysqldb' | The hostname for the database. Note: The manifest uses traduora-mysqldb, but since the MySQL container is in the same pod, localhost would typically be used. This might be an oversight in the preview file. |
TR_DB_PORT | '3306' | The port for the database connection. |
TR_DB_USER | 'root' | The user for the database connection. |
TR_MAIL_DEBUG | 'false' | A flag to enable or disable mail debugging. |
Sources: deploy/k8s/traduora-preview.yaml:88-100
Secret
The traduora Secret provides sensitive credentials. The manifest includes a warning that these are for preview purposes only and should not be used in production.
| Key | Value (stringData) | Description |
|---|---|---|
TR_SECRET | tJW4Js889dxjr3KLueEQ4cfSTfm0JfiabLpX/ouBrd0= | The application's secret key. |
TR_DB_PASSWORD | pNGWiZR6dRI/MEgdRsk4976ucuVwRT0WhChTihe5nDQ= | The password for the TR_DB_USER. |
MYSQL_ROOT_PASSWORD | pNGWiZR6dRI/MEgdRsk4976ucuVwRT0WhChTihe5nDQ= | The root password for the MySQL container. |
MYSQL_DATABASE | traduora_preview | The database to be created on MySQL container startup. |
Sources: deploy/k8s/traduora-preview.yaml:102-115
Data Seeding
The application can automatically run seed scripts on startup if the TR_SEED_DATA=true environment variable is set. This is useful for populating the database with initial data, such as a default admin user. This variable would be added to the ConfigMap or Deployment environment section to enable this feature.
Sources: README.md:104-106, api/package.json:30-31
Ingress and External Access
To expose the Traduora service to the internet, an Ingress resource is required. The repository provides two examples.
GCP Ingress
The traduora-preview-ingress-gcp.yaml file defines an Ingress resource tailored for Google Kubernetes Engine (GKE). It assumes a static IP has been provisioned and is specified by the kubernetes.io/ingress.global-static-ip-name annotation. It routes all traffic from the host preview.traduora.co to the traduora service on port 80.
Sources: deploy/k8s/traduora-preview-ingress-gcp.yaml
NGINX Ingress
The traduora-preview-ingress-nginx.yaml file provides an Ingress configuration for clusters using the NGINX Ingress Controller. It routes traffic for preview.traduora.co to the traduora service on port 80. It also includes annotations for cert-manager to automatically provision an SSL certificate from Let's Encrypt.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traduora-preview
namespace: traduora-preview
annotations:
kubernetes.io/ingress.class: nginx
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
spec:
tls:
- hosts:
- preview.traduora.co
secretName: traduora-preview-tls
rules:
- host: preview.traduora.co
http:
paths:
- backend:
serviceName: traduora
servicePort: 80