{"id":680,"date":"2018-10-23T04:22:34","date_gmt":"2018-10-23T04:22:34","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw93\/?p=680"},"modified":"2018-10-24T02:05:58","modified_gmt":"2018-10-24T02:05:58","slug":"reducing-your-aws-spend-with-autospotting-and-rancher","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw93\/index.php\/2018\/10\/23\/reducing-your-aws-spend-with-autospotting-and-rancher\/","title":{"rendered":"Reducing Your AWS Spend with AutoSpotting and Rancher"},"content":{"rendered":"<p>Back in older times, B.C. as in Before Cloud, to put a service live you<br \/>\nhad to:<\/p>\n<ol>\n<li>Spend months figuring out how much hardware you needed<\/li>\n<li>Wait at least eight weeks for your hardware to arrive<\/li>\n<li>Allow another four weeks for installation<\/li>\n<li>Then, configure firewall ports<\/li>\n<li>Finally, add servers to config management and provision them<\/li>\n<\/ol>\n<p>All of this was in an organised company!<\/p>\n<h2>The Now<\/h2>\n<p>The new norm is to use hosted instances. You can scale these up and down<br \/>\nbased on requirements and demand. Servers are available in a matter of<br \/>\nseconds. With containers, you no longer care about actual servers. You<br \/>\nonly care about compute resource. Once you have an orchestrator like<br \/>\n<a href=\"https:\/\/rancher.com\/quick-start\/\">Rancher<\/a>, you don\u2019t need to worry<br \/>\nabout maintaining scale or setting where containers run, as Rancher<br \/>\ntakes care of all of that. Rancher continuously monitors and assesses<br \/>\nthe requirements that you set and does its best to ensure that<br \/>\neverything is running. Obviously, we need some compute resource, but it<br \/>\ncan run for days or hours. The fact is, with containers, you pretty much<br \/>\ndon\u2019t need to worry.<\/p>\n<h2>Reducing Cost<\/h2>\n<p>So, how can we take advantage of the flexibility of containers to help<br \/>\nus reduce costs? There are a couple of things that you can do. Firstly<br \/>\n(and this goes for VMs as well as containers), do you need all your<br \/>\nenvironments running all the time? In a world where you own the kit and<br \/>\nthere is no cost advantage to shutting down environments versus keeping<br \/>\nthem running, this practice was accepted. But in the on-demand world,<br \/>\nthere is a cost associated with keeping things running. If you only<br \/>\nutilise a development or testing environment for eight hours a day, then<br \/>\nyou are paying four times as much by keeping it running 24 hours a day!<br \/>\nSo, shutting down environments when you\u2019re not using them is one way to<br \/>\nreduce costs. The second thing you can do (and the main reason behind<br \/>\nthis post) is using <a href=\"https:\/\/aws.amazon.com\/ec2\/spot\/\">Spot Instances<\/a>.<br \/>\nNot heard of them? In a nutshell, they\u2019re a way of getting cheap<br \/>\ncompute resource in AWS. Interested in saving up to 80% of your AWS EC2<br \/>\nbill? Then keep reading. The challenge with Spot Instances is that they<br \/>\ncan terminate after only two minutes\u2019 notice. That causes problems for<br \/>\ntraditional applications, but containers handle this more fluid nature<br \/>\nof applications with ease. Within AWS, you can directly request Spot<br \/>\nInstances, individually or in a fleet, and you set a maximum price for<br \/>\nthe instance. Once you breach this price, AWS gives you two minutes and<br \/>\nthen terminates the instance.<\/p>\n<h2>AutoSpotting<\/h2>\n<p>What if you could have an Auto Scaling Group (ASG) with an On-Demand<br \/>\nInstance type to which you could revert if you breached the Spot<br \/>\nInstance price? Step forward an awesome piece of open-source software<br \/>\ncalled AutoSpotting. You can find the source and more information on<br \/>\n<a href=\"https:\/\/github.com\/cristim\/autospotting\">GitHub<\/a>. AutoSpotting works by<br \/>\nreplacing On-Demand Instances from within an ASG with individual Spot<br \/>\nInstances. AutoSpotting takes a copy of the launch config of the ASG and<br \/>\nstarts a Spot Instance (of equivalent spec or more powerful) with the<br \/>\nexact same launch config. Once this new instance is up and running,<br \/>\nAutoSpotting swaps out one of the On-Demand Instances in the ASG with<br \/>\nthis new Spot Instance, in the process terminating the more expensive<br \/>\nOn-Demand Instance. It will continue this process until it replaces all<br \/>\ninstances. (There is a configuration option that allows you to specify<br \/>\nthe percentage of the ASG that you want to replace. By default, it\u2019s<br \/>\n100%.) AutoSpotting isn\u2019t application aware. It will only start a<br \/>\nmachine with an identical configuration. It doesn\u2019t perform any<br \/>\ngraceful halting of applications. It purely replaces a virtual instance<br \/>\nwith a cheaper virtual instance. For these reasons, it works great for<br \/>\nDocker containers that are managed by an orchestrator like Rancher. When<br \/>\na compute instance disappears, then Rancher takes care of maintaining<br \/>\nthe scale. To facilitate a smoother termination, I\u2019ve created a helper<br \/>\nservice, AWS-Spot-Instance-Helper, that monitors to see if a host is<br \/>\nterminating. If it is, then the helper uses the Rancher evacuate<br \/>\nfunction to more gracefully transition running containers from the<br \/>\nterminating host. This helper isn\u2019t tied to AutoSpotting, and anyone<br \/>\nwho is using Spot Instances or fleets with Rancher can use it to allow<br \/>\nfor more graceful terminations. Want an example of what it does to the<br \/>\ncost of running an environment?<br \/>\n<a href=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/10\/13065924\/aws-auto.png\"><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/10\/13065924\/aws-auto.png\" alt=\"\" \/><\/a><br \/>\nCan you guess which day I implemented it? OK, so I said up to 80%<br \/>\nsavings but, in this environment, we didn\u2019t replace all instances at the<br \/>\npoint when I took this measurement. So, why are we blogging about it<br \/>\nnow? Simple: We\u2019ve taken it and turned it into a Rancher Catalog<br \/>\napplication so that all our Rancher AWS users can easily consume it.<\/p>\n<h2>3 Simple Steps to Saving Money<\/h2>\n<h3>Step 1<\/h3>\n<p>Go to the Catalog &gt; Community and select AutoSpotting.<br \/>\n<a href=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/10\/13070030\/auto.png\"><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/10\/13070030\/auto-247x300.png\" alt=\"\" \/><\/a><\/p>\n<h3>Step 2<\/h3>\n<p>Fill in the AWS Access Key and Secret Key. (These are the only<br \/>\nmandatory fields.) The user must have the following AWS permissions:<\/p>\n<p>autoscaling:DescribeAutoScalingGroups<\/p>\n<p>autoscaling:DescribeLaunchConfigurations<\/p>\n<p>autoscaling:AttachInstances<\/p>\n<p>autoscaling:DetachInstances<\/p>\n<p>autoscaling:DescribeTags<\/p>\n<p>autoscaling:UpdateAutoScalingGroup<\/p>\n<p>ec2:CreateTags<\/p>\n<p>ec2:DescribeInstances<\/p>\n<p>ec2:DescribeRegions<\/p>\n<p>ec2:DescribeSpotInstanceRequests<\/p>\n<p>ec2:DescribeSpotPriceHistory<\/p>\n<p>ec2:RequestSpotInstances<\/p>\n<p>ec2:TerminateInstances<\/p>\n<p>Optionally, set the Tag Name. By default, it will look for<br \/>\nspot-enabled. I\u2019ve slightly modified the original code to allow the<br \/>\nflexibility of running multiple AutoSpotting containers in an<br \/>\nenvironment. This modification allows you to use multiple policies in<br \/>\nthe same AWS account. Then, click Launch.<\/p>\n<h3>Step 3<\/h3>\n<p>Add the tag (user-specified or spot-enabled, with a value of<br \/>\ntrue) to any AWS ASGs on which you want to save money. Cheap (and<br \/>\noften more powerful) Spot Instances will gradually replace your<br \/>\ninstances. To deploy the AWS-Spot-Instance-Helper service, simply<br \/>\nbrowse to the Catalog &gt; Community and launch the application.<br \/>\n<a href=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/10\/13070120\/helper.png\"><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/10\/13070120\/helper-250x300.png\" alt=\"\" \/><\/a><br \/>\nThanks goes out to Cristian M\u0103gheru\u0219an-Stanciu and <a href=\"https:\/\/github.com\/cristim\/autospotting\/graphs\/contributors\">other<br \/>\ncontributors<\/a><br \/>\nfor writing such a great piece of open-source software.<\/p>\n<h3>About the Author<\/h3>\n<p><img decoding=\"async\" src=\"http:\/\/cdn.rancher.com\/wp-content\/uploads\/2017\/11\/21103711\/ChrisUrwin-300x286.jpg\" alt=\"\" \/>Chris Urwin works<br \/>\nas a field engineer for Rancher Labs based out of the UK, helping our<br \/>\nenterprise clients get the most out of Rancher.<\/p>\n<p><a href=\"https:\/\/rancher.com\/reducing-aws-spend\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in older times, B.C. as in Before Cloud, to put a service live you had to: Spend months figuring out how much hardware you needed Wait at least eight weeks for your hardware to arrive Allow another four weeks for installation Then, configure firewall ports Finally, add servers to config management and provision them &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw93\/index.php\/2018\/10\/23\/reducing-your-aws-spend-with-autospotting-and-rancher\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Reducing Your AWS Spend with AutoSpotting 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-680","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\/680","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=680"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/680\/revisions"}],"predecessor-version":[{"id":688,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/posts\/680\/revisions\/688"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/media?parent=680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/categories?post=680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw93\/index.php\/wp-json\/wp\/v2\/tags?post=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}