diff --git a/ansible/roles/microservices/files/robocar/car/deployments.yaml b/ansible/roles/microservices/files/robocar/car/deployments.yaml index fb1c474..ca9433d 100644 --- a/ansible/roles/microservices/files/robocar/car/deployments.yaml +++ b/ansible/roles/microservices/files/robocar/car/deployments.yaml @@ -117,8 +117,10 @@ spec: - name: dev mountPath: /dev env: - - name: MQTT_BROKER + - name: MQTT_BROKER_HOST value: localhost # because use host network + - name: MQTT_BROKER_PORT + value: "30183" - name: MQTT_USERNAME valueFrom: secretKeyRef: diff --git a/ansible/roles/microservices/files/robocar/common/configmap.yaml b/ansible/roles/microservices/files/robocar/common/configmap.yaml index 452d417..bf711d9 100644 --- a/ansible/roles/microservices/files/robocar/common/configmap.yaml +++ b/ansible/roles/microservices/files/robocar/common/configmap.yaml @@ -4,8 +4,9 @@ metadata: name: robocar data: # Broker configuration - MQTT_BROKER_HOST: mqtt.robocar.svc.cluster.local - MQTT_BROKER: "tcp://mqtt.robocar.svc.cluster.local:1883" + MQTT_BROKER_HOST: nats-server.nats.svc.cluster.local + #MQTT_BROKER: "tcp://mqtt.robocar.svc.cluster.local:1883" + MQTT_BROKER: "tcp://nats-server.nats.svc.cluster.local:1883" # Camera MQTT_TOPIC_CAMERA: car/satanas/part/camera/color diff --git a/ansible/roles/microservices/files/robocar/common/endpoints.yaml b/ansible/roles/microservices/files/robocar/common/endpoints.yaml deleted file mode 100644 index c3fad01..0000000 --- a/ansible/roles/microservices/files/robocar/common/endpoints.yaml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/ansible/roles/microservices/files/robocar/common/kustomization.yaml b/ansible/roles/microservices/files/robocar/common/kustomization.yaml index 255fff5..85d6e3a 100644 --- a/ansible/roles/microservices/files/robocar/common/kustomization.yaml +++ b/ansible/roles/microservices/files/robocar/common/kustomization.yaml @@ -4,7 +4,6 @@ kind: Kustomization resources: - deployments.yaml - - endpoints.yaml - services.yaml - configmap.yaml diff --git a/ansible/roles/microservices/files/robocar/nats/configmaps.yaml b/ansible/roles/microservices/files/robocar/nats/configmaps.yaml new file mode 100644 index 0000000..b24782c --- /dev/null +++ b/ansible/roles/microservices/files/robocar/nats/configmaps.yaml @@ -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 + } \ No newline at end of file diff --git a/ansible/roles/microservices/files/robocar/nats/kustomization.yaml b/ansible/roles/microservices/files/robocar/nats/kustomization.yaml new file mode 100644 index 0000000..cf80522 --- /dev/null +++ b/ansible/roles/microservices/files/robocar/nats/kustomization.yaml @@ -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 \ No newline at end of file diff --git a/ansible/roles/microservices/files/robocar/nats/namespace.yaml b/ansible/roles/microservices/files/robocar/nats/namespace.yaml new file mode 100644 index 0000000..bdabcad --- /dev/null +++ b/ansible/roles/microservices/files/robocar/nats/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: nats \ No newline at end of file diff --git a/ansible/roles/microservices/files/robocar/nats/serviceaccount.yaml b/ansible/roles/microservices/files/robocar/nats/serviceaccount.yaml new file mode 100644 index 0000000..acea98d --- /dev/null +++ b/ansible/roles/microservices/files/robocar/nats/serviceaccount.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: nats-server +automountServiceAccountToken: false \ No newline at end of file diff --git a/ansible/roles/microservices/files/robocar/nats/services.yaml b/ansible/roles/microservices/files/robocar/nats/services.yaml new file mode 100644 index 0000000..526fda1 --- /dev/null +++ b/ansible/roles/microservices/files/robocar/nats/services.yaml @@ -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 diff --git a/ansible/roles/microservices/files/robocar/nats/statefulset.yaml b/ansible/roles/microservices/files/robocar/nats/statefulset.yaml new file mode 100644 index 0000000..ce934dc --- /dev/null +++ b/ansible/roles/microservices/files/robocar/nats/statefulset.yaml @@ -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