Cloudforet minimal installation
Published: 2023-12-04 12:49:06

## Overview

> This is Cloudforet minimum installation. Just for installation disabling lots of components.

> This has new helm values (minimum.yaml file)

```
#############################################
# Minimum deployment for developer
# * Very small CPU, Memory resources (3GB minikube)
# * Disable scheduler, worker
#############################################


spacectl:
  enabled: false
marketplace-assets:
  enabled: false
plugin:
  enabled: true
  scheduler: false
  worker: false
cost-analysis:
  enabled: false
notification:
  enabled: false
statistics:
  enabled: true
  scheduler: false
  worker: false
monitoring:
  enabled: true
  scheduler: false
  worker: false
  rest: false
inventory:
  enabled: true
  scheduler: false
  worker: false
```

## Prerequisites
- AWS EC2 VM (ex. t3.medium 2 cores, 4GB memory, 30GB Disk) 
- [Docker/Docker Desktop](https://docs.docker.com/engine/install/) 
  - If you don't have Docker installed, minikube will return an error as minikube uses docker as the driver.
  - Highly recommend installing **Docker Desktop** based on your OS.
- [Minikube](https://minikube.sigs.k8s.io/docs/start/)
  - Requires minimum **Kubernetes version of 1.21+**.  
- [Kubectl](https://kubernetes.io/docs/tasks/tools/)
- [Helm](https://helm.sh/docs/intro/install/) 
  - Requires minimum **Helm version of 3.11.0+**.
  - If you want to learn more about Helm, refer to [this](https://helm.sh/).


Before diving into the Cloudforet Installation process, start minikube by running the command below. 

At least, 3GB memory is needed


```
minikube start --driver=docker --memory=3000mb
```



## Installation
You can install the Cloudforet by the following the steps below.

### 1) Setting up Helm Chart Repository
This command adds Helm repository.
```bash
helm repo add cloudforet https://cloudforet-io.github.io/charts 
```

This command updates repositories basd on latest version of chart repository.
```bash
helm repo update
```

This command list contents of the repository.
```bash
helm search repo
```

### 2) Create Namespaces

```bash
kubectl create ns spaceone
```
```bash
kubectl create ns spaceone-plugin
```

### 3) Create Role and RoleBinding
First, download the [rbac.yaml](examples/rbac.yaml) file.


The rbac.yaml file basically serves as a means to regulate access to computer or network resources based on the roles of individual users. For more information about RBAC Authorization in Kubernetes, refer to [this](https://kubernetes.io/docs/reference/access-authn-authz/rbac/).

If you are used to downloading files via command-line, run this command to download the file. 
```bash
wget https://raw.githubusercontent.com/cloudforet-io/charts/master/examples/rbac.yaml -O rbac.yaml
```

Next, execute the following command.
```bash
kubectl apply -f rbac.yaml -n spaceone-plugin
```

### 4) Install Cloudforet Chart

> Download helm values.yaml for minimal install

```
wget https://raw.githubusercontent.com/cloudforet-io/charts/master/examples/values/minimum.yaml
```

This command basically let Helm search for the chart named cloudforet in the repository named spaceone.

```bash
helm install cloudforet cloudforet/spaceone -n spaceone -f minimum.yaml
```

After executing the above command, check the status of the pod.

```bash
mzc01-choonhoson@MZC01-CHOONHOSON values % k get pod -n spaceone
NAME                                    READY   STATUS      RESTARTS        AGE
board-6785c9fb6d-dt76q                  1/1     Running     0               3h19m
config-5956655ccc-2j4f5                 1/1     Running     0               3h19m
console-7d4595758b-wbnf4                1/1     Running     0               3h19m
console-api-56f4496f7d-59986            2/2     Running     1 (3h18m ago)   3h19m
console-api-v2-rest-644b847b57-m68tb    2/2     Running     0               3h19m
dashboard-759ccd74b7-d2f6l              1/1     Running     0               3h19m
file-manager-85dbb6c46b-r85gp           1/1     Running     0               3h19m
identity-644b45c8df-49jk8               1/1     Running     0               3h19m
inventory-6bd9df778b-v2t9x              1/1     Running     0               3h19m
mongodb-7fd58fcf75-dzrfg                1/1     Running     0               3h26m
monitoring-5c994d99fc-7wrh2             1/1     Running     0               3h19m
plugin-598865d6dc-mnn2x                 1/1     Running     0               3h19m
redis-646677656f-snnmc                  1/1     Running     0               3h19m
repository-79b7475999-zjznn             1/1     Running     0               3h19m
secret-5d7c9b86bf-24h6v                 1/1     Running     0               3h19m
statistics-5fd4bcb4cc-5w766             1/1     Running     0               3h19m
supervisor-scheduler-84b8b4b659-lwww9   2/2     Running     0               3h19m
```

### 5) Initialize the Configuration  
First, download the [initializer.yaml](examples/initializer.yaml) file.

For more information about the initializer, please refer to the [spaceone-initializer](https://github.com/cloudforet-io/spaceone-initializer).

If you are used to downloading files via command-line, run this command to download the file.
```bash
wget https://raw.githubusercontent.com/cloudforet-io/charts/master/examples/initializer.yaml -O initializer.yaml
```
And execute the following command.
```bash
helm install initializer cloudforet/spaceone-initializer -n spaceone -f initializer.yaml
```

### 6) Set the Helm Values and Upgrade the Chart
Complete the initialization, you can get the system token from the initializer pod logs.

To figure out the pod name for the initializer, run this command first to show all pod names for namespace spaceone.
```bash
kubectl get pods -n spaceone 
```

Then, among the pods shown copy the name of the pod that starts with **initialize-spaceone**.

```
mzc01-choonhoson@MZC01-CHOONHOSON values % k get pod -n spaceone
NAME                                    READY   STATUS      RESTARTS        AGE
board-6785c9fb6d-dt76q                  1/1     Running     0               3h19m
config-5956655ccc-2j4f5                 1/1     Running     0               3h19m
console-7d4595758b-wbnf4                1/1     Running     0               3h19m
console-api-56f4496f7d-59986            2/2     Running     1 (3h18m ago)   3h19m
console-api-v2-rest-644b847b57-m68tb    2/2     Running     0               3h19m
dashboard-759ccd74b7-d2f6l              1/1     Running     0               3h19m
file-manager-85dbb6c46b-r85gp           1/1     Running     0               3h19m
identity-644b45c8df-49jk8               1/1     Running     0               3h19m
initialize-spaceone-6suok-lwhsx         0/1     Completed   0               3h22m
inventory-6bd9df778b-v2t9x              1/1     Running     0               3h19m
mongodb-7fd58fcf75-dzrfg                1/1     Running     0               3h26m
monitoring-5c994d99fc-7wrh2             1/1     Running     0               3h19m
plugin-598865d6dc-mnn2x                 1/1     Running     0               3h19m
redis-646677656f-snnmc                  1/1     Running     0               3h19m
repository-79b7475999-zjznn             1/1     Running     0               3h19m
secret-5d7c9b86bf-24h6v                 1/1     Running     0               3h19m
statistics-5fd4bcb4cc-5w766             1/1     Running     0               3h19m
supervisor-scheduler-84b8b4b659-lwww9   2/2     Running     0               3h19m
```

> To execute the below kubectl logs command, the status of POD(Ex: here initialize-spaceone-6suok-lwhsx) should be Completed . Proceeding with this while the POD is INITIALIZING will give errors

Get the token by getting the log information of the pod with the name you found above.

```bash
kubectl logs initialize-spaceone-6suok-lwhsx -n spaceone

...
TASK [Create project manager role] *************************************************************************************
TASK [Create project viewer role] **************************************************************************************
TASK [Add daily cloud service summary] *********************************************************************************
TASK [Print Admin API Key] *********************************************************************************************
"eyJhbGciOiJSUzI1NiIsIXXXXXXXiKinQe6CTDi5_oSdcwnRsX2PuUkekJKbtmAVvORNVErvY_-pJC_kB9tAYmsKNy31sr00pdNV9tpojmg42QLfS41M1bAFJcrdyRahgLQx32mqWRFTDurz8HrrXw"

FINISHED [ ok=23, skipped=0 ] ******************************************************************************************

FINISH SPACEONE INITIALIZE
```

Open minimum.yaml

```
#############################################
# Minimum deployment for developer
# * Very small CPU, Memory resources (2 cores, 2GB)
# * Disable scheduler, worker
#############################################
console:
  production_json:
    CONSOLE_API:
      ENDPOINT: http://127.0.0.1:8081  # http://ec2_public_ip:8081 for EC2 users
    CONSOLE_API_V2:
      ENDPOINT: http://127.0.0.1:8082  # http://ec2_public_ip:8082 for EC2 users

global:
  shared_conf:
    TOKEN: eyJhbGciOiJSUzI1NiIsInR5cCI6IXXXXXXX__YOUR_TOKEN__S41M1bAFJcrdyRahgLQx32mqWRFTDurz8HrrXw

spacectl:
  enabled: false
marketplace-assets:
  enabled: false
...
```

After editing the `minimum.yaml` file, upgrade the helm chart.


```bash
helm upgrade cloudforet cloudforet/spaceone -n spaceone -f minimum.yaml
```

After upgrading, delete the pods related to the namespace named spaceone.
After upgrading, delete the pods in spaceone namespace that have the label app.kubernetes.io/instance and value cloudforet. 
```bash
kubectl delete po -n spaceone -l app.kubernetes.io/instance=cloudforet
```

### 7) Check the status of the pods
```bash
kubectl get pod -n spaceone
```

If all pods are in `Running` state, the setup is complete.

## Port-forwarding
Installing Cloudforet on minikube doesn't provide any Ingress objects such as Amazon ALB or NGINX ingress controller.
We can use **kubectl port-forward** instead.

Run the following commands for port forwarding.
```bash
# CLI commands
kubectl port-forward -n spaceone svc/console 8080:80 --address='0.0.0.0' &
```

```bash
kubectl port-forward -n spaceone svc/console-api 8081:80 --address='0.0.0.0' &
```

```bash
kubectl port-forward -n spaceone svc/console-api-v2-rest 8082:80 --address='0.0.0.0' &
```

## Start Cloudforet

### Log-In (Sign in for Root Account)
> For EC2 users: open browser with http://your_ec2_server_ip:8080

Open browser (http://127.0.0.1:8080)

| ID | PASSWORD |
|---|---|
| admin | Admin123!@# |