PostgreSQL
This guide shows you how to use PostgreSQL, a powerful, open source object-relational database system.
To run it, follow these steps:
-
Install the
kraftCLI tool and a container runtime engine, for example Docker. -
Clone the
examplesrepository andcdinto theexamples/postgres/directory:
Code(bash)
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
This guide uses fra (Frankfurt, ๐ฉ๐ช):
Code(bash)
When done, invoke the following command to deploy this app on Unikraft Cloud:
Code(bash)
The output shows the instance address and other details:
Code(ansi)
In this case, the instance name is postgres-saan9 and the service young-thunder-fbafrsxj.
They're different for each run.
If you use port 5432/tls per the example above, you can now directly connect to postgres:
Code
Use the unikraft password at the password prompt.
You should see output like:
Code(ansi)
Use SQL and psql commands for your work.
Idle Scale-to-Zero
This example uses the idle scale-to-zero policy by default (see the labels section in the Kraftfile).
It means that the instance will scale-to-zero even in the presence of psql connections.
To ensure that the instance isn't put into standby even for long running queries
(during which the connections are also idle).
The PostgreSQL example makes use of scale-to-zero app support.
To this end, the example loads the pg_ukc_scaletozero module into PostgreSQL, which suspends scale-to-zero during query processing.
You can see this in action by running SELECT pg_sleep(10); and verifying that the instance keeps on running.
If you'd like to use a port other than 5432/tls you'll need to use the kraft cloud tunnel command to connect to PostgreSQL.
See the tunneling guide for more information.
Additionally, you need to explicitly disable scale-to-zero by either changing the label in the Kraftfile or use --scale-to-zero off in the deploy command.
You can list information about the instance by running:
Code(bash)
Code(text)
When done, you can remove the instance:
Code(bash)
Using volumes
You can use volumes for data persistence for you PostgreSQL instance.
For that you would first create a volume:
Code
Then start the PostgreSQL instance and mount that volume:
Code
Customize your deployment
Your deployment is a standard PostgreSQL installation. Customizing the deployment means providing a different environment.
An obvious one is to use a different database password when starting PostgreSQL.
For that you use a different POSTGRES_PASSWORD environment variable when starting the PostgreSQL instance.
You could also a different location to mount your volume or set extra configuration options.
You can use the PostgreSQL instance in conjunction with a frontend service, see the guide here. But in that case make sure to disable scale-to-zero if you plan to use the DB internally.
Support for scale-to-zero for internal instances is coming soon.
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Code(bash)
Or visit the CLI Reference.