WEBVTT

00:00.140 --> 00:06.500
So right now we have two node ports set up to expose our external services.

00:06.500 --> 00:12.530
However, we want to actually create a new ingress resource because behind the scenes, Google Kubernetes

00:12.530 --> 00:19.040
engine will automatically provision us a load balancer and give us a single IP address that we can use

00:19.040 --> 00:24.150
to make requests to our entire application, which is what we want to do.

00:24.170 --> 00:30.590
So to easily accomplish this, let's open up our folder and we're going to add a new file in the templates

00:30.590 --> 00:34.390
directory called Ingress dot Yaml.

00:34.400 --> 00:42.050
This will have an API version of networking.k80s.io/v one.

00:42.080 --> 00:48.680
The kind will be of type of ingress and we're going to have some metadata here where we give it a name

00:48.680 --> 00:49.880
of sleeper.

00:49.880 --> 00:58.010
And then we importantly we define the spec with a rules section and then we specify the Http paths in

00:58.010 --> 00:59.600
our application.

00:59.600 --> 01:09.180
So go ahead and specify a paths list here and we'll specify the first path, which will be slash reservations.

01:09.180 --> 01:14.610
And we'll use a wild card here to direct all traffic to our reservation service.

01:14.640 --> 01:21.810
We're going to go ahead and also specify the path type as implementation specific, which just means

01:21.810 --> 01:26.790
Google Kubernetes engine will handle all of the routing back end section here.

01:26.790 --> 01:32.160
We'll have a service and we're going to go ahead and specify the name of the service, which of course

01:32.160 --> 01:34.290
we know for reservations.

01:34.290 --> 01:40.920
We have our service Yaml where the name is reservations, so we'll simply provide the name of the reservations

01:40.920 --> 01:44.940
service and then provide the port number that we're going to access it on.

01:44.940 --> 01:47.420
So in this case it'll be 3004.

01:47.430 --> 01:53.580
Let's go ahead and do the same thing now for the slash auth routes in our application.

01:53.580 --> 01:58.770
We're going to go ahead and direct them as a implementation specific route.

01:58.770 --> 02:06.630
And the back end here will have a service with a name of auth Http because we want to be directing traffic

02:06.630 --> 02:11.190
to our Http auth service and not the TCP one.

02:11.190 --> 02:17.310
So make sure we specify the name of the auth Http here, which matches the name we've specified.

02:17.310 --> 02:21.900
And the port for Http if we take a look, is 3003.

02:21.900 --> 02:24.870
So we'll go ahead and specify the port as 3003.

02:24.870 --> 02:31.290
So make sure we actually change the port here to the number field and specify 3003.

02:31.290 --> 02:36.210
And don't forget to add the wild card path to the auth path here.

02:36.210 --> 02:42.240
So we catch all traffic that starts with auth and then proxy the rest of the path onwards to our service.

02:42.270 --> 02:50.550
We'll go ahead and run helm upgrade Sleeper to install our new ingress resource so we can also go in

02:50.550 --> 02:57.240
the Google Cloud engine UI and under the services and ingress section, we can see that there is a section

02:57.240 --> 02:58.980
for ingress here.

02:58.980 --> 03:05.220
If we click on it, we can see that our ingress is currently being created and it's picked up these

03:05.220 --> 03:11.280
routes we defined earlier on reservations and auth and we can even click into it and see a bunch more

03:11.280 --> 03:17.760
detail, including the annotations, the pods it's going to be serving and the state of the underlying

03:17.760 --> 03:18.720
deployments here.

03:18.720 --> 03:25.080
You can see our auth and reservation deployments haven't yet responded back to the health check, so

03:25.080 --> 03:27.870
we just need to wait a bit until these finish.

03:27.870 --> 03:34.920
So after a bit you should be able to run Kubectl, get ingress and see the address for our externally

03:34.920 --> 03:39.240
provisioned load balancer which is associated with our ingress.

03:39.240 --> 03:47.850
So now we can copy this external address and go into Postman and launch an Http request and paste in

03:47.850 --> 03:54.330
the IP address that you have here and hit slash reservations and send a request.

03:54.360 --> 04:01.230
If you see this 502 server error, give your application a bit of time before it ends up resolving these

04:01.230 --> 04:05.010
health checks and you should see the 502 error here go away.

04:05.250 --> 04:13.890
Now, if we launch a request at our external IP here at Http slash login and post our usual body of

