# Kubernetes with Helm

The presented example uses Helm charts, if you haven’t used the tool before, we highly recommend getting familiar with the [Helm quick-start docs](https://helm.sh/docs/intro/quickstart/).

The repository provides Helm charts for two setups: CKEditor AI On-Premises standalone, with its own MySQL database and Redis, and CKEditor AI On-Premises together with Collaboration Server On-Premises, where both services share one MySQL database and Redis.

<a id="prerequisites">

## Prerequisites

Helm v3 and Kubernetes 1.19+ are required to run examples from the section.

To fetch a Git repository with a pre-configured Helm chart, `git` needs to be installed.

To fetch required docker images you will need to authorize to the CKEditor AI On-Premises Docker Registry.\
Please prepare the download token from the [Customer Portal](https://portal.ckeditor.com/).

> **Warning**
>
> The presented example is not meant for production purposes! This configuration is insecure, not persistent and its purpose is testing only. For production usage, please check the [architecture](../architecture.md) and [requirements](../requirements.md) articles.

> **Note**
>
> A valid license key is needed in order to install CKEditor AI On-Premises.\
> [Contact us](https://ckeditor.com/contact/) for a trial license key.

<a id="preparing-development-environment">

## Preparing development environment

1. Clone the `cksource/ckeditor-cs-on-premises-infrastructure` Git repository.

```sh
git clone git@github.com:cksource/ckeditor-cs-on-premises-infrastructure.git
```

2. Go to the `kubernetes/helm` directory.

```sh
cd ckeditor-cs-on-premises-infrastructure/kubernetes/helm
```

3. Create `imagePullSecret` for pulling images from the CKEditor container registry, replace the placeholder with the download token.

```sh
kubectl create secret docker-registry docker-cke-cs-com \
	--docker-username "ai-service" \
	--docker-server "https://docker.cke-cs.com" \
	--docker-password="<PASSWORD>"
```

<a id="running-the-standalone-scenario">

## Running the standalone scenario

The standalone scenario runs CKEditor AI On-Premises with a MySQL and single instance of Redis.

Create the `dev.values.yaml` file in the `ai-service-development-stack` directory. Replace the placeholders with your CKEditor AI On-Premises license key, which can be found in [the Customer Portal](https://portal.ckeditor.com/), and with your LLM provider and API key. See [LLM providers](../llm-providers.md) for available providers.

```yaml
ai-service:
  secret:
	data:
	  LICENSE_KEY: '<LICENSE_KEY>'
	  PROVIDERS: '{"openai":{"type":"openai","apiKeys":["<API_KEY>"]}}'
```

Install the chart:

```sh
cd ai-service-development-stack &&
helm dependency update &&
helm install ai-service . --values dev.values.yaml
```

then expose the CKEditor AI On-Premises port

```sh
kubectl port-forward service/ai-service 8000:8080
```

<a id="running-the-scenario-with-collaboration-server">

## Running the scenario with Collaboration Server

This scenario runs CKEditor AI On-Premises and Collaboration Server On-Premises on a shared MySQL and single instance of Redis. See [Collaboration Server integration](../collaboration-server-integration.md) for details.

Create the `dev.values.yaml` file in the `cs-with-ai` directory. Replace the placeholders with your Collaboration Server On-Premises and CKEditor AI On-Premises license keys, and with your LLM provider API key.

```yaml
sharedDatabase: &sharedDatabase
  DATABASE_HOST: cs-with-ai-mysql
  DATABASE_USER: root
  DATABASE_PASSWORD: root-password
sharedRedis: &sharedRedis
  REDIS_HOST: cs-with-ai-redis-master

ckeditor-cs:
  server:
	secret:
	  data:
		<<: [*sharedDatabase, *sharedRedis]
		ENVIRONMENTS_MANAGEMENT_SECRET_KEY: secret
		LICENSE_KEY: '<COLLABORATION_SERVER_LICENSE_KEY>'

ai-service:
  secret:
	data:
	  <<: [*sharedDatabase, *sharedRedis]
	  ENVIRONMENTS_MANAGEMENT_SECRET_KEY: secret
	  LICENSE_KEY: '<AI_SERVICE_LICENSE_KEY>'
	  PROVIDERS: '{"openai":{"type":"openai","apiKeys":["<API_KEY>"]}}'

mysql:
  enabled: true
redis:
  enabled: true
```

Install the chart:

```sh
cd cs-with-ai &&
helm dependency update &&
helm install cs-with-ai . --values dev.values.yaml
```

then expose the Collaboration Server On-Premises and CKEditor AI On-Premises ports

```sh
kubectl port-forward service/cs-with-ai-ckeditor-cs-server 8000 &
kubectl port-forward service/cs-with-ai-ai-service 8001:8080
```

**Note: This is not a production-ready solution. To expose the application to the public in a production environment use a proper proxy configuration.**

<a id="deleting-installation">

## Deleting installation

The command below will stop and remove all pods which were started during the tutorial.

```sh
helm delete ai-service
```

For the scenario with Collaboration Server, use `helm delete cs-with-ai`.

<a id="customizing-scenario">

## Customizing scenario

You can adjust the example configuration to your needs by modifying the `values.yaml` file in the `.../kubernetes/helm/ai-service/` directory.

---

Full index of the Cloud Services documentation: [llms.txt](../../../../llms.txt)
