Aiven Operator for Kubernetes®
Manage Aiven infrastructure with Aiven Operator for Kubernetes® by using Custom Resource Definitions (CRD).
The Aiven Kubernetes Operator documentation includes an API reference and example usage for the resources.
Get started
Take your first steps by configuring the Aiven Operator and deploying a PostgreSQL® database.
Prerequisites
- Sign up for Aiven.
- Install the Aiven Operator.
- Have admin access to a Kubernetes cluster where you can run the operator.
- Create a personal token.
- Create a Kubernetes Secret.
Deploy Aiven for PostgreSQL®
This example creates an Aiven for PostgreSQL service using the operator's custom resource:
-
Create a file named
pg-sample.yamland add the following:apiVersion: aiven.io/v1alpha1kind: PostgreSQLmetadata:name: pg-samplespec:# Gets the token from the `aiven-token` secretauthSecretRef:name: aiven-tokenkey: token# Outputs the PostgreSQL connection information to the `pg-connection` secretconnInfoSecretTarget:name: pg-connectionproject: PROJECT-NAMEcloudName: google-europe-west1plan: startup-4maintenanceWindowDow: fridaymaintenanceWindowTime: 23:00:00# PostgreSQL configurationuserConfig:pg_version: '16'Where
PROJECT-NAMEis the name of the Aiven project to create the service in. -
To apply the resource, run:
kubectl apply -f pg-sample.yaml -
Verify the status of your service by running:
kubectl get postgresqls.aiven.io pg-sampleOnce the
STATEfield isRUNNING, your service is ready for use.
The connection information is automatically created by the operator
within a Kubernetes Secret named pg-connection. For PostgreSQL, the connection
information is the service URI.
Create a connection pool
This example creates a
PgBouncer connection pool
for the pg-sample service.
-
Create a file named
pg-pool.yamland add the following:apiVersion: aiven.io/v1alpha1kind: ConnectionPoolmetadata:name: pg-connection-poolspec:authSecretRef:name: aiven-tokenkey: token# Outputs the pool connection information to the `pg-connection-pool-secret` secretconnInfoSecretTarget:name: pg-connection-pool-secretproject: PROJECT-NAMEserviceName: pg-sampledatabaseName: defaultdbusername: avnadminpoolMode: transactionpoolSize: 25Where
PROJECT-NAMEis the name of the Aiven project,defaultdbis an existing database on thepg-sampleservice, andavnadminis an existing service user.notepoolSizecan be from 1 to 1000 with the Aiven Operator for Kubernetes, lower than the maximum of 10000 available through the console, CLI, Terraform, or API. -
To apply the resource, run:
kubectl apply -f pg-pool.yaml -
Verify the status of your connection pool by running:
kubectl get connectionpools.aiven.io pg-connection-pool
Use the service
When the service is running, you can deploy a pod to test the connection to PostgreSQL from Kubernetes.
-
Create a file named
pod-psql.yamlwith the following:apiVersion: v1kind: Podmetadata:name: psql-test-connectionspec:restartPolicy: Nevercontainers:- image: postgres:11-alpinename: postgrescommand: ['psql', '$(DATABASE_URI)', '-c', 'SELECT version();']# The pg-connection secret becomes environment variablesenvFrom:- secretRef:name: pg-connection -
Apply the resource to create the pod and test the connection by running:
kubectl apply -f pod-psql.yaml -
To check the logs, run:
kubectl logs psql-test-connection
Clean up
-
To destroy the resources, run:
kubectl delete pod psql-test-connectionkubectl delete connectionpools.aiven.io pg-connection-poolkubectl delete postgresqls.aiven.io pg-sample -
To remove the operator and
cert-manager, run:helm uninstall aiven-operatorhelm uninstall aiven-operator-crdskubectl delete -f https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml