目标
继续接前一篇的NFS文件系统,目前的需求是需要能够控制集群中运行的应用,比如现在需要运行并行跨节点程序A,那么需要先调度停止正在运行的程序B,这就需要构建一个消息传递系统,能够基于消息驱动来完成操作任务。
前景和基本架构设计
-
Swift被设定为Tensorflow下一代的机器学习语言,参见Swift for Tensorflow,目前尝试着用Swift来编写应用。
-
使用MQTT协议来发送和接收需要处理的数据。
-
利用TinyML技术收集家用设备电器上传感器产生的数据,从而使得家电更加智能。
目前的设想是使用RabbitMQ做为消息中间件,Swift编写服务端应用推送消息,客户端需要一个UI应用接受和处理对应的消息事件,以下就是介绍一款基于消息驱动的可视化编程工具。
发现 Node-Red
Node-Red是由IBM开发的基于流程的可视化编程工具。
个人觉得它的优点就是开发物联网应用原型速度快,支持Arduino,Raspberry Pi等设备,简单易用,基于事件驱动,原生开发语言为nodejs,支持可扩展插件。
运行在K3s上
node-red.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: node-red
namespace: science
labels:
app: node-red
spec:
replicas: 1
selector:
matchLabels:
app: node-red
template:
metadata:
labels:
app: node-red
spec:
containers:
- name: node-red
image: $image
imagePullPolicy: Always
ports:
- containerPort: 1880
volumeMounts:
- mountPath: /data
name: data-volume
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: node-red-pvc
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: node-red-pvc
namespace: science
annotations:
volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 6Gi
---
apiVersion: v1
kind: Service
metadata:
name: node-red
namespace: science
spec:
selector:
app: node-red
ports:
- protocol: TCP
port: 1880
targetPort: 1880
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: node-red-ingress
namespace: science
spec:
rules:
- host: foo.bar.host
http:
paths:
- backend:
serviceName: node-red
servicePort: 1880
Run RabbitMQ On K3s
rabbitmq-conf-rabbitmq-env-configmap.yaml
apiVersion: v1
data:
RABBITMQ_DEFAULT_PASS: xxxxx
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_HOST: rabbitmq
RABBITMQ_PORT: "5672"
kind: ConfigMap
metadata:
name: rabbitmq-conf-rabbitmq-env
namespace: science
rabbitmq-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: rabbitmq
name: rabbitmq
namespace: science
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq
template:
metadata:
labels:
app: rabbitmq
spec:
hostname: rabbitmq
containers:
- env:
- name: RABBITMQ_DEFAULT_PASS
valueFrom:
configMapKeyRef:
key: RABBITMQ_DEFAULT_PASS
name: rabbitmq-conf-rabbitmq-env
- name: RABBITMQ_DEFAULT_USER
valueFrom:
configMapKeyRef:
key: RABBITMQ_DEFAULT_USER
name: rabbitmq-conf-rabbitmq-env
- name: RABBITMQ_HOST
valueFrom:
configMapKeyRef:
key: RABBITMQ_HOST
name: rabbitmq-conf-rabbitmq-env
- name: RABBITMQ_PORT
valueFrom:
configMapKeyRef:
key: RABBITMQ_PORT
name: rabbitmq-conf-rabbitmq-env
image: 192.168.1.114:5000/rabbitmq:3.8.5-management-alpine
ports:
- containerPort: 5672
name: port
protocol: TCP
- containerPort: 15672
name: web-port
protocol: TCP
name: rabbitmq
volumeMounts:
- mountPath: /var/lib/rabbitmq
name: rabbitmq-volume
restartPolicy: Always
volumes:
- name: rabbitmq-volume
persistentVolumeClaim:
claimName: rabbitmq-volume
rabbitmq-service.yaml
apiVersion: v1
kind: Service
metadata:
name: rabbitmq
namespace: science
labels:
app: rabbitmq
spec:
ports:
- protocol: TCP
port: 5672
targetPort: 5672
name: port
- protocol: TCP
port: 15672
targetPort: 15672
name: web-port
selector:
app: rabbitmq
rabbitmq-volume-persistentvolumeclaim.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: rabbitmq-volume
namespace: science
spec:
accessModes:
- ReadWriteOnce
storageClassName: managed-nfs-storage
resources:
requests:
storage: 10Gi