BYOC on Red Hat OpenShift
Run the official connectmqcom/broker image on OpenShift Container Platform 4.11+, Red Hat OpenShift Service on AWS (ROSA), Azure Red Hat OpenShift (ARO) or OpenShift Dedicated. Read the BYOC overview first.
Architecture
What is different from plain Kubernetes
| OpenShift behaviour | What to do |
|---|---|
The default restricted-v2 SCC assigns a random UID, but the image runs as UID 1654 | Run the pod with a service account that may use the nonroot-v2 SCC (any non-root UID). |
| Routes are HTTP/SNI routers and hide the client IP | Do not expose MQTT through a Route. Use a LoadBalancer service (or MetalLB / NodePort on bare metal). |
| Projects are namespaces with quotas | Create a dedicated project, for example connectmq. |
Deploy
Create the project, secrets and service account
oc new-project connectmq
oc create secret generic connectmq --from-literal=BROKER_SECRET_KEY='<your-secret>'
oc create secret generic connectmq-certs --from-file=broker.pem=./broker.pem # optional
oc create serviceaccount connectmq-broker
oc adm policy add-scc-to-user nonroot-v2 -z connectmq-brokerApply the deployment and service
connectmq-broker.yaml:
apiVersion: apps/v1
kind: Deployment
metadata: {name: connectmq-broker}
spec:
replicas: 1 # one pod per Broker ID
strategy: {type: Recreate} # never run two pods with the same Broker ID
selector: {matchLabels: {app: connectmq-broker}}
template:
metadata: {labels: {app: connectmq-broker}}
spec:
serviceAccountName: connectmq-broker
securityContext:
runAsNonRoot: true
runAsUser: 1654
runAsGroup: 1654
fsGroup: 1654
seccompProfile: {type: RuntimeDefault}
containers:
- name: broker
image: docker.io/connectmqcom/broker:1.0.0
env:
- {name: BROKER_ID, value: my-broker-01}
- {name: PUBLIC_BROKER_ENABLED, value: "false"}
envFrom: [{secretRef: {name: connectmq}}]
ports:
- {containerPort: 1883}
- {containerPort: 8883}
- {containerPort: 8083}
- {containerPort: 8084}
securityContext:
allowPrivilegeEscalation: false
capabilities: {drop: [ALL]}
resources:
requests: {cpu: 500m, memory: 1Gi}
limits: {memory: 2Gi}
readinessProbe: {tcpSocket: {port: 1883}, periodSeconds: 15}
volumeMounts:
- {name: certs, mountPath: /app/certs, readOnly: true}
- {name: logs, mountPath: /app/logs}
volumes:
- name: certs
secret: {secretName: connectmq-certs, optional: true}
- name: logs
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata: {name: connectmq-broker}
spec:
type: LoadBalancer
externalTrafficPolicy: Local # keep the real client IP
selector: {app: connectmq-broker}
ports:
- {name: mqtts, port: 8883, targetPort: 8883}
- {name: wss, port: 8084, targetPort: 8084}oc apply -f connectmq-broker.yaml
oc get service connectmq-broker # external IP or hostname for your DNS recordOnly 8883 and 8084 are exposed here, so mount the connectmq-certs secret (see TLS with Let's Encrypt for the PEM format); add 1883 and 8083 only if the load balancer is internal. To pull through your mirror registry, change image: to its path.
Point DNS at the load balancer
Create mqtt.example.com → the external address. Clients connect to mqtts://mqtt.example.com:8883 or wss://mqtt.example.com:8084/mqtt with their ConnectMQ credentials.
Platform notes
| Platform | Load balancer |
|---|---|
| ROSA (AWS) | Add service.beta.kubernetes.io/aws-load-balancer-type: nlb to the service annotations to get a Network Load Balancer. |
| ARO (Azure) | The service gets an Azure Load Balancer (layer 4) by default. Use service.beta.kubernetes.io/azure-load-balancer-internal: "true" for a private one. |
| OpenShift on bare metal / vSphere | Install the MetalLB Operator and give it an address pool, or use a NodePort service behind your own layer-4 load balancer. |
Egress: the pod must reach https://brokerapi.connectmq.com (443). If your cluster has an egress firewall (EgressFirewall or a proxy), allow that host.
Not supported on OpenShift
Routes and the ingress controller for MQTT traffic (they are layer-7 / SNI routers and do not keep the client IP), and more than one replica per Broker ID.