Repository navigation
Cluster Setup
How a cluster is created, how servers join it, which ports and files are involved, and how certificates work. The package and container are in Installing and Packaging; the settings are in Configuration; the part of the API used here is in REST API Reference.
A node is uninitialized until it creates or joins a cluster, then standalone (a one-server cluster) or clustered. While a node is uninitialized only /healthz, /readyz and /setup/* work; everything else answers 503 node_uninitialized. On first start kingresd writes a one-time setup token to <data-dir>/setup-token (owner-only) and logs only the file name.
From the console: open the panel of the first server (the package listens on 127.0.0.1:8091 only; from elsewhere use ssh -L 8091:127.0.0.1:8091 server), enter the setup token, choose "Create new cluster", give the cluster name and the administrator account. Through the API, the same thing:
kingresd -data-dir /var/lib/kingres -pg-bin-dir /opt/kingres/bin -listen 127.0.0.1:8091
curl -s -X POST http://127.0.0.1:8091/api/v1/setup/init-cluster \
-H "X-Setup-Token: $(cat /var/lib/kingres/setup-token)" -H 'Content-Type: application/json' \
-d '{"clusterName":"prod","admin":{"username":"root_admin","password":"a-long-password"},
"dataPaths":{"dataDirectory":"/var/lib/kingres"},"memoryQuota":{"totalMegabytes":4096}}'
curl -s http://127.0.0.1:8091/api/v1/setup/state # follow setupTask until it is done
kingresd creates the instance under <data-dir>/instances/1, the administrator role, the cluster certificate authority and the system database kingres_system, starts the instance and removes the token file. dataPaths.dataDirectory must be the data directory kingresd was started with; walDirectory and logDirectory must be null at setup (a separate WAL directory is not supported yet: 422; the log directory of a server can be changed later with PATCH /api/v1/this-server/settings, see Servers Databases and Roles).
The setup operations accept calls from loopback addresses only, unless allow-remote-setup is true (the container image sets it, because a published port reaches kingresd from the Docker bridge). The setup token is still required.
If setup is interrupted, the task resumes at its first step not done, except the step that needs the administrator password (it exists only in the memory of the request): then the task fails with secret_unavailable and you call init-cluster again with the same data directory and token. See the data directory notes in the control-plane README.
| Setting | Value (example for db2.example.com) |
Why |
|---|---|---|
server-host |
db2.example.com |
The server id; its certificate names it; the others and the sharding extension connect to it. It must resolve to this server from every other server |
listen |
0.0.0.0:8091 |
The REST API and the console |
internal-listen |
0.0.0.0:8092 |
The mutual-TLS internal API, by convention the port above listen; kingresd warns when it is not |
pg-port, pg-listen
|
5432, 127.0.0.1,db2.example.com
|
The other servers' instances connect here; 127.0.0.1 stays for kingresd itself |
pg-bin-dir |
/opt/kingres/bin |
Programs of the managed PostgreSQL |
allow-remote-setup |
false |
Adding a server does not need remote setup |
Ports to open between the servers: the internal API port (8092 in the example) and the PostgreSQL port (5432). The REST port is for the console and clients. Every server runs one major of PostgreSQL, the same on all.
There are two ways; both end in the same task server.add on the manager leader.
The new server joins. On the new server, with its own setup token:
curl -s -X POST http://127.0.0.1:8091/api/v1/setup/join-cluster \
-H "X-Setup-Token: $(cat /var/lib/kingres/setup-token)" -H 'Content-Type: application/json' \
-H 'X-Kingres-Pin-Sha256: <fingerprint of the existing server>' \
-d '{"existingNodeAddress":"db1.example.com:8091","admin":{"username":"root_admin","password":"..."},
"dataPaths":{"dataDirectory":"/var/lib/kingres"},"memoryQuota":{"totalMegabytes":4096}}'
The cluster adds it. On any server, signed in as kingres_ops or better, with the new server's setup token (a request to a server that is not the leader is forwarded):
curl -s -X POST http://db1.example.com:8091/api/v1/servers -H "Authorization: Bearer $TOKEN" \
-H 'Content-Type: application/json' -H 'X-Kingres-Pin-Sha256: <fingerprint of the new server>' \
-d '{"address":"db3.example.com:8091","setupToken":"..."}'
The steps of server.add: wait for the new server's certificate; prepare its instance with the cluster's settings and managed network rules; trust the new server on every server; copy the roles (verifiers and memberships, never passwords) and every user database with its extensions; register the server with kingres.add_node in every database that uses kingres_shard (after this step nothing is cleaned up any more); record the server; finish. A joined server creates a primary of a new shard group and the standby of a neighbouring group. It is listed as pendingRebalance and no data moves until a rebalance runs (Rebalancing); databases created afterwards spread their buckets over all servers at once.
The first contact has no common certificate authority. The internal API of a server without a cluster presents a self-signed certificate (its SHA-256 fingerprint is logged at start and is shown in the console on the setup and This server pages); a clustered server presents the cluster certificate. The expected fingerprint goes in the header X-Kingres-Pin-Sha256. Since contract 0.6.0 a pin is required for addServer and joinCluster unless the request says allowUnpinned: true. Without a pin, a network attacker at that moment can read the setup token or the administrator's password. Pin whenever the address was not typed from your own records. The control-plane README states what each mode protects against.
The task is resumable. A failure before the registration step cleans up (the new server deletes its instance and key and becomes uninitialized, its certificate is revoked); fix the cause and add it again. A failure during or after registration is not undone: add the server again with the same token and the task continues. A joining server whose join was refused shows setupTask.state = failed and keeps a valid token.
DELETE /api/v1/servers/{serverId} (kingres_ops) removes a server that owns no buckets; POST /api/v1/this-server/leave-cluster (kingres_admin) is the same driven from the leaving server. Refusals: 409 server_owns_buckets (rebalance first: set shouldHaveShards to false, run a rebalance, then remove), server_hosts_map_group, last_server, rebalance_in_progress, operation_in_progress; a dead server is refused with 422 node_state_invalid (fail it over first). Removal revokes the server's certificate and resets it to uninitialized; it can join again. No data moves in a removal. See Servers Databases and Roles.
- The first server creates the cluster certificate authority (ECDSA P-256, ten years) in
<data-dir>/pki/;ca.keyhas mode 0600 and is never copied. Each server generates its own key and sends only a request; it gets a one-year server certificate (common name and subject alternative name: itsserver-host, pluslocalhostand127.0.0.1). The same certificate serves as server and client certificate for the internal API and for that server's PostgreSQL instance. - Servers renew their certificates before expiry (
certificate-renew-fraction, default0.3333); an administrator can renew now (POST /servers/{serverId}/certificates/renewals) or revoke (.../revocations). The authority itself is not rotated. - Every instance runs with
ssl = on(TLS 1.3). Its generatedpg_hba.confbegins withhostssl ... certrules for each server, and apg_ident.confmap lets any server's certificate act as any role, so a statement routed from one server to another runs as the same role with no stored password. Every server of a cluster is fully trusted by every other. Clients on the servers themselves must usesslmode=disableor present a certificate. - The escrow of the certificate authority key is off until an administrator switches it on (the Certificate authority tab of the Security page, or
PUT /api/v1/certificate-authority/escrow). With it on, the leader seals the key and the revocation list to every server that hosts a ready standby of the map group, so a new leader can go on issuing certificates; a server that holds a copy can become the authority, so switch it on only when those servers are as trusted as the leader. Without it, after a failover of the map group the new leader raises the critical alertcertificateAuthorityUnavailableuntil the operator restorespki/ca.keyandpki/revoked.jsonfrom the old leader's backup (High Availability, Runbooks). - Server-to-server calls use an internal protocol that is not part of the public contract and is versioned separately; a server refuses a peer of another version.
Under <data-dir> (/var/lib/kingres in the package): node-state.json, setup-token (until setup finishes), service-credentials (0600), audit.jsonl, pki/, ledger/keys/signing/ (on the leader and on servers of shard group 0), instances/<id>/pgdata with kingres-managed.conf, kingres-config.conf, pg_hba.conf and pg_ident.conf (generated; do not edit), and the sockets under run/<id> (/run/kingres in the package, never /tmp). The whole directory contains the CA key and the service credentials: treat any copy as a secret.
When kingresd stops, the instances keep running and kingresd re-adopts them on start; kingresd -stop-instances stops them (every instance is asked for a fast shutdown at once, primaries first; see High Availability, "Stopping and starting a node"). In the package one systemctl stop kingres stops the database too.
- One session belongs to the server that created it; sign in once per server.
- A cluster-wide task takes the list of servers when it starts; do not add a server while
database.createordatabase.dropruns. - A server must be reachable at the id it registers; a DNS change needs the trust rules to be applied again (any membership change does that).
- Writing the WAL to another directory is not supported yet, and the log directory cannot be set at setup.
KingresDB's own code is licensed under AGPL-3.0-only. PostgreSQL code keeps the PostgreSQL License. Copyright of the project's own code: RooyeKhat Media Co. KingresDB is derived from PostgreSQL and is not endorsed by the PostgreSQL project. Repository | Licence | COPYRIGHT
KingresDB
1. Product
- Product Overview and Features
- Status and Roadmap
- User Guide
- Administrator Guide
- REST API Reference
- Web Console
- Command Line Client
- Extensions
- Limitations and Known Issues
- Release Notes
Features in detail
- Sharding
- Sharding Query Pushdown
- Sharding Table Lifecycle
- High Availability
- Ledger
- Ledger Signing and Publication
- Ledger Anchoring
- The Verifier
- Analytics Extensions
Administration
- Cluster Setup
- Servers Databases and Roles
- Rebalancing
- Configuration
- Memory and Warm-up
- Control Plane and REST API
- Upgrades
2. Architecture (arc42)
- Architecture
- Architecture Introduction and Goals
- Architecture Constraints
- Architecture System Context
- Architecture Containers
- Architecture Components
- Architecture Runtime Views Sharding
- Architecture Runtime Views Availability and Ledger
- Architecture Deployment
- Architecture Crosscutting Concepts
- Security Model
- Architecture Decisions
- Architecture Quality Requirements
- Architecture Risks and Technical Debt
- Enterprise Architecture
3. Data architecture
- Data Architecture
- Data Model Sharding
- Data Model Ledger
- Data Model System Database
- Data Model Analytics
- Data Lifecycle
- Backup Restore and PITR
- Data Security
- Data Quality and Integrity
4. Development
- Building from Source
- Development and Testing
- Repository Layout
- Coding Standards
- Branching and Synchronisation
- Testing Strategy
- Review Process
- Release Process
- Contributing
5. Operations