Creating a NATS Super Cluster in Digital Ocean with Helm

    Next, open up the firewall across the 3 regions to be able to access the client, leafnode and gateways ports:

    1. doctl compute firewall add-rules $firewall --inbound-rules protocol:tcp,ports:4222,address:0.0.0.0/0
    2. doctl compute firewall add-rules $firewall --inbound-rules protocol:tcp,ports:7422,address:0.0.0.0/0
    3. doctl compute firewall add-rules $firewall --inbound-rules protocol:tcp,ports:7522,address:0.0.0.0/0
    4. done

    The Helm definition would look as follows for the 3 clusters:

    1. # super-cluster.yaml
    2. nats:
    3. externalAccess: true
    4. logging:
    5. debug: false
    6. trace: false
    7. cluster:
    8. enabled: true
    9. gateway:
    10. enabled: true
    11. # NOTE: defined via --set gateway.name="$ctx"
    12. # name: $ctx
    13. gateways:
    14. - name: do-ams3-nats-k8s-ams3
    15. urls:
    16. - nats://142.93.251.181:7522
    17. - nats://161.35.12.245:7522
    18. - nats://161.35.2.153:7522
    19. - name: do-nyc1-nats-k8s-nyc1
    20. urls:
    21. - nats://142.93.251.181:7522
    22. - nats://161.35.12.245:7522
    23. - nats://161.35.2.153:7522
    24. - nats://142.93.251.181:7522
    25. - nats://161.35.12.245:7522
    26. - nats://161.35.2.153:7522
    27. natsbox:
    28. enabled: true

    That’s it! It should now be possible to send some messages across regions:

    1. # Start subscription in Amsterdam
    2. nats-box:~# kubectl --context do-ams3-nats-k8s-ams3 exec -it nats-box -- /bin/sh -l
    3. nats-box:~# nats-sub -s nats hello
    4. # Send messages from San Francisco region
    5. nats-box:~# kubectl --context do-sfo2-nats-k8s-sfo2 exec -it nats-box -- /bin/sh -l
    6. nats-box:~# nats-pub -s nats hello 'Hello World!'
    7. # From outside of k8s can use the external IPs
    8. $ nats-pub -s 161.35.2.153 hello 'Hello World!'