nats-io / nats-streaming-operator

NATS Streaming Operator
Apache License 2.0
174 stars 44 forks source link

Unable connect nats with ingress #84

Open kuccilim opened 3 years ago

kuccilim commented 3 years ago

I was successful connect it with kubectl port-forward svc/example-nats 4222:4222, but how to expose it with nginx-ingress?

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: client.test-stan.xyz
      http:
        paths:
          - backend:
              serviceName: example-nats
              servicePort: 4222

Code:

import nats from "node-nats-streaming";

const stan = nats.connect("example-stan", "abc", {
  // url: "http://localhost:4222", // successful connected
  url: "nats://client.test-stan.xyz:4222", // failed
});

stan.on("connect", () => {
  console.log("Publisher connected to NATS");

  const data = 'hello world!';

  stan.publish("nats:created", data, () => {
    console.log("Event published");
  });
});