---
# System prepended metadata

title: NET Conf 2020 - Lab-4
tags: [.NET Conf 2020, Event]

---

---
title: 'NET Conf 2020 - Lab-4'
disqus: hackmd
---

.NET Conf 2020 - Lab-4
===
## 微服務部署 
>1.部署mongodb
```gherkin=
oc process openshift//mongodb-persistent \
    -p MONGODB_USER=ratingsuser \
    -p MONGODB_PASSWORD=ratingspassword \
    -p MONGODB_DATABASE=ratingsdb \
    -p MONGODB_ADMIN_PASSWORD=ratingspassword | oc create -f -
```
>2.確認是否正常運行
```gherkin=
oc get all
```
>3.查看MongoDB相關網路狀態
```gherkin=
oc get svc mongodb
```
>4.部署Rating應用
```gherkin=
oc new-app https://github.com/ChunPingWang/rating-api.git --strategy=source
```
>5. 查看 Build Config
```gherkin=
oc logs -f bc/rating-api
```
>6.在Web Console中的 Doployment Config->Environment之中的NAME加入下列
```gherkin=
MONGODB_URI
```
>之中的VALUE加入下列
```gherkin=
mongodb://ratingsuser:ratingspassword@mongodb:27017/ratingsdb
```
>亦可用command line 加入環境變數
```gherkin=
oc set env dc/rating-api MONGODB_URI=mongodb://ratingsuser:ratingspassword@mongodb:27017/ratingsdb
```
>7.確定服務是否正常執行，並取得
```gherkin=
oc get svc rating-api
```

>8.部署 rating-web
```gherkin=
oc new-app https://github.com/ChunPingWang/rating-web.git --strategy=source
```
>9.將rating-api設定在rating-web(也可以用Web Console)  
```gherkin=
oc set env dc rating-web API=http://rating-api:8080
```
>10.對外提供服務
```gherkin=
oc expose svc/rating-web
```
>11.查看 rating-web 路由 
```gherkin=
oc get route rating-web
```

>12. 刪除所有應用與服務
```gherkin=
oc delete all --selector app=rating-web
oc delete all --selector app=rating-api
oc delete all --selector template=mongodb-persistent-template
```
###### tags: `Event` `.NET Conf 2020`