Using Weave to Network Containerized Microservices on Amazon ECS
Amazon EC2 Container Service (ECS) is a Docker container management service, part of Amazon Web Services (AWS) cloud. By using Weave Net, a software-defined networking solution, you can deploy containers onto ECS more easily, without...
March Release - Weave GitOps 2022.03
Weave GitOps Enterprise: A First Look at the November 2021 Release
Weave GitOps Core: Continuous declarative delivery
Amazon EC2 Container Service (ECS) is a Docker container management service, part of Amazon Web Services (AWS) cloud. By using Weave Net, a software-defined networking solution, you can deploy containers onto ECS more easily, without having to use host network and manage port allocation and remapping. Weave Net simplifies this by handling service discovery and load balancing for you. It is a unique service discovery option because it doesn’t use an external database or a consensus algorithm, relying instead on gossip protocol. Additionally, Weave Net supports other use cases, which include transparent cross-region connectivity, cross-cloud, and multicast.
Although Amazon ECS already provides infrastructure for Docker container management, using Weave Net with built-in service discovery removes the need for external load balancing for each internal service that needs connection. Containers can find each other with nothing more than a DNS query and can communicate with each other via standard IP networking. Default ports, such as 80 for HTTP and 443 for HTTPS can be used, as each container gets a unique IP address.
Weave Net allows you to build a container networking solution in minutes, conserving valuable time and money. It can be used as a standalone product; in combination with Weave Scope, software for container visualization and monitoring; or as part of Weave Cloud, a container microservices solution that utilizes the power of both Weave Net and Weave Scope. Whatever your decision, here’s how to get started.
Setting Up and Getting Started
Now you need to configure your stack. You do that by enabling “Specify an Amazon S3 template URL,” entering your stack name, choosing the name of the key pair you’ve generated, and tick the capabilities acknowledgement box.
Once you’ve done this, the CloudFormation stack dashboard will appear, allowing you to monitor the progress of your stack creation. This will take roughly 15 minutes to complete.
After stack creation is complete, select the outputs tab and look for the URLs for both the ThePixelMonsterzApp and Weave Scope. ThePixelMonsterzApp generates unique avatars for signed up users in a forum and identifies them, without them having to sign up for an external service, like Gravatar.
The app generates a new monster avatar on each container, caches it, showing it to each visitor, who hits that particular container which is load-balanced by the Elastic Load Balancer (ELB). It also picks another random monster, just for fun.
Monsters are counted based on app instances with a unique IP address that is assigned to the container by Weave Net.
Now it’s time to display the container infrastructure of the demo by launching Weave Scope. On the Outputs tab of your CloudFormation Dashboard, choose the link for the Weave Scope UI.
The view you’ll see is filtered by container and shows you a container level view of your app’s infrastructure set up. By clicking on the Redis node you’ll see how all of the containers connected to it are highlighted when you mouseover or click on it. On the right side is a details panel which displays a number of different metrics about the Redis database.
This view filters nodes by DNS name. The details panel is visible by clicking on redis again. Here you can see the containers and processes, as well as other high-level metrics such as memory and cpu usage.
You can easily redesign the app without having to implement complex port-mapping or introduce any beefy load-balancers for what is really a simple task.
Testing Performance and Balancing Loads
Once you have set up this example network, you’re ready to begin testing the performance of the HTTP Server containers on the network. Pick any or all of the following URLs and enter them into your browser:
You should then see a web page displaying a “chosen data producer message.” Reload your browser to force the HTTP Server to refresh its Data Producer address list, which will balance the load between the EC2 instances and likely change the IP address that is displayed on the web page.
When you’re finished with the example, run the following command in the Amazon CLI tool to clean up after yourself:
How It Works
Weave serves as an intermediary when launching containers, intercepting the Amazon ECS command to initialize a container before the command reaches Docker. Once the command is received, Weave assigns an IP address to the container, registers the container with the Weave DNS service discovery and places it on the Weave network.
In this simple example, the Data Producer containers and HTTP Server containers operate in a complementary, interconnected fashion. As long as the containers are running, the HTTP Server continually contacts a Data Producer over TCP port 4540. After each instance of contact, the Data Producer then sends a message back to the HTTP Server, which in this example is a short greeting containing the Data Producer’s IP address. Finally, the HTTP Server constructs an HTML message that will be displayed to you when you contact an HTTP Server by visiting one of the above URLs.
If you decided to use Weave Cloud while setting up for this example, you can visualize this connection by logging into Weave Cloud while you are running the test. Visit https://cloud.weave.works to log in if you obtained a service token during setup; otherwise, you can still view the visualization if you attach “:4040” (signifying the Weave Scope application listening on port 4040) to the end of one of the above URLS (e.g. “http://foo.region.compute.amazonaws.com:4040”).
Assuming that you have set up the example correctly, you should see a graph with connections extending from the chosen HTTP Server container (the one visited by your browser) to the three Data Producer containers. These three simultaneous connections represent the automatic load balancing that Weave performs by randomizing the IP address of each container.
Although this example is extremely straightforward, it clearly demonstrates some of the key features of Weave, including service discovery and load balancing, and the ease with which you can use Weave to set up and deploy containerized microservices on Amazon ECS. Whether used as a standalone piece of software or in conjunction with Weave Scope to provide container visualization and monitoring, Weave Net is able to have your Docker containers running and communicating on Amazon ECS within minutes and with minimal difficulty.