Productive Developer Tools - Deploying OpenShift "Container Development Kit"

This is Part 1 of my technical blog on the OpenShift CDK. You can find Part 2 here > Using your OpenShift CDK to Build & Deploy ASP.NET Containerized Applications.

Arctiq is excited to be working with customers that are starting their journey down the wonderful new world of "Containers" and accelerating "DevOps Practices".  Most of Arctiq's container projects are mainly focused on Red Hat's OpenShift Container Platform.  If you don't know about OpenShift yet you can read about it here:  In short it’s a Container Platform As A Service (PaaS), but it's really a lot more that that...

In this Blog I will be showing you how to deploy Red Hat’s Openshift CDK - (Container Development Kit).  Think of it as (OpenShift “In a Box"), enabling developers or infrastructure teams to get hands on experience with OpenShift without needing access to a full virtual or physical environment.  Red Hat has just release a new version last week - v2.2.0

Red Hat Container Development Kit provides a pre-built Container Development Environment based on Red Hat Enterprise Linux to help you develop container-based (sometimes called Docker) applications quickly. The containers you build can be easily deployed on any Red Hat container host or platform, including: Red Hat Enterprise Linux, Red Hat Enterprise Linux Atomic Host, and our platform-as-a-service solution, OpenShift Enterprise 3.

This Guide is focused on OSX, here is a link to an overview and links for other platforms:

Download the Container Development Kit software components from the Red Hat Product Downloads web site. You must log in with a Red Hat account to get access to this page.

Don't worry it's free for developers, just create an acount - Check out this site

You need to download the following items:

  • Red Hat Container Tools

  • RHEL 7.2 Vagrant box for VirutalBox

We need 2 other tools to get this all up and running:

Vagrant and VirtualBox (Make sure to use the same versions I link to in this blog):

I decided to put all the required software in the following folder on my macbook

Go ahead and unzip the cdk-2.2.0.zip into this folder

pwd

/Users/kylebassett/openshift-cdk

ls

VirtualBox-5.0.26-108824-OSX.dmg
cdk
cdk-2.2.0.zip
rhel-cdk-kubernetes-7.2-29.x86_64.vagrant-virtualbox.box
vagrant_1.8.1.dmg

Let get things installed - Go ahead and Install VirtualBox and Vagrant

Container Development Kit offers two Vagrantfiles for initializing the Container Development Environment with different services:

OpenShift (rhel-ose): Use the OpenShift Vagrantfile to launch a Red Hat Enterprise Linux Server virtual machine (VM) with OpenShift Enterprise running in it. With OpenShift running, you can use either the web user interface from a web browser on your desktop, or docker, oc, and related commands by logging into the VM.

Kubernetes (rhel-k8s-singlenode-setup): Use the Kubernetes Vagrantfile to start a more generic Container Development Kit VM. Because OpenShift is not running, you can configure a more basic Kubernetes configuration or use Docker directly.  We won't get into this much in this blog, we will focus on OpenShift.

Let’s go ahead and install the Kubernetes Node

cd cdk
ls

LICENSE     README.md   components  plugins

cd plugins
ls

vagrant-registration-1.3.0.gem      vagrant-service-manager-README.adoc
vagrant-registration-README.md      vagrant-sshfs-1.2.0.gem
vagrant-service-manager-1.3.3.gem   vagrant-sshfs-README.md

RUN THIS:
ls -1 *.gem

vagrant-registration-1.3.0.gem
vagrant-service-manager-1.3.3.gem
vagrant-sshfs-1.2.0.gem

RUN THIS:

vagrant plugin install \
>   ./vagrant-registration-*.gem \
>   ./vagrant-service-manager-*.gem \
>   ./vagrant-sshfs-*.gem

Installing the './vagrant-registration-1.3.0.gem' plugin. This can take a few minutes...
Installed the plugin 'vagrant-registration (1.3.0)'!
Installing the './vagrant-service-manager-1.3.3.gem' plugin. This can take a few minutes...
Installed the plugin 'vagrant-service-manager (1.3.3)'!
Installing the './vagrant-sshfs-1.2.0.gem' plugin. This can take a few minutes...
Installed the plugin 'vagrant-sshfs (1.2.0)'!

RUN THIS:
vagrant plugin list

vagrant-registration (1.3.0)
  - Version Constraint: 1.3.0
vagrant-service-manager (1.3.3)
  - Version Constraint: 1.3.3
vagrant-share (1.1.5, system)
vagrant-sshfs (1.2.0)
  - Version Constraint: 1.2.0

cd ..
cd ..
ls

VirtualBox-5.0.26-108824-OSX.dmg
cdk
cdk-2.2.0.zip
rhel-cdk-kubernetes-7.2-29.x86_64.vagrant-virtualbox.box
vagrant_1.8.1.dmg

RUN THIS:
vagrant box add --name cdkv2 rhel-cdk-kubernetes-7.2-29.x86_64.vagrant-virtualbox.box

==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'cdkv2' (v0) for provider:
    box: Unpacking necessary files from: file:///Users/kylebassett/openshift-cdk/rhel-cdk-kubernetes-7.2-29.x86_64.vagrant-virtualbox.box
==> box: Successfully added box 'cdkv2' (v0) for 'virtualbox'!!

RUN THIS:
vagrant box list
cdkv2 (virtualbox, 0)

ls

VirtualBox-5.0.26-108824-OSX.dmg                rhel-cdk-kubernetes-7.2-25.x86_64.vagrant-virtualbox.box
cdk                             vagrant_1.8.1.dmg
cdk-2.1.0.zip

cd cdk
ls

LICENSE     README.md   components  plugins

cd /components/rhel/misc/rhel-k8s-singlenode-setup

RUN THIS:
vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'cdkv2'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: rhel-k8s-singlenode-setup_default_1474938405738_63460
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Registering box with vagrant-registration...
    default: Would you like to register the system now (default: yes)? [y|n]y
    default: username: kyle.bassett@arctiq.ca
    default: password:
==> default: Registration successful.
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Copying TLS certificates to /Users/kylebassett/openshift-cdk/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/.vagrant/machines/default/virtualbox/docker
==> default: Mounting SSHFS shared folder...
==> default: Mounting folder via SSHFS: /Users/kylebassett => /Users/kylebassett
==> default: Checking Mount..
==> default: Checking Mount..
==> default: Folder Successfully Mounted!
==> default: Docker service configured successfully...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: kubernetes single node cluster setup successfully

Install the OpenShift Node

cd /components/rhel/rhel-ose

RUN THIS:
vagrant up

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'cdkv2'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: rhel-ose_default_1474939063260_27698
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Remote connection disconnect. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Registering box with vagrant-registration...
    default: Would you like to register the system now (default: yes)? [y|n]y
    default: username: kyle.bassett@arctiq.ca
    default: password:
==> default: Registration successful.
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Copying TLS certificates to /Users/kylebassett/openshift-cdk/cdk/components/rhel/rhel-ose/.vagrant/machines/default/virtualbox/docker
==> default: Mounting SSHFS shared folder...
==> default: Mounting folder via SSHFS: /Users/kylebassett => /Users/kylebassett
==> default: Checking Mount..
==> default: Checking Mount..
==> default: Folder Successfully Mounted!
==> default: Docker service configured successfully...
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default: Running provisioner: shell...
    default: Running: inline script
==> default:
==> default: Successfully started and provisioned VM with 2 cores and 3072 MB of memory.
==> default: To modify the number of cores and/or available memory set the environment variables
==> default: VM_CPU respectively VM_MEMORY.
==> default:
==> default: You can now access the OpenShift console on: https://10.1.2.2:8443/console
==> default:
==> default: To use OpenShift CLI, run:
==> default: $ vagrant ssh
==> default: $ oc login
==> default:
==> default: Configured users are (<username>/<password>):
==> default: openshift-dev/devel
==> default: admin/admin
==> default:
==> default: If you have the oc client library on your host, you can also login from your host.

Note the connection information for you new environment:

==> default: You can now access the OpenShift console on: https://10.1.2.2:8443/console

==> default:

==> default: To use OpenShift CLI, run:

==> default: $ vagrant ssh

==> default: $ oc login

==> default:

==> default: Configured users are (<username>/<password>):

==> default: openshift-dev/devel

==> default: admin/admin

==> default:

==> default: If you have the oc client library on your host, you can also login from your host.

Open up your VirtualBox (You should see the VM up and running)

You can stop the rhel-k8e virtual machine if you want to free up some resources

Connect to your OpenShift WEBUI - https://10.1.2.2:8443/console admin/admin

You can then go create a project and play around, You will see some default project have been created. (the default project is important, have a look but don’t delete any POD’s or the default project).

I will dig into some example projects in my next blog, We may even experment with ASP.NET on OpenShift.  You will see some default project have been created.

Here is some information and links to the Getting Started Guide:

The Container Development Kit Getting Started Guide provides information on:

  • Using installed Vagrant plugins
  • Interacting with Vagrant boxes
  • Starting with container development
  • Using Docker, Kubernetes, and OpenShift Enterprise

Now it’s time to configure the client tools so you can dive into some advanced tasks via command line.

Download Client Tools Here:

Extract the file, dig down to the end of the directory tree and find the oc file.  Copy it to the same location you have the other software we download.  

Go ahead and run it (you can do this by double clicking or run from command line)

Now let’s add it to your path - this will allow you to run oc commands

echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
Move oc to your path - mv oc /usr/bin

Now you can login to your openshift environment

oc login 10.1.2.2:8443

Authentication required for https://10.1.2.2:8443 (openshift)

Username: admin

Password:

Login successful.

You have access to the following projects and can switch between them with 'oc project <projectname>':

 * default (current)

 * openshift

 * openshift-infra

 * sample-project

 * test

Using project "default".

* If you have any issues with you environment you can use these uninstall instructions:

Look out for my next blog where we will dive into running some applications on OpenShift.

Want to chat about Containers and or OpenShift we would love to hear from you

Kyle