Introduction
In this tutorial, we will explore how we can deploy Kill Bill in AWS by leveraging the existing Docker killbill container.
The deployment will rely on:
-
One EC2 instance where the killbill docker container runs
-
One RDS instance for mysql
Requirements: You need to create an AWS account and have an access to the AWS console
Note that those steps are mostly for the purpose of a demo; they omit production-like features such as DB backup, Monitoring, or even deploying multiple EC2 instances for HA or horizontal scalability purpose. However, all those are more a matter of configuring AWS towards that end and spawning more instances, so in final, the steps can be used as a basis to deploy Kill Bill in the cloud to handle your production traffic.
AWS Setup
The AWS setup is little bit convoluted, and even though there is a lot of documentation on aws, we will go through the various steps. To summarize the steps:
-
Setup of the VPC, that is now required by some instances
-
Setup and launch the RDS instance
-
Setup and launch the EC2 Killbill docker container
Configuring the VPC
From AWS console, choose VPC service:
-
Create the VPC
NameTag : dockerdemo CIDR block : 172.50.0.0/16 Tenancy : Default
Then select
Actions
to setDNS Resolution
andDNS Hostname
-
Then create an Internet Gateway
This is necessary to make sure the public IP is visible from the outside world.
Specifying a Name: dockerdemo Right click on the created gateway, and select 'attach to VPC'; chose the VPC previously created
-
Add subnets to VPC
Subnet sub menu
Create Subnet
:Name Tag: dockerdemo-e1b VPC: select previously created VPC Availability zone: us-east-1b CIDR block : 172.50.1.0/24 Select 'Modify Auto-Assign Plublic IP'
Repeat twice to create the other subnets with {us-east-1c, 172.50.2.0/24}, {us-east-1d, 172.50.3.0/24})
-
Create Custom Route Tables:
Route Tables Menu
Create Route table
:Name tag: dockerdemo VPC: prevous VPC Edit the routes to add the gateway: Destination: 0.0.0.0/0 Target: select the gateway igw-xxxx Tag 'Subnet associations': Edit and click on all subnet to 'associate'
-
Security Group for EC2 instances:
Security Group Menu
Create Security Group
:Name Tag: dockerdemo Group Name: dockerdemo VPC: select VPC Edit SG: Add following rules: {Type=SSH, Protocol=TCP, Port=22, Source=0.0.0.0/0 or your IP machine if you want to be more restrictive) {Type=HTTP, Protocol=TCP, Port=8080, Source=0.0.0.0/0)
-
Security Group for RDS instance:
Security Group Menu
Create Security Group
:Name Tag: dockerdemo-db Group Name: dockerdemo VPC: select VPC Edit SG: Add following rules: {Type=SSH, Protocol=TCP, Port=3306, Source=0.0.0.0/0 or your IP machine if you want to be more restrictive)
Configuring the RDS Instance
From AWS console, choose RDS service:
-
Add the subnet group for the DB:
Subnet Group Menu: Create DB subnet Group Name: dockerdemo-db VPC ID: select VPC Availability zone: pick one (us-east-1b) Add the 3 subnets prevoulsy created
-
Launch DB instance (select MySQL Community Edition)
Instance class: db.t2.micro Use Existing VPC: Select VPC Multi AZ: false DB Instance Identifier: dockerdemo Master Username: dockerdemo Master Password: dockerdemo Advanced Setting: VPC :select dockerdemo VPC security group : select the dockerdemo-db (oprt open for tcp 3306) Database name: killbill
-
Launch the database
Write down the endpoint (e.g dockerdemo.cah16olm8gkg.us-east-1.rds.amazonaws.com)
Configuring the EC2 Instance
From AWS console, choose EC2 service:
-
Launch instance: Chose AMI (ami-9eaa1cf6) Ubuntu Server 14.04 LTS (HVM), SSD Volume Type (for example)
Instance: t2.small (or adjust to your needs) Configure Details: Select VPC: dockerdemo Auto assign IP: Use subnet setting (Enable)
-
In order to get
dockerd
installed and started automatically, the folks from docker created a script that can be invoked byCloud-Init
:
InAdvanced Detail Section
:User Data: As text Enter in the box: #include https://get.docker.com
-
Next screen, edit security group and select thr previoulsy created security group (
dockerdemo
which opens port 22 and 8080) -
Launch the instance:
Create new key pair: dockerdemo
Download the private key
dockerdemo.pem
that will be needed later to download into the zone.
Kill Bill Setup
At this stage you have both a dockerized instance of EC2 running and an RDS instance. We need to setup the database and start Kill Bill. Also, and as an example we will deploy the stripe plugin along with Kill Bill.
Note: Replace the DNS names below in the rest of the doc with your RDS and EC2 DNS name
Since the RDS instance is not publicly available, we will configure it through our EC2 instance, so first we will need to ssh to the EC2 instance:
> chmod 400 docker.pem # make sure private key is read-only
> ssh -i dockerdemo.pem [email protected]
> ps -ef | grep dockerd # Or:
> sudo docker info
Configuring the Kill Bill database
Since the RDS instance is not publicly available, we will configure it through our EC2 instance. First we install the missing mysql-client package and then upload the database schema:
> sudo apt-get install -y mysql-client
> curl -q http://killbill.io/wp-content/uploads/2014/11/killbill-0.12.0.ddl | mysql -h dockerdemo.cah16olm8gkg.us-east-1.rds.amazonaws.com -u dockerdemo -pdockerdemo killbill
> curl -q https://raw.githubusercontent.com/killbill/killbill-stripe-plugin/master/db/ddl.sql | mysql -h dockerdemo.cah16olm8gkg.us-east-1.rds.amazonaws.com -u dockerdemo -pdockerdemo killbill
Configuring the Stripe Plugin
Create the stripe configuration:
> mkdir -p /home/ubuntu/killbil/etc/
> vi /home/ubuntu/killbil/etc/stripe.yml
Fill the details with your own keys:
:stripe:
:api_secret_key: API_SECRET_KEY
:test: true
:database:
:adapter: jdbcmysql
:jndi: killbill/osgi/jdbc
:connection_alive_sql: select 1
:pool: 25
Final Step
Finally download the docker image, and start it:
> sudo docker pull killbill/killbill:0.12.1
> sudo docker run -tid \
–name dockerdemo \
-p 8080:8080 \
-v /home/ubuntu/killbil/etc/stripe.yml:/etc/killbill/stripe.yml \
-e KILLBILL_PLUGIN_STRIPE=1 \
-e KILLBILL_CONFIG_DAO_URL=jdbc:mysql://dockerdemo.cah16olm8gkg.us-east-1.rds.amazonaws.com:3306/killbill \
-e KILLBILL_CONFIG_DAO_USER=dockerdemo \
-e KILLBILL_CONFIG_DAO_PASSWORD=dockerdemo \
-e KILLBILL_CONFIG_OSGI_DAO_URL=jdbc:mysql://dockerdemo.cah16olm8gkg.us-east-1.rds.amazonaws.com:3306/killbill \
-e KILLBILL_CONFIG_OSGI_DAO_USER=dockerdemo \
-e KILLBILL_CONFIG_OSGI_DAO_PASSWORD=dockerdemo \
killbill/killbill:0.12.1
> sudo docker logs -f dockerdemo # check for instance to be up and running
From this point, you can check everything is working by doing the same curls from the docker blog