Skip to main content
The PostgreSQL database service provides persistent data storage for the exchange platform.

Deployment Configuration

apiVersion: apps/v1
kind: Deployment
metadata:
  name: exchange-postgres-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: exchange-postgres
  template:
    metadata:
      labels:
        app: exchange-postgres
    spec:
      containers:
        - name: exchange-postgres
          image: postgres:12.2
          ports:
            - containerPort: 5432
          env:
            - name: POSTGRES_USER
              valueFrom:
                configMapKeyRef:
                  name: exchange-postgres-config
                  key: POSTGRES_USER
            - name: POSTGRES_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: exchange-postgres-config
                  key: POSTGRES_PASSWORD
            - name: POSTGRES_DB
              valueFrom:
                configMapKeyRef:
                  name: exchange-postgres-config
                  key: POSTGRES_DB
          volumeMounts:
            - mountPath: /var/lib/postgresql/data
              subPath: postgres-data
              name: postgres-storage
      volumes:
        - name: postgres-storage
          persistentVolumeClaim:
            claimName: postgres-pvc

Service Configuration

apiVersion: v1
kind: Service
metadata:
  name: exchange-postgres-service
spec:
  selector:
    app: exchange-postgres
  ports:
    - protocol: TCP
      port: 80
      targetPort: 5432
  type: ClusterIP

Persistent Volume Claim

The database uses persistent storage to ensure data durability:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: standard-rwo
  volumeMode: Filesystem

ConfigMap

Database credentials and configuration:
apiVersion: v1
kind: ConfigMap
metadata:
  name: exchange-postgres-config
data:
  POSTGRES_USER: root
  POSTGRES_PASSWORD: root
  POSTGRES_DB: exchange-db
The ConfigMap contains plaintext credentials. In production, use Kubernetes Secrets or a secrets management solution.

Database Configuration

ParameterValue
Database Nameexchange-db
Userroot
Passwordroot
Port5432 (container), 80 (service)
Imagepostgres:12.2

Storage Configuration

ParameterValue
Storage Classstandard-rwo
Access ModeReadWriteOnce
Storage Size5Gi
Mount Path/var/lib/postgresql/data
SubPathpostgres-data

Connection String

Services can connect to PostgreSQL using:
postgres://root:[email protected]:80/exchange-db

Data Persistence

Data is persisted to a PersistentVolume, ensuring that database data survives pod restarts and redeployments. The volume is mounted at /var/lib/postgresql/data with a subpath postgres-data.

Build docs developers (and LLMs) love