# Manually create and use an NFS Linux Server volume with AKS
###### tags: `Technical` `Azure` `AKS` `Container` `NFS`
開一台Ubuntu 虛機,建立一個nfs-server-setup.sh的檔案,將下方指令貼進去
```bash
#!/bin/bash
# This script should be executed on Linux Ubuntu Virtual Machine
EXPORT_DIRECTORY=${1:-/export/data}
DATA_DIRECTORY=${2:-/data}
AKS_SUBNET=${3:-*}
echo "Updating packages"
apt-get -y update
echo "Installing NFS kernel server"
apt-get -y install nfs-kernel-server
echo "Making data directory ${DATA_DIRECTORY}"
mkdir -p ${DATA_DIRECTORY}
echo "Making new directory to be exported and linked to data directory: ${EXPORT_DIRECTORY}"
mkdir -p ${EXPORT_DIRECTORY}
echo "Mount binding ${DATA_DIRECTORY} to ${EXPORT_DIRECTORY}"
mount --bind ${DATA_DIRECTORY} ${EXPORT_DIRECTORY}
echo "Giving 777 permissions to ${EXPORT_DIRECTORY} directory"
chmod 777 ${EXPORT_DIRECTORY}
parentdir="$(dirname "$EXPORT_DIRECTORY")"
echo "Giving 777 permissions to parent: ${parentdir} directory"
chmod 777 $parentdir
echo "Appending bound directories into fstab"
echo "${DATA_DIRECTORY} ${EXPORT_DIRECTORY} none bind 0 0" >> /etc/fstab
echo "Appending localhost and Kubernetes subnet address ${AKS_SUBNET} to exports configuration file"
echo "/export ${AKS_SUBNET}(rw,async,insecure,fsid=0,crossmnt,no_subtree_check)" >> /etc/exports
echo "/export localhost(rw,async,insecure,fsid=0,crossmnt,no_subtree_check)" >> /etc/exports
nohup service nfs-kernel-server restart
```
```bash
sudo bash nfs-server-setup.sh
chmod +x ~/nfs-server-setup.sh
```
[https://docs.microsoft.com/en-us/azure/aks/azure-nfs-volume](https://docs.microsoft.com/en-us/azure/aks/azure-nfs-volume)
在AKS上掛接Persistent Volume
```yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: faminfs
labels:
type: nfs
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
server: 10.240.0.7
path: /export
```
```yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: faminfs
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
resources:
requests:
storage: 1Gi
selector:
matchLabels:
type: nfs
```
[https://ithelp.ithome.com.tw/articles/10214707](https://ithelp.ithome.com.tw/articles/10214707)
1. 建立一個會寫log的app
2. 包成container上傳到docker hub
3. 部署yaml到k8s
會寫log的flask api => app.py
```python
from flask import Flask
import os
import time
import logging
app = Flask(__name__)
@app.route("/")
def hello_world():
now = str(time.time())
FORMAT = '%(asctime)s [%(levelname)s]: %(funcName)s %(message)s'
logging.basicConfig(
filename="/mnt/faminfs/pyflask_{}.log".format(now),
filemode='a',
level=logging.INFO,
format=FORMAT
)
logging.info("We Are Family")
f = open('/mnt/faminfs/test_{}.txt'.format(now),'w')
f.write(now + '[Info] Processed We Are Family { Latitude: 25, Longitude: 134 } in 034 ms.')
f.close()
return "<p>We Are Family!!!</p>"
```
本機測試
```bash
docker run -it --name flask python:3.6-slim /bin/bash
```
Docker File
```docker
FROM python:3.6-slim
WORKDIR /app
COPY . /app/
RUN pip install -r requirements.txt --src /usr/local/src
COPY . .
EXPOSE 5000
CMD [ "flask", "run", "--host=0.0.0.0" ]
```
建立docker image
```bash
docker build -t familog .
```
[https://ithelp.ithome.com.tw/articles/10192397](https://ithelp.ithome.com.tw/articles/10192397)
執行測試
```bash
docker run -v "系統路徑":"docker內路徑" -p 5000:5000 familog
```
## 壓測工具
jmeter
[https://jmeter.apache.org/](https://jmeter.apache.org/)
[https://ithelp.ithome.com.tw/articles/10203900?sc=hot](https://ithelp.ithome.com.tw/articles/10203900?sc=hot)
## 本地壓測
教學網站
[https://ithelp.ithome.com.tw/articles/10233147](https://ithelp.ithome.com.tw/articles/10233147)
AKS Test ap
[http://20.198.192.140:5000/](http://20.198.192.140:5000/)
執行指令
```bash
ab -n 10000 -c 100 http://localhost:5000/
```
測試結果
```bash
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: localhost
Server Port: 49155
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 137.388 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 72.79 [#/sec] (mean)
Time per request: 1373.883 [ms] (mean)
Time per request: 13.739 [ms] (mean, across all concurrent requests)
Transfer rate: 12.58 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.5 1 11
Processing: 43 1370 267.8 1332 2708
Waiting: 22 1366 268.1 1329 2708
Total: 44 1370 267.8 1333 2709
Percentage of the requests served within a certain time (ms)
50% 1333
66% 1399
75% 1440
80% 1477
90% 1675
95% 1931
98% 2136
99% 2243
100% 2709 (longest request)
```
## 推送到雲端
docker push w24351789/familog:tagname
**Configure a Pod to Use a PersistentVolume for Storage**
[https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/](https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/)
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: familog-deployment
labels:
app: familog
spec:
replicas: 3
selector:
matchLabels:
app: familog
template:
metadata:
labels:
app: familog
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: faminfs
containers:
- name: familog
image: w24351789/familog
ports:
- containerPort: 5000
volumeMounts:
- mountPath: "/mnt/faminfs"
name: task-pv-storage
---
apiVersion: v1
kind: Service
metadata:
name: familog-service
spec:
ports:
- port: 5000
protocol: TCP
targetPort: 5000
selector:
app: familog
type: LoadBalancer
```
## 雲端壓測
1000 10
```python
Benchmarking 20.198.192.140 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 10
Time taken for tests: 62.136 seconds
Complete requests: 1000
Failed requests: 0
Total transferred: 177000 bytes
HTML transferred: 23000 bytes
Requests per second: 16.09 [#/sec] (mean)
Time per request: 621.365 [ms] (mean)
Time per request: 62.136 [ms] (mean, across all concurrent requests)
Transfer rate: 2.78 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 43 62 6.2 61 85
Processing: 69 555 36.7 554 677
Waiting: 47 331 152.9 330 677
Total: 133 617 37.2 617 734
Percentage of the requests served within a certain time (ms)
50% 617
66% 623
75% 631
80% 634
90% 648
95% 660
98% 669
99% 674
100% 734 (longest request)
```
10000 10
```python
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 10
Time taken for tests: 618.037 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 16.18 [#/sec] (mean)
Time per request: 618.037 [ms] (mean)
Time per request: 61.804 [ms] (mean, across all concurrent requests)
Transfer rate: 2.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 62 11.8 61 1075
Processing: 58 556 40.4 552 1557
Waiting: 47 337 153.2 357 1550
Total: 125 618 42.9 613 1616
Percentage of the requests served within a certain time (ms)
50% 613
66% 619
75% 624
80% 626
90% 635
95% 646
98% 670
99% 692
100% 1616 (longest request)
```
10000 100 (1 pod)
```python
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 616.324 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 16.23 [#/sec] (mean)
Time per request: 6163.243 [ms] (mean)
Time per request: 61.632 [ms] (mean, across all concurrent requests)
Transfer rate: 2.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 61 6.6 61 182
Processing: 68 6069 374.1 6071 7240
Waiting: 53 3089 1754.6 3078 7230
Total: 130 6131 374.3 6132 7310
Percentage of the requests served within a certain time (ms)
50% 6132
66% 6156
75% 6178
80% 6199
90% 6272
95% 6355
98% 6497
99% 6737
100% 7310 (longest request)
```
10000 100 (5 pods)
```python
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 619.635 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 16.14 [#/sec] (mean)
Time per request: 6196.350 [ms] (mean)
Time per request: 61.964 [ms] (mean, across all concurrent requests)
Transfer rate: 2.79 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 41 62 21.0 61 1080
Processing: 63 6100 430.4 6070 7351
Waiting: 63 3543 1712.3 3577 7327
Total: 121 6162 431.2 6131 7411
Percentage of the requests served within a certain time (ms)
50% 6131
66% 6163
75% 6192
80% 6208
90% 6285
95% 6774
98% 7267
99% 7292
100% 7411 (longest request)
```
測試變因
同虛網壓測
雲對雲
```json
C:\Users\mike830526\Desktop\Apache24\bin>ab -n 10000 -c 100 http://20.198.192.140:5000/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 27.926 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 358.09 [#/sec] (mean)
Time per request: 279.259 [ms] (mean)
Time per request: 2.793 [ms] (mean, across all concurrent requests)
Transfer rate: 61.90 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 5.9 0 31
Processing: 0 275 23.9 281 344
Waiting: 0 173 72.6 188 328
Total: 16 278 23.9 281 344
Percentage of the requests served within a certain time (ms)
50% 281
66% 281
75% 297
80% 297
90% 297
95% 313
98% 313
99% 328
00% 344 (longest request)
```
nfs規格
premium ssd p30 iops5000
雲對雲
```json
C:\Users\mike830526\Desktop\Apache24\bin>ab -n 10000 -c 100 http://20.198.192.140:5000/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 30.566 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 327.16 [#/sec] (mean)
Time per request: 305.660 [ms] (mean)
Time per request: 3.057 [ms] (mean, across all concurrent requests)
Transfer rate: 56.55 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 30.7 0 3016
Processing: 0 301 299.7 266 3328
Waiting: 0 193 279.5 172 3267
Total: 0 304 301.2 281 3328
Percentage of the requests served within a certain time (ms)
50% 281
66% 281
75% 281
80% 281
90% 297
95% 313
98% 313
99% 3266
100% 3328 (longest request)
```
地對雲
10000 100
```yaml
C:\Users\TED\Downloads\httpd-2.4.49-win64-VS16\Apache24\bin>ab -n 10000 -c 100 http://20.198.192.140:5000/
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 612.556 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 16.33 [#/sec] (mean)
Time per request: 6125.556 [ms] (mean)
Time per request: 61.256 [ms] (mean, across all concurrent requests)
Transfer rate: 2.82 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 40 61 6.8 61 191
Processing: 61 6032 368.9 6044 7172
Waiting: 52 3087 1745.2 3081 7100
Total: 121 6093 369.2 6105 7233
Percentage of the requests served within a certain time (ms)
50% 6105
66% 6133
75% 6156
80% 6172
90% 6213
95% 6243
98% 6296
99% 6696
100% 7233 (longest request)
```
升級node節點到d8
```json
This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 20.198.192.140 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Werkzeug/2.0.1
Server Hostname: 20.198.192.140
Server Port: 5000
Document Path: /
Document Length: 23 bytes
Concurrency Level: 100
Time taken for tests: 607.560 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1770000 bytes
HTML transferred: 230000 bytes
Requests per second: 16.46 [#/sec] (mean)
Time per request: 6075.598 [ms] (mean)
Time per request: 60.756 [ms] (mean, across all concurrent requests)
Transfer rate: 2.85 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 40 61 7.4 61 165
Processing: 53 5984 365.7 6002 7098
Waiting: 47 3035 1735.2 3033 7019
Total: 114 6045 366.0 6062 7156
Percentage of the requests served within a certain time (ms)
50% 6062
66% 6086
75% 6103
80% 6115
90% 6141
95% 6163
98% 6198
99% 6628
100% 7156 (longest request)
```
azure file
write console
[Manually create and use a volume with Azure Files share in AKS](https://www.notion.so/Manually-create-and-use-a-volume-with-Azure-Files-share-in-AKS-65d35512b1a94d4796824a0c17e94c8a)
[Final Test Result](https://www.notion.so/Final-Test-Result-d5b88b4d77664d13b4415c0dd5e5c16b)
[Linux VM to NFS](https://www.notion.so/Linux-VM-to-NFS-245484e3be6f49a7b628ea6b52a58477)
[1/7 AKS 第二次提問](https://www.notion.so/1-7-AKS-14432240c5074e388e856d0ca13d69c5)