Book Image

OpenShift Cookbook

By : Shekhar Gulati
Book Image

OpenShift Cookbook

By: Shekhar Gulati

Overview of this book

Table of Contents (19 chapters)
OpenShift Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Running OpenShift on a Virtual Machine
Index

A brief introduction into OpenShift


A few years ago, I wanted to write a web application that would process a stream of tweets about a movie and then output the overall sentiment about it. This would help me decide whether I should watch a movie or not. So, I researched for a hosting provider and found out that I could rent a few virtual machines from Amazon to host my web application. This was my entry into the world of cloud computing. Cloud computing allows access to a shared pool of computing (both hardware and software) resources available as a service over the network, which is pay per use, has an elastic nature (that is, can be scaled up and down), and is available on demand. It has three delivery models:

  • Infrastructure as a Service (IaaS): This is the most fundamental delivery model where a user can provision compute, storage, and other resources such as network to run an application, but the user has to install and manage the application stack required to run the application. Examples of IaaS include Amazon EC2, Google Compute Engine, and Rackspace.

  • Platform as a Service (PaaS): PaaS provides an application development platform to help developers build their applications using the runtimes, tools, libraries, and services provided by the platform provider. Examples of PaaS include OpenShift, Cloud Foundry, and Heroku.

  • Software as a Service (SaaS): SaaS is a set of applications (or software) that run on the cloud and are available as a service. Examples of SaaS include Google Apps and Microsoft Office 365.

As a developer, I liked the concept of PaaS, as it enabled me to use my skillset to focus only on the application code and let someone else worry about managing the application stack and infrastructure for me.

OpenShift is an open source, a polyglot, and a scalable PaaS from Red Hat. At the time of writing this book, OpenShift officially supports the Java, Ruby, Python, Node.js, PHP, and Perl programming language runtimes, along with MySQL, PostgreSQL, and MongoDB databases, and a lot of other features. Along with all the supported services, OpenShift users can also leverage marketplace (https://marketplace.openshift.com/home) to try and use other cloud services managed by various partners. The services supported by the partners vary from databases such as ElephantSQL scalable PostgreSQL as a Service to SendGrid's Email as a Service.

OpenShift is an umbrella under which three subprojects coexist. These three subprojects differ in the way they deliver the OpenShift technology to the users, developers, and community members. Each of the subprojects is described as follows:

  • OpenShift Origin: OpenShift Origin is the open sourced, Apache License 2.0, community-supported version of OpenShift. It is the upstream feeder project to both OpenShift Online and OpenShift Enterprise. The project is available on GitHub at https://github.com/openshift.

  • OpenShift Online: OpenShift Online is the public-managed version of OpenShift. It runs on top of Amazon EC2 and uses a hardened and stabilized version of OpenShift Origin. Every OpenShift Online user is entitled to a free plan. The free plan gives users access to three small instances with 512 MB RAM and 1 GB of disk space. OpenShift Online is also available as commercial offering via Bronze and Silver plans. The commercial plans allow users to get more resources, storage, and Red Hat professional support. You can learn about the OpenShift Online pricing at https://www.openshift.com/products/pricing.

  • OpenShift Enterprise: OpenShift Enterprise is a Red Hat fully supported, private PaaS solution, which can run on enterprise hardware. OpenShift Enterprise can help make enterprises more agile and meet their business application demands.

This book will focus mainly on OpenShift Online, but the recipes apply to all three.

As a developer, you can interact with OpenShift in the following four ways:

  • Web console: This is the easiest way to get started with OpenShift, as it does not require you to install any software on your machine. You can log in to the web console and start creating applications. At the time of writing this book, the web console lacks all the features available in the command-line tool.

  • The rhc command line: This is a command-line tool that interacts with OpenShift. It is available as a Ruby gem. It is the most powerful way to interact with OpenShift because it exposes all the OpenShift functionalities.

  • IDE Integration: If you are a developer who likes to do most of the coding from within an IDE, then you will be happy to know that OpenShift has first class integration with various IDEs such as Eclipse, IntelliJ IDEA, Zend Studio, and Titanium Studio.

  • The REST API: You can write your own client using the OpenShift REST API. You can use this API to write plugins for IDEs such as NetBeans or write another command-line client. You can read the REST API documentation at https://access.redhat.com/knowledge/docs/en-US/OpenShift/2.0/html-single/REST_API_Guide/index.html.

The important OpenShift components are shown in the following diagram:

As shown in the preceding diagram, a developer interacts with OpenShift using one of the client interfaces, that is, the web console, rhc command-line client, or IDE support. OpenShift has the following three main components:

  • Broker: All the clients interact with the broker using a well-defined REST interface exposed by the broker. The broker is responsible for all application management activities. It is a Ruby on Rails application that manages user logins, DNS management, and general application orchestration.

  • Node: This is a set of RHEL instances that provides a multitenant environment for end user applications.

  • Gear: A gear is a secure container that runs inside a node and host user applications. It is constrained by CPU, disk space, and memory.

Note

The broker and nodes use the ActiveMQ message queue to talk with each other. They both have the MCollective client installed on them to send instructions to each other.

Now that you know what OpenShift is and how you can work with it, let's kick off the first chapter. This chapter presents a number of recipes that gets you up to speed quickly by giving you information you need to create cloud applications using OpenShift. You will learn how to create your first OpenShift application using the web console, clone the application using Git, make your first source code change, and finally deploy that change to OpenShift. If this is the first time you are working with OpenShift, then you will be amazed by the speed at which you can create and deploy applications on OpenShift. This chapter will also cover how to install the rhc command-line client and perform some basic operations using it.