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).
OpenShift Architectural Considerations
Section titled “OpenShift Architectural Considerations”- Security Context Constraints (SCC):
- KoAkademy’s production image runs
supervisordto manage FrankenPHP, Inertia SSR, and worker processes, and switches child processes to thelaraveluser (1000:1000). - Grant the
anyuidSCC 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 enforcingrestricted-v2.
- KoAkademy’s production image runs
- OpenShift Routes:
- OpenShift uses
Routeobjects backed by HAProxy routers for ingress traffic and automatic TLS edge termination.
- OpenShift uses
- Storage:
- For multi-replica setups without S3/R2 object storage, ensure your StorageClass supports
ReadWriteMany(RWX) for/app/storage.
- For multi-replica setups without S3/R2 object storage, ensure your StorageClass supports
Step 1: Create Project & Secrets
Section titled “Step 1: Create Project & Secrets”Create a dedicated OpenShift project:
oc new-project koakademy --display-name="KoAkademy School System"oc adm policy add-scc-to-user anyuid -z default -n koakademyCreate OpenShift secrets:
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"Step 2: Create ConfigMap
Section titled “Step 2: Create ConfigMap”apiVersion: v1kind: ConfigMapmetadata: name: koakademy-config namespace: koakademydata: 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:
oc apply -f koakademy-configmap.yamlStep 3: Deploy Gotenberg, PostgreSQL & Redis
Section titled “Step 3: Deploy Gotenberg, PostgreSQL & Redis”Deploy Gotenberg alongside your OpenShift PostgreSQL and Redis services:
apiVersion: apps/v1kind: Deploymentmetadata: name: gotenberg namespace: koakademyspec: 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: v1kind: Servicemetadata: name: gotenberg namespace: koakademyspec: selector: app: gotenberg ports: - port: 3000 targetPort: 3000Apply dependencies (and provision postgresql and redis via OpenShift operators or StatefulSets):
oc apply -f dependencies.yamlStep 4: Release Migration Job
Section titled “Step 4: Release Migration Job”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:
apiVersion: batch/v1kind: Jobmetadata: name: koakademy-migrate namespace: koakademyspec: 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-secretsStep 5: Deploy KoAkademy Application, Horizon & Scheduler
Section titled “Step 5: Deploy KoAkademy Application, Horizon & Scheduler”apiVersion: apps/v1kind: Deploymentmetadata: name: koakademy namespace: koakademyspec: 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/v1kind: Deploymentmetadata: name: koakademy-horizon namespace: koakademyspec: 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/v1kind: Deploymentmetadata: name: koakademy-scheduler namespace: koakademyspec: 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: v1kind: Servicemetadata: name: koakademy namespace: koakademyspec: selector: app: koakademy ports: - name: http port: 8000 targetPort: 8000The application deployment is applied in the next step, after the migration job completed.
Step 6: Expose OpenShift Route with TLS
Section titled “Step 6: Expose OpenShift Route with TLS”Create an edge-terminated OpenShift Route:
apiVersion: route.openshift.io/v1kind: Routemetadata: 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: RedirectApply Route:
oc apply -f koakademy-route.yamlStep 7: Run the Migrations and Verify Deployment
Section titled “Step 7: Run the Migrations and Verify Deployment”Prepare the schema before the application starts:
oc apply -f koakademy-migrate-job.yamloc -n koakademy wait --for=condition=complete job/koakademy-migrate --timeout=10mThe application deployment is only applied once the migration job completed, so no pod starts against a schema it does not expect:
oc apply -f koakademy-deployment.yamlCheck deployment status:
oc get pods -n koakademyoc logs -f deployment/koakademy -n koakademyOpen 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:
oc -n koakademy delete job koakademy-migrate --ignore-not-foundoc apply -f koakademy-migrate-job.yamloc -n koakademy wait --for=condition=complete job/koakademy-migrate --timeout=10m