Okay.
So back in the Google console, we are going to make use of the Google Cloud to deploy our application
in a Kubernetes cluster as well as to store our Docker images.
The reason why we're using Google Cloud is because, as you can see up top here, we can start a free
trial and get $300 in credit, which means we can deploy our application in a production setting completely
free using this free credit.
So let's go ahead and get started by looking up the container registry in the search bar here.
And this is where we're going to push our Docker images to.
It will be a private Docker registry.
And this is so that only our Kubernetes cluster or our local cluster will be able to access these images,
which is exactly what we want.
So let's go ahead and start by clicking Enable this API and you can see we have billing required, so
let's hit, cancel and then up top where you see start your free trial.
Let's go ahead and click Activate to activate this free trial.
I'll go ahead and select other for our organization, accept the terms and conditions and click next.
So next, we have to supply a credit card or billing method in Google Cloud.
So go ahead and provide this note that we will get $300 in free credit and don't worry about getting
charged at all.
This is a $300 free credit and if this credit runs out, we will not be charged, as you can see here.
Okay.
So after signing up for our Google Cloud free trial, I'm going to go back into the search bar here
and look for the registry here.
And we're going to choose the artifact registry.
And then we're going to go ahead and click enable to enable the API.
Next we're going to go ahead and click Create Repository and we're going to go ahead and create four
repositories for each of our microservices.
So let's go ahead and start off by creating the reservations repository.
And each one of these will be where we are going to push our Docker images to.
So of course we'll keep the format here as Docker for the region here.
I'll go ahead and select us East four Feel free to select whichever region you'd like and then go ahead
and click Create.
You can see that our new repository has been created.
Go ahead and repeat the same process for the three other services, the auth service notifications and
payments.
Okay.
So after creating the remaining repositories for all of our services, you can see we have our four
repositories here now.
So if we click on any one of these, for example, the reservations and then we'll click on the setup
instructions button where we'll have the instructions.
You can first see that we need to make sure we have the Google Cloud SDK installed, which is what we're
going to be utilizing a lot in this production deployment to communicate with the Google cloud on our
CLI as well as to configure Docker here, we'll need to do in order to authenticate with Gcloud and
make sure we have access to push and pull these images.
So let's go ahead and click this link to go to the Google Cloud SDK documentation where you can see
we have a guide and a quickstart.
So I'll click on the quickstart to install the Google Cloud CLI.
Then I'll scroll down to the instructions to install the latest Gcloud CLI version and you can see we
have instructions for all different operating systems here.
So select your operating system and follow the instructions to install gcloud.
I'm using a mac OS so of course I'll firstly check to see that I have Python three running.
So I'll go ahead and confirm this in my terminal by running Python 3-V and you can see we have python
installed.
If you don't have Python installed in your system, simply go to python.org and then go to the download
sections where you can find the correct download for your system.
Next, I'm going to go ahead and select the correct platform for my system.
You can see here we can run Uname dash M from the command line to find out the correct version on your
Mac if you're using Mac.
In my case, I'm using the 686 by 64 and here I'll go ahead and download this.
Lastly, you can see here we have an optional step to add the Gcloud CLI tools to our path.
That way we can easily access the commands anywhere in our system.
So let's go ahead and copy this command here to run the install script, which will do this for us.
So back in the terminal here, I'm going to CD to my home directory where I moved the download to and
have extracted it to.
And you can see now I'm able to CD into a Google Cloud SDK folder.
So I'll go ahead and now run the Install.sh script, which was from the documentation you can see here,
it'll ask if you want us to modify our path and enable Shell command completion, I'll go ahead and
select yes, and I'll go ahead and tell it to use my existing zshrc file.
Or you can choose whichever path you'd want to update your path variable.
Finally, it asks us if we want to install.
Commended modules.
I'll go ahead and select.
Yes.
Next we're going to go ahead and initialize gcloud.
By running Gcloud config configurations create and I'll create a new configuration here for Sleeper.
Okay.
So next we're going to go ahead and initialize gcloud by running gcloud config configurations.
Create and I'll go ahead and create a new configuration called Sleeper here.
And also this will activate it.
Okay.
So lastly, go back into the Gcloud console and under the projects section, take note of the project
ID here and back in the terminal.
We're going to go ahead and use Gcloud config set project and then paste in this project ID to update
our default project ID and make sure that all commands execute against this project.
Okay.
So back in the artifact registry, if we continue on to the setup instructions, we have initialized
Gcloud and now we're going to continue to the next step configure application default credentials,
which is how we're going to authenticate our Gcloud CLI to be able to communicate with our artifact
registry.
So let's go ahead and click on this link and learn how we can do this.
You can see we have a command we can run here called application Default login, which will allow us
to obtain user credentials via a web flow and allow us to easily authenticate when developing locally.
So let's go ahead and do this.
We're going to go ahead and copy this command here to log in to Gcloud.
Then I'll go ahead and paste this command in the terminal here, which should open up a browser for
authentication.
Okay.
So you can see we're now brought to this authentication screen.
I'll go ahead and continue with this account and allow trust to the Google Auth library.
And you can now see we have successfully authenticated with the Gcloud CLI and further in the terminal
we can see that our credentials got saved to this file here on the application default credentials dot
json.
Okay.
After everything set up, we then should be able to run gcloud artifacts repositories list.
To see all the repositories that we have created and we should now see all of our repositories.
So lastly, let's go back to our artifact registry setup instructions, and you can see we have this
command here to configure Docker locally, to use Gcloud to authenticate when pushing or pulling our
images.
So go ahead and copy this command and go ahead and paste this command in here which will update our
Docker configuration.
So now we've correctly set the credentials for our Gcloud registry.
Let's go ahead and start building images and pushing to our external repository.
Okay, so let's go ahead and try pushing up our first image.
I'll go ahead and CD to the apps directory and then directly into the reservations folder, run Docker,
build tag reservations, and I'll go ahead and specify the Docker file path is at the current directory.
And then I'm going to specify the context where we want to actually run this from two directories up
at the root.
Let's go ahead and build our Docker file next in Gcloud console, let's go back to the artifact registry,
click on our reservations repository and let's go ahead and click the copy button here to copy the URI
for the reservations repository.
Okay, So next, let's go ahead and run Docker tag reservations and paste in our Gcloud repository URL
and add one more slash.
And this is going to be the name of the image.
I'm going to go ahead and call this production as if we're building a production image.
And finally we can go ahead and copy the full Docker image name here and run Docker image, push and
paste it in here.
And now we can see our image is being pushed to Gcloud.
So go ahead and let this complete.
After our image has finished pushing, we should then be able to go back to our repository here for
reservations, refresh the page and now we can go ahead and see.
We have our first image here.
Tagged production pushed up.
Now let's go ahead and repeat this same exact process for the rest of our microservices.
Auth Notifications Payments.