Closed BuddhiWathsala closed 5 years ago
You should try to connect to the NATS service to be able to publish messages to NATS Streaming. I recommend you to look at trying to connect to the service created by the NATS Operator first: https://github.com/nats-io/nats-operator/ If just want to try on minikube then can do a port-forward locally as well
I changed the type of service to LoadBalancer
which created by the NATS operator. And I tried to connect to the NATS streaming server using this streaming example. But it gives an error as below.
Exception in thread "main" java.io.IOException: stan: connect request timeout
at io.nats.streaming.StreamingConnectionImpl.connect(StreamingConnectionImpl.java:156)
at io.nats.streaming.NatsStreaming.connect(NatsStreaming.java:90)
at io.nats.streaming.examples.Subscriber.run(Subscriber.java:82)
at io.nats.streaming.examples.Subscriber.main(Subscriber.java:273)
But I was able to connect to that service from this non-streaming example. Since that service created by NATS operator only contains the labels of NATS cluster, how that service would connect to the NATS streming cluster?
Hi @BuddhiWathsala , could you share more details and code from your solution? I'm facing similiar problem: I have minikube with nats-streaming, and want to create ingress for it, so that I can send message to it from golang script. Which minikube version are you using?
@Koshmaar, you can try the following steps. And here I've used minikube version: v1.4.0
.
First, you need to create an ingress using the following YAML (use kubectl apply -f
).
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /testpath
backend:
serviceName: test
servicePort: 80
After that I installed NATS operator and NATS streaming operator.
Install a NATS cluster and a STAN cluster in Kuberentes using following YAMLs (use kubectl apply -f
).
apiVersion: nats.io/v1alpha2
kind: NatsCluster
metadata:
name: nats-siddhi
spec:
size: 1
---
apiVersion: streaming.nats.io/v1alpha1
kind: NatsStreamingCluster
metadata:
name: stan-siddhi
spec:
size: 1
natsSvc: nats-siddhi
Then do the followings that describe in this comment
minikube addons disable ingress
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl get deploy nginx-ingress-controller -n ingress-nginx -o yaml>> nginx-ingress-controller.yaml
spec.template.spec.hostNetwork = true
to the above ingress controller YAML and redeploy it.Expose NATS TCP endpoind as follows. For more details refer this doc.
kubectl get cm -n ingress-nginx -o yaml > tcp.yaml
4222: "default/nats-siddhi:4222"
. In this configuration first 4222
means the port that I need to expose NATS externally. The default
is the namespace in which NATS installed. The nats-siddhi:4222
is the URL of the NATS server I installed previously.
apiVersion: v1
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"ConfigMap","metadata":{"annotations":{},"labels":{"app.kubernetes.io/name":"ingress-nginx","app.kubernetes.io/part-of":"ingress-nginx"},"name":"tcp-services","namespace":"ingress-nginx"}}
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
name: tcp-services
namespace: ingress-nginx
selfLink: /api/v1/namespaces/ingress-nginx/configmaps/tcp-services
data:
4222: "default/nats-siddhi:4222"
Now you can access the NATS and STAN servers externally using your minikube IP and port 4222. You can check the availability using following command.
$ netstat <MINIKUBE_IP>:4222
@BuddhiWathsala Thank you very much :) It's detailed and helpful description.
I installed the
nats-streaming-operator
to my minikube cluster. It installed without any issue. Sincenats
service created bynats-operator
is aClusterIP
one I unable to send data into that service externally. So I tried two approaches to send data.Approach 1
Create a service like below of type
LoadBalancer
and try to send data.Approach 2
Create a different kubernetes deployment of https://github.com/nats-io/go-nats-streaming/tree/master/examples and use that deployment to send data.
I used the following command to send requests.
But from both approaches, I got an error as
So I want to know that how can I external send data to
nats-streaming-server
in the kubernetes cluster?Specifications