Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / containers / Kubernetes

Get Up and Running with OpenShift on AWS

0.00/5 (No votes)
2 Feb 2017CPOL3 min read 7.7K  
Setting up your own OpenShift cluster can be a little complex, but in this article I'll show you how to make it fairly painless.

Get up and running with OpenShift on AWS

OpenShift is Red Hat's platform-as-a-service offering for hosting and scaling applications. It's built on top of Google's popular Kubernetes system.

Getting up and running with OpenShift Online is straightforward, as it is a cloud hosted solution. Setting up your own cluster is a little more complex, but in this article, I'll show you how to make it fairly painless.

Get up and running with OpenShift on AWS

The repo for this project is at github.com/dwmkerr/terraform-aws-openshift.

Creating the Infrastructure

OpenShift has some fairly specific requirements about what hardware it runs on1. There's also DNS to set up, as well as internet access and so on.

All in all, for a bare-bones setup, you'll need something like this:

Get up and running with OpenShift on AWS

Which is (deep breath):

  1. A network
  2. A public subnet, with internet access via a gateway
  3. A master host, which will run the OpenShift master
  4. A pair of node hosts, which will run additional OpenShift nodes
  5. A hosted zone, which allows us to configure DNS
  6. A bastion, which allows us to SSH onto hosts, without directly exposing them
  7. Some kind of basic log aggregation, which I'm using CloudWatch for

This is not a production grade setup, which requires redundant masters and so on, but it provides the basics.

Rather than setting this infrastructure up by hand, this is all scripted with Terraform. To set up the infrastructure, clone the github.com/dwmkerr/terraform-aws-openshift repo:

Bash
$ git clone git@github.com:dwmkerr/terraform-aws-openshift
...
Resolving deltas: 100% (37/37), done.  

Then use the terraform CLI2 to create the infrastructure:

Bash
$ cd terraform-aws-openshift/
$ terraform get && terraform apply

You'll be asked for a region, to deploy the network into, here I'm using us-west-1:

Get up and running with OpenShift on AWS

After a few minutes, the infrastructure will be set up:

Get up and running with OpenShift on AWS

A quick glance at the AWS console shows the new hosts we've set up:

Get up and running with OpenShift on AWS

The next step is to install OpenShift.

Installing OpenShift

There are a few different ways to install OpenShift, but the one we'll use is called the 'advanced installation3'. This essentially involves:

  1. Creating an 'inventory', which specifies the hosts OpenShift will be installed on and the installation options
  2. Downloading the advanced installation code
  3. Running the advanced installation Ansible Playbook

To create the inventory, we just run:

Bash
sed "s/\${aws_instance.master.public_ip}/$(terraform output master-public_ip)/" 
inventory.template.cfg > inventory.cfg  

This takes our 'inventory template4' and populates it with the public IP of our master node, which is recorded in a Terraform output variable.

We can then copy the inventory to the bastion:

Bash
ssh-add ~/.ssh/id_rsa  
scp ./inventory.cfg ec2-user@$(terraform output bastion-public_dns):~  

We can again use the Terraform output variables, this time to get the bastion IP. Finally, we pipe our install script to the bastion host:

Bash
cat install-from-bastion.sh | ssh -A ec2-user@$(terraform output bastion-public_dns) 

There's a bug which means you might see ansible-playbook: command not found, if so, just run the script again. The install script clones the installation scripts and runs them, using the inventory we've provided:

Get up and running with OpenShift on AWS

This'll probably take about 10 minutes to run. And that's it, OpenShift is installed:

Bash
open "https://$(terraform output master-public_dns):8443" 

Hit 'advanced' and continue, as we're using a self-signed certificate most browsers will complain:

Get up and running with OpenShift on AWS

Enter any username and password (the system is configured to allow anyone to access it by default) and you'll be presented with the OpenShift console:

Get up and running with OpenShift on AWS

As the setup requires three t2.large instances, which are not available on the free plan, you might want to clean up when you are done with:

Bash
terraform destroy 

Wrapping Up

Hopefully, you've found this useful, there are more details and references on the README of the github repo:

Comments and feedback are always welcome!

History

  • 2nd February, 2017: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)