Skip to content

Self-Hosting on Red Hat OpenShift

This guide covers running KoAkademy on Red Hat OpenShift Container Platform (OCP), Azure Red Hat OpenShift (ARO), or Red Hat OpenShift on AWS (ROSA).

  1. Security Context Constraints (SCC):
    • KoAkademy’s production image runs supervisord to manage FrankenPHP, Inertia SSR, and worker processes, and switches child processes to the laravel user (1000:1000).
    • Grant the anyuid SCC to the deployment’s ServiceAccount (oc adm policy add-scc-to-user anyuid -z default -n koakademy), or run FrankenPHP directly as an unprivileged entrypoint when enforcing restricted-v2.
  2. OpenShift Routes:
    • OpenShift uses Route objects backed by HAProxy routers for ingress traffic and automatic TLS edge termination.
  3. Storage:
    • For multi-replica setups without S3/R2 object storage, ensure your StorageClass supports ReadWriteMany (RWX) for /app/storage.

Create a dedicated OpenShift project:

Terminal window
oc new-project koakademy --display-name="KoAkademy School System"
oc adm policy add-scc-to-user anyuid -z default -n koakademy

Create OpenShift secrets:

Terminal window
oc create secret generic koakademy-secrets \
--from-literal=APP_KEY="base64:YOUR_32_BYTE_APP_KEY" \
--from-literal=DB_PASSWORD="YourSecurePostgresPassword" \
--from-literal=REDIS_PASSWORD="YourSecureRedisPassword"

koakademy-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: koakademy-config
namespace: koakademy
data:
APP_NAME: "KoAkademy"
APP_ENV: "production"
APP_DEBUG: "false"
APP_URL: "https://koakademy.apps.cluster.example.com"
PORTAL_HOST: "koakademy.apps.cluster.example.com"
ADMIN_HOST: "koakademy.apps.cluster.example.com"
TRUSTED_PROXIES: "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
OCTANE_SERVER: "frankenphp"
HORIZON_IN_HTTP_CONTAINER: "false"
AUTO_MIGRATE: "false"
RUN_OPTIMIZE: "foreground"
# DB & Redis
DB_CONNECTION: "pgsql"
DB_HOST: "postgresql"
DB_PORT: "5432"
DB_DATABASE: "koakademy"
DB_USERNAME: "koakademy"
CACHE_STORE: "redis"
SESSION_DRIVER: "redis"
QUEUE_CONNECTION: "redis"
REDIS_HOST: "redis"
REDIS_PORT: "6379"
# PDF Service
GOTENBERG_URL: "http://gotenberg:3000"
FILESYSTEM_DISK: "public"

Apply the ConfigMap:

Terminal window
oc apply -f koakademy-configmap.yaml

Step 3: Deploy Gotenberg, PostgreSQL & Redis

Section titled “Step 3: Deploy Gotenberg, PostgreSQL & Redis”

Deploy Gotenberg alongside your OpenShift PostgreSQL and Redis services:

dependencies.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: gotenberg
namespace: koakademy
spec:
replicas: 1
selector:
matchLabels:
app: gotenberg
template:
metadata:
labels:
app: gotenberg
spec:
containers:
- name: gotenberg
image: gotenberg/gotenberg:8
ports:
- containerPort: 3000
resources:
requests:
cpu: 200m
memory: 512Mi
limits:
cpu: 1000m
memory: 1Gi
---
apiVersion: v1
kind: Service
metadata:
name: gotenberg
namespace: koakademy
spec:
selector:
app: gotenberg
ports:
- port: 3000
targetPort: 3000

Apply dependencies (and provision postgresql and redis via OpenShift operators or StatefulSets):

Terminal window
oc apply -f dependencies.yaml

Migrations are a release step, not a container boot. The application is only started after the schema is prepared.

Create koakademy-migrate-job.yaml. The job reads the same configuration and the same secrets as the application, so it migrates the application database:

koakademy-migrate-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: koakademy-migrate
namespace: koakademy
spec:
backoffLimit: 3
template:
spec:
restartPolicy: Never
containers:
- name: migrate
# The same release-specific FrankenPHP tag the application deployment uses.
image: ghcr.io/yukazakiri/koakademy:v1.30.0-franken
imagePullPolicy: IfNotPresent
command: ["php", "artisan", "migrate", "--force", "--no-interaction"]
envFrom:
- configMapRef:
name: koakademy-config
- secretRef:
name: koakademy-secrets

