Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Clever Operator, fixes #458 #520

Merged
merged 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/styles/config/vocabularies/Doc/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ VSCode
webroot
Wildfly
Zooper
CRDs
namespace
namespaces
Kubectl
toolchain
1 change: 1 addition & 0 deletions content/guides/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ llmsTxtOptional: true
{{< card link="kibana" title="Customize Kibana" subtitle= "Deploy and customize a Kibana server on Clever Cloud" icon="kibana" >}}
{{< card link="pgpool" title="Pgpool-II" subtitle= "How to configure and use Pgpool-II for PostgreSQL add-ons" icon="pg" >}}
{{< card link="proxysql" title="ProxySQL" subtitle= "Configure and use ProxySQL for MySQL add-ons" icon="mysql" >}}
{{< card link="clever-operator" title="Clever Operator" subtitle= "Manage your Clever Cloud databases and addons seamlessly from Kubernetes" icon="kubernetes" >}}
{{< /cards >}}
257 changes: 257 additions & 0 deletions content/guides/clever-operator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
---
title: Clever Operator
description: Manage your Clever Cloud databases and addons seamlessly from Kubernetes with Clever Operator.
tags:
- guides
keywords:
- Kubernetes
- operator
- databases
- crd
type: "docs"
comments: false
draft: false
---

## What's the Clever Operator

