---
# System prepended metadata

title: wekan 架設流程
tags: [規格書]

---

# wekan wsl架設流程
> 前言
>1. 這只是簡單的教學只適用於測試環境，實際公司部屬規則更嚴謹，看完教學後還是    要去了解docker跟minikube的詳細操作方式
>2. 部屬時依照需求可以架設在實體或雲端伺服器
>3. 如果環境部屬過的可以直接跳到wekan架設的部分
# 環境部署
## 1. **開啟虛擬化和windows子系統**
> 控制台 -> 系統及安全性 -> 程式集 -> 開啟或關閉windows功能
- ![1713392542333](https://hackmd.io/_uploads/H18nTaaeC.jpg)
- 或是下指令開啟(如果勾選後沒有套用的話)
    
    - **啟用wsl**
    ```
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

    ```
    - **啟用虛擬平台**
    ```
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

    ```
    - **將wsl2設為默認版本**
    ```
    wsl --set-default-version 2
    ```
## 2. 重啟電腦(一定要做)

## 3. **安裝linux發行版(找個自己喜歡的版本就好了，這裡用ubnutu)**
![1713392270800](https://hackmd.io/_uploads/rkykRT6xA.jpg)

## 4. 安裝docker
- **更新 apt**
```
sudo apt update && sudo apt upgrade
```
- **安裝docker(後面所有步驟都在wsl上執行)** 
```
sudo apt install docker.io
```
- **啟動docker**
```
sudo service docker start
```
- **添加用戶到docker**
```
sudo usermod -aG docker username
```
## 6. 安裝minikube
- **下載minikube**
```
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
```
or
```
sudo install minikube-linux-amd64 /usr/local/bin/minikube
```
- **啟動minikube**
```
minikube start --driver=docker
```
>　若要設定其他環境變數讓外部的docker client透過這些參數來連線minikube環境做進階操控。可以參考下列指令
```
# minikube docker-env
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://192.168.99.100:2376
export DOCKER_CERT_PATH=/Users/peihsinsu/.minikube/certs
# Run this command to configure your shell:
# eval $(minikube docker-env)
```
- **查看minikube狀態**
```
minikube status
```
- **安裝kubectl**
```
curl -LO "https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
```
- **查看節點狀態確認部屬環境是否正常運行**
```
kubectl get nodes
```
---
#### ==**環境若沒有正常運行可以參考以下解決方法**==
- **添加用户到 docker 组**
```
sudo usermod -aG docker $USER
newgrp docker
```
- **重啟docker**
```
sudo service docker restart
```
- **重啟minikube**
```
minikube start --driver=docker
```
---
- ==**minikube基本管理指令**==
`minikube dashboard`：啟動一个 web 控制台。
`minikube status`：查看集群狀態。
`minikube stop`：停止 Minikube 集群。
`minikube delete`：刪除 Minikube 集群。
`kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
`:創建Deployment
`kubectl expose deployment hello-minikube --type=NodePort --port=8080
`:發布服務
`minikube service hello-minikube --url
`:獲取服務URL
`minikube start --memory 4096 --cpus 2
`:創建時資源分配
--- 
# wekan架設(正片開始)
## 1. 開設專案資料夾
```
mkdir minikube
cd minikube
mkdir wekan
cd wekan
```
## 創建 MongoDB 的 Deployment 和 Service
> 建立`mongodb-deployment.yaml`文件
```yaml=
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - name: mongodb
        image: mongo:4.2
        ports:
        - containerPort: 27017
          name: mongo
        volumeMounts:
        - name: mongo-storage
          mountPath: /data/db
      volumes:
      - name: mongo-storage
        emptyDir: {}

---
apiVersion: v1
kind: Service
metadata:
  name: mongodb-service
spec:
  ports:
  - port: 27017
    targetPort: 27017
  selector:
    app: mongodb

```
- 部署 MongoDB
```
kubectl apply -f mongodb-deployment.yaml
```
- 補充文件解釋
## 創建 Wekan 的 Deployment 和 Service
>　創建　`wekan-deployment.yaml`　文件
```yaml=
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wekan
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wekan
  template:
    metadata:
      labels:
        app: wekan
    spec:
      containers:
      - name: wekan
        image: quay.io/wekan/wekan
        env:
        - name: MONGO_URL
          value: "mongodb://mongodb-service:27017/wekan"
        - name: ROOT_URL
          value: "http://<your-ip-address>:8080"
        ports:
        - containerPort: 8080
          name: wekan

---
apiVersion: v1
kind: Service
metadata:
  name: wekan-service
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    nodePort: 30001
  selector:
    app: wekan

```
- 部署 Wekan
```
kubectl apply -f wekan-deployment.yaml

```
- 補充文件解釋
## 建立 ingress
> 建立 `wekan-ingress.yaml` 文件
```yaml=

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: wekan-ingress
spec:
  rules:
  - host: testwekan.com
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: wekan-service
            port:
              number: 8080

```
- 部屬ingress
```
kubectl apply -f wekan-ingress.yaml
```
## 查看部屬環境是否正常運行
> 查看service狀態
![1713390538165](https://hackmd.io/_uploads/r1xViAagC.jpg)
> 查看pods狀態
![1713390523415](https://hackmd.io/_uploads/rJH4i0TlA.jpg)

---
## 開啟 minikube tunnel
> minikube tunnel是為了建立一個管道虛擬機外的環境能夠連線到minikube的服務，因此執行後要保持中tunnel與wsl開啟
![1713390499528](https://hackmd.io/_uploads/By6qjApeA.jpg)

## 取得wekan 連線IP
> 要連tunnel後的版本
![1713390489596](https://hackmd.io/_uploads/Sk6zn0pxR.jpg)