04:13.890 --> 04:20.490
an email and password, we can go ahead and log in with our known email here.

04:20.490 --> 04:22.740
So I'll go ahead and log in with our known email.

04:22.740 --> 04:26.460
And of course we get our JWT cookie set from the auth service.

04:26.460 --> 04:35.430
And then on the same external URL, we'll now going to hit slash reservations to create a new reservation.

04:35.430 --> 04:41.340
I'll go ahead and copy an existing payload from one of our previous requests and paste it in here.

04:41.340 --> 04:41.790
Now.

04:41.790 --> 04:48.330
I'll then go ahead and change the amount to 35 and send off the request to create a new reservation.

04:48.330 --> 04:49.920
And you can see our 201.

04:49.920 --> 04:51.300
Created response.

04:51.450 --> 04:57.390
So before we test out our new load balancer, I'm going to go ahead and authorize our Gmail API one

04:57.390 --> 04:59.940
more time and get an up to date refresh.

04:59.970 --> 05:00.600
Token.

05:00.600 --> 05:02.930
So go back to the Oauth2 playground.

05:02.940 --> 05:06.840
Make sure you've entered your OAuth client ID and secret here.

05:06.840 --> 05:09.870
And we've selected the Mail Google API.

05:09.900 --> 05:15.390
We'll go ahead and authorize it and exchange the authorization code for tokens.

05:15.420 --> 05:24.660
Go ahead and copy the refresh token and go ahead and base 64 encoded using the echo dash n open quote,

05:24.660 --> 05:31.830
paste the refresh token, end quote, and then pipe it to the base 64 command.

05:31.830 --> 05:40.890
We'll go ahead and copy this and edit our secret Google and replace the refresh token and paste it in

05:40.890 --> 05:43.920
and then go ahead and save the up to date secret.

05:43.950 --> 05:51.480
Now, after updating the secret, make sure we restart our notifications Pod by running rollout, restart

05:51.480 --> 05:59.340
deployment notifications so we can go ahead and run Kubectl get in here short for ingress and see that

05:59.340 --> 06:04.900
we have an external load balancer IP now in the address field here.

06:04.900 --> 06:10.240
So we want to copy this and this will be the IP address that we can access all of the routes in our

06:10.240 --> 06:12.820
application inside of this ingress.

06:12.820 --> 06:16.960
So this is the address of the load balancer in Google Kubernetes engine.

06:16.960 --> 06:23.530
We're going to go ahead and paste the request to Http, colon slash, slash enter in that load balancer

06:23.530 --> 06:30.610
address and go to auth slash login and change our request to a post request here.

06:30.610 --> 06:32.710
And now you can see we're getting a 401.

06:32.710 --> 06:34.330
Because we're unauthorized.

06:34.330 --> 06:38.230
So you can see we're actually able to communicate with the auth service.

06:38.230 --> 06:47.020
Let's go ahead and provide a raw Json body here and go ahead and copy a login payload from our previous

06:47.020 --> 06:54.280
login route so we can copy this body, paste it in to the Json body field.

06:54.280 --> 06:58.600
And this is going to be the email associated with our Gmail account.

06:58.600 --> 07:06.190
So we'll go ahead and send this to log in and get back the JWT cookie here for our user.

07:06.190 --> 07:15.040
So now we can launch a request at slash reservations and copy a reservations payload from our previous

07:15.040 --> 07:18.220
requests and paste it into this body.

07:18.220 --> 07:21.100
And let's change the amount here to 45.

07:21.130 --> 07:25.270
So now we have a new reservation and we'll go ahead and send it off.

07:25.300 --> 07:26.980
You can see we have a response.

07:26.990 --> 07:32.950
404 Make sure that we add a trailing slash here to match the exact ingress route.

07:33.340 --> 07:39.370
So now if we send this off, we can see that we have a new reservation that's been created and we can

07:39.370 --> 07:46.840
send a slash get make sure you send no body for this request and we can see all of the reservations

07:46.840 --> 07:47.800
in our system.

07:47.800 --> 07:55.300
Back in Gmail, I can see I have a new notification saying our $45 payment has completed successfully.

07:55.300 --> 08:03.220
And if we go into Stripe and refresh the payments screen, I can see a new payment that succeeded for

08:03.220 --> 08:04.570
$45.

08:04.570 --> 08:09.490
So now we can see that our application is fully running on Google Kubernetes engine.