Step 5: Deploy KoAkademy Application, Horizon & Scheduler

Section titled “Step 5: Deploy KoAkademy Application, Horizon & Scheduler”
koakademy-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: koakademy
namespace: koakademy
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: koakademy
template:
metadata:
labels:
app: koakademy
spec:
containers:
- name: app
# The same release-specific FrankenPHP tag the migration job uses.
image: ghcr.io/yukazakiri/koakademy:v1.30.0-franken
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8000
name: http
- containerPort: 2019
name: admin
envFrom:
- configMapRef:
name: koakademy-config
- secretRef:
name: koakademy-secrets
resources:
requests:
cpu: 500m
memory: 1Gi
limits:
cpu: 2000m
memory: 2Gi
livenessProbe:
httpGet:
path: /up
port: 8000
initialDelaySeconds: 30
periodSeconds: 15
readinessProbe:
httpGet:
path: /up
port: 8000
initialDelaySeconds: 10
periodSeconds: 10
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: koakademy-horizon
namespace: koakademy
spec:
replicas: 1
selector:
matchLabels:
app: koakademy-horizon
template:
metadata:
labels:
app: koakademy-horizon
spec:
containers:
- name: horizon
image: ghcr.io/yukazakiri/koakademy:v1.30.0-franken
imagePullPolicy: IfNotPresent
env:
- name: CONTAINER_MODE
value: "horizon"
- name: AUTO_MIGRATE
value: "false"
- name: RUN_OPTIMIZE
value: "false"
- name: RUN_SCOUT_SETTINGS
value: "false"
envFrom:
- configMapRef:
name: koakademy-config
- secretRef:
name: koakademy-secrets
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: koakademy-scheduler
namespace: koakademy
spec:
replicas: 1
selector:
matchLabels:
app: koakademy-scheduler
template:
metadata:
labels:
app: koakademy-scheduler
spec:
containers:
- name: scheduler
image: ghcr.io/yukazakiri/koakademy:v1.30.0-franken
imagePullPolicy: IfNotPresent
env:
- name: CONTAINER_MODE
value: "scheduler"
- name: AUTO_MIGRATE
value: "false"
- name: RUN_OPTIMIZE
value: "false"
- name: RUN_SCOUT_SETTINGS
value: "false"
envFrom:
- configMapRef:
name: koakademy-config
- secretRef:
name: koakademy-secrets
---
apiVersion: v1
kind: Service
metadata:
name: koakademy
namespace: koakademy
spec:
selector:
app: koakademy
ports:
- name: http
port: 8000
targetPort: 8000

The application deployment is applied in the next step, after the migration job completed.


Create an edge-terminated OpenShift Route:

koakademy-route.yaml
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: koakademy
namespace: koakademy
annotations:
haproxy.router.openshift.io/timeout: "300s"
haproxy.router.openshift.io/proxy-body-size: "100m"
spec:
host: koakademy.apps.cluster.example.com
to:
kind: Service
name: koakademy
weight: 100
port:
targetPort: http
tls:
termination: edge
insecureEdgeTerminationPolicy: Redirect

Apply Route:

Terminal window
oc apply -f koakademy-route.yaml

Step 7: Run the Migrations and Verify Deployment

Section titled “Step 7: Run the Migrations and Verify Deployment”

Prepare the schema before the application starts:

Terminal window
oc apply -f koakademy-migrate-job.yaml
oc -n koakademy wait --for=condition=complete job/koakademy-migrate --timeout=10m

The application deployment is only applied once the migration job completed, so no pod starts against a schema it does not expect:

Terminal window
oc apply -f koakademy-deployment.yaml

Check deployment status:

Terminal window
oc get pods -n koakademy
oc logs -f deployment/koakademy -n koakademy

Open the OpenShift Route URL (https://koakademy.apps.cluster.example.com/setup) in your browser to complete installation.

A later release repeats the same step. Remove the finished job first, because a job name can only be used once:

Terminal window
oc -n koakademy delete job koakademy-migrate --ignore-not-found
oc apply -f koakademy-migrate-job.yaml
oc -n koakademy wait --for=condition=complete job/koakademy-migrate --timeout=10m