Deploy Keycloak with PostgreSQL on Kubernetes: IAM Template

Deploying Keycloak on Kubernetes with a persistent backend requires a PostgreSQL StatefulSet, NetworkPolicies to isolate the database, and an Ingress to expose the auth endpoints externally. This template configures all of that in a single manifest, giving you a complete deploy Keycloak on Kubernetes setup with PostgreSQL persistence, network-level database isolation, and external access to the Keycloak admin console and authentication endpoints.
| Component | Type | Port | Role |
|---|---|---|---|
| Keycloak | Deployment | 8080 | Identity and access management application |
| ConfigMap | ConfigMap | - | Keycloak image and environment configuration |
| PostgreSQL | StatefulSet + Service | 5432 | Backend database with persistent storage |
| PostgreSQL PVC | PersistentVolumeClaim | - | Persistent storage for PostgreSQL data |
| Network Policy | NetworkPolicy | - | Restricts database access to Keycloak pods only |
| Ingress | Ingress | 80/443 | External access to Keycloak auth and admin endpoints |
Keycloak runs as a Deployment configured via a ConfigMap that sets the database connection details and runtime environment. PostgreSQL runs as a StatefulSet with a PVC for data durability, exposed internally via a headless Service. A NetworkPolicy enforces that only the Keycloak pod can reach the PostgreSQL port, blocking all other cluster traffic to the database. The NGINX Ingress routes external requests to the Keycloak Service for authentication and admin console access.
kubectl get pods -n <namespace>.https://<your-domain>/auth/admin and verify the Keycloak admin console loads.This template configures a Keycloak deployment on Kubernetes backed by a PostgreSQL StatefulSet, with NetworkPolicy-enforced database isolation and external ingress routing preconfigured.