Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions examples/kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Kubernetes Example: SQLite to PostgreSQL Hook

This example demonstrates how to use `postgres-sqlite` in a Kubernetes environment to redirect an application`s SQLite calls to a PostgreSQL database without modifying the application image.

## How it works

1. **Init Container**: Downloads the `sqlite_hook.so` library and installs `libpq5` (the PostgreSQL client library). It then copies the hook and `libpq.so.5` to a shared `emptyDir` volume.
2. **Environment Variables**:
* `LD_PRELOAD`: Tells the dynamic linker to load our hook before any other libraries.
* `LD_LIBRARY_PATH`: Ensures the linker can find `libpq.so.5` inside the shared volume.
* `PG_CONNINFO`: Provides the PostgreSQL connection string used by the hook.
3. **Volume Sharing**: Both the init container and the main container mount the `patch-libs` volume to share the library files.

## Files

- `deployment.yaml`: A sample Kubernetes Deployment manifest.

## Usage

1. Customize the `PG_CONNINFO` in `deployment.yaml`.
2. Ensure your main container image is based on an OS compatible with the downloaded `.so` (e.g., Ubuntu 24.04).
3. Apply the manifest:
```bash
kubectl apply -f deployment.yaml
```
50 changes: 50 additions & 0 deletions examples/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: sqlite-app-postgres
spec:
replicas: 1
selector:
matchLabels:
app: sqlite-app
template:
metadata:
labels:
app: sqlite-app
spec:
initContainers:
- name: download-sqlite-hook
# Use an image matching your target OS (e.g., Ubuntu 24.04 for Noble based apps)
image: ubuntu:24.04
command:
- /bin/sh
- -c
- |
apt-get update && apt-get install -y curl libpq5
# Fetch the pre-compiled hook for your architecture/OS
curl -L -o /patch/sqlite_hook.so https://github.com/ganey/postgres-sqlite/releases/download/v1.0.0/sqlite_hook-ubuntu.so
# Copy libpq dependency to the shared volume so the hook can find it
cp /usr/lib/x86_64-linux-gnu/libpq.so.5* /patch/
chmod 644 /patch/sqlite_hook.so /patch/libpq.so.5*
volumeMounts:
- name: patch-libs
mountPath: /patch
containers:
- name: main
image: your-sqlite-app-image:latest
env:
# PostgreSQL connection details
- name: PG_CONNINFO
value: "postgresql://user:password@postgres-host:5432/dbname"
# Ensure the hook can find its dependencies in the shared volume
- name: LD_LIBRARY_PATH
value: /patch
# Preload the hook to intercept SQLite calls
- name: LD_PRELOAD
value: /patch/sqlite_hook.so
volumeMounts:
- name: patch-libs
mountPath: /patch
volumes:
- name: patch-libs
emptyDir: {}
Loading