Using Static PV When Deploying Kong API Gateway
Overviewβ
By default, when creating a Kong Gateway using the APIM UI, Persistent Volume Claim (PVC) and Persistent Volume (PV) are dynamically provisioned via StorageClass. However, in certain environments, you may want to use pre-provisioned static PVs. This guide explains how to configure and deploy a Kong Gateway using static PVs.
Pre-deployment Setupβ
Define Gateway Name in Advanceβ
Decide and list the Gateway names you plan to deploy.
Example:
- test-gw
- dev-gw
Manually Create PVC Bound to Static PVβ
PVC naming convention:
data-<GATEWAY_NAME>-postgresql-0
Example:
data-test-gw-postgresql-0
Make sure the PVC is pre-bound to the appropriate static PV.
Deploy Gateway and Handle Init Migrationβ
Create Gateway via APIM UIβ
Use the same name as previously defined (e.g., test-gw) during Gateway creation in the APIM UI.
Handle Migration Pod Startup Failureβ
- At the init-migrations step, the Pod may fail if the DB is not ready yet.
- This is usually due to timing issues where Kong starts before the DB is fully initialized.
Manual Migration Executionβ
Check Kong Pod Logsβ
Confirm that the Pod is waiting for migration via one of the following logs:
kong migrations bootstrap
or
kong migrations up
Add Sleep Command to Kong Containerβ
Modify the Deployment spec with a custom command to keep the Kong container running:
command: ["/bin/bash", "-c", "sleep 300000"]
This ensures the Kong container enters a sleep state after the init-container finishes.
Execute Manual Migration (Inside Pod)β
Run the following commands to perform migration manually:
k exec -it -n <namespace> <kong-pod-name> -- kong migrations bootstrap
k exec -it -n <namespace> <kong-pod-name> -- kong migrations up
Finalizing for Normal Operationβ
Remove Sleep and Restart Kong:
- Revert or delete the custom command from the Deployment spec.
- Restart the Kong Pod to allow it to start normally.
Additional Notesβ
- This procedure is only necessary when using static PVs during initial Gateway setup.
- In production environments, ensure that the DB is fully ready before Kong starts. Use appropriate settings like:
- initContainer
- readinessProbe