From 34b494d3e5002d8b0b9ea87ee08dfce03048e490 Mon Sep 17 00:00:00 2001 From: "noussair.hamrit" Date: Wed, 16 Apr 2025 18:02:17 +0200 Subject: [PATCH] first commit --- ConfigMap-ingress-nginx.yaml | 7 +++++++ ConfigMap.yaml | 27 +++++++++++++++++++++++++ deployment.yaml | 39 ++++++++++++++++++++++++++++++++++++ ingress.yaml | 22 ++++++++++++++++++++ mosquitto-passwd-secret.yaml | 8 ++++++++ namespace.yaml | 6 ++++++ pvc.yaml | 12 +++++++++++ svc.yaml | 27 +++++++++++++++++++++++++ 8 files changed, 148 insertions(+) create mode 100644 ConfigMap-ingress-nginx.yaml create mode 100644 ConfigMap.yaml create mode 100644 deployment.yaml create mode 100644 ingress.yaml create mode 100644 mosquitto-passwd-secret.yaml create mode 100644 namespace.yaml create mode 100644 pvc.yaml create mode 100644 svc.yaml diff --git a/ConfigMap-ingress-nginx.yaml b/ConfigMap-ingress-nginx.yaml new file mode 100644 index 0000000..2ddf9b3 --- /dev/null +++ b/ConfigMap-ingress-nginx.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: tcp-services + namespace: nginx +data: + "1883": "mosquitto/mosquitto-mqtt:1883" diff --git a/ConfigMap.yaml b/ConfigMap.yaml new file mode 100644 index 0000000..9a84b93 --- /dev/null +++ b/ConfigMap.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: mosquitto-config + namespace: mosquitto +data: + mosquitto.conf: | + + persistence true + persistence_location /mosquitto/data/ + log_dest stdout + log_type all + connection_messages true + log_timestamp true + + password_file /mosquitto/secrets/passwd + allow_anonymous false + + # MQTTS listener + listener 1883 + protocol mqtt + + # WS Listener + listener 9001 + protocol websockets + + \ No newline at end of file diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 0000000..487544c --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,39 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mosquitto + namespace: mosquitto +spec: + replicas: 1 + selector: + matchLabels: + app: mosquitto + template: + metadata: + labels: + app: mosquitto + spec: + containers: + - name: mosquitto + image: eclipse-mosquitto + ports: + - containerPort: 1883 + - containerPort: 9001 + volumeMounts: + - mountPath: /mosquitto/config/mosquitto.conf + subPath: mosquitto.conf + name: config + - mountPath: /mosquitto/secrets + name: passwd + - mountPath: /mosquitto/data/ + name: data + volumes: + - name: config + configMap: + name: mosquitto-config + - name: passwd + secret: + secretName: mosquitto-passwd + - name: data + persistentVolumeClaim: + claimName: mosquitto-data \ No newline at end of file diff --git a/ingress.yaml b/ingress.yaml new file mode 100644 index 0000000..e7dea37 --- /dev/null +++ b/ingress.yaml @@ -0,0 +1,22 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: mosquitto-ws + namespace: mosquitto + annotations: + nginx.ingress.kubernetes.io/backend-protocol: "HTTP" # Required for WebSocket + nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" # Keep connections alive + nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" +spec: + ingressClassName: nginx + rules: + - host: mosquitto.infrastructure.helmholz.cloud + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: mosquitto-ws + port: + number: 9001 \ No newline at end of file diff --git a/mosquitto-passwd-secret.yaml b/mosquitto-passwd-secret.yaml new file mode 100644 index 0000000..42be33d --- /dev/null +++ b/mosquitto-passwd-secret.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + name: mosquitto-passwd + namespace: mosquitto +type: Opaque +data: + passwd: YWRtaW46JDckMTAxJGl6U0tJOHVSazU2QnVOSGMkSEorNXFOSUlVdStFNGo1ZXB0TnpNUWJIZnJvK0ZRQTlBM0NOY2h2YXJoQU1WN25hb3hxYUdaMzBLMkorU2dVeFBBZGdsTnVFN1VqdndacVNQdUtTS3c9PQo= diff --git a/namespace.yaml b/namespace.yaml new file mode 100644 index 0000000..e370c39 --- /dev/null +++ b/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: mosquitto + labels: + name: mosquitto \ No newline at end of file diff --git a/pvc.yaml b/pvc.yaml new file mode 100644 index 0000000..975dc90 --- /dev/null +++ b/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mosquitto-data + namespace: mosquitto +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: longhorn diff --git a/svc.yaml b/svc.yaml new file mode 100644 index 0000000..d6067ec --- /dev/null +++ b/svc.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: Service +metadata: + name: mosquitto-mqtt + namespace: mosquitto +spec: + type: ClusterIP + selector: + app: mosquitto + ports: + - name: mqtt + port: 1883 + targetPort: 1883 + protocol: TCP + +--- +apiVersion: v1 +kind: Service +metadata: + name: mosquitto-ws + namespace: mosquitto +spec: + type: ClusterIP + selector: + app: mosquitto + ports: + - port: 9001 \ No newline at end of file