Virtualization Red Hat CDK Lead image: Lead Image © Paulus NR, 123RF.com
Lead Image © Paulus NR, 123RF.com
 

Red Hat Container Development Toolkit for container-based applications

Container Helpers

Vagrant software makes it possible to set up a development environment quickly and efficiently. The Container Development Kit takes advantage of this feature to create a container-based environment built on Red Hat Enterprise Linux under Windows, Mac OS X, or Linux. By Thorsten Scherf

In another article in the Features section of this issue, I addressed the subject of .NET development under Linux. The .NET Core is an open source project from Microsoft based on the .NET framework. As could be expected after the release of .NET Core, many Windows developers became interested in the idea of creating software directly under Linux. This approach works when it is clear from the beginning that a Linux system is used as the target platform for the .Net application. Unfortunately, developers under these circumstances frequently find that they have to build a corresponding platform by themselves. It is not clear how such a platform looks when finished, and the extent to which the platform is identical with the target platform is unknown, but these are topics for another day.

Containers serve as a solution for the platform construction issue if a development team creates and maintains the required container images. In addition to Red Hat, various Linux distributions offer preconfigured images that include different run times for the development of applications. Microsoft also entered the marketplace for images suitable for the operation of Windows-based application containers when the company released Windows 2016.

It goes without saying that it is important to identify the environment in which the container is supposed to run. In the Linux world, Kubernetes has become the de facto standard for managing and orchestrating containers. Diverse Platform as a Service (PaaS) solutions are based on this framework. For example, Red Hat offers various versions of OpenShift [1], which is a Kubernetes-based PaaS platform. A word of caution is appropriate at this point: A fair amount of know-how and effort go into installing and configuring an environment of this kind.

Preconfigured Container

Here is where the Container Development Kit (CDK) [2] comes into play. The software offers preconfigured Vagrant boxes for Red Hat Enterprise Linux. The virtualization platforms supported by Vagrant include VirtualBox, Hyper-V, and of course KVM/libvirt. The virtual systems created in this manner provide a preconfigured environment that is used to operate containers. Vagrant offers a pure Kubernetes environment, as well as an environment for OpenShift. The latter includes the Kubernetes framework for managing individual containers. All of this means that developers quickly find they have a preconfigured and standardized run-time environment at their fingertips with which they can then develop container-based applications.

The PaaS OpenShift platform has multiple container images with different run times. More detailed information about the current 3.2 release of OpenShift is found online [3]. Access to the OpenShift platform can be accomplished via the graphical interface or the oc command-line tool. The complete life cycle of an application can be controlled, beginning with the definition of the initial project, extending up through deployment of the completed application inside of a container. If desired, it is also possible to integrate the CDK and the OpenShift platform in the JBoss Developer Studio IDE [4].

Installing CDK

The Red Hat Development Suite [5] environment contains all of the components necessary for installing the CDK under Windows, including the CDK, Vagrant, and the JBoss IDE. Operating the CDK under Linux or OS X requires manual installation of the individual components. The example here is based on a Fedora 23 host system, with the prerequisite that KVM and libvirt have been configured as the virtualization platform. The CDK and Vagrant Box for Red Hat Enterprise Linux can be downloaded from the Red Hat Developers website [2]. Note that Red Hat offers all of the development tools free of charge [6].

The next step is to install the Vagrant tool from the default Fedora software repository. The accompanying PolicyKit rules ensure that all of the vagrant group can administer the virtual machines created by Vagrant:

# yum install vagrant vagrant-libvirt vagrant-libvirt-doc rubygem-ruby-libvirt
# cp /usr/share/vagrant/gems/doc/vagrant-libvirt-0.0.24/polkit/10-vagrant-libvirt.rules /etc/polkit-1/rules.d
# usermod -a -G vagrant <local user>

The decompressed CDK and the Vagrant Box are found under ~/devel/cdk/ in this example. The first thing to do, therefore, is to install the necessary Vagrant plugins and the Vagrant Box:

# cd ~/devel/cdk/
# vagrant plugin install plugins/vagrant-registration-1.2.2.gem
# vagrant plugin install plugins/vagrant-service-manager-1.1.0.gem
# vagrant box add --name cdkv2 rhel-cdk-kubernetes-7.2-25.x86_64.vagrant-libvirt.box

Both of the plugins serve to register the virtual machine automatically in the Red Hat network when the machine starts so that software can be pulled from it. To avoid having to enter access data each time, you can save the data in the ~/.vagrant.d/Vagrantfile file. The service manager plugin helps explore either the OpenShift environment or the Kubernetes environment that is inside the virtual machine. If the Vagrant Box import has been successful, then it should be displayed when vagrant box list is called.

The CDK comes with two Vagrant files that can be used to create either a single-node Kubernetes system or an OpenShift system. Both files are found in the CDK folder under components/rhel/. This example now creates an instance of OpenShift. It is necessary to switch into the corresponding folder where the virtual system is started by issuing the vagrant up command:

# cd components/rhel/rhel-ose/
# vagrant up

If all goes well, the system created by Vagrant should be displayed when vagrant global-status is called. You can manage the entire OpenShift installation and likewise the Docker installation from the host system. When you call the Vagrant service manager, it will set environment variables that enable you to access the virtual system from the host system:

# eval "$(vagrant service-manager env)"

Afterward, things like the container images and the currently active container of the virtual machine can be displayed by issuing the commands:

# docker images
# docker ps

You can access the OpenShift web interface from https://10.1.2.2:8443/console. Developers log in with openshift-dev/devel (Figure 1), and administrators access the PaaS platform with admin/admin. There, they can incorporate new run times if desired. Detailed documentation for the platform is found online [1].

Once the virtual machine is started, an example project is available to help developers become familiar with the platform.
Figure 1: Once the virtual machine is started, an example project is available to help developers become familiar with the platform.

Conclusion

The CDK is a very powerful tool that administrators and developers can use to install a standardized environment for developing container-based applications. Integration in the Eclipse IDE helps to further simplify the development process and helps when deploying the applications directly from the IDE in containers.