Microservices are a great way to architect your applications. In the old days, most applications consisted of a single, large executable containing all of the components of the application. Today, however, more and more people are designing their applications using a series of many relatively independent and decoupled services, known as microservices.
A microservice architecture comes with a host of benefits. Because your application is broken up into small, independent parts, different parts of the application can be built using completely different tools, languages, and frameworks. This allows you to use the best tools for every job. Another benefit of microservices is that they allow individual application components to be separately scaled. If one part of your application needs more resources, you can assign more resources to only that part. Under the old, single-executable architecture, on the other hand, you are forced to scale the entire applications, even those parts that don’t need it, based upon the application’s most resource-hungry components. In addition to this, the relative isolation of application components can increase stability, often limiting the impact of bugs and issues. These are just a few of the benefits of a microservice architecture.
The Need for Orchestration
A microservice architecture does come with some additional complexity. Deploying and managing microservices, and ensuring that different components of the application can talk to each other, can become a daunting task in the context of a complex microservice architecture. Orchestration tools like Kubernetes provide the automation tools you need in order to manage a microservice application and fully realize the benefits of microservices.
A Microservice Application in Kubernetes
If you want to get hands-on with Kubernetes and microservices, one great way to do that is to install a sample microservice application in a Kubernetes cluster. In order to follow along, you will need a working cluster. There are several Linux Academy courses, such as Kubernetes Essentials, that can help you get a cluster set up quickly.
We will be installing Stan’s Robot Shop. This is a sample microservice application from Instana. It is a fairly lightweight application, but it includes many services using a variety of technologies.
We’ll be working with the Linux Academy fork of the original Stan’s Robot Shop repo.
First, clone the repo to any machine where you can access the cluster using kubectl.
cd ~/ git clone https://github.com/linuxacademy/robot-shop.git
Create a namespace and deploy the application objects to the namespace using the deployment descriptors from the git repo.
kubectl create namespace robot-shop kubectl -n robot-shop create -f ~/robot-shop/K8s/descriptors/
Get a list of the application’s pods, and wait for all of them to finish starting up.
kubectl get pods -n robot-shop -w
Once all the pods are up, you can access the application in a browser using the public IP of one of your Kubernetes servers and port 30080.
List the pods.
kubectl get pods -n robot-shop
You will see multiple services represented here, with a variety of technologies such as Redis, MongoDB, and RabbitMQ. All of these are microservices that communicate with one another in order to provide the full functionality of the Stan’s Robot Shop application.
You can learn more about the basics of Kubernetes, as well as how it interacts with microservices, in my new Kubernetes Essentials course!