Database Integrations
Overview
KubeArchive requires a database to store resources. This document lists the databases supported, how to set up the database schema and how to add new database integrations.
PostgreSQL
Currently, PostgreSQL is the only fully supported database engine. The KubeArchive integration test suite runs with the PostgreSQL version detailed under the postgresql database integration directory.
The PostgreSQL implementation is available here.
The PostgreSQL schema is available here.
Configuration and Customization
Schema
KubeArchive offers a setup.sql file and migration scripts with the instructions to set up
the schema as part of the installation process.
|
The provided schema includes indexes. KubeArchive users should review and customize the indexes if needed based on the expected queries and the amount and distribution of the expected archived data. |
The schema includes the creation of the database kubearchive owned by the kubearchive user.
The schema expects the existence of a kubearchive database user fow owning this database.
|
An account with admin privileges should run the
|
Database Credentials
The kubearchive-database-credentials Secret stores the information to connect KubeArchive with the Database.
The Secret ships with empty values and must be populated before KubeArchive can connect to the database:
kind: Secret
type: Opaque
metadata:
name: kubearchive-database-credentials
namespace: kubearchive
stringData:
DATABASE_KIND: ""
DATABASE_PORT: ""
DATABASE_URL: ""
DATABASE_DB: ""
DATABASE_USER: ""
DATABASE_PASSWORD: ""
Populate the secret with the specific values of your database and restart the pods accordingly to pick the new values. The command for setting the most common values, URL and password, is:
kubectl patch secret -n kubearchive kubearchive-database-credentials \
--patch='{"stringData": {
"DATABASE_URL": "database.example.com", (1)
"DATABASE_PASSWORD": "password" (2)
}}'
| 1 | The database URL |
| 2 | The database password |
|
If you change the |
|
Remember to restart kubearchive sink and api as both access the database:
|
Password Rotation
To rotate the password of the kubearchive database user, follow these steps:
-
Change the password on the database side. A database administrator should update the
kubearchiveuser password. For PostgreSQL:ALTER USER kubearchive WITH PASSWORD 'new-password'; (1)1 Replace with the new password. -
Update the
kubearchive-database-credentialsSecret in thekubearchivenamespace:kubectl patch secret -n kubearchive kubearchive-database-credentials \ --patch='{"stringData": { "DATABASE_PASSWORD": "new-password" (1) }}'1 Replace with the new password. -
Rollout restart the KubeArchive deployments that access the database:
kubectl rollout -n kubearchive restart deployment kubearchive-sink kubearchive-api-server -
Verify that the deployments are running correctly:
kubectl rollout -n kubearchive status deployment kubearchive-sink kubearchive-api-server
|
Both the database password and the Kubernetes Secret must be updated to match. If they are out of sync, the KubeArchive components will fail to connect to the database. |
Adding a New Database engine
To add a new database integration, follow the instructions:
-
Create a new file under
pkg/databasenamed after the new database engine. If it’s a SQL engine, it should be underpkg/database/sql. -
Include a new entry on the
RegisteredDatabasesmap with the instance of the newDatabaseimplementation.
The Database implementation
|
This section includes the development guidelines expected by the KubeArchive maintainers. |
If the engine is a SQL one, Database implementation should be a struct with
sqlDatabaseImpl
embedded. sqlDatabaseImpl is a partial implementation, so make sure the new engine implementation
fully implements all methods required by the Database interface.
Make sure to implement the interfaces that are part of it:
|
All the interfaces work with objects from the sqlbuilder Go library. Check out the docs to see how to work with them. |
|
Some interfaces, like Other interfaces, like Those implementations may have the functionality that you need. Check them before implementing your own. |
If the database interaction logic changes from the implementation in the Database struct,
override the implementation of the affected functions.
For example, a database that does not support upsert queries
needs to implement ResourceInserter as a series of SELECT and an INSERT statements.
Take a look at the current database integrations and feel free to contribute to our code adding new database integrations!