文章目录
展开本文章为k8s的集群实践,在搭建好的k8s集群上部署服务并完成相关实验。
搭建k8s集群环境可参考docker+k8s 随记 。
1. 集群说明
本实践k8s集群由一个主节点、两个从节点构成,详细信息如下:
节点名称 | 主机类型 | 主机公网IP |
---|---|---|
k8s-master | 阿里云ECS服务器(2C2G) | 39.101.71.XX |
k8s-node-01 | 阿里云ECS服务器(2C2G) | 8.130.94.XXX |
k8s-node-01 | 阿里云ECS服务器(2C2G) | 8.130.10.XXX |
2. 服务介绍
对应服务都写了yml文件,只需 kubectl create -f xx.yaml
即可。
2.1 基于python+keras+flask的目标检测服务
服务参考 keras-app 。
镜像:haoxi/keras-app。
部署文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
apiVersion: apps/v1 kind: Deployment metadata: name: imagerecon-deployment labels: app: imagerecon spec: replicas: 1 selector: matchLabels: app: imagerecon template: metadata: labels: app: imagerecon spec: containers: - name: imagerecon image: haoxi/keras-app:latest ports: - containerPort: 2400 |
上传图片:curl -X POST -F image=@XXX.jpg 'http://<IP>:2400/predict'
结果展示:
1 2 3 |
[root@k8s-master imagerecon]# curl -X POST -F image=@dog.jpg 'http://10.244.2.12:2400/predict' {"predictions":[{"label":"beagle","probability":0.9735041260719299},{"label":"Walker_hound","probability":0.0059484257362782955},{"label":"pot","probability":0.004326358903199434},{"label":"bluetick","probability":0.0024500428698956966},{"label":"basset","probability":0.0017100044060498476}],"success":true} |
2.2 基于PaddleOCR+flask的文字识别服务
服务参考 PaddleOCR-Flask-deploy 。
镜像:haoxi/paddle-ocr
部署文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
apiVersion: apps/v1 kind: Deployment metadata: name: paddleocr-deployment labels: app: paddleocr spec: replicas: 1 selector: matchLabels: app: paddleocr template: metadata: labels: app: paddleocr spec: containers: - name: paddleocr image: haoxi/paddle-ocr:latest ports: - containerPort: 8090 |
上传图片:curl -X POST -F file=@XXX.jpg 'http://<IP>:8090/ocr'
结果展示:
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@k8s-master paddle-ocr]# curl -X POST -F file=@1.jpg 'http://10.244.2.13:8090/ocr' { "服务状态": "success", "识别时间": "3.7110s", "识别结果": [ "You", "always", "have a", "choice." ] } |
2.3 基于Helsinki NLP+flask的翻译服务
服务参考 machine-translation-service 。
镜像:haoxi/translation-app
部署文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
apiVersion: apps/v1 kind: Deployment metadata: name: translation-deployment labels: app: translation spec: replicas: 1 selector: matchLabels: app: translation template: metadata: labels: app: translation spec: containers: - name: translation image: haoxi/translation-app:latest ports: - containerPort: 5000 |
上传文字:
1 2 3 4 5 6 7 8 |
curl --location --request POST 'http://<IP>:5000/translate' \ --header 'Content-Type: application/json' \ -d '{ "text":"<TEXT>", "source":"zh", "target":"en" }' |
结果展示:
1 2 3 4 5 6 7 8 9 10 11 |
[root@k8s-master translation]# curl --location --request POST 'http://10.244.1.12:5000/translate' --header 'Content-Type: application/json' -d '{ "text":"学部将始终坚持育人为本、严谨治学,瞄准国家重大需求和国际学术前沿,以国家中长期科技发展规划为导向,坚持高质量人才培养与高水平学术研究并重,努力建设成为中国特色、世界一流、天大品格的智能与计算学部。", "source":"zh", "target":"en" }' { "output": [ "The Ministry of Science and Technology will always adhere to the fundamentals of human life, to the strict management of science, to the vital needs of the country and to the international academic frontier. It will be guided by the country's medium- and long-term scientific and technological development plan. It will adhere to high-quality human development and high-level academic research. It will strive to build an intellectual and computational department that will become a Chinese character, a world-class and a natural character." ] } |
3. 目前存在的问题
- 基础设施不足以支撑调度,从节点02很难单独跑起translation服务。