We've now got some code put together to publish an event to our net streaming server.
But if we go back over to our terminal inside of our nets test directory and run NPM run publish we'll
see a nasty error saying that we cannot connect to the Napster server.
So how are we going to fix this.
Well the whole issue here is that we are trying to run our program right now and access some program
that's running inside of a pod inside of our cluster to access something inside the cluster.
There are a couple of different options available to us so we can use a very classic option that we
are now very much familiar with.
Option number one.
Here's our Nats pod.
We created a cluster IP service to govern access to that pod so we can very easily go into our ingress
engine exe file and add in some routes inside there.
That's going to expose the cluster IP service to the outside world so that we could tell our publisher
program to just communicate directly with ingress engine X..
So this is option number one.
And we could definitely make this work.
However there's something kind of interesting about this test program that I want to put together.
One of the very key things I want to show you is what happens if our publisher program or the listener
program suddenly loses its connection with that Nats streaming server pod.
So I want to very easily be able to essentially break that link and then very quickly toggle it back
on without a lot of complicated commands or anything like that.
So even though option number one would definitely work.
It's a little bit too heavy weight for what we're trying to do right now.
So option number two we could create a node port service to expose the Nats pod directly to the outside
world or whatever is running outside of our Cuban that is cluster.
So this would definitely work as well and we could definitely probably figure out how to easily write
a command to very quickly delete that service that we could simulate breaking that connection and then
repairing it very quickly.
However this would still require us to write out a config file.
That's OK.
But right now we're just making a very small little test program and again creating a config file just
a little bit heavyweight.
So there actually is option number three to get access to running or something or running inside of
a pod inside of our cluster very easily inside of a strictly development setting.
So here's what we can do we can run a command at our terminal that tells our Cuban is cluster to port
forward a port off of a very specific pod inside of our cluster when we use this port forwarding thing
that's going to cause our cluster to essentially behave as though it has a node port service running
inside of it.
It's going to expose this pod or a very specific port on it to the outside world and allow us to connect
to it directly from our local machine.
So this is what we're going to do to get access to that and that's streaming server pod let me show
you how to set up this port forwarding thing we're going to first go back to our terminal I'm going
to close the NPM run publish by adding controls see I'm then going to get a list of all my different
running pods with cubes GTL get pods I'll find the name of the pod that is running in mine that's streaming
server I'm going to copy the name and then I will run cube GTL or it forward then the name of the pod
and then the ports that I want to set up port forwarding to the first number right here is the ports
on my local machine that I want to yield to access to get at this pod the second number is gonna be
the port on the pod that I'm trying to actually access in this case we're going to just say connect
directly through 4 2 2 to 4 2 2 so I gonna run that and we'll see a little prompt right here saying
okay we are forwarding all traffic from local host port 4 2 2 2 2 4 2 2 2 on that actual pod sound we
should be able to go back over to another terminal I said back over really we want to open another terminal
window we want you to leave this thing running so I can open another terminal window and we will run
NPM run publish in here and now we should see publisher connected to Nats OK.
So this port forwarding command is not just restricted to using Nats or something like that we can use
this for any different pod any kind of thing we create that we want to connect directly to if it is
a very temporary little connection.
The nice thing about using port forward is that as I mentioned we want to build to break the connection
here very easily to do so all we have to do is stop that process running these port forward command
we're not gonna do that just yet.
I'll show you what happens we do it all a bit later on.
So we are now connected between our publisher program and the Nats board.
So another quick pause right here and we'll continue adding in some code to our publisher in the next
video.