Skip to content

wreckedred/newrelic-k8s-guestbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

newrelic-k8s-guestbook

simple kubernetes app instrumented using New Relic APM

blog post based on this environment: https://blog.newrelic.com/2017/11/27/monitoring-application-performance-in-kubernetes/ Thank you Clay Smith. https://github.com/smithclay This updated application is based on his work.

Requirements

  • New Relic License Key
  • AWS or Google Cloud Account
  • kubectl

You'll want to fork this repository and adjust the NEWRELIC_LICENSE_KEY environment variable to point to your account.

APM instrumentation background

This example uses the Kubernetes Downward API to expose Pod metadata to the running container as environment variables.

Inside the node.js application, newrelic.addCustomParameters() is used to annoate every express.js web transcation (and an error) with Kuberenetes metadata.

var CUSTOM_PARAMETERS = {
    'K8S_NODE_NAME': process.env.K8S_NODE_NAME,
    'K8S_HOST_IP': process.env.K8S_HOST_IP,
    'K8S_POD_NAME': process.env.K8S_POD_NAME,
    'K8S_POD_NAMESPACE': process.env.K8S_POD_NAMESPACE,
    'K8S_POD_IP': process.env.K8S_POD_IP,
    'K8S_POD_SERVICE_ACCOUNT': process.env.K8S_POD_SERVICE_ACCOUNT,
    'K8S_POD_TIER': process.env.K8S_POD_TIER
};

app.use(function(req, res, next) {
  newrelic.addCustomParameters(CUSTOM_PARAMETERS);
  next();
});

This makes it easier to debug and troubleshoot cluster-specific issues using application transaction traces and is surfaced in the UI (and Insights):

traced_error_for_error_-newrelic-k8s-node-redis-_new_relic

Kubernetes infrastructure metrics are also collected using the New Relic Infrastructure integration.

Creating the cluster

A Kubernetes cluster is required. This has been tested using Google Container Engine (i.e. Google-flavored managed Kubernetes) and AWS using the kops tool but should work on any Kubernetes 1.8 cluster.

AWS (kops)

The latest version of kops makes setting up a kubernetes cluster on AWS significantly easier. Follow the kops installation instructions for your AWS account.

Google Cloud

If using Google Cloud make sure you've imported your cluster credentials so kubectl will work correctly.

gcloud container clusters get-credentials [gke-cluster-name] --zone [gke-zone]

Run the following commands using kubectl on the cluster. It will create the nessecary services and deployments.

Installing the demo application

Running the New Relic-instrumented guestbook app on the cluster

With kubectl connected to the cluster, run:

$ kubectl create -f k8s/guestbook.yaml
service "redis-master" created
deployment "redis-master" created
service "redis-slave" created
deployment "redis-slave" created
service "frontend" created
deployment "frontend" created

Installing New Relic Infrastructure

Based on the instructions on the New Relic documentation website.

Install kube-state-metrics.

Next, install the New Relic Infrastructure daemonset. Modify the file to point to your cluster and license key:

$ kubectl apply -f k8s/newrelic/newrelic-infra-daemonset.yaml

Deleting the deployment

$ kubectl delete -f k8s/guestbook.yaml

Deleting the cluster

$ kops delete cluster <<cluster-name>>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors