feat: replace rabbitmq with nats

This commit is contained in:
Cyrille Nofficial 2022-10-07 14:42:25 +02:00
parent e446025e76
commit 220162f6f4
10 changed files with 143 additions and 17 deletions

View File

@ -117,8 +117,10 @@ spec:
- name: dev - name: dev
mountPath: /dev mountPath: /dev
env: env:
- name: MQTT_BROKER - name: MQTT_BROKER_HOST
value: localhost # because use host network value: localhost # because use host network
- name: MQTT_BROKER_PORT
value: "30183"
- name: MQTT_USERNAME - name: MQTT_USERNAME
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:

View File

@ -4,8 +4,9 @@ metadata:
name: robocar name: robocar
data: data:
# Broker configuration # Broker configuration
MQTT_BROKER_HOST: mqtt.robocar.svc.cluster.local MQTT_BROKER_HOST: nats-server.nats.svc.cluster.local
MQTT_BROKER: "tcp://mqtt.robocar.svc.cluster.local:1883" #MQTT_BROKER: "tcp://mqtt.robocar.svc.cluster.local:1883"
MQTT_BROKER: "tcp://nats-server.nats.svc.cluster.local:1883"
# Camera # Camera
MQTT_TOPIC_CAMERA: car/satanas/part/camera/color MQTT_TOPIC_CAMERA: car/satanas/part/camera/color

View File

@ -1,13 +0,0 @@
---
apiVersion: v1
kind: Endpoints
metadata:
name: mqtt
labels:
app: mqtt
subsets:
- addresses:
- ip: 192.168.2.221
# - ip: 192.168.217.19
ports:
- port: 1883

View File

@ -4,7 +4,6 @@ kind: Kustomization
resources: resources:
- deployments.yaml - deployments.yaml
- endpoints.yaml
- services.yaml - services.yaml
- configmap.yaml - configmap.yaml

View File

@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nats
data:
standalone.conf: |
server_name: nats
http: 0.0.0.0:8222
jetstream {
store_dir: /data/datastore
}
mqtt {
listen: 0.0.0.0:1883
}
authorization: {
user: satanas,
password: satanas
}

View File

@ -0,0 +1,11 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: nats
resources:
- namespace.yaml
- serviceaccount.yaml
- configmaps.yaml
- statefulset.yaml
- services.yaml

View File

@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: nats

View File

@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: nats-server
automountServiceAccountToken: false

View File

@ -0,0 +1,41 @@
apiVersion: v1
kind: Service
metadata:
name: nats-server-ext
spec:
type: NodePort
ports:
- port: 4222
name: tcp-nats-client
targetPort: tcp-nats-client
nodePort: 30422
- name: http-monitoring
port: 8222
targetPort: http-monitoring
nodePort: 30822
- name: tcp-mqtt
port: 1883
targetPort: tcp-mqtt
nodePort: 30183
selector:
appli: nats-server
---
apiVersion: v1
kind: Service
metadata:
name: nats-server
spec:
type: ClusterIP
ports:
- port: 4222
name: tcp-nats-client
targetPort: tcp-nats-client
- name: http-monitoring
port: 8222
targetPort: http-monitoring
- name: tcp-mqtt
port: 1883
targetPort: tcp-mqtt
selector:
appli: nats-server

View File

@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nats-server
annotations:
reloader.stakater.com/auto: "true"
spec:
selector:
matchLabels:
appli: nats-server
serviceName: nats
replicas: 1
revisionHistoryLimit: 0
template:
metadata:
name: nats-server
labels:
appli: nats-server
spec:
serviceAccountName: nats-server
containers:
- name: nats-server
image: docker.io/library/nats:latest
args:
- --http_port=8222
- --config=/etc/nats/standalone.conf
ports:
- containerPort: 4222
name: tcp-nats-client
- name: http-monitoring
containerPort: 8222
- name: tcp-mqtt
containerPort: 1883
volumeMounts:
- mountPath: /etc/nats
name: nats-config
- name: nats-data
mountPath: /data
securityContext:
runAsUser: 1234
runAsGroup: 1234
fsGroup: 1234
fsGroupChangePolicy: Always
volumes:
- name: nats-config
configMap:
name: nats
volumeClaimTemplates:
- metadata:
name: nats-data
spec:
resources:
requests:
storage: 1Gi
storageClassName: local-path
accessModes:
- ReadWriteOnce