A K8S Init-container for configuring a Prisma Server based on properties from a Secret
331
Goal: A simple utility which can be run as an init-container to setup Prisma Server configuration based on properties defined in a Secret.
Prisma is a Database ORM exposing the database via a GraphQL interface.
For a project I wanted to run Prisma Server in Kubernetes. When creating a Helm Chart for starting Prisma, I did not wanted to expose secrets in a ConfigMap as suggested by some examples. Also I wanted to be able to change Prisma config settings via Helm's --set <property>=<value> so it is possible to change the Chart configuration for different CI environments from a CI script.
Ideally I would like to create a Kubernetes Operator to run Prisma. However, since I had to create something quick, I created this tool instead to run as an init-container to setup the configuration for the Prisma Server.
This prisma-server-init tool:
k8s/secret.yaml)EmptyDir which is shared with the Prisma Server container. (See k8s/pod.yaml)The prisma-servr-init tool takes 2 arguments:
The Prisma Server PRISMA_CONFIG_PATH environment variable must be set to the location of the config file in the EmptyDir volume. (see k8s/pod.yaml)
These properties are currently supported in a Secret.
| properties | required? |
|---|---|
| managementApiSecret | no |
| apiPort | yes |
| connector | yes |
| host | yes |
| dbPort | yes |
| user | yes |
| password | yes |
| migrations | no |
The config created by this tool:
managementApiSecret: testManagementApiSecret
port: testApiPort
databases:
default:
connector: testConnector
host: testHost
port: testDbPort
user: testuser
password: testpassword
migrations: testMigrations
This tool has been writting in Java (version 8) and compiled into native code using GraalVM.
To create this tool locally:
bin folder to your PATH.sdk install java graalvm-ce <path-to-graalvm>/Content/Home.
Then 'use' this version as you would with any other Java version: sdk use java graalvm-ce.gu install native-imagemvn testnative-image -cp target/classes eu.diversit.k8s.prisma.server.InitConfig prisma-server-initThe Docker image uses GraalVM to create a native-image and then copies the prisma-server-init tool into a small alpine image.
Build the docker image.
docker build -t prisma-server-init:latest .
Use the Kubernetes files in k8s folder to:
Expose the Prisma Server via kubectl forward-proxy pod/prisma 4466:4466.
Open a browser to http://localhost:4466.
Note: if the managementApiKey property was set, to be able to access the Prisma server, the environment variable PRISMA_MANAGEMENT_API_SECRET to the value of the managementApiKey. Then prisma token can be used to generate a JWT token which can be used in the GraphQL Playground - HTTP Headers.
GraphQL Playground - HTTP Headers
{
"Authorization": "Bearer <your jwt token>"
}
Deploy a database model
prima.yaml fileendpoint: http://localhost:4466/ipos-api/develop
datamodel: datamodel.prisma
Define a database.model
Deploy the database model:
prisma deploy
Content type
Image
Digest
Size
43.4 MB
Last updated
about 7 years ago
docker pull diversit/prisma-server-init