title |
---|
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.
Take your first steps by configuring the Aiven Operator and deploying a PostgreSQL® database.
- 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.
This example creates an Aiven for PostgreSQL service using the operator's custom resource:
-
Create a file named
pg-sample.yaml
and add the following:apiVersion: aiven.io/v1alpha1 kind: PostgreSQL metadata: name: pg-sample spec: # Gets the token from the `aiven-token` secret authSecretRef: name: aiven-token key: token # Outputs the PostgreSQL connection information to the `pg-connection` secret connInfoSecretTarget: name: pg-connection project: PROJECT-NAME cloudName: google-europe-west1 plan: startup-4 maintenanceWindowDow: friday maintenanceWindowTime: 23:00:00 # PostgreSQL configuration userConfig: pg_version: '16'
Where
PROJECT-NAME
is 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-sample
Once the
STATE
field 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.
When the service is running, you can deploy a pod to test the connection to PostgreSQL from Kubernetes.
-
Create a file named
pod-psql.yaml
with the following:apiVersion: v1 kind: Pod metadata: name: psql-test-connection spec: restartPolicy: Never containers: - image: postgres:11-alpine name: postgres command: ['psql', '$(DATABASE_URI)', '-c', 'SELECT version();'] # The pg-connection secret becomes environment variables envFrom: - 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
-
To destroy the resources, run:
kubectl delete pod psql-test-connection kubectl delete postgresqls.aiven.io pg-sample
-
To remove the operator and
cert-manager
, run:helm uninstall aiven-operator helm uninstall aiven-operator-crds kubectl delete -f https://github.com/jetstack/cert-manager/releases/latest/download/cert-manager.yaml