A few weeks ago Rancher added a Docker Load Balancing service in 0.16 version which allows users to distribute traffic between Docker containers. Last week Rancher 0.20 version was released with a new great functionality which takes Load Balancing to a new level: Services. A Rancher Service is a group of containers running the same Docker image that you can scale up/down as needed. Rancher allows you to define Load Balancer services that you can link to any service group in order to automatically distribute traffic to the containers running in the linked group. When you scale up a service Rancher will randomly deploy the new container on any active host, and automatically add it to the linked Load Balancer so it will receive traffic when started. In my last post I was talking about building a distributed and persistent storage solution for Docker and Rancher using GlusterFS. Today we are using that storage in conjunction with Rancher Services/LB feature to show you how to deploy Highly Available, scalable and distributable web applications. In this post we are deploying a group of WordPress containers for publishing a blog site on AWS. We are also using a Percona XtraDB Cluster and the GlusterFS storage from last post so there is no Single Point of Failure in our setup. At the end we are testing scalability and HA capabilities for this solution. This is why the post is divided in these sections:
PrerequisitesPreparing AWS environmentBefore deploying the WordPress environment you need to satisfy the following requirements in AWS:
#!/bin/bash docker run -d -p 8080:8080 rancher/server:v0.20.0 Creating Docker hostsIn Rancher UI, click + Add Host button and choose Amazon EC2 provider. You need to specify, at least, the following information:
After a while you will see your three hosts up and running. Deploying the storage clusterAs described in my last post, you can deploy the storage following these instructions. First, click + Add Container button on wordpress1 host and enter the following information:
Expand Advanced Options and follow these steps:
Now wait for gluster1 container to be created and copy its Rancher IP address, you are needing it now. Then click + Add Container button on wordpress2 host to create the second GlusterFS server container with the following configuration:
Expand Advanced Options and follow these steps:
Now wait for gluster2 container to be created and open its menu, then click View Logs option. You will see the following messages at the bottom of log screen confirming that shared volume was successfully created. Deploying the database clusterNow it is time to create the database containers, which are running a Percona XtraDB Cluster (PXC). As PXC needs at least three nodes for quorum you are deploying three DB containers now, each one running on a different Docker host for better availability and performance. Click + Add Container on wordpress1 host and enter the following information:
Expand Advanced Options and follow these steps:
Show pxc1 logs and copy the values of PXC_NODES, PXC_SST_PASSWORD and PXC_ROOT_PASSWORD variables that you are needing now. You will also see messages informing that PXC cluster has been bootstraped. Now add a new PXC container with this configuration
Expand Advanced Options and follow these steps:
Finally wait for pxc2 to start, and add the third PXC container with this configuration:
Expand Advanced Options and follow these steps:
Wait for pxc3 to start. Then you can check how all MySQL processes are started on all PXC containers by showing their logs: Deploying the wordpress and LB servicesAs I introduced before, we are launching one Rancher Service for wordpress and another one for Load Balancers. This will allow us to easily scale up wordpress as Rancher will automatically deploy the new containers and add them to the Load Balancers by only clicking one button. All Rancher Services belong to a Rancher Environment. Environments are namespaces where services are deployed, so you can have different sets of services. To create the wordpress service go to Services section on Rancher UI and click + Add Environment button. Create a new environment named TEST. The process of creating a service is the same as creating a new container. Just click + Add Service and configure it as follows:
Expand Advanced Options and follow these steps:
Note that we are not defining any volume because we are using GlusterFS storage, and no ports are exposed because Load Balancers are publishing our WordPress service for us. Now click Start button on wordpress service and Rancher will automatically create and start 10 wordpress containers for you. Now we are creating the wordpress Load Balancers. To do so, click + Add Load Balancer button and enter this configuration:
After creating the LB service group you have to start it by clicking the Start button. At this point you have your HA wordpress environment up and running. Go to Hosts section and you will see your wordpress and LB containers deployed. Note that each Docker host is running a LB container, so you can use DNS balancing to get better availability. Completing wordpress installationNow that all our containers are started we have to browse to WordPress site and complete the installation. First of all configure a DNS registry to resolve all your Docker hosts IPs so LBs will receive web traffic. In my case, for testing purposes, I’m adding the following to my /etc/hosts file (I’m simulating a LB failover later): 52.24.85.40 #52.24.137.235 #52.10.158.122 Then browse to http:// (replace it with your current domain) and complete wordpress installation. Once finished you will see the wordpress Hello World post. You can customize your wordpress installation now, but we are doing a more interesting thing: testing the scalability and HA capabilities. Testing scalabilityIn case you need to handle more traffic and hence to scale up your environment you only have to click + Scale Up button on wordpress service group, and Rancher will automatically handle containers creation and will add them to the Load Balancers for you. I wish I would write more about this step but it’s that easy to scale up services now To test how Rancher added wordpress11 container to the LBs you may want to stop all wordpress1-10 containers and check that your site is still online. In case you need to scale down your infrastructure just delete some containers. In my case I’m deleting the wordpress11 container I have just created. Testing HA capabilitiesOur wordpress environment will be reliable if, at least, all these conditions are met:
To test this let’s simulate the worst case scenario:
Now browse to your blog and you will see that it’s still online. Login on wordpress so you will enter administration page. Then do the following in order to simulate a failover on all services, from storage to LB:
Navigate to wordpress administration. It is not only reachable but you also are able to use the same session because you were not logged out, so no matter which container is covering your services because you won’t note any service disruption. ConclusionRancher has added a new service feature to make it easier to distribute traffic across different Docker containers. Now you can scale up/down your environments from Rancher UI in just one step, and Rancher will automatically create new containers and add them to the appropriated Load Balancers. This simplifies the way to create Highly Available, scalable, and distributable environments ready for production use. As an example we have deployed a WordPress installation with redundant services for storage, database, web application, and Load Balancers. We have simulated common production failover/degradation scenarios and proved that our setup was fault tolerant and therefore users wouldn’t notice any service disruption. During our next Online Meetup, we’ll be providing a hands-on demonstration of how to build this type of application using Rancher and Docker Compose. Please join us:
Manel Martinez is a Linux systems engineer with experience in the design and management of scalable, distributable and highly available open source web infrastructures based on products like KVM, Docker, Apache, Nginx, Tomcat, Jboss, RabbitMQ, HAProxy, MySQL and XtraDB. He lives in spain, and you can find him on Twitter @manel_martinezg. |
|