Skip to main content

Aiven Operator for Kubernetes®

Manage Aiven infrastructure with Aiven Operator for Kubernetes® by using Custom Resource Definitions (CRD).

The Aiven 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

Deploy Aiven for PostgreSQL®

This example creates an Aiven for PostgreSQL service using the operator's custom resource:

  1. 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.

  2. To apply the resource, run:

    kubectl apply -f pg-sample.yaml
  3. Verify the status of your service by running:

    kubectl get postgresqls.aiven.io pg-sample

    Once the STATE field is RUNNING, 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.

Use the service

When the service is running, you can deploy a pod to test the connection to PostgreSQL from Kubernetes.

  1. 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
  2. Apply the resource to create the pod and test the connection by running:

    kubectl apply -f pod-psql.yaml
  3. To check the logs, run:

    kubectl logs psql-test-connection

Clean up

  1. To destroy the resources, run:

    kubectl delete pod psql-test-connection
    kubectl delete postgresqls.aiven.io pg-sample
  2. 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