@NTUST
# ONAP - Based [I] SMO Deployment
###### tags: `osc` `smo`
:::info
**Outline:**
[TOC]
**Reference:**
- [OSC SMO 部屬教學 by NYCU](https://hackmd.io/@KflrygviTAa4Bw7zSKk2CA/H1kOzqEv6)
- [ONAP - Based \[H\] SMO Deployment](https://hackmd.io/Cf5E97XqTXSr00xC7bzfeA?view)
:::
## Environment
### Minimum Requirements
:::success
- **Hardware**
```
6 or more CPU cores
28+ GB of RAM
50 GB of Disk
```
- **Software**
```
Ubuntu 22.04 server
Kubernetes v1.27.5
python3 3.10.12 # Version should upper or equal to 3.9
```
:::
## Prerequisite
### 1. Install Kubernetes with kubespray
```bash=
python3 --version # Version should upper or equal to 3.9
apt install -y python3-pip
git clone https://github.com/kubernetes-sigs/kubespray -b release-2.23
cd kubespray
pip install -r requirements.txt
sed -i 's/\(kube_version: \)[^"]*/\1v1.27.5/' inventory/local/group_vars/k8s_cluster/k8s-cluster.yml
ansible-playbook -i inventory/local/hosts.ini --become --become-user=root cluster.yml
mkdir -p ~/.kube/config
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
```
## Deployment
### 1. Download the IT/dep repository from gerrit
```bash=
# Latest version
cd ~
git clone https://gerrit.o-ran-sc.org/r/it/dep.git -b master --recursive
```
:::warning
:bulb: **Note:** You need to ==add the recurse sub modules flag== as some parts are git submodules pointing to existing related charts (ONAP)
:::
### 2. Setup Helm Charts
- Execute the following commands being logged as root.
```bash=
cd dep
##Setup ChartMuseum
./smo-install/scripts/layer-0/0-setup-charts-museum.sh
##Setup HELM3
./smo-install/scripts/layer-0/0-setup-helm3.sh
## Build ONAP/ORAN charts
./smo-install/scripts/layer-1/1-build-all-charts.sh
```
### 3. Deploy components
- Execute the following commands ==being logged as root==:
```bash=
./smo-install/scripts/layer-2/2-install-oran.sh
```
### 4. Wait for pod finished
```bash=
kubectl get pods -n onap && kubectl get pods -n nonrtric
```
### 5. Result

## Deployment of dmaap-InfluxDB-adapter, InfluxDB and Grafana
<!-- :::info
**Reference:**
- [O1VES使用說明](https://hackmd.io/Hw7LhuyuTzWFNifY2g0tFQ?view)
- [[F] SMO to [G] O-DU Slice Enable Scheduler with O1 Enable](https://hackmd.io/@H141319/BkYwSCVSh)
- [Deployment of dmaap-InfluxDB-adapter, InfluxDB and Grafana](https://hackmd.io/lZK4w7EdTiyH-So34_FZRw?both#Deployment-of-dmaap-InfluxDB-adapter-InfluxDB-and-Grafana)
- Here I use Helm to deploy.
::: -->
### 0. Pre-Request
- Finished the installation of ONAP SMO.
### 1. Deploy
- Helm repo add and install
```bash=
helm repo add winlab https://harbor.winfra.cs.nycu.edu.tw/chartrepo/winlab-oran
helm install --namespace=o1ves o1ves winlab/o1ves-visualization --create-namespace
```
:::warning
:red_circle: **NOTE:** Using a release name other than o1ves may cause unexpected errors.
:::
### 2. Edit the values.yaml file
```bash=
helm show values winlab/o1ves-visualization > values.yaml
```
:::info
- Modify the **rules**.
- Add buckets to automatically create influxdb buckets.
:::
#### `values.yaml`
:::spoiler Example `values.yaml`
```yaml=
fullnameOverride: o1ves
grafana:
fullnameOverride: o1ves-grafana
enabled: true
defaultDashboardsTimezone: Asia/Taipei
adminPassword: smo
service:
type: NodePort
nodePort: 30000
persistence:
enabled: true
storageClassName: "local-storage-grafana"
size: 10Gi
influxdb2:
fullnameOverride: o1ves-influxdb2
enabled: true
persistence:
enabled: true
storageClass: "local-storage-influxdb2"
accessMode: ReadWriteOnce
size: 50Gi
mountPath: /var/lib/influxdb2
subPath: ""
image:
repository: influxdb
tag: 2.3.0-alpine
pullPolicy: IfNotPresent
dmaap-influxdb-adapter:
enabled: true
image:
repository: harbor.winfra.cs.nycu.edu.tw/winlab-oran/dmaap-influxdb-adapter
influxdb:
host: o1ves-influxdb2
port: 80
tokenSecret: o1ves-influxdb2-auth
org: influxdata
logLevel: DEBUG
rules:
- topic: unauthenticated.SEC_FAULT_OUTPUT
rules:
- bucket: influxdb
measurement: fault
matches:
- key: event.commonEventHeader.domain
value: fault
tags:
- key: type
value: test
- key: sourceId
field: event.commonEventHeader.sourceId
fields:
- key: faultFieldsVersion
field: event.faultFields.faultFieldsVersion
type: string
buckets:
- name: influxdb
image:
pullPolicy: IfNotPresent
```
:::
<br>
In this case, we use this `values_Akmal.yaml` file.
```yaml=
dmaap-influxdb-adapter:
image:
pullPolicy: Always
logLevel: DEBUG
rules:
- topic: unauthenticated.VES_MEASUREMENT_OUTPUT
rules:
- bucket: my-bucket
measurement: slice-measurement
matches:
- key: event.commonEventHeader.domain
value: stndDefined
tags:
- key: vendor
value: ntust-taiwan-lab
- key: sourceName
field: event.commonEventHeader.sourceName
fields:
- key: avg-throughput-downlink
field: event.stndDefinedFields.data.measurements[0].value
type: int
- key: ue-avg-mcs-index
field: event.stndDefinedFields.data.measurements[1].value
type: float
buckets:
- name: my-bucket
```
### Delete
```bash=
helm uninstall --namespace o1ves o1ves
kubectl delete ns o1ves
sudo rm -r /dockerdata-nfs/o1ves-*
```
:::warning
#### :red_circle: **NOTE:**
- If you edit the `values.yaml` , you need to **upgrade the pod** or delete and redeploy.
```bash=
## Upgrade
helm upgrade --namespace=o1ves o1ves winlab/o1ves-visualization --create-namespace -f value2.yml
## Redeploy
helm uninstall --namespace o1ves o1ves
kubectl delete ns o1ves
sudo rm -r /dockerdata-nfs/o1ves-*
helm install --namespace=o1ves o1ves winlab/o1ves-visualization --create-namespace -f values.yaml
```
- You can write a ves event then use this command to test sent the event to influxdb.
```bash=
curl -X POST \
-H 'Content-Type: application/json' \
-u sample1:sample1 \
-d @file.json \
https://192.168.8.12:30417/eventListener/v7
```
- Check whether influxdb-adapter receive the event or not.
```bash=
kubectl logs -n o1ves o1ves-dmaap-influxdb-adapter-64cf8bf7b8-qf6sg
```
:::
### InfluxDB, Grafana Web UI and Set InfluxDB Data Source
#### InfluxDB Web UI
- http://<server-ip/>:30001
> Here we use http://192.168.8.12:30001
- username and password : (admin/)
:::warning
- Use this command to find the password.
```bash=
kubectl get secret -n o1ves o1ves-influxdb2-auth -o json
# find the password then echo
echo OGMwdDRYRG1xUXNyR29BQ3hCZFdVZkZGeGJqUlRpTlc= | base64 -d
```
- If InfluxDB port didn't open, you can refer this.
```bash=
kubectl edit svc -n o1ves o1ves-influxdb2
# line 33 add: nodePort:30001
# line 41 type change to NodePort
```
:::
#### Grafana Web UI
- http://<server-ip/>:30000
> Here we use http://192.168.8.12:30000
- username and password : (admin/smo)
#### Set influxdb data source
- Go Administration/Data sources you will see InfluxDB default.
- Check the seeting:
- Query Language: Flux
- URL: http://o1ves-influxdb2.o1ves
- Auth
- Basic auth: Disable
- InfluxDB Details
- Organization: influxdb
- Token: my-token
- Save & test
### Result
- Check pods are running

- InfluxDB Web UI

- Grafana Web UI

<!-- ## Error Record
### Error 01: Pod in CrashLoopBackoff (Kubernetes DNS issue)
:::danger
#### Pod keep in CrashLoopBackoff (Kubernetes DNS issue)

:::success
#### Solution:
> Reference: [解決Ubuntu能Ping到 DNS卻無法解析域名](https://hackmd.io/@CynthiaChuang/Fix-Can-Ping-to-DNS-but-Cannot-Resolve-Domain-Name)、[用resolvconf配置DNS服务器](https://note.qidong.name/2020/05/resolvconf/)、[Ubuntu解決DNS問題](https://hackmd.io/ktU2eAjgQRubeeOVk0j1VA#Ubuntu%E8%A7%A3%E6%B1%BADNS%E5%95%8F%E9%A1%8C)
:warning: **Before installing resolvconf, please temporarily set the DNS file, otherwise the installation will fail.**
- Modify /etc/resolv.conf
```bash=
sudo vim /etc/resolv.conf
```
- Add nameserver:
```bash=
nameserver 8.8.8.8
```
---
1. Install resolvconf
```bash=
sudo apt install resolvconf
```
2. Modify `/etc/resolvconf/resolv.conf.d/head` file to add nameserver
```bash=
sudo vim /etc/resolvconf/resolv.conf.d/head
```
```=
# Google IP
nameserver 8.8.8.8
# router IP
nameserver 192.168.8.9
```
3. Update the resolv.conf file based on the current DNS configuration.
```bash=
sudo resolvconf -u
```
4. Restart NetworkManager.service and check the DNS configuration is exists.
```bash=
sudo systemctl restart NetworkManager.service
cat /etc/resolv.conf
```
5. Ping URL to test if is work
```bash=
ping www.google.com
```
::: -->