The [Clever Operator](https://github.com/CleverCloud/clever-operator) is an open source project designed to seamlessly integrate [Clever Cloud](https://www.clever-cloud.com/)’s managed services into Kubernetes environments. By leveraging Kubernetes [Custom Resource Definitions (CRDs)](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions)), the Clever Operator enables developers to manage Clever Cloud resources directly from their Kubernetes clusters, aligning cloud-native practices with Clever Cloud’s powerful platform.

Modern applications often require a combination of containerized workloads and managed services, such as databases or caches. Managing these resources separately across platforms can become complex and error-prone. The Clever Operator simplifies this process by acting as a bridge, allowing developers to define and interact with Clever Cloud’s resources using familiar Kubernetes paradigms.

Key features of the Clever Operator include:

- **Custom Resource Definitions (CRDs):** Extend Kubernetes capabilities to manage Clever Cloud services like PostgreSQL, Redis, and more.
- **Declarative Resource Management:** Use YAML manifests to declare and maintain the desired state of your services.
- **Seamless Integration:** Interact with Clever Cloud’s API securely and efficiently.
- **Scalability and Flexibility:** Manage resources across multiple namespaces with consistent configurations.

This documentation guide you through:

- Installing and configuring the Clever Operator in your Kubernetes cluster.
- Managing Clever Cloud resources such as PostgreSQL and Redis through examples.


## Prerequisites

Before you begin, ensure that you have the following tools and resources based on your intended actions:

### To Build the Operator

- **Git:** Clone the Clever Operator repository to access the source code.
- **Rust toolchain:** Install the Rust programming language and its toolchain to compile the operator from source. Follow the installation guide at [https://rustup.rs/](https://rustup.rs/).
- **Docker:** Build container images for deploying the operator in Kubernetes.

### To Deploy the Operator

- **Kubernetes Cluster:** Ensure you have access to a running Kubernetes cluster.
- **Kubectl:** Install Kubernetes command-line tool for managing cluster resources Installation guide available at https://kubernetes.io/docs/tasks/tools/.
- **Clever Cloud Account Credentials:** [Obtain API tokens and secrets from your Clever Cloud]({{< ref "/api/howto" >}} "API Overview") account to configure the operator.

These prerequisites are essential for getting started with the Clever Operator, whether you're contributing to its development or deploying it in production.

## Installation

The simplest ways to deploy the Clever Operator are either directly from Docker Hub or using the Helm chart.

### Deploying from DockerHub

Applying the deployment scripts:

```bash
kubectl apply -f https://raw.githubusercontent.com/CleverCloud/clever-operator/main/deployments/kubernetes/v1.24.0/10-custom-resource-definition.yaml
kubectl apply -f https://raw.githubusercontent.com/CleverCloud/clever-operator/main/deployments/kubernetes/v1.24.0/20-deployment.yaml
```


### Installing via Helm Chart

1. Configuring `values.yaml` in `deployments/kubernetes/helm` with your values.

2. Installing the chart:
```bash
helm install clever-operator -n clever-operator --create-namespace -f values.yaml .
```


### Building from Source

1. Cloning the repository:

```bash
git clone https://github.com/CleverCloud/clever-operator.git
cd clever-operator
```

2. Building the binary:

```bash
make build
```

3. Running the operator:

```bash
target/release/clever-operator
```

### Building and Deploying the Docker Image

1. Building the Docker image:

```bash
DOCKER_IMG=<your-registry>/<your-namespace>/clever-operator:latest make docker-build
```

1. Pushing the image to your registry:

```bash
DOCKER_IMG=<your-registry>/<your-namespace>/clever-operator:latest make docker-push
```

3. Updating the Kubernetes deployment script:

Modify `deployments/kubernetes/v1.24.0/20-deployment.yaml` to use your Docker image.

4. Deploying to Kubernetes:
```bash
make deploy-kubernetes
```


## Configuration

The Clever Operator requires configuration to connect to Clever Cloud's API and manage resources within your Kubernetes cluster. Configuration options are available at two levels: global (applies to all namespaces) and namespace-specific.

For details on how to obtain these credentials, follow the instructions on the [How to obtain the credentials for the Clever Operator](./credentials.md) document.

### Global Configuration

Global configuration settings apply across all namespaces and are defined via environment variables or configuration files.

Check warning on line 130 in content/guides/clever-operator.md

View workflow job for this annotation

GitHub Actions / Run Vale Linter

[vale] reported by reviewdog 🐶 [Google.Passive] In general, use active voice instead of passive voice ('are defined'). Raw Output: {"message": "[Google.Passive] In general, use active voice instead of passive voice ('are defined').", "location": {"path": "content/guides/clever-operator.md", "range": {"start": {"line": 130, "column": 63}}}, "severity": "INFO"}

- **Environment Variables:**

- `CLEVER_OPERATOR_API_ENDPOINT`: The endpoint for the Clever Cloud API.
- `CLEVER_OPERATOR_API_TOKEN`: Your Clever Cloud API token.
- `CLEVER_OPERATOR_API_SECRET`: The secret associated with your API token.
- `CLEVER_OPERATOR_API_CONSUMER_KEY`: Your Clever Cloud consumer key
- `CLEVER_OPERATOR_API_CONSUMER_SECRET`: Your Clever Cloud consumer secret.

- **Configuration Files:** By default, if the `--config` flag isn't provided to the binary, the operator looks at the following locations to retrieve its configuration (in order of priority):

1. `/usr/share/clever-operator/config.{toml,yaml,json}`
2. `/etc/clever-operator/config.{toml,yaml,json}`
3. `$HOME/.config/clever-operator/config.{toml,yaml,json}`
4. `$HOME/.local/share/clever-operator/config.{toml,yaml,json}`
5. `config.{toml,yaml,json}` (in the current working directory)


### Namespace-Level Configuration

Namespace-level configurations override the global settings for specific namespaces. They're defined using a Kubernetes Secret resource named `clever-operator` with the `config` key.

- **Creating a Namespace-Level Configuration:** Create a Kubernetes Secret with the necessary configuration keys:

```yaml
apiVersion: v1
kind: Secret
metadata:
name: clever-operator
namespace: my-namespace
data:
config: |-
api:
endpoint: "https://api.clever-cloud.com/v2"
token: "<your-api-token>"
secret: "<your-api-secret>"
consumerKey: "<your-consumer-key>"
consumerSecret: "<your-consumer-secret>"
proxy:
host: "proxy.example.com"
port: 8080
```
- **Applying the Configuration:** Apply the Secret to your namespace:
```bash
kubectl apply -f namespace-config.yaml
```


The operator automatically detects and applies namespace-specific configurations when interacting with resources in that namespace.

### Validating Configuration

To ensure your configuration applies correctly, look at the operator logs for any errors or warnings:

```bash
kubectl logs -n clever-operator <operator-pod-name>
```

## Usage Examples

The Clever Operator enables you to manage Clever Cloud resources directly from your Kubernetes cluster using custom resources. Below are examples for PostgreSQL and Redis.

### Managing PostgreSQL Resources

- **Creating a PostgreSQL Instance:** Define a YAML manifest for the PostgreSQL resource:

```yaml
apiVersion: clever-cloud.com/v1
kind: PostgreSQL
metadata:
name: my-postgresql
namespace: default
spec:
version: "14"
plan: "dev"
region: "par"
```

Apply the manifest to your cluster:

```bash
kubectl apply -f postgresql.yaml
```

- **Verifying the Deployment:** Check the status of the PostgreSQL resource:

```bash
kubectl get postgresql my-postgresql -o yaml
```

- **Accessing PostgreSQL:** Retrieve the connection details from the Clever Cloud dashboard or the resource’s status field.


### Managing Redis Resources

- **Creating a Redis Instance:** Define a YAML manifest for the Redis resource:

```yaml
apiVersion: clever-cloud.com/v1
kind: Redis
metadata:
name: my-redis
namespace: default
spec:
version: "704"
plan: "dev"
region: "par"
```

Apply the manifest to your cluster:

```bash
kubectl apply -f redis.yaml
```

- **Verifying the Deployment:** Check the status of the Redis resource:

```bash
kubectl get redis my-redis -o yaml
```

- **Accessing Redis:** Retrieve the connection details from the Clever Cloud dashboard or the resource’s status field.

These examples demonstrate the simplicity and power of using the Clever Operator to manage cloud resources in a declarative way in Kubernetes.

1 change: 1 addition & 0 deletions data/icons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,4 @@ hugo: <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="cu
html: <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M1.5 0h21l-1.91 21.563L11.977 24l-8.564-2.438L1.5 0zm7.031 9.75l-.232-2.718 10.059.003.23-2.622L5.412 4.41l.698 8.01h9.126l-.326 3.426-2.91.804-2.955-.81-.188-2.11H6.248l.33 4.171L12 19.351l5.379-1.443.744-8.157H8.531z"/></svg>
mdbook: <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M22.77 5.343c.023.337 0 .613-.073.817l-4.314 14.227c-.072.252-.24.445-.504.6a1.67 1.67 0 0 1-.805.23H3.772c-1.154 0-1.839-.337-2.079-1.01-.096-.264-.096-.469.012-.625.108-.144.288-.216.553-.216h12.52c.89 0 1.514-.168 1.85-.493.337-.324.686-1.07 1.034-2.21l3.954-13.05c.216-.71.12-1.334-.265-1.875-.384-.54-.937-.817-1.646-.817H8.735c-.12 0-.373.048-.734.132l.012-.048A2.458 2.458 0 0 0 7.33.933a.979.979 0 0 0-.517.168 1.794 1.794 0 0 0-.385.337c-.096.12-.18.264-.276.456a5.76 5.76 0 0 0-.228.517 7.95 7.95 0 0 1-.217.505c-.084.18-.156.324-.24.444-.06.073-.144.18-.24.3-.096.121-.193.241-.265.337a.776.776 0 0 0-.132.265c-.024.084-.012.216.024.384.036.168.048.289.048.373-.036.36-.168.829-.396 1.394-.229.564-.433.973-.613 1.213a5.201 5.201 0 0 1-.312.325c-.169.168-.277.312-.313.444-.036.048-.036.18-.012.409.036.216.048.372.036.456-.036.325-.156.757-.36 1.298a9.47 9.47 0 0 1-.601 1.322c-.024.06-.108.168-.24.336-.133.168-.217.3-.24.409-.025.072-.013.216.011.408.024.193.024.337-.012.433-.072.36-.216.805-.432 1.322-.217.516-.433.949-.65 1.321-.06.097-.131.205-.24.337-.096.132-.18.24-.24.336a.927.927 0 0 0-.12.3.53.53 0 0 0 .048.277c.036.132.048.228.048.313-.012.132-.024.312-.06.528-.024.216-.048.349-.048.385-.216.576-.204 1.19.024 1.826.264.745.745 1.382 1.43 1.899.685.516 1.406.769 2.139.769H17.05c.625 0 1.214-.205 1.767-.625.553-.42.925-.937 1.105-1.55l3.966-13.05c.216-.696.12-1.31-.265-1.862-.204-.3-.48-.505-.853-.649ZM7.16 15.677l1.707-5.143h1.297c.457 0 3.46-.204 3.052 2.103-.408 2.307-2.259 3.028-4.422 3.052-2.162.024-1.634-.012-1.634-.012zm2.283-.721c.565-.012 2.271-.349 2.656-2.055.384-1.706-1.382-1.61-1.382-1.61h-1.07l-1.225 3.665c.012.012.469.012 1.021 0zm-.396-5.78 1.646-5.107h1.178l.096 4.086 2.835-4.086h1.19l-1.634 5.107h-.853l1.502-4.253-2.944 4.253h-.817l-.096-4.205-1.298 4.205z"/></svg>
nuxt: <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M13.4642 19.8295h8.9218c.2834 0 .5618-.0723.8072-.2098a1.5899 1.5899 0 0 0 .5908-.5732 1.5293 1.5293 0 0 0 .216-.783 1.529 1.529 0 0 0-.2167-.7828L17.7916 7.4142a1.5904 1.5904 0 0 0-.5907-.573 1.6524 1.6524 0 0 0-.807-.2099c-.2833 0-.5616.0724-.807.2098a1.5904 1.5904 0 0 0-.5907.5731L13.4642 9.99l-2.9954-5.0366a1.5913 1.5913 0 0 0-.591-.573 1.6533 1.6533 0 0 0-.8071-.2098c-.2834 0-.5617.0723-.8072.2097a1.5913 1.5913 0 0 0-.591.573L.2168 17.4808A1.5292 1.5292 0 0 0 0 18.2635c-.0001.2749.0744.545.216.783a1.59 1.59 0 0 0 .5908.5732c.2454.1375.5238.2098.8072.2098h5.6003c2.219 0 3.8554-.9454 4.9813-2.7899l2.7337-4.5922L16.3935 9.99l4.3944 7.382h-5.8586ZM7.123 17.3694l-3.9083-.0009 5.8586-9.8421 2.9232 4.921-1.9572 3.2892c-.7478 1.1967-1.5972 1.6328-2.9163 1.6328z"/></svg>
kubernetes: <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -10.44 722.846 722.846"><path fill="currentColor" d="M358.986 10.06a46.725 46.342 0 0 0-17.905 4.531L96.735 131.341a46.725 46.342 0 0 0-25.28 31.437l-60.28 262.25a46.725 46.342 0 0 0 6.344 35.533 46.725 46.342 0 0 0 2.656 3.688l169.124 210.278a46.725 46.342 0 0 0 36.53 17.44l271.22-.062a46.725 46.342 0 0 0 36.532-17.408l169.062-210.312a46.725 46.342 0 0 0 9.03-39.22l-60.372-262.248a46.725 46.342 0 0 0-25.282-31.438L381.644 14.59a46.725 46.342 0 0 0-22.658-4.53zm2.42 52.492c9.256 0 16.76 8.34 16.761 18.624.005 1.458.086 3.415.035 4.763-.22 5.933-1.514 10.472-2.292 15.937-1.41 11.697-2.627 21.393-1.897 30.405.661 4.511 3.296 6.294 5.478 8.381.05 1.216.246 5.253.395 7.486 53.292 4.735 102.783 29.105 139.135 67.222l6.375-4.55c2.16.129 6.922.783 10.172-1.108 7.5-5.05 14.331-12.054 22.598-20.45 3.787-4.017 6.567-7.84 11.066-11.71 1.028-.884 2.58-2.068 3.724-2.974 8.04-6.415 19.227-5.731 25 1.505 5.771 7.236 3.92 18.297-4.12 24.71-1.133.912-2.61 2.176-3.69 2.974-4.774 3.526-9.172 5.33-13.93 8.13-10.025 6.19-18.335 11.323-24.926 17.512-3.114 3.33-2.88 6.483-3.152 9.49-.93.855-4.209 3.758-5.945 5.337 14.448 21.503 25.279 45.91 31.409 72.594 6.073 26.439 7.017 52.864 3.508 78.254l6.77 1.968c1.217 1.723 3.718 5.907 7.234 7.27 8.624 2.717 18.33 3.715 30.048 4.944 5.501.456 10.247.185 16.08 1.29 1.397.264 3.434.818 4.871 1.145 9.88 2.384 16.222 11.466 14.182 20.413-2.041 8.949-11.692 14.388-21.63 12.25-.073-.018-.177-.02-.253-.038-.112-.025-.21-.079-.321-.105-1.386-.305-3.121-.608-4.333-.932-5.734-1.535-9.888-3.826-15.042-5.801-11.09-3.977-20.277-7.302-29.225-8.596-4.545-.359-6.862 1.811-9.383 3.473-1.224-.245-4.994-.912-7.163-1.253-16.06 50.473-50.26 94.175-96.624 121.553.8 1.932 2.158 6.04 2.793 6.768-1.06 2.827-2.65 5.532-1.29 9.883 3.254 8.437 8.517 16.685 14.863 26.612 3.072 4.586 6.216 8.109 8.99 13.358.663 1.256 1.544 3.185 2.184 4.512 4.31 9.217 1.148 19.832-7.126 23.817-8.34 4.017-18.709-.226-23.173-9.492-.637-1.312-1.536-3.057-2.077-4.297-2.374-5.44-3.2-10.103-4.87-15.364-3.807-11.15-6.93-20.38-11.496-28.185-2.555-3.777-5.687-4.26-8.56-5.194-.531-.916-2.516-4.555-3.582-6.447a217.484 217.484 0 0 1-28.758 8.669c-43.49 9.874-87.027 5.867-125.921-9.062l-3.796 6.875c-2.826.757-5.551 1.525-7.224 3.52-6.104 7.282-8.539 18.97-12.974 30.11-1.67 5.26-2.46 9.923-4.835 15.363-.538 1.232-1.442 2.954-2.08 4.264-.004.01.006.025 0 .035-.005.014-.028.022-.035.036-4.473 9.235-14.807 13.463-23.134 9.455-8.275-3.984-11.436-14.6-7.128-23.817.64-1.326 1.486-3.256 2.15-4.512 2.772-5.25 5.917-8.808 8.99-13.395 6.345-9.927 11.917-18.83 15.17-27.265.818-2.804-.392-6.643-1.49-9.479l3.044-7.306c-44.615-26.437-79.849-68.569-96.661-120.694l-7.306 1.255c-1.959-1.097-5.898-3.695-9.634-3.403-8.95 1.295-18.136 4.618-29.225 8.595-5.156 1.976-9.307 4.231-15.04 5.767-1.213.324-2.948.663-4.335.967-.111.028-.209.083-.321.108-.075.016-.18.02-.252.035-9.939 2.142-19.588-3.3-21.631-12.247-2.042-8.947 4.303-18.028 14.182-20.415.073-.016.173-.053.25-.07l.145-.038c1.405-.329 3.192-.796 4.475-1.04 5.832-1.104 10.582-.83 16.083-1.287 11.717-1.229 21.422-2.226 30.046-4.942 2.735-1.122 5.348-4.881 7.199-7.27l7.02-2.042c-7.866-54.47 5.444-107.928 34.201-151.207l-5.372-4.798c-.343-2.092-.793-6.926-3.367-9.67-6.59-6.19-14.901-11.322-24.926-17.513-4.758-2.799-9.12-4.604-13.895-8.13-1.016-.75-2.37-1.897-3.475-2.792-.083-.064-.17-.115-.25-.18-8.042-6.411-9.89-17.475-4.118-24.712 3.246-4.07 8.205-6.085 13.358-5.908 4.007.136 8.157 1.6 11.675 4.404 1.144.906 2.703 2.093 3.724 2.972 4.5 3.872 7.244 7.696 11.031 11.711 8.267 8.396 15.097 15.365 22.598 20.413 3.94 2.296 6.964 1.374 9.957.97a280.97 280.971 0 0 0 6.053 4.296c28.527-30.267 65.998-52.685 109.518-62.568a218.134 218.134 0 0 1 30.299-4.655l.393-7.09c2.232-2.161 4.734-5.27 5.445-8.668.727-9.012-.453-18.708-1.862-30.405-.78-5.465-2.073-10.005-2.293-15.937-.045-1.216.021-2.9.034-4.3-.002-.155-.034-.305-.034-.463 0-10.285 7.504-18.623 16.76-18.624zm-20.987 130.005a176.633 176.633 0 0 0-17.872 3.08c-32.66 7.414-61.003 23.516-83.159 45.303l72.092 51.107.145-.07a14.69 14.69 0 0 0 8.702 2.827c7.948 0 14.42-6.28 14.755-14.145l.358-.18 4.979-87.922zm42.008 0 4.979 87.78.072.034a14.677 14.677 0 0 0 3.222 8.561c4.956 6.213 13.914 7.364 20.272 2.722l.249.105 71.628-50.782c-27.023-26.464-62.289-43.73-100.422-48.42zm-169.184 81.225c-19.535 31.825-28.79 69.998-24.497 109.267l84.379-24.354.07-.286a14.775 14.775 0 0 0 7.665-5.049c4.957-6.214 4.08-15.177-1.862-20.342l.072-.359-65.827-58.877zm295.859.035-65.468 58.592.036.178a14.653 14.653 0 0 0-4.693 7.845c-1.768 7.748 2.9 15.474 10.493 17.548l.073.359 84.807 24.424c1.796-18.296.703-37.227-3.653-56.192-4.409-19.195-11.815-36.9-21.595-52.754zm-161.199 63.39-16.797 20.916 6.018 26.145 24.281 11.674 24.211-11.639 6.016-26.143-16.76-20.953h-26.969zm86.456 71.7c-1.91.097-3.826.587-5.66 1.469-7.16 3.448-10.274 11.929-7.163 19.16l-.106.143 33.878 81.834c32.658-20.805 57.1-51.892 69.874-87.78l-87.278-14.755-.143.18a14.748 14.748 0 0 0-3.402-.25zm-146.587.357a15.06 15.06 0 0 0-2.9.253l-.144-.18-86.526 14.682c13.354 36.948 38.317 67.06 69.659 87.173l33.521-81.012-.252-.321a14.634 14.634 0 0 0 .826-9.097c-1.548-6.78-7.524-11.404-14.184-11.498zm73.095 35.493a14.795 14.795 0 0 0-12.498 7.807h-.072l-42.545 76.928c29.444 10.033 61.961 12.278 94.582 4.87a176.783 176.784 0 0 0 17.048-4.762l-42.653-77.073h-.324c-1.426-2.665-3.691-4.889-6.625-6.302a14.628 14.628 0 0 0-6.911-1.468h-.002z"/></svg>
Loading