So right now we have two node ports set up to expose our external services.
However, we want to actually create a new ingress resource because behind the scenes, Google Kubernetes
engine will automatically provision us a load balancer and give us a single IP address that we can use
to make requests to our entire application, which is what we want to do.
So to easily accomplish this, let's open up our folder and we're going to add a new file in the templates
directory called Ingress dot Yaml.
This will have an API version of networking.k80s.io/v one.
The kind will be of type of ingress and we're going to have some metadata here where we give it a name
of sleeper.
And then we importantly we define the spec with a rules section and then we specify the Http paths in
our application.
So go ahead and specify a paths list here and we'll specify the first path, which will be slash reservations.
And we'll use a wild card here to direct all traffic to our reservation service.
We're going to go ahead and also specify the path type as implementation specific, which just means
Google Kubernetes engine will handle all of the routing back end section here.
We'll have a service and we're going to go ahead and specify the name of the service, which of course
we know for reservations.
We have our service Yaml where the name is reservations, so we'll simply provide the name of the reservations
service and then provide the port number that we're going to access it on.
So in this case it'll be 3004.
Let's go ahead and do the same thing now for the slash auth routes in our application.
We're going to go ahead and direct them as a implementation specific route.
And the back end here will have a service with a name of auth Http because we want to be directing traffic
to our Http auth service and not the TCP one.
So make sure we specify the name of the auth Http here, which matches the name we've specified.
And the port for Http if we take a look, is 3003.
So we'll go ahead and specify the port as 3003.
So make sure we actually change the port here to the number field and specify 3003.
And don't forget to add the wild card path to the auth path here.
So we catch all traffic that starts with auth and then proxy the rest of the path onwards to our service.
We'll go ahead and run helm upgrade Sleeper to install our new ingress resource so we can also go in
the Google Cloud engine UI and under the services and ingress section, we can see that there is a section
for ingress here.
If we click on it, we can see that our ingress is currently being created and it's picked up these
routes we defined earlier on reservations and auth and we can even click into it and see a bunch more
detail, including the annotations, the pods it's going to be serving and the state of the underlying
deployments here.
You can see our auth and reservation deployments haven't yet responded back to the health check, so
we just need to wait a bit until these finish.
So after a bit you should be able to run Kubectl, get ingress and see the address for our externally
provisioned load balancer which is associated with our ingress.
So now we can copy this external address and go into Postman and launch an Http request and paste in
the IP address that you have here and hit slash reservations and send a request.
If you see this 502 server error, give your application a bit of time before it ends up resolving these
health checks and you should see the 502 error here go away.
Now, if we launch a request at our external IP here at Http slash login and post our usual body of
an email and password, we can go ahead and log in with our known email here.
So I'll go ahead and log in with our known email.
And of course we get our JWT cookie set from the auth service.
And then on the same external URL, we'll now going to hit slash reservations to create a new reservation.
I'll go ahead and copy an existing payload from one of our previous requests and paste it in here.
Now.
I'll then go ahead and change the amount to 35 and send off the request to create a new reservation.
And you can see our 201.
Created response.
So before we test out our new load balancer, I'm going to go ahead and authorize our Gmail API one
more time and get an up to date refresh.
Token.
So go back to the Oauth2 playground.
Make sure you've entered your OAuth client ID and secret here.
And we've selected the Mail Google API.
We'll go ahead and authorize it and exchange the authorization code for tokens.
Go ahead and copy the refresh token and go ahead and base 64 encoded using the echo dash n open quote,
paste the refresh token, end quote, and then pipe it to the base 64 command.
We'll go ahead and copy this and edit our secret Google and replace the refresh token and paste it in
and then go ahead and save the up to date secret.
Now, after updating the secret, make sure we restart our notifications Pod by running rollout, restart
deployment notifications so we can go ahead and run Kubectl get in here short for ingress and see that
we have an external load balancer IP now in the address field here.
So we want to copy this and this will be the IP address that we can access all of the routes in our
application inside of this ingress.
So this is the address of the load balancer in Google Kubernetes engine.
We're going to go ahead and paste the request to Http, colon slash, slash enter in that load balancer
address and go to auth slash login and change our request to a post request here.
And now you can see we're getting a 401.
Because we're unauthorized.
So you can see we're actually able to communicate with the auth service.
Let's go ahead and provide a raw Json body here and go ahead and copy a login payload from our previous
login route so we can copy this body, paste it in to the Json body field.
And this is going to be the email associated with our Gmail account.
So we'll go ahead and send this to log in and get back the JWT cookie here for our user.
So now we can launch a request at slash reservations and copy a reservations payload from our previous
requests and paste it into this body.
And let's change the amount here to 45.
So now we have a new reservation and we'll go ahead and send it off.
You can see we have a response.
404 Make sure that we add a trailing slash here to match the exact ingress route.
So now if we send this off, we can see that we have a new reservation that's been created and we can
send a slash get make sure you send no body for this request and we can see all of the reservations
in our system.
Back in Gmail, I can see I have a new notification saying our $45 payment has completed successfully.
And if we go into Stripe and refresh the payments screen, I can see a new payment that succeeded for
$45.
So now we can see that our application is fully running on Google Kubernetes engine.