@NTUST
# [F Release] Installation Guide of Near-RT RIC Platform
###### tags:`F Release`
>[name=Tori Zhang][time=Sat, July 2, 2022 19:00 ][color=#178BD4]
:::info
**Introduction:**
Near-RT RIC includes RIC Platform and xApp. If we want to run the xApp in Near-RT RIC, we need to install platform first.
**Gaol:**
- [x] [Install Near-RT RIC in F Release](#26-Check-the-Status-of-Near-RT-RIC-deployment)
**Reference:**
- [Installation Guides](https://docs.o-ran-sc.org/projects/o-ran-sc-ric-plt-ric-dep/en/latest/installation-guides.html#installing-near-realtime-ric-in-ric-cluster)
- [Near-RT RIC Deployment](https://wiki.o-ran-sc.org/display/SIM/Near-RT+RIC+Deployment)
:::
::: warning
**1. Hardware requests:**
- RAM:8G RAM
- CPU:6 core
- Disk:40G Storage
**2. Installation Environment:**
- Host:Windows 10
- Hypervisor:VMware Workstation 16 Player
- VM:Ubuntu 20.04 LTS (Focal Fossa)
**3. Platform Environment:**
- Kubernetes:1.16.0
- Kubernetes - CNI:0.7.5
- Helm:3.5.4
- Docker:20.10.12
**4. Important updates in RIC Platform:**
- The os version update from Ubuntu 18.04 to Ubuntu 20.04
- The deployment of RIC Platform is possible without the it/dep repo
:::
:::success
**Installation Date:**
- First Installation:**2022/07/02 (Sat)**
- First Verification by Yueh-Huan on July 3, 2022
- Second Verification by Ming on July 4, 2022
- Third Verification:
- Ming re-install the Near-RT RIC in Lab VM on July 8, 2022, there are some new Problems. => Solved
- 1st modify the Installation first:**2022/07/14 (Thur) and 2022/08/31 (Wed)**
- I Fix the version problem of flannel component in k8s installation in 07/14
- The OSC fix the problem in 08/15 (Mon), so I remove the modification part about it in 08/31, we can use osc source code directly.
- The OSC also solve the problem of kubernetes-helm/tiller, so I remove the modification part about it in 08/31, we can use osc source code directly.
- 2nd modify the Installation:**2023/04/27 (Thur)**
- The docker version is updated from 20.10.12 to 20.04.1, the OSC had updated this issue in the latest branch, so we need to [modify it](#12-Download-the-source-code-of-RIC-Platform) here by ourselves.
:::
[toc]
::: spoiler VMware Installation and VM Creation ( If you don't know how to create the vm, you can reference it.)
### Step 1:Download VMware
==Enter [website](https://www.vmware.com/tw/products/workstation-player.html) and download Workstation Player==



### Step 2:Download Ubuntu 20.04
==Enter [website](https://releases.ubuntu.com/focal/) and download desktop image==

### Step 3:Install Virtual Machine
==Create a New virtual Machine==

==Select the image files that we have downloaded Ubuntu 20.04==

==Enter the hostname and user name : myric==

==Set whatever you want==

==Hardware setting==




- Check VM Setting and start the installation
==Wait the installation and get into next step==

:::
## 1. Install the Docker, Kubernetes and Helm 3
**Open terminate (Ctrl+Alt+T):**

**Become root user:**
==Note:== All the commands need to be executed as root.
``` shell=
sudo -i
```

### 1.1 Install the Dependent Tools
``` shell=
apt-get update
apt-get install -y git vim curl net-tools openssh-server python3-pip nfs-common
```

### 1.2 Download the source code of RIC Platform
``` shell=
cd ~
git clone https://gerrit.o-ran-sc.org/r/ric-plt/ric-dep -b f-release
```

**Modify the docker version :**
``` shell=
cd ric-dep/bin
vim install_k8s_and_helm.sh
```

``` shell=
vim install_k8s_and_helm.sh
```

- You can delete old file and create new file, then copy the following codes to the new one.
- filname:
- install_k8s_and_helm.sh
``` shell=
#!/bin/bash
################################################################################
# Copyright (c) 2022 Nokia. #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
################################################################################
echo "Installing servecm (Chart Manager) and common templates to helm3"
helm plugin install https://github.com/jdolitsky/helm-servecm
eval $(helm env |grep HELM_REPOSITORY_CACHE)
echo ${HELM_REPOSITORY_CACHE}
# servecm can download chartmuseum binary, but the hardcoded location does not work anymore
# so, we download it now before starting servecm, so that it's available when servecm
# tries to start the chartmuseum binary
curl -LO https://get.helm.sh/chartmuseum-v0.15.0-linux-386.tar.gz
tar xzvf chartmuseum-v0.15.0-linux-386.tar.gz
chmod +x ./linux-386/chartmuseum
cp ./linux-386/chartmuseum /usr/local/bin
nohup helm servecm --port=8879 --context-path=/charts --storage local --storage-local-rootdir $HELM_REPOSITORY_CACHE/local/ <<EOF &
yes
EOF
CURL_CMD="curl --silent --output /dev/null http://127.0.0.1:8879/charts"
`${CURL_CMD}`
READY=$?
while [ ${READY} != 0 ]; do
echo "servecm not yet running. sleeping for 2 seconds"
sleep 2
`${CURL_CMD}`
READY=$?
done
echo "servcm up and running"
eval $(helm env |grep HELM_REPOSITORY_CACHE)
echo ${HELM_REPOSITORY_CACHE}
mkdir -p "${HELM_REPOSITORY_CACHE}/local/"
export COMMON_CHART_VERSION=$(cat ../ric-common/Common-Template/helm/ric-common/Chart.yaml | grep version | awk '{print $2}')
helm package -d /tmp ../ric-common/Common-Template/helm/ric-common
cp /tmp/ric-common-${COMMON_CHART_VERSION}.tgz "${HELM_REPOSITORY_CACHE}/local/"
helm repo remove local
helm repo add local http://127.0.0.1:8879/charts
echo "checking that ric-common templates were added"
helm search repo local/ric-common
```
### 1.3 Execute the Installation Script of the Docker, Kubernetes and Helm 3
``` shell=
./install_k8s_and_helm.sh
```

### 1.4 Check the Status of Kubernetes deployment
``` shell=
kubectl get pods -n kube-system
```

## 2. Install the Near-RT RIC Platform
### 2.1 Add the ric-common templates
``` shell=
./install_common_templates_to_helm.sh
```

``` shell=
./setup-ric-common-template
```

### 2.2 [Edit Deployment Configuration](https://hackmd.io/@Min-xiang/S1o407hqc)
### 2.3 Install nfs for InfluxDB
``` shell=
kubectl create ns ricinfra
helm repo add stable https://charts.helm.sh/stable
helm install nfs-release-1 stable/nfs-server-provisioner --namespace ricinfra
kubectl patch storageclass nfs -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
sudo apt install nfs-common
```
### 2.4 Execute the Installation Script of Near-RT RIC
**Find your IP of VM:**
``` shell=
ip a
```

**Modify the IP of RIC and AUX:**
``` shell=
vim ~/ric-dep/RECIPE_EXAMPLE/example_recipe_oran_f_release.yaml
```

**Deploy the RIC Platform:**
``` shell=
cd ~/ric-dep/bin
./install -f ../RECIPE_EXAMPLE/example_recipe_oran_f_release.yaml -c "jaegeradapter influxdb"
```

### 2.5 Check the Status of Near-RT RIC deployment
- Results similar to the output shown below indicate a complete and successful deployment, **all are either “Completed” or “Running”**, and that none are “Error”, “Pending”, “Evicted”,or “ImagePullBackOff”.
- The status of pods **"PodInitializing" & "Init" & "ContainerCreating"** mean that the pods are creating now, you need to wait for deploying.
``` shell=
kubectl get pods -A
```

## 3. Install the DMS Tool
### 3.1 Install the Chartmuseum for DMS Tool
**Customized Setting:**
``` shell=
cd ~
vim chart.yaml
```
- Press "i" to edit the following content
``` shell=
env:
open:
STORAGE: local
CONTEXT_PATH: /charts
DISABLE_API: false
persistence:
enabled: true
accessMode: ReadWriteOnce
size: 8Gi
storageClass: nfs
service:
type: NodePort
```

- Press "Esc" and ":wq" to save
**Install Chatmuseum:**
``` shell=
helm install r4-chartmuseum stable/chartmuseum -f chart.yaml --namespace ricinfra
```

**Verify the IP and Port:**
``` shell=
export NODE_PORT=$(kubectl get --namespace ricinfra -o jsonpath="{.spec.ports[0].nodePort}" services r4-chartmuseum-chartmuseum)
export NODE_IP=$(kubectl get nodes --namespace ricinfra -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/
```

### 3.2 Install the DMS tool
**Prepare source code:**
``` shell=
git clone https://gerrit.o-ran-sc.org/r/ric-plt/appmgr -b f-release
```

**Install DMS tool:**
``` shell=
cd ~/appmgr/xapp_orchestrater/dev/xapp_onboarder
pip3 install ./
```

## Appendix
### Uninstall Near-RT RIC Platform
```bash=
cd ~/ric-dep/bin
./uninstall
```
### Script to Deploy RIC Platform quickly
```shell=
sudo -i
touch Deploy_RIC-Platform_F-Relese.sh
chmod +x Deploy_RIC-Platform_F-Relese.sh
vim Deploy_RIC-Platform_F-Relese.sh
```
```bash=
#!/bin/sh
# -----------------------------------
echo "===> Install the Dependent Tools"
apt-get update
apt-get install -y git vim curl net-tools openssh-server python3-pip nfs-common
# -----------------------------------
echo "===> Install the Docker, Kubernetes and Helm 3"
cd ~
git clone https://github.com/ToriRobert/nRT-RIC_Installation.git -b release-f ric-dep
cd ~/ric-dep/bin
./install_k8s_and_helm.sh
kubectl get pods -n kube-system
# -----------------------------------
echo "===> Add the ric-common templates"
./install_common_templates_to_helm.sh
./setup-ric-common-template
# -----------------------------------
echo "===> Install nfs for InfluxDB"
kubectl create ns ricinfra
helm repo add stable https://charts.helm.sh/stable
helm install nfs-release-1 stable/nfs-server-provisioner --namespace ricinfra
kubectl patch storageclass nfs -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
sudo apt install nfs-common
# -----------------------------------
echo "===> Install the Near-RT RIC Platform"
cd ~/ric-dep/bin
./install -f ../RECIPE_EXAMPLE/example_recipe_oran_f_release.yaml -c "jaegeradapter influxdb"
kubectl get pods -A
# -----------------------------------
echo "===> Install the DMS Tool"
cd ~/ric-dep
helm install r4-chartmuseum stable/chartmuseum -f chart.yaml --namespace ricinfra
export NODE_PORT=$(kubectl get --namespace ricinfra -o jsonpath="{.spec.ports[0].nodePort}" services r4-chartmuseum-chartmuseum)
export NODE_IP=$(kubectl get nodes --namespace ricinfra -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/
cd ~
git clone https://gerrit.o-ran-sc.org/r/ric-plt/appmgr -b f-release
cd ~/appmgr/xapp_orchestrater/dev/xapp_onboarder
pip3 install ./
```
``` shell=
./Deploy_RIC-Platform_F-Relese.sh
```
### Issues of InfluxDB & NFS
**Issue 1:Pod is Crashbackoff**
``` shell=
Warning FailedMount 110s kubelet MountVolume.SetUp failed for volume "pvc-759e2292-6938-4b8e-b6e3-67bbf9b7b904" : mount failed: exit status 32
```
- Solution:Re-install the dependent tools
``` shell=
apt-get install -y nfs-common
```
**Issue 2:Unauthorized**
- If the xApp need to access the InfluxDB, it maybe need to login-in by using user/password
``` shell=
Error: raise InfluxDBClientError(err_msg, response.status_code) influxdb.exceptions.InfluxDBClientError: 401: {"code":"unauthorized","message":"Unauthorized"}
```
- Solution:Modify the user/password in the xApp code
Step 1:Enter the secret of InfluxDB
``` shell=
kubectl get secret -n ricplt
kubectl edit secret -n ricplt <InfluxDB secret>
```
Step 2:Decode the user/password
``` shell=
echo 'amYzOTJoZjc4MmhmOTMyaAo=' | base64 --decode
```
Step 3:Modify the InfluxDB user/password in the xApp using the decoded user/password
### Can't install docker
:::info
- When I ran this command `./install_k8s_and_helm.sh`, it appeared this error

- Can't find this docker version 20.10.12-0ubuntu2~20.04.1
- Command ` apt-get install -y --allow-downgrades --allow-change-held-packages --allow-unauthenticated --ignore-hold docker.io=20.10.12-0ubuntu2~20.04.1`
- error
```shell
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Version '20.10.12-0ubuntu2~20.04.1' for 'docker.io' was not found
```
:::
:::success
- **solution**
- Install master version
```javascript=
git clone https://gerrit.o-ran-sc.org/r/ric-plt/ric-dep -b master
```
- Because the version of docker becomes 20.10.21-0ubuntu1~20.04.2
- After cloning the master version, ensure that you have already installed the new version of Docker. However, make sure to switch back to the 'f' release using 'gic checkout' after completing the Docker installation.
:::warning
- ***Remind (important):***
After successfully installing the step 2.1, remember to switch the branch to f-release, or your influxdb version will be wrong and a1mediator will crash.
- False influxdb

- Correct influxdb

:::