Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Sample Microservices Application Running on Kubernetes

DZone's Guide to

Sample Microservices Application Running on Kubernetes

This example application will help you learn how to deploy a microservice to a Kubernetes cluster and install the Instana agent for monitoring.

· Microservices Zone ·
Free Resource

Containerized Microservices require new monitoring. See why a new APM approach is needed to even see containerized applications.

Stan's Robot Shop - Sample Microservices Application

We introduced the sample microservice application called Stan's Robot Shop in a previous post. In this article, we'll take you through deploying that microservice application to a Kubernetes cluster and installing the Instana agent. The Robot Shop code already includes any extra set up, so all infrastructure technology will be automatically discovered, and every request will be traced end to end.

Install

First, choose your environment. I will be using Google Cloud Platform Kubernetes Engine, you may also use minikube to run everything locally on your laptop. Once you have your Kubernetes cluster running, you're going to install the Instana agent; then deploy the Robot Shop application.

Installing and Configuring Kubernetes

To work with Kubernetes, install a copy of kubectl locally on your machine. If you are using Google Kubernetes Engine, you will also need a copy of gcloud installed locally.

From the Google Kubernetes Engine dashboard, create a basic cluster of 3 nodes. Click on the connect button, then copy and paste the command to a shell prompt. This will configure the kubectl command to work against your newly created cluster. Test that everything is working so far:

$ kubectl cluster-info

Great, you have a running Kubernetes cluster and you can talk to it via kubectl.

Instana Agent

A deployment descriptor file is included with Stan's Robot Shop code. You can download this via git:

$ git clone https://github.com/instana/robot-shop

If you do not have git installed, go to the GitHub page and click on the download link on the top right. This will download a Zip file, expand this into a directory.

Under the Robot Shop project directory, there is a sub-directory named instana. This is where you will find the YAML file that describes the agent deployment. You will need to edit this to configure your unique agent key, which must be base64 encoded. Get your unique agent key from the Instana dashboard under Management Portal.

$ echo -n "your unique agent key" | base64

Save the changes to the deployment. Then deploy the agent.

$ kubectl create -f instana-agent.yaml
namespace "instana-agent" created
serviceaccount "instana-admin" created
secret "instana-agent-secret" created
daemonset "instana-agent" created

The agent is deployed as a daemonset in its own namespace and is configured to only run on nodes with the label agent=instana. There is helper script label.sh which will label all nodes.

$ ./label.sh

The agent will take a moment or two to start and then report into the Instana backend, after which it will appear in the Instana dashboard.

Excellent work, the Instana dashboard is showing the empty Kubernetes cluster. Although we have not yet deployed the Robot Shop application, you can see that the Instana agent has already discovered a number of running containers (these are system containers like system processes of an operating system). You can learn more about what goes on under the covers of Kubernetes in a previous post.

Robot Shop Application

All the deployment and service definition files for deploying the Robot Shop to Kubernetes are included in the source under the K8s directory.

If you are using Google Kubernetes Engine, edit the deployment file for the web service: K8s/web-service.yaml Change the type from NodePort to LoadBalancer. No changes are required if you are using minikube.

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert -f ../docker-compose.yaml
    kompose.version: 1.8.0 (0c0c027)
  creationTimestamp: null
  labels:
    io.kompose.service: web
  name: web
spec:
  type: LoadBalancer
  ports:
    - name: "8080"
    port: 8080
    targetPort: 8080
    nodePort: 30080
  selector:
    io.kompose.service: web
status:
  loadBalancer: {}

Create a separate namespace to put the application in and deploy the application:

$ kubectl create namespace robot-shop
$ kubectl -n robot-shop create -f K8s

It will take a few minutes for Kubernetes to download all the images and create the Pods to start running the application. As the Pods are created and the images start running, the Instana agent will automatically discover them and dynamically load the matching sensor to start monitoring the technology. You can watch this happen in real time on the Instana infrastructure dashboard.

If you are running via minikube, Stan's Robot Shop will be available via the IP address of your minikube instance.

$ minikube ip

The above command will print out the IP address of your minikube instance, open your browser http://<minikube ip>:30080/.

If you are using Google Kubernetes Engine, select Discovery & load balancing from the left menu, and then click on the web service. This will bring up the service details.

Click on the External endpoint link to open the shop in your browser. You're an APM Rock Star now! You have just deployed a modern containerized microservices application with Kubernetes - with full monitoring. Don't tell your boss how easy it really is with Instana; you will shatter the illusion.

Load Generation

You can click around the application to generate some traffic through the application ( don't worry you will not actually purchase anything). There is also a separate load generation utility under the load-gen directory. It runs locally via a Docker image: edit load-gen.sh and set the environment variable HOST to the URL of your deployed shop, save and run the script.

As some load is put through the application, Instana will automatically trace every request end-to-end and build the service map.

Conclusion

Monitoring a modern containerized orchestrated microservices application is not that difficult when you have Stan helping you. Watch for future posts when we cover topics such as End User Monitoring (EUM) and integrating OpenTracing spans.

About Instana:

As the leading provider of Application Performance Management solutions for containerized microservice applications, Instana applies automation and artificial intelligence to deliver the visibility needed to effectively manage the performance of today’s dynamic applications across the DevOps lifecycle. Founded by Application Monitoring veterans, Instana provides true AI-powered APM to help organizations deliver high-performance applications today and in the future. Visit us at https://instana.com to learn more.

Automatically manage containers and microservices with better control and performance using Instana APM. Try it for yourself today.

Topics:
microservices ,monitoring ,deployment

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}