# Kubernetes

Before beginning, make sure you have `kubectl` and `helm` installed.

This README describes the process of setting up the Kubernetes infrastructure used for Gotography.
It should be read from top to bottom and executed in the same order.

## Permissions (permissions.yaml)

Using the administrator's certificate (found on any of the control plane nodes), create the roles to allow administration of the cluster by the team members.

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

```bash
    # Create certificate signing request (client)
    openssl req -new -key <key>.pem -out <user>.csr -subj "/CN=<user>"

    # Sign certificate (server)
    openssl x509 -req -in <user>.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out <user>.crt -days 300
```

The user certificate and key can then be compiled into a `kubectl` compatible configuration.

## Initial configuration (init.yaml)

Create separate namespaces for Gotography, MetalLB and Traefik.

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

## Installation of Traefik

We are using [Traefik](https://traefik.io/traefik/) as our proxy, installed using [helm](https://helm.sh/).

```bash
helm repo add traefik https://traefik.github.io/charts
helm install traefik traefik/traefik --version 23.0.1 --namespace marketminds-traefik --values traefik-values.yaml
```

## Deployment of resources

Now everything is ready for the applications.
It is recommended to follow the file order, especially to provide some local storage to ScyllaDB before deploying that.

```bash
    kubectl apply -f storage.yaml 
    kubectl apply -f postgres.yaml
    kubectl apply -f ai-services.yaml
    kubectl apply -f marketminds.yaml
    kubectl apply -f web.yaml        
```
