当前位置:网站首页>Deploy netron services through kubernetes and specify model files at startup
Deploy netron services through kubernetes and specify model files at startup
2022-06-11 00:34:00 【xujingyiss】
netron Basic service deployment
Linux Deployed on the server netron The service is very simple . I am using python The way :
# install netron
pip3 install netron
# start-up netron, The default port is 8080, Can pass -p Parameters change
netron
Then you can pass ip:8080 Visited .

When you use it , Select the model file locally to import .
If it is docker Mode deployment , When starting, you need to add --host Parameters , Can be accessed outside the container :
netron --host 0.0.0.0 -p 8080 -b
scene
Because the platform I made , The model file is not local to the user , But on the company's cloud storage . Users can only use various model files in the platform . So in this case , The above deployment method can not meet my requirements , Because the model file cannot be imported !
But there are ways to solve , It's starting up netron Specify the model file path (netron The model file path can be specified in the startup command of ).
in other words , Whenever a user wants to pass netron When viewing the model , I create one through the platform docker Containers , And specify the path of the model ! Because other functions have been used in the project kubernetes 了 , So it is also directly used here kubernetes To create containers , Finally through ingress External exposure services !
Make some customization
By default netron Realization , After opening the model , In the upper left corner , It provides the function of model export , And in my scene , This operation is obviously not allowed , So we need to make some customization .
The way is to github Download source code , Modify the code , For example, delete the export function , Then REPACK , Then deploy in the same way as above .
adopt k8s Create the container and specify the model file at startup
To prevent too many containers from being created , I set that each user can only create one netron Containers , In other words, only one model file can be opened at the same time .
Prepare the image in advance , It's installed inside python Environmental Science , as well as netron.
The startup script
Because I haven't found it yet kubernetes Automatically execute when creating a container netron How to start the command , I tried several ways, but they didn't work , So write the startup command to a shell Script , Before each container creation , Write the startup command in the background code first ( It mainly replaces the model file name ), Then designate kubernetes Execute the script when you start the container .
netron --host 0.0.0.0 -p 8080 -b /netron/test.caffemodel
deployment
When it finally happens pod The name needs to be modified according to the model .
For the sake of simplicity , Posted is yml, Actual background implementation , It's using fabric8, Create... Programmatically deployment,service, as well as ingress. therefore deploymentName,serviceName,ingressName When creating resources in the background , Specified according to different models .
Model files and scripts are placed on the host /data/netron Big catalog , Mount as... In the container when creating the container /netron Catalog .
Specify the script to execute when the container starts start.sh.
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: netron-dep
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: netron-dep
template:
metadata:
labels:
app: netron-dep
spec:
containers:
- image: netron_python:v1.0
imagePullPolicy: IfNotPresent
name: netron-container
command:
- "/bin/bash"
args:
- "/netron/script/user1/start.sh"
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /netron
name: model-path
volumes:
- name: model-path
hostPath:
path: /data/netronservice
Used to access... Within the cluster pod.
apiVersion: v1
kind: Service
metadata:
name: netron-svc
namespace: default
spec:
ports:
- port: 8070
targetPort: 8080
selector:
app: netron-depMultiple service You can specify the same port

service After creation ,netron The service can be accessed inside the cluster , But it can not be accessed outside the cluster , For example, browser . Need to create ingress To expose services to the outside .
Of course , Use service Of NodePort Patterns can also expose services , But you have to specify an extra one 30000 Ports above , And this port cannot be duplicated . That is to say, each container must specify a host port to expose services , This is obviously troublesome , So we decided to use ingress The way .
ingress
External exposure netron service , With someone service binding .
The effect I want is , Of different models netron service , The difference is made through the access path :
- Model A, adopt xx.xx.xx.xx/path1/ To visit
- Model B, adopt xx.xx.xx.xx/path2/ To visit
- ......
The final yml The contents are as follows , The most important thing is path and annotations Configuration of .
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: netron-igr
namespace: default
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: 'rewrite ^(/test)$ $1/ permanent;'
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /test/
backend:
serviceName: netron-svc
servicePort: 8070According to the above yml, When the browser accesses xx.xx.xx.xx/test/ when , You can access service Corresponding services .
path & rewrite-target
ingress Internally configured - path: /test/ , Do not represent netron Must be provided in the container /test Interface , stay annotations Added in rewrite-target Parameters , It is used to rewrite the request path . It's configured here /test/ It is only used to distinguish different services . So , When you create a container ,path、ingressName、serviceName、deploymentName To correspond , In this way, we can pass path To find the appropriate service .
Here I put path Rewrite to "/", Because inside the container , netron The request path for service opening is "/", Access in a container is through localhost:8080 Visiting .
Be careful : At the time of the visit, the last "/" Is a must , Take the above request as an example , Must be xx.xx.xx.xx/test/, And can't be xx.xx.xx.xx/test. Of course , It should be possible to solve this problem with regular expressions , But I'm too lazy to delve into it .
configuration-snippet
Path for rewriting static files .
above path and rewrite-target, It only solves the problem of rewriting the request path . and netron There's an interface , So many static files are involved , such as js, Pictures and the like . This configuration-snippet Can be used to rewrite the path of a static file . Note that the path of each service is also different .
As for this rewrite grammar , I didn't study it carefully , But what is provided above is available .
ssl-redirect
Set to false, Prevent redirection . The default is true Of , So you need to reset . I don't need it ssl, It is also used directly when accessing ip, So this is set to false, Otherwise, an error will be reported :

ingress After deployment , You can access the corresponding on the browser according to different request paths netron Yes .
xx.xx.xx.xx/test/

xx.xx.xx.xx/test2/

边栏推荐
- Multipass中文文档-概览
- [no title] 4555
- From the perspective of Confucius Temple IP crossover, we can see how the six walnuts become "butterflies" for the second time
- 【无标题】4555
- JVM garbage collection mechanism and common garbage collectors
- Is it safe to open an account for stock speculation in Shanghai?
- Static method static learning
- yum源更新
- Things about Bluetooth development (1) -- starting with packet capturing data
- mybaits merge into
猜你喜欢

字符串时间排序,对时间格式字符串进行排序

Bluetooth development (2) -- initialization

Safety training management measures

Unable to return to the default page after page Jump

VTK例子--三个相交的平面

Bluetooth development (6) -- literacy of Bluetooth protocol architecture

ASP. Net programming version C (notes along with learning progress)

【JVM】线程

安全培训管理办法
![[network planning] 1.3 packet switching and circuit switching in the network core](/img/a8/74a1b44ce4d8b0b1a85043a091a91d.jpg)
[network planning] 1.3 packet switching and circuit switching in the network core
随机推荐
Things about Bluetooth development (10) -- getting to know ble for the first time
市值215亿,这个四川80后会让电视机成为历史?
three hundred and thirty-three thousand three hundred and thirty-three
【无标题】测试下啊
对象作为点(Objects as Points) 个人总结
Room first use
B 树的简单认识
学习笔记:插件化Activity之Hook点位
Unity mesh patch generates parabola and polyline
Bluetooth development (8) -- avdtp connection process
【JVM】类加载机制
[network planning] 2.1.1 brief introduction to client server system and P2P system
Brief introduction to MySQL lock and transaction isolation level
Multipass中文文档-使用指引(目录页)
Review of software architecture in Harbin Institute of technology -- LSP principle, covariance and inversion
ts+fetch实现选择文件上传
Static method static learning
Database table structure
LeetCode 1673. 找出最具竞争力的子序列**
Bluetooth development (4) -- about flow control