> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formal.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Formal Kubernetes Operator

> Automatically register in-cluster services as Formal resources

## What is the Kubernetes Operator?

The Formal Kubernetes Operator watches for custom resources in your cluster and automatically manages the corresponding Formal resources, listeners, native users, and policies via the Formal API. This removes the need to manually configure resources via Terraform or the Control Plane when your services already live in Kubernetes.

> [!NOTE]
>
> `FormalNativeUser` creates legacy Native Users, which are deprecated. See the
> [migration guide](https://docs.formal.ai/docs/guides/core-concepts/resources/native-users-legacy).

The operator introduces the following Custom Resource Definitions (CRDs):

* **FormalResource**: Declares a backend service (e.g., a PostgreSQL database) that should be registered as a Formal resource
* **FormalListener**: Declares a listener on an existing Formal connector with routing rules that point to resources
* **FormalNativeUser**: Declares a legacy Native User, with credentials sourced from a Kubernetes Secret
* **FormalNativeUserV3**: Declares a Native User V3 on a resource that has `nativeUsersV3Enabled: true`
* **FormalNativeUserSelection**: Chooses which Native User V3 a session connects as
* **FormalPolicy**: Declares a Formal policy from Rego code
* **FormalConnectorHostname**: Declares the hostname of an existing Formal connector, either Formal-Managed or with its TLS certificate sourced from a Kubernetes Secret

When you create, update, or delete these custom resources, the operator reconciles the desired state with the Formal Control Plane. Finalizers ensure that Formal-side resources are cleaned up when Kubernetes resources are deleted.

## How It Works

```mermaid theme={"languages":{"custom":["/languages/cel.json","/languages/rego.json"]}}
sequenceDiagram
    participant K8s as Kubernetes
    participant Op as Operator
    participant CP as Formal Control Plane

    K8s->>Op: FormalResource created
    Op->>CP: Create resource
    CP-->>Op: Resource ID
    Op->>K8s: Update status

    K8s->>Op: FormalListener created
    Op->>CP: Create listener + rules
    CP-->>Op: Listener ID
    Op->>K8s: Update status

    K8s->>Op: FormalResource deleted
    Op->>CP: Delete resource
    Op->>K8s: Remove finalizer
```

The operator continuously watches for changes and keeps Formal in sync with your cluster state. Secret updates (e.g., rotated database credentials) are automatically propagated to the corresponding native users in Formal.

## Prerequisites

* A Kubernetes cluster (v1.28+)
* A Formal [API key](https://app.formal.ai/api-keys), or an [OIDC integration](https://docs.formal.ai/docs/guides/integrations/oidc.md)
* An existing Formal connector (the operator manages listeners and resources, not connectors themselves)


## Related topics

- [Kubernetes Operator](https://docs.formal.ai/docs/changelog/kubernetes-operator.md)
- [Deploy the Kubernetes Operator](https://docs.formal.ai/docs/guides/core-concepts/kubernetes-operator/deployment.md)
- [Kubernetes Operator Custom Resources](https://docs.formal.ai/docs/guides/core-concepts/kubernetes-operator/custom-resources.md)
- [Formal Endpoint for Kubernetes](https://docs.formal.ai/docs/guides/client-apps/kubernetes-egress.md)
- [Formal Control Plane](https://docs.formal.ai/docs/guides/control-plane/overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.