Deploying MongoDB Database Demo

The course is part of these learning paths

AZ-303 Exam Preparation: Technologies for Microsoft Azure Architects
course-steps
28
certification
7
lab-steps
13
description
1
AZ-400 Exam Prep: Microsoft Azure DevOps Solutions
course-steps
17
lab-steps
5
description
1
AZ-104 Exam Preparation: Microsoft Azure Administrator
course-steps
20
certification
4
lab-steps
16
more_horizSee 1 more
play-arrow
Start course
Overview
DifficultyIntermediate
Duration1h 42m
Students914
Ratings
3.6/5
starstarstarstar-halfstar-border

Description

AKS is a super-charged Kubernetes managed service which makes creating and running a Kubernetes cluster a breeze!

This course explores AKS, Azure’s managed Kubernetes service, covering the fundamentals of the service and how it can be used. You’ll first learn about how as a managed service it takes care of managing and maintaining certain aspects of itself, before moving onto the core AKS concepts such as cluster design and provisioning, networking, storage management, scaling, and security. After a quick look at Azure Container Registry, the course then moves on to an end-to-end demonstration that shows how to provision a new AKS cluster and then deploy a sample cloud-native application into it.

For any feedback, queries, or suggestions relating to this course, please contact us at support@cloudacademy.com.

Learning Objectives

  • Learn about what AKS is and how to provision, configure and maintain an AKS cluster
  • Learn about AKS fundamentals and core concepts
  • Learn how to work with and configure many of the key AKS cluster configuration settings
  • And finally, you’ll learn how to deploy a fully working sample cloud-native application into an AKS cluster

Intended Audience

  • Anyone interested in learning about AKS and its fundamentals
  • Software Engineers interested in learning about how to configure and deploy workloads into an AKS cluster
  • DevOps and SRE practitioners interested in understanding how to manage and maintain an AKS cluster

Prerequisites

To get the most from this course it would help to have a basic understanding of:

  • Kubernetes (if you’re unfamiliar with Kubernetes, and/or require a refresher then please consider taking our dedicated Introduction to Kubernetes learning path)
  • Containers, containerization, and microservice-based architectures
  • Software development and the software development life cycle
  • Networks and networking

Resources

If you wish to follow along with the demonstrations in part two of this course, you can find all of the coding assets hosted in the following three GitHub repositories:

Transcript

Okay, I'll clear the terminal and moving on to step four, we now need to create the CloudAcademy namespace. So, this namespace we'll deploy all of our sample cloud native resources into. I'll simply copy this command here, jump into the terminal, Enter. Okay, the CloudAcademy namespace has been created. And, what we want to do now is set it as the default namespace. So, I'll do that and we're good to go.

Okay, moving on to step five, we're going to deploy the backend database. And in our sample cloud native application, this will be a MongoDB ReplicaSet consisting of three nodes. So, when we deploy Mongo into our AKS cluster, each of those nodes will actually be a pod.

Okay, step 5.1. I'm simply going to take a look at the storage classes within AKS, and I'll draw your attention to the default one which happens to be an Azure disk, and that will be what I will use for the backend storage layer for our MongoDB database.

So, step 5.2 is where we actually go ahead and create the MongoDB StatefulSet. So, clear the terminal, Paste + Enter. Okay, so the StatefulSet for MongoDB has been created, and we need to watch the startup process for this. So, one of the things about a StatefulSet is that it has an ordered startup process. So you can see here that the first Mongo-0 pod is being created. Only once that has completed being created and is in a running status will the second Mongo pod be created. And then when that is finished, the third and final one will be created.

So, we can see here that the first one is now running and that the second one is starting to be provisioned. Okay, the second one is now up and running. And the third and final Mongo pod is now being created.

Okay, excellent. All three StatefulSet MongoDB pods are now in a running status. So we'll exit the watch, Ctrl + C, and this time if we just do a straight "kubectl get pods" we can indeed see our three pods that make up our MongoDB StatefulSet. We can examine the labels and then we can also filter on a particular label. So in this case I'm filtering on the label "role=db," which again should return our three pods, as it does. And then finally, we can actually look at the, not only the pods, but the persistent volume and persistent volume claims. And we should see three persistent volumes and three persistent volume claims. One for each of the pods, which we do.

Okay, moving on to step 5.4. We need to create a new Headless Service. And this Headless Service is headless because of the fact that the clusterIP attribute is set to None. And the Headless Service's name is set to Mongo. So, we'll copy that, I'll clear the terminal, Paste + Enter. Okay, so the Headless Service is now in place.

So under step 5.5, we can now examine the Headless Service as created within the cluster, and we can see here that our Mongo Headless Service exists and it's headless because the clusterIP attribute is set to None. Now, what that gives us is a stable set of IP addresses and DNS names. And we need this to configure and set up our MongoDB replica set, which consists of three pods.

So, to take a closer look at the DNS records that have been created, I'll spin up a utility pod that has some networking utilities within it. Okay, now that I'm inside that pod I'll simply run the command host mongo." And here we can see clearly that the following three DNS records have been generated and created within the cluster for us automatically. One per pod, within our StatefulSet for MongoDB.

Additionally, I can run the following "for" command, which will loop through the numbers zero through to two; zero, one and two. And again, we can see that we've got the following DNS records. One per pod again, in the StatefulSet.

Okay, we exit out of the pod, I'll clear the terminal, and then this time I'll run the following command which will test that we can indeed resolve the mongo-0.mongo, mongo-1.mongo, and mongo-2.mongo DNS names. And we can see here that this has indeed been successful.

So, here's the first one, the second one, and the third one. So that puts us in a really good place and we can now set up the replication within the MongoDB StatefulSet. So, I'll copy this command here, I'll clear the terminal, paste it.

Okay, so that's completed successfully. And this time if we run "rs.status " on the first pod, using the Mongo client, we should see that the replication is up and running. So I'll now paste that command, and that gives us the following result. So if we look closely at it we can see that the mongo-2.mongo host is set up as a secondary, the mongo-1.mongo host is also set up as a secondary, and the last host is set up as our primary.

So, that concludes that the MongoDB replication is now up and running and has been successful. So our writes that go to the primary will then be replicated across to the secondaries. So, that's a great result. I'll finish by clearing the terminal.

Under step 5.7, we'll now run the following command, which is just loading data into our MongoDB database. I'll paste it here, and that looks good. So we've now loaded data into our MongoDB database.

Finally, under step 5.8, if I run the following command, I'll just test that all of our data is indeed there. And it is, so we take a closer look we can see that we've got six documents, one for each of the languages, in this case we've got C#, votes are set to zero, we've got python, votes are set to zero, javascript, votes are set to zero, et cetera. So that completes the setup for the backend database.

About the Author
Students36269
Labs33
Courses93
Learning paths23

Jeremy is the DevOps Content Lead at Cloud Academy where he specializes in developing technical training documentation for DevOps.

He has a strong background in software engineering, and has been coding with various languages, frameworks, and systems for the past 20+ years. In recent times, Jeremy has been focused on DevOps, Cloud, Security, and Machine Learning.

Jeremy holds professional certifications for both the AWS and GCP cloud platforms.