Skip to content

Commit ced79d1

Browse files
feat: make API internal-only, expose only Portal externally
- Disable api.gateway and api.ingress by default - Portal remains externally accessible via Gateway API (default) - Add helper functions to auto-generate internal Service URLs - Portal accesses API via cluster Service (http://<release>-api:8000) - Update values-gateway.yaml and values-ingress.yaml examples - Update README.md documentation BREAKING CHANGE: API is no longer exposed externally by default. The Portal communicates with the API via internal cluster Service.
1 parent 8763671 commit ced79d1

6 files changed

Lines changed: 66 additions & 132 deletions

File tree

tron/README.md

Lines changed: 29 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ This Helm chart installs [Tron Platform](https://github.com/grid-labs-tech/tron)
1111

1212
The architecture diagram above illustrates the complete Tron Platform deployment on Kubernetes, including:
1313

14-
- **External Access**: Users and developers accessing the platform
15-
- **Ingress/Gateway API**: Traffic routing and TLS termination
16-
- **Frontend**: Portal service (React application)
17-
- **Backend**: API service (FastAPI)
14+
- **External Access**: Users and developers accessing the Portal
15+
- **Ingress/Gateway API**: Traffic routing and TLS termination (Portal only)
16+
- **Frontend**: Portal service (React application) - externally exposed
17+
- **Backend**: API service (FastAPI) - internal only, accessed via cluster Service
1818
- **Data Layer**: PostgreSQL database with persistent storage
1919
- **Configuration**: ConfigMaps and Secrets for application configuration
2020
- **Management**: HPA (autoscaling), PDB (high availability), and NetworkPolicy (security)
@@ -76,8 +76,8 @@ helm uninstall tron
7676
| `api.image.tag` | API image tag | `latest` |
7777
| `api.service.type` | API service type | `ClusterIP` |
7878
| `api.service.port` | API service port | `8000` |
79-
| `api.ingress.enabled` | Enable Ingress for API | `false` |
80-
| `api.gateway.enabled` | Enable Gateway API for API | `true` |
79+
| `api.ingress.enabled` | Enable Ingress for API (internal by default) | `false` |
80+
| `api.gateway.enabled` | Enable Gateway API for API (internal by default) | `false` |
8181
| `portal.enabled` | Enable Portal deployment | `true` |
8282
| `portal.replicaCount` | Number of Portal replicas | `2` |
8383
| `portal.image.repository` | Portal image repository | `grid-labs-tech/tron-portal` |
@@ -126,35 +126,17 @@ api:
126126
127127
### Gateway API (Default)
128128
129-
By default, the chart uses Kubernetes Gateway API to expose services. To configure:
129+
By default, only the **Portal is exposed externally** via Gateway API. The API is internal-only and accessed by the Portal via cluster Service.
130130
131131
```yaml
132-
api:
133-
gateway:
134-
enabled: true
135-
gatewayRef:
136-
name: my-gateway
137-
namespace: default # Optional, uses release namespace if not specified
138-
hostnames:
139-
- api.tron.example.com
140-
rules:
141-
- path: /
142-
pathType: PathPrefix
143-
tls:
144-
enabled: true
145-
mode: Terminate
146-
certificateRefs:
147-
- name: tron-api-tls
148-
kind: Secret
149-
150132
portal:
151133
gateway:
152134
enabled: true
153135
gatewayRef:
154136
name: my-gateway
155-
namespace: default
137+
namespace: default # Optional, uses release namespace if not specified
156138
hostnames:
157-
- portal.tron.example.com
139+
- tron.example.com
158140
rules:
159141
- path: /
160142
pathType: PathPrefix
@@ -168,42 +150,28 @@ portal:
168150
169151
**Note**: To use Gateway API, you need to have Gateway API CRDs installed in your cluster. The chart does not create the Gateway resource, only the HTTPRoutes that reference an existing Gateway.
170152
153+
See `values-gateway.yaml` for a complete example configuration.
154+
171155
### Ingress Controller (Alternative)
172156

173-
The chart also supports traditional Ingress Controller as an alternative to Gateway API. To use Ingress:
157+
The chart also supports traditional Ingress Controller as an alternative to Gateway API. To use Ingress for the Portal:
174158

175159
```yaml
176-
api:
177-
gateway:
178-
enabled: false # Disable Gateway API
179-
ingress:
180-
enabled: true
181-
className: nginx
182-
hosts:
183-
- host: api.tron.example.com
184-
paths:
185-
- path: /
186-
pathType: Prefix
187-
tls:
188-
- secretName: tron-api-tls
189-
hosts:
190-
- api.tron.example.com
191-
192160
portal:
193161
gateway:
194162
enabled: false # Disable Gateway API
195163
ingress:
196164
enabled: true
197165
className: nginx
198166
hosts:
199-
- host: portal.tron.example.com
167+
- host: tron.example.com
200168
paths:
201169
- path: /
202170
pathType: Prefix
203171
tls:
204172
- secretName: tron-portal-tls
205173
hosts:
206-
- portal.tron.example.com
174+
- tron.example.com
207175
```
208176

209177
See `values-ingress.yaml` for a complete example configuration using Ingress Controller.
@@ -399,49 +367,32 @@ portal:
399367
enabled: true
400368
minReplicas: 3
401369
maxReplicas: 15
402-
403-
postgresql:
404-
primary:
405-
persistence:
406-
size: 100Gi
407-
resources:
408-
requests:
409-
cpu: 1000m
410-
memory: 2Gi
411-
limits:
412-
cpu: 2000m
413-
memory: 4Gi
414-
415-
api:
416370
gateway:
417371
enabled: true
418372
gatewayRef:
419373
name: production-gateway
420374
namespace: gateway-system
421375
hostnames:
422-
- api.tron.example.com
423-
tls:
424-
enabled: true
425-
mode: Terminate
426-
certificateRefs:
427-
- name: tron-api-tls
428-
kind: Secret
429-
430-
portal:
431-
gateway:
432-
enabled: true
433-
gatewayRef:
434-
name: production-gateway
435-
namespace: gateway-system
436-
hostnames:
437-
- portal.tron.example.com
376+
- tron.example.com
438377
tls:
439378
enabled: true
440379
mode: Terminate
441380
certificateRefs:
442381
- name: tron-portal-tls
443382
kind: Secret
444383
384+
postgresql:
385+
primary:
386+
persistence:
387+
size: 100Gi
388+
resources:
389+
requests:
390+
cpu: 1000m
391+
memory: 2Gi
392+
limits:
393+
cpu: 2000m
394+
memory: 4Gi
395+
445396
networkPolicy:
446397
enabled: true
447398
```
@@ -482,7 +433,8 @@ This chart is available on [Artifact Hub](https://artifacthub.io/packages/helm/g
482433

483434
### Chart Features
484435

485-
- ✅ Support for Gateway API (default) and Ingress Controller
436+
- ✅ Portal exposed via Gateway API (default) or Ingress Controller
437+
- ✅ API internal-only (accessed via cluster Service)
486438
- ✅ Horizontal Pod Autoscaler (HPA)
487439
- ✅ Pod Disruption Budgets
488440
- ✅ Network Policies

tron/templates/_helpers.tpl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,17 @@ Generate API token secret if not provided
240240
{{- end }}
241241
{{- end }}
242242
{{- end }}
243+
244+
{{/*
245+
Internal API URL (for Portal to access API via cluster Service)
246+
*/}}
247+
{{- define "tron.api.internalUrl" -}}
248+
{{- printf "http://%s-api:%d" (include "tron.fullname" .) (.Values.api.service.port | int) }}
249+
{{- end }}
250+
251+
{{/*
252+
Internal Portal URL
253+
*/}}
254+
{{- define "tron.portal.internalUrl" -}}
255+
{{- printf "http://%s-portal:%d" (include "tron.fullname" .) (.Values.portal.service.port | int) }}
256+
{{- end }}

tron/templates/configmap.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ metadata:
66
labels:
77
{{- include "tron.labels" . | nindent 4 }}
88
data:
9-
API_URL: {{ .Values.config.apiUrl | quote }}
10-
PORTAL_URL: {{ .Values.config.portalUrl | quote }}
9+
API_URL: {{ .Values.config.apiUrl | default (include "tron.api.internalUrl" .) | quote }}
10+
PORTAL_URL: {{ .Values.config.portalUrl | default (include "tron.portal.internalUrl" .) | quote }}
1111
DATABASE_HOST: {{ include "tron.database.host" . | quote }}
1212
DATABASE_PORT: {{ include "tron.database.port" . | quote }}
1313
DATABASE_NAME: {{ include "tron.database.name" . | quote }}

tron/values-gateway.yaml

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
11
# Example values for Gateway API with TLS enabled
2-
# Gateway API is enabled by default, this file shows a production-ready configuration
2+
# Only Portal is exposed externally, API is internal-only
33
# Usage: helm install tron grid-labs-tech/tron -f values-gateway.yaml
44

5-
api:
6-
gateway:
7-
enabled: true
8-
gatewayRef:
9-
name: my-gateway # Name of your Gateway resource
10-
namespace: default # Namespace where Gateway is deployed
11-
hostnames:
12-
- api.tron.example.com
13-
rules:
14-
- path: /
15-
pathType: PathPrefix
16-
tls:
17-
enabled: true
18-
mode: Terminate
19-
certificateRefs:
20-
- name: tron-api-tls
21-
kind: Secret
22-
235
portal:
246
gateway:
257
enabled: true
268
gatewayRef:
279
name: my-gateway # Name of your Gateway resource
2810
namespace: default # Namespace where Gateway is deployed
2911
hostnames:
30-
- portal.tron.example.com
12+
- tron.example.com
3113
rules:
3214
- path: /
3315
pathType: PathPrefix

tron/values-ingress.yaml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
# Example values using Ingress Controller instead of Gateway API
2+
# Only Portal is exposed externally, API is internal-only
23
# Usage: helm install tron grid-labs-tech/tron -f values-ingress.yaml
34

4-
api:
5-
gateway:
6-
enabled: false # Disable Gateway API
7-
ingress:
8-
enabled: true
9-
className: nginx # Change to your ingress class (nginx, traefik, etc.)
10-
annotations:
11-
# nginx.ingress.kubernetes.io/rewrite-target: /
12-
# cert-manager.io/cluster-issuer: letsencrypt-prod
13-
hosts:
14-
- host: api.tron.example.com
15-
paths:
16-
- path: /
17-
pathType: Prefix
18-
tls:
19-
- hosts:
20-
- api.tron.example.com
21-
secretName: tron-api-tls
22-
235
portal:
246
gateway:
257
enabled: false # Disable Gateway API
@@ -30,11 +12,11 @@ portal:
3012
# nginx.ingress.kubernetes.io/rewrite-target: /
3113
# cert-manager.io/cluster-issuer: letsencrypt-prod
3214
hosts:
33-
- host: portal.tron.example.com
15+
- host: tron.example.com
3416
paths:
3517
- path: /
3618
pathType: Prefix
3719
tls:
3820
- hosts:
39-
- portal.tron.example.com
21+
- tron.example.com
4022
secretName: tron-portal-tls

tron/values.yaml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Default values for tron
22
# This is a YAML-formatted file.
33
#
4-
# Gateway API is enabled by default. To use Ingress Controller instead,
5-
# disable Gateway API and enable Ingress in the api.ingress and portal.ingress sections.
6-
# See values-ingress.yaml for an example configuration using Ingress Controller.
4+
# Only the Portal is exposed externally by default (via Gateway API).
5+
# The API is internal-only and accessed by the Portal via cluster Service.
6+
# To use Ingress Controller instead of Gateway API, see values-ingress.yaml.
77

88
global:
99
imageRegistry: ""
@@ -26,7 +26,10 @@ api:
2626
port: 8000
2727
targetPort: 8000
2828

29-
# Ingress Configuration (alternative to Gateway API)
29+
# API is internal-only by default (accessed via cluster Service)
30+
# Enable ingress or gateway only if you need external API access
31+
32+
# Ingress Configuration (disabled by default)
3033
ingress:
3134
enabled: false
3235
className: ""
@@ -38,9 +41,9 @@ api:
3841
pathType: Prefix
3942
tls: []
4043

41-
# Gateway API Configuration (default)
44+
# Gateway API Configuration (disabled by default)
4245
gateway:
43-
enabled: true
46+
enabled: false
4447
gatewayRef:
4548
name: ""
4649
namespace: ""
@@ -149,20 +152,20 @@ portal:
149152
className: ""
150153
annotations: {}
151154
hosts:
152-
- host: tron-portal.local
155+
- host: tron.local
153156
paths:
154157
- path: /
155158
pathType: Prefix
156159
tls: []
157160

158-
# Gateway API Configuration (default)
161+
# Gateway API Configuration (default for Portal)
159162
gateway:
160163
enabled: true
161164
gatewayRef:
162165
name: ""
163166
namespace: ""
164167
hostnames:
165-
- tron-portal.local
168+
- tron.local
166169
rules:
167170
- path: /
168171
pathType: PathPrefix
@@ -278,9 +281,10 @@ externalDatabase:
278281

279282
# Application Configuration
280283
config:
281-
# API Configuration
282-
apiUrl: "http://tron-api:8000"
283-
portalUrl: "http://tron-portal:3000"
284+
# Internal URLs are auto-generated based on release name
285+
# Override only if using external services
286+
apiUrl: "" # Leave empty to auto-generate: http://<release>-api:<port>
287+
portalUrl: "" # Leave empty to auto-generate: http://<release>-portal:<port>
284288

285289
# Database Configuration
286290
database:

0 commit comments

Comments
 (0)