January 6, 2016
TABLE OF CONTENTS
Docker provides the most concise way to create portable containers for all types of software applications. When you start moving into large, distributed production environments, you quickly find that provisioning, deployment and orchestration can become a bit complex and confusing within the Docker paradigm. That’s where Rancher comes in.
Rancher is open source software that makes it simple for organizations to deploy a private container service and deliver Docker orchestration to users. Within a team, authorized users are able to create resource pools from any hosts, and then launch containers or application templates from Rancher’s UI or CLI. Users have complete control over how their applications are deployed, and Rancher provides all of the necessary infrastructure services such as networking, load balancing, and storage to ensure the application runs brilliantly on any infrastructure.
Whether you like starting containers with the Docker CLI or prefer Docker Compose, Rancher works in the background to provide consistent infrastructure services.
Rancher implements a global, DNS-based service discovery function that allows containers to automatically register themselves as services, as well as services to dynamically discover each other over the network. It also provides an integrated, elastic load balancing service to distribute traffic between containers or services. Based on HA proxy, the service allows session management, health checks and can be scaled across containers to meet demand.
Today we’re going to take a look at deploying Rancher to AWS and then spinning up a small Rails application with a Postgres DB. We’ll use the same container that we’ve been developing in my previous blogposts about Rails+Docker Development.
The first thing we’ll do is log into the AWS console and spin up a server which will act as our Rancher server.
Provision a Linux host with 64-bit Ubuntu 14.04, which must have a kernel of 3.10+. Please make sure the Linux host has at least 1GB memory.
I’ll be using Ubuntu Server 14.04 LTS (HVM), SSD Volume Type – ami-d05e75b8 as a t2.micro instance.
Once it’s spun up, SSH into the instance so we can install Docker and Rancher.
$ wget -qO- https://get.docker.com/ | sh
All you need is one command to launch Rancher server. After launching the container, we’ll tail the logs to see when the server is up and running.
sudo docker run -d --restart=always -p 8080:8080 rancher/server
Once that container has been started, you can run a sudo docker ps to see the running process.
4da21cc4a03c rancher/server “/usr/bin/s6-svscan /” 4 minutes ago Up 4 minutes 3306/tcp, 0.0.0.0:8080->8080/tcp modest_torvalds
Now that port 8080 is exposing our Rancher container, we can navigate to
_your_ec2_ip:8080 and login to the Rancher UI. First we’ll need to modify our Security Group for this instance to allow incoming TCP connections on port 8080:
Now you can navigate to port 8080 of your EC2 instance in your browser. You should see the Rancher UI with a warning about Access Control.
Now we want to create a Host and it’s probably a good idea to create an IAM user with AdministratorAccess first and download the credentials. This IAM user will execute things on behalf of Rancher and you’ll need the User Name, Access Key ID and Secret Access Key.
Hosts are the most basic unit of resource within Rancher and is represented as any Linux server, virtual or physical, with the following minimum requirements:
Click on Add Host and you should see the following:
Save, click Next and you’ll be taken to the Add Hosts page. Digital Ocean will be highlighted by default but we’re going to select AWS EC2 to begin. You’ll want to enter your IAM user credentials here so that Rancher can create and manage EC2 instances on your behalf.
Click Next to Authenticate and select a network. If your IAM user has sufficient access, you’ll see this below:
Now we can click next to set up our Security Groups. Here it’s best to let the default rancher-machine group be created as it has all the necessary ports opened.
The next section will ask for some basic instance info and all you really need to worry about is the name and the Docker install url which should be http://get.docker.com.
Click Create and you’ll see Rancher reaching out to AWS to create a new host on an EC2 instance.
This process takes a few minutes as it spins up an EC2 instance, installs the Rancher agent and Docker and then networks it in.
Once this is complete, you’ll see the host listed.
Now we can tab over to the AWS console and verify that this new EC2 instance has been created. If you look below, you see that one instance running the Rancher server was able to provision an EC2 instance directly from the GUI. That’s pretty cool and provides a great PaaS-like abstraction from EC2 (or DigitalOcean and a bunch of other Cloud providers).
Now we want to actually do something with this Host, i.e. deploy some Docker container apps to it.
If we click on Applications in the Rancher GUI, we will be able to deploy an app.
We’re going to deploy a Rails app and a PostgresDB. Let’s start by adding a Stack. We’ll use docker-compose.yml, slightly modified from our project to deploy this.
db: image: postgres web: image: denmanjd/rails_app ports: - "3000:3000" links: - db
Click Create and we’ll see Rancher starting to spin this Stack up. Once it’s done you’ll see both containers started and you can navigate to port 3000 of this host to view your application.
This deployment process is much more intuitive than using Amazon ECS or something manual and Rancher handles instantiating and deleting instances for you. While this is a simple overview, things really get interesting when you network multiple hosts over multiple cloud providers and Rancher deploys distributed container applications for you.
We here at Levvel are really passionate about container technology and managing, orchestrating and deploying containerized apps in a DevOps paradigm. Feel free to reach out to us for help in modernizing your DevOps development efforts.
Levvel is an IT consulting firm that combines the innovative DNA of a start up with the wisdom, scalability, and process rigor of a Fortune 100 company. We offer both technical implementation services as well as strategic advisory services. Levvel offers you an “unfair advantage” over your competition with comprehensive services including DevOps, Cloud, Mobile, UI/UX, Big Data, Analytics, Payment Strategy, and more.
Businesses face a higher bar for application performance than ever before. Users will simply abandon a service that is not responsive enough. Performance testing enables teams to develop more efficient code that makes an application run smoothly.
Levvel CEO Chris Hart spoke at HMG Strategy's CIO Executive Leadership Summit event. In this video series, Hart talks about effective collaboration, communication, and culture in the c-suite, as well as how technology sharpens the competitive edge.
At the end of lunch with a mentee, I used the items on our table to express the fundamental concepts of Kubernetes. Sometime after explaining the purpose of the Kubernetes scheduler, she asked a question I spent the next several weeks thinking about.
API design is crucial, giving structure to application interaction. Given cross-functional teams and applications, development time is reduced with a clear, intuitive way to access data. API development often follows two approaches: REST and GraphQL.