{"id":55816,"date":"2022-11-24T13:17:23","date_gmt":"2022-11-24T07:47:23","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=55816"},"modified":"2022-11-24T13:17:23","modified_gmt":"2022-11-24T07:47:23","slug":"manage-stateful-ecs-services-using-rex-ray","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/manage-stateful-ecs-services-using-rex-ray\/","title":{"rendered":"Manage Stateful ECS Services using REX-Ray"},"content":{"rendered":"<h2><b>Introduction<\/b><\/h2>\n<p><span data-preserver-spaces=\"true\">We have been looking for a solution that would help us to mount hundreds of GBs of storage in the ECS tasks spawned by specific ECS services. ECS cluster does provide an option to increase the storage allocated to the tasks, but that applies to all the ECS services running inside the cluster. Sometimes, we need the same warehouse to be available for new ECS tasks.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">REX-Ray is an open-source storage management that is built on the libStorage framework. It supports both of our use cases, i.e., it helps us to deploy stateful applications on ECS. This functionality could be extended to various use cases, such as running databases or Jenkins in a containerized environment. It supports multiple docker orchestration tools( Kubernetes, Mesos Frameworks, Docker Swarm, etc.) to automatically orchestrate storage tasks between hosts in the cluster.<\/span><\/p>\n<h2><strong><span data-preserver-spaces=\"true\">Problem Statement<\/span><\/strong><\/h2>\n<ul>\n<li><span data-preserver-spaces=\"true\">To manage stateful ECS services to persist and maintain its data after the container&#8217;s life cycle has ended.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">To provide additional storage in the ECS tasks where multiple large files are to be downloaded and processed.<\/span><\/li>\n<\/ul>\n<h2><strong><span data-preserver-spaces=\"true\">Solution Approach<\/span><\/strong><\/h2>\n<p><span data-preserver-spaces=\"true\">We require additional storage at a specific path inside ECS tasks for a particular ECS service.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">\u201cREX-Ray &#8211; a docker volume plugin\u201d provides the capability to use shared storage as a Docker volume. In AWS, it supports EBS to be used as a docker volume in ECS tasks.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-55815\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-24-at-9.46.22-AM-1024x744.png\" alt=\"\" width=\"625\" height=\"454\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-24-at-9.46.22-AM-1024x744.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-24-at-9.46.22-AM-300x218.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-24-at-9.46.22-AM-768x558.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-24-at-9.46.22-AM-624x453.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-24-at-9.46.22-AM.png 1126w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><strong>Steps to configure the plugin:<br \/>\n<\/strong><\/p>\n<ol>\n<li>Every EC2 instance running inside an ECS cluster should have the plugin installed.<br \/>\nAdd the below command to the user data in the launch template used to launch instances in the ECS cluster.<br \/>\n<code>#docker plugin install rexray\/ebs --grant-all-permissions<br \/>\n<\/code><code> <\/code><\/li>\n<li>Configure the task definition to use the REX-Ray plugin as below under \u201cAdd Volume\u201d section:<strong><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-55812\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM-967x1024.png\" alt=\"\" width=\"625\" height=\"662\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM-967x1024.png 967w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM-283x300.png 283w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM-768x813.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM-624x660.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM-24x24.png 24w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-6.31.31-PM.png 1438w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><\/strong><\/p>\n<ul>\n<li>\u201cName\u201d &#8211; EBS volume will be created using this name. If already created, provide the name of the Volume.<\/li>\n<li>\u201cVolume type\u201d &#8211; Select the volume type as \u201cDocker.\u201d<\/li>\n<li>\u201cDriver\u201d &#8211; Specify the driver name as \u201crexray\/ebs\u201d<\/li>\n<li>\u201cScope\u201d &#8211; Select \u201ctask\u201d if you need a new volume to be created with every new task created under the ECS service. Select \u201cshared\u201d if you need the new task to use the existing volume being used by a previously running task.<br \/>\nWhile using \u201cshared\u201d mode, please check its behavior while running multiple tasks in single and multiAz environments.<\/li>\n<li>\u201cEnable auto-provisioning\u201d: This option is applicable in \u201cshared\u201d mode. In \u201cshared\u201d mode, you can either use the existing volume or, if the volume is not present, the plugin will create one for you.<\/li>\n<li>\u201cDriver options\u201d: Under driver options, the volume size can be specified in case of new volume creation.<\/li>\n<\/ul>\n<\/li>\n<li>The next step is to update the service with the new task revision created after the above configuration. Once the service is deployed, you should be able to see similar output on EC2 instance using \u201clsblk\u201d command:\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-55814\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM.png\" alt=\"\" width=\"3490\" height=\"298\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM.png 3490w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM-300x26.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM-1024x87.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM-768x66.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM-1536x131.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM-2048x175.png 2048w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.27.50-PM-624x53.png 624w\" sizes=\"(max-width: 3490px) 100vw, 3490px\" \/><\/li>\n<\/ol>\n<h2><b>Debugging<\/b><\/h2>\n<ul>\n<li>Verify if the REX-Ray plugin is enabled on the container instance by viewing its attributes. Search for \u201crexray\u201d in the list, if present, the plugin is enabled.<br \/>\n<h2><strong><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-55813\" src=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.13.00-PM-300x109.png\" alt=\"\" width=\"300\" height=\"109\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.13.00-PM-300x109.png 300w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.13.00-PM-1024x371.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.13.00-PM-768x278.png 768w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.13.00-PM-624x226.png 624w, \/blog\/wp-ttn-blog\/uploads\/2022\/11\/Screenshot-2022-11-23-at-7.13.00-PM.png 1324w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/strong><\/h2>\n<\/li>\n<li>The debug flag can be used with any command in order to get the verbose output:<br \/>\n# rexray volume -l debug<\/li>\n<li>Ensure EBS creation permissions are attached to the EC2 instances.<\/li>\n<li>When \u201cScope\u201d is selected as \u201ctask,\u201d upon the termination of the ECS tasks, rexray plugin does not delete the detached volumes.<\/li>\n<\/ul>\n<h2><b>More Use Cases:<\/b><\/h2>\n<p><span data-preserver-spaces=\"true\">We have been using this plugin for over 3 years, and it is working as expected.<\/span><\/p>\n<p><span data-preserver-spaces=\"true\">Other use cases where we are using it are:<\/span><\/p>\n<ul>\n<li><span data-preserver-spaces=\"true\">Running Ldap in ECS and maintaining the configuration in EBS volumes using the REX-Ray plugin in \u201cshared\u201d mode.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">Running Nexus as an ECS service while maintaining configuration in EBS volume using this plugin.<\/span><\/li>\n<li><span data-preserver-spaces=\"true\">REX-Ray supports multiple Operating Systems and Storage Providers and can be used in numerous ways as per the requirement. Reference Link: https:\/\/rexray.readthedocs.io\/en\/stable\/<\/span><\/li>\n<\/ul>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Introduction We have been looking for a solution that would help us to mount hundreds of GBs of storage in the ECS tasks spawned by specific ECS services. ECS cluster does provide an option to increase the storage allocated to the tasks, but that applies to all the ECS services running inside the cluster. Sometimes, [&hellip;]<\/p>\n","protected":false},"author":506,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":61},"categories":[1174,4308,2348],"tags":[5046],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/55816"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/506"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=55816"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/55816\/revisions"}],"predecessor-version":[{"id":55819,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/55816\/revisions\/55819"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=55816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=55816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=55816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}