{"id":1209,"date":"2019-02-10T01:20:56","date_gmt":"2019-02-10T01:20:56","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw93\/?p=1209"},"modified":"2019-02-10T01:22:14","modified_gmt":"2019-02-10T01:22:14","slug":"running-our-own-elk-stack-with-docker-and-rancher","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw93\/index.php\/2019\/02\/10\/running-our-own-elk-stack-with-docker-and-rancher\/","title":{"rendered":"Running our own ELK stack with Docker and Rancher"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h5>A Detailed Overview of Rancher&#8217;s Architecture<\/h5>\n<p>This newly-updated, in-depth guidebook provides a detailed overview of the features and functionality of the new Rancher: an open-source enterprise Kubernetes platform.<\/p>\n<p><a href=\"http:\/\/info.rancher.com\/rancher2-technical-architecture\" target=\"blank\">Get the eBook<\/a><\/p>\n<p><a href=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2015\/09\/14203235\/kibana2.png\"><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2015\/09\/14203235\/kibana2-300x205.png\" alt=\"kibana2\" \/><\/a>At<br \/>\nRancher Labs we generate a lot of logs in our internal environments. As<br \/>\nwe conduct more and more testing on these environments we have found the<br \/>\nneed to centrally aggregate the logs from each environment. We decided<br \/>\nto use <a href=\"http:\/\/rancher.com\/rancher\/\">Rancher<\/a>to build and run a scalable<br \/>\nELK stack to manage all of these logs. For those that are unfamiliar<br \/>\nwith the ELK stack, it is made up of Elasticsearch, Logstash and Kibana.<br \/>\nLogstash provides a pipeline for shipping logs from various sources and<br \/>\ninput types, combining, massaging and moving them into Elasticsearch, or<br \/>\nseveral other stores. It is a really powerful tool in the logging<br \/>\narsenal. Elasticsearch is a document database that is really good at<br \/>\nsearch. It can take our processed output from Logstash, analyze and<br \/>\nprovides an interface to query all of our logging data. Together with<br \/>\nKibana, a powerful visualization tool that consumes Elasticsearch data,<br \/>\nyou have amazing ability to gain insights from your logging. Previously,<br \/>\nwe have been using Elastic\u2019s Found product and have been very impressed.<br \/>\nOne of the interesting things we realized while using Found for<br \/>\nElasticsearch is that the ELK stack really is made up of discrete parts.<br \/>\nEach part of the stack has its own needs and considerations. Found<br \/>\nprovided us Elasticsearch and Kibana. There was no Logstash end point<br \/>\nprovided, though it was sufficiently documented how to use Found with<br \/>\nLogstash. So, we have always had to run our own Logstash pipeline.<br \/>\nLogstash Our Logstash implementation includes three tiers, one each<br \/>\nfor collection, queueing and processing. Collection- responsible for<br \/>\nproviding remote endpoints for logging inputs. Like Syslog, Gelf,<br \/>\nLogstash. Once it receives these logs it places them quickly onto a<br \/>\nRedis Queue. Queuing tier &#8211; provided by Redis, a very fast in memory<br \/>\ndatabase. It acts as a buffer between the collection and processing<br \/>\ntier. Processing tier &#8211; removes messages from the queue, and applies<br \/>\nfilter plugins to the logs that manipulate the data to a desired format.<br \/>\nThis tier does the heavy lifting and is often a bottleneck in a log<br \/>\npipeline. Once it processes the data it forwards it along to the final<br \/>\ndestination, which is Elasticsearch. <a href=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2015\/09\/14203235\/Logstash-Pipeline.svg\"><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2015\/09\/14203235\/Logstash-Pipeline.svg\" alt=\"Logstash\nPipeline\" \/><\/a><br \/>\n<em>Each Logstash container has a configuration sidekick that provides<br \/>\nconfiguration through a shared volume.<\/em> By breaking the stack into these<br \/>\ntiers, you can scale and adapt each part without major impact to the<br \/>\nother parts of the stack. As a user, you can also scale and adjust each<br \/>\ntier to suit your needs. A good read on how to scale Logstash can be<br \/>\nfound on Elastic\u2019s web page here: <a href=\"https:\/\/www.elastic.co\/guide\/en\/logstash\/current\/deploying-and-scaling.html\">Deploying and Scaling<br \/>\nLogstash<\/a>.<br \/>\nTo build the Logstash stack we stared as we usually do. In general, we<br \/>\ntry to reuse as much as possible from the community. Looking at the<br \/>\nDockerHub registry, we found there is already an official Logstash image<br \/>\nmaintained by Docker. The real magic is in configuration of Logstash at<br \/>\neach of the tiers. To achieve maximum flexibility with configuration, we<br \/>\nbuilt a confd container that consumes KV, or Key Value, data for its<br \/>\nconfiguration values. The logstash configurations are the most volatile,<br \/>\nand unique to an organization as they provide the interfaces for the<br \/>\ncollection, indexing, and shipping of the logs. Each organization is<br \/>\ngoing to have different processing needs, formatting, tagging etc. To<br \/>\nachieve maximum flexibility we leveraged the confd tool and Rancher<br \/>\nsidekick containers. The sidekick creates an atomic scheduling unit<br \/>\nwithin Rancher. In this case, our configuration container exposes the<br \/>\nconfiguration files to our Logstash container through volume sharing. In<br \/>\ndoing this, there is no modification needed to the default Docker<br \/>\nLogstash image. How is that for reuse! Elasticsearch Elasticsearch<br \/>\nis built out in three tiers as well. When reading the production<br \/>\ndeployment recommendations, it discusses having nodes that are dedicated<br \/>\nmasters, data nodes and client nodes. We followed the same deployment<br \/>\nparadigm with this application as the logstash implementation. We deploy<br \/>\neach role as a service. Each service is composed of an official image<br \/>\nand paired with a Confd sidekick container to provide configuration. It<br \/>\nends up looking like this: <a href=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2015\/09\/14203235\/Elastic-Search-Tier.svg\"><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2015\/09\/14203235\/Elastic-Search-Tier.svg\" alt=\"Elastic Search\nTier\" \/><\/a><br \/>\n<em>Each tier in the Elasticsearch stack has a confd container providing<br \/>\nconfigurations through a shared volume. These containers are scheduled<br \/>\ntogether inside of Rancher.<\/em> In the current configuration, we use the<br \/>\nmaster service to provide node discovery. When using the Rancher private<br \/>\nnetwork, we disable multicast and enable unicast. Since every node in<br \/>\nthe cluster points to the master they can talk to one another. The<br \/>\nRancher network also allows the nodes to talk to one another. As a part<br \/>\nof our stack, we also use the Kopf tool to quickly visualize our<br \/>\nclusters health and perform other maintenance tasks. Once you bring up<br \/>\nthe stack you will see that you can use Kopf to see that all the nodes<br \/>\ncame up in the cluster. Kibana 4 Finally, in order to view all of<br \/>\nthese logs and make sense of the data, we bring up Kibana to complete<br \/>\nour ELK stack. We have chosen to go with Kibana 4 in this stack. Kibana<br \/>\n4 is launched with an Nginx container to provide basic auth behind a<br \/>\nRancher load balancer. The Kibana 4 instance is the Official image which<br \/>\nis hosted on DockerHub. The Kibana 4 image talks to the Elasticsearch<br \/>\nclient nodes. So now we have a full ELK stack for taking logs and<br \/>\nshipping them to Elasticsearch for visualization in Kibana. The next<br \/>\nstep is getting the logs from the hosts running your application.<br \/>\nBringing up the Stack on Rancher So now you have the backstory on<br \/>\nhow we came up with our ELK stack configuration. Here are instructions<br \/>\nto run the ELK stack on Rancher. This assumes that you already have a<br \/>\nRancher environment running with at least one compute node. We will also<br \/>\nbe using the Rancher compose CLI tool. Rancher-compose can be found on<br \/>\nGitHub here<br \/>\n<a href=\"https:\/\/github.com\/rancher\/rancher-compose\">rancher\/rancher-compose<\/a>.<br \/>\nYou will need API keys from your Rancher deployment. In the instructions<br \/>\nbelow, we will bring up each component of the ELK stack, as its own<br \/>\nstack in Rancher. A stack in Rancher is a collection of services that<br \/>\nmake up an application, and are defined by a Docker Compose file. In<br \/>\nthis example, we will build the stacks in the same environment and use<br \/>\ncross stack linking to connect services. Cross stack linking allows<br \/>\nservices in different stacks to discover each other through a DNS name.<\/p>\n<ol>\n<li>Clone our compose template repository: git clone<br \/>\n<a href=\"https:\/\/github.com\/rancher\/compose-templates.git\">https:\/\/github.com\/rancher\/compose-templates.git<\/a><\/li>\n<li>First lets bring up the Elasticsearch cluster.<br \/>\na. cd compose-templates\/elasticsearch<br \/>\nb. rancher-compose -p es up (Other services assume es as the<br \/>\nelasticsearch stack name) This will bring up four services.<br \/>\n&#8211; elasticsearch-masters<br \/>\n&#8211; elasticsearch-datanodes<br \/>\n&#8211; elasticsearch-clients<br \/>\n&#8211; kopf<br \/>\nc. Once Kopf is up, click on the container in the Rancher UI, and<br \/>\nget the IP of the node it is running on.<br \/>\nd. Open a new tab in your browser and go to the IP. You should see<br \/>\none datanode on the page.<\/li>\n<li>Now lets bring up our Logstash tier.<br \/>\na. cd ..\/logstash<br \/>\nb. rancher-compose -p logstash up<br \/>\nc. This will bring up the following services<br \/>\n&#8211; Redis<br \/>\n&#8211; logstash-collector<br \/>\n&#8211; logstash-indexer<br \/>\nd. At this point, you can point your applications at<br \/>\nlogtstash:\/\/host:5000.<\/li>\n<li>(Optional) Install logspout on your nodes<br \/>\na. cd ..\/logspout<br \/>\nb. rancher-compose -p logspout up<br \/>\nc. This will bring up a logspout container on every node in your<br \/>\nRancher environment. Logs will start moving through the pipeline<br \/>\ninto Elasticsearch.<\/li>\n<li>Finally, lets bring up Kibana 4<br \/>\na. cd ..\/kibana<br \/>\nb. rancher-compose -p kibana up<br \/>\nc. This will bring up the following services<br \/>\n&#8211; kibana-vip<br \/>\n&#8211; nginx-proxy<br \/>\n&#8211; kibana4<br \/>\nd. Click the container in the kibana-vip service in the Rancher UI.<br \/>\nVisit the host ip in a separate browser tab. You will be<br \/>\ndirected to the Kibana 4 landing page to select your index.<\/li>\n<\/ol>\n<p>Now that you have a fully functioning ELK stack on Rancher, you can<br \/>\nstart sending your logs through the Logstash collector. By default the<br \/>\ncollector is listening for Logstash inputs on UDP port 5000. If you are<br \/>\nrunning applications outside of Rancher, you can simply point them to<br \/>\nyour Logstash endpoint. If your application runs on Rancher you can use<br \/>\nthe optional Logspout-logstash service above. If your services run<br \/>\noutside of Rancher, you can configure your Logstash to use Gelf, and use<br \/>\nthe Docker log driver. Alternatively, you could setup a Syslog listener,<br \/>\nor any number of supported Logstash input plugins. Conclusion<br \/>\nRunning the ELK stack on Rancher in this way provides a lot of<br \/>\nflexibility to build and scale to meet any organization\u2019s needs. It<br \/>\nalso creates a simple way to introduce Rancher into your environment<br \/>\npiece by piece. As an operations team, you could quickly spin up<br \/>\npipelines from existing applications to existing Elasticsearch clusters.<br \/>\nUsing Rancher you can deploy applications following container best<br \/>\npractices by using sidekick containers to customize standard containers.<br \/>\nBy scheduling these containers as a single unit, you can separate your<br \/>\napplication out into separate concerns. On Wednesday, September 16th,<br \/>\nwe hosted an online meetup focused on container logging, where I<br \/>\ndemonstrated how to build and deploy your own ELK stack. If you\u2019d like<br \/>\nto view a recording of this you can view it<br \/>\n<a href=\"http:\/\/rancher.com\/container-logging-with-docker-and-elk-september-2015-recorded-online-meetup\/\">here<\/a>.<br \/>\nIf you\u2019d like to learn more about using Rancher, please join us for an<br \/>\n<a href=\"http:\/\/rancher.com\/events\/\">upcoming online meetup<\/a>, or join our <a href=\"http:\/\/info.rancher.com\/beta\">beta<br \/>\nprogram<\/a> or request a discussion with one<br \/>\nof our engineers.<\/p>\n<p><a href=\"https:\/\/rancher.com\/running-our-own-elk-stack-with-docker-and-rancher\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; A Detailed Overview of Rancher&#8217;s Architecture This newly-updated, in-depth guidebook provides a detailed overview of the features and functionality of the new Rancher: an open-source enterprise Kubernetes platform. Get the eBook At Rancher Labs we generate a lot of logs in our internal environments. As we conduct more and more testing on these environments &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw93\/index.php\/2019\/02\/10\/running-our-own-elk-stack-with-docker-and-rancher\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Running our own ELK stack with Docker and Rancher&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1209","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/1209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/comments?post=1209"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/1209\/revisions"}],"predecessor-version":[{"id":1210,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/1209\/revisions\/1210"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/media?parent=1209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/categories?post=1209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/tags?post=1209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}