Chapter 1. Getting Started with Container Development Kit

This section contains information about setting up, installing, updating and uninstalling Container Development Kit.

1.1. Introducing Red Hat Container Development Kit

Red Hat Container Development Kit is a platform for developing containerized applications on a single, personal system. It enables developers to quickly and easily set up an environment for developing and testing containerized applications on the Red Hat Enterprise Linux platform.

Container Development Kit:

  • Provides a personal Container Development Environment you can install on your own laptop, desktop, or server system. The Container Development Environment is provided in the form of a Red Hat Enterprise Linux virtual machine. The Container Development Environment itself can also be installed in a virtual machine.
  • Includes the same container-development and run-time tools used to create and deploy containers for large data centers.
  • CDK version 3 offers an easy installation method based on the minishift tool.
  • Runs on Microsoft Windows, macOS, and Linux operating systems as a Linux virtual machine, thus allowing developers to use their favorite platform while producing applications ready to be deployed in the Red Hat Enterprise Linux ecosystem.

Container Development Kit is a part of the Red Hat Developers program, which provides tools, resources, and support for developers who wish to utilize Red Hat solutions and products to create applications, both locally and in the cloud. For additional information and to register to become a part of the program, visit developers.redhat.com.

1.1.1. Additional Information

Refer to the following documents for further information:

To report issues, refer to the following:

  • For Red Hat Container Development Kit issues or to request new CDK features, refer to the CDK Project.
  • For issues with Red Hat Container Development Kit documentation or to request new documentation, refer to CDK Project Documentation.

1.2. Preparing to Install Container Development Kit

1.2.1. Overview

Container Development Kit version 3.1 is based on the Minishift project version 1.5.0. Using a single executable file, the minishift command deploys Container Development Kit as a Red Hat Enterprise Linux virtual machine, running OpenShift (which includes Kubernetes, the docker service, and other container development and deployment software).

Container Development Kit setup procedure can, and should, be run as a regular user that has special permission to launch virtual machines. In the procedure, you will see how to assign that permission, along with ways to configure your hypervisor and command shell to start and effectively interact with Container Development Kit.

Note

Container Development Kit version 2.x was based on Vagrant. Because of the completely different deployment and management methods, there is no upgrade path from CDK 2.x to CDK 3.x versions. You need to do a fresh setup.

The following section describes how to install Container Development Kit and the required dependencies.

1.2.2. Prerequisites

Container Development Kit requires a hypervisor to start the virtual machine on which the OpenShift cluster is provisioned. Verify that the hypervisor of your choice is installed and enabled on your system before you set up Container Development Kit. Once the hypervisor is up and running, additional setup is required for Container Development Kit to work with that hypervisor (as described in the coming setup procedure).

Depending on your host operating system, you have the choice of the following hypervisors:

macOS
Red Hat Enterprise Linux, Fedora, CentOS or other Linux system
Windows

Refer to the documentation for each hypervisor to determine the hardware and operating system versions needed to run that hypervisor.

1.2.3. Understanding Container Development Kit Installation

These are the basic steps for setting up Container Development Kit on your personal laptop or desktop system:

  1. Set up your virtualization environment
  2. Download CDK software for your operating system from the Container Development Kit Download Page
  3. Set up CDK
  4. Start CDK
  5. Configure CDK so you can use it efficiently

1.3. Container Development Kit Installation

1.3.1. Installing Container Development Kit

The following steps describe how to prepare your virtualization environment (hypervisor) for CDK, download CDK software, set up CDK, and start using it.

1.3.2. Step 1: Set up your virtualization environment

Follow the appropriate procedure to set up virtualization for your particular operating system and hypervisor. Container Development Kit uses Docker Machine and its driver plug-in architecture to provide a consistent way to manage the OpenShift VM.

Some hypervisors require that the driver plug-in be manually installed. Container Development Kit embeds VirtualBox drivers so no additional steps are required to configure the driver. However, later you will need to run a minishift command to tell Container Development Kit to use VirtualBox.

1.3.2.1. Set up hypervisor on Red Hat Enterprise Linux

Choose between KVM (default) and VirtualBox for your hypervisor. Manual driver setup is required for KVM The driver is automatically configured if you install VirtualBox. However, a minishift command would be required later to identify VirtualBox to Container Development Kit.

On Red Hat Enterprise Linux with KVM virtualization: Container Development Kit is currently tested against docker-machine-driver-kvm version 0.7.0. Follow these steps to install the KVM driver and configure your user account to use the libvirtd service.

  1. As root, install the KVM binary and make it executable as follows:

    # curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.7.0/docker-machine-driver-kvm -o /usr/local/bin/docker-machine-driver-kvm
    # chmod +x /usr/local/bin/docker-machine-driver-kvm

    For more information, see the GitHub documentation of the docker machine KVM driver.

  2. As root, install libvirt and qemu-kvm on your system and add yourself to the libvirt group:

    # yum install libvirt qemu-kvm
    # usermod -a -G libvirt <username>
  3. Update your current user session to apply the group change:

    $ newgrp libvirt
  4. Start the libvirtd service as root:

    # systemctl start libvirtd
    # systemctl enable libvirtd

1.3.2.2. Set up hypervisor on macOS

Choose between xhyve (default) and VirtualBox for your hypervisor. Manual driver setup is required for xhyve. The driver is automatically configured if you install VirtualBox. However, a minishift command would be required later to identify VirtualBox to Container Development Kit.

On macOS with xhyve virtualization:

Container Development Kit on macOS with xhyve virtualization is currently tested against docker-machine-driver-xhyve version 0.3.1. To manually install the xhyve driver, you need to download and install the docker-machine-driver-xhyve binary and place it in a directory which is on your PATH environment variable. The directory /usr/local/bin is most likely a good choice, since it is the default installation directory for Docker Machine binaries.

The following steps explain the installation of the docker-machine-driver-xhyve binary to the /usr/local/bin/ directory:

  1. Download the docker-machine-driver-xhyve binary using:

    $ sudo curl -L  https://github.com/zchee/docker-machine-driver-xhyve/releases/download/v0.3.1/docker-machine-driver-xhyve -o /usr/local/bin/docker-machine-driver-xhyve
  2. Enable root access for the docker-machine-driver-xhyve binary and add it to the default wheel group:

    $ sudo chown root:wheel /usr/local/bin/docker-machine-driver-xhyve
  3. Set owner User ID (SUID) for the binary as follows:

    $ sudo chmod u+s,+x /usr/local/bin/docker-machine-driver-xhyve
Note

The downloaded docker-machine-driver-xhyve binaries are compiled against a specific version of macOS. It is possible that the driver fails to work after an macOS version upgrade. In this case you can try to compile the driver from source:

$ go get -u -d github.com/zchee/docker-machine-driver-xhyve
$ cd $GOPATH/src/github.com/zchee/docker-machine-driver-xhyve

# Install docker-machine-driver-xhyve binary into /usr/local/bin
$ make install

# docker-machine-driver-xhyve need root owner and uid
$ sudo chown root:wheel /usr/local/bin/docker-machine-driver-xhyve
$ sudo chmod u+s /usr/local/bin/docker-machine-driver-xhyve

For more information, see the xhyve driver documentation on GitHub.

1.3.2.3. Set up hypervisor on Windows

Choose between Hyper-V (default on Windows 10) and VirtualBox (Windows 7 or Windows 10) for your hypervisor. Manual driver setup is required for Hyper-V. The driver is automatically configured if you install VirtualBox. However, a minishift command would be required later to identify VirtualBox to Container Development Kit.

On Windows with Hyper-V virtualization:

  1. Install Hyper-V.
  2. Add an External Virtual Switch. Verify that you pair the virtual switch with a network card (wired or wireless) that is connected to the network.
  3. If you have multiple virtual switches, set the environment variable HYPERV_VIRTUAL_SWITCH to the name of the external virtual switch you want to use for Container Development Kit.

    For example, on Command Prompt use:

    C:\> set HYPERV_VIRTUAL_SWITCH=External (Wireless)

    Note that using quotes in Command Prompt results in the following error:

    C:\> set HYPERV_VIRTUAL_SWITCH="External (Wireless)"
    Error creating the VM. Error with pre-create check: "vswitch \"\\\"External (Wireless)\\\"\" not found"

    However, on PowerShell you need to use the quotes:

    PS C:\> $env:HYPERV_VIRTUAL_SWITCH="External (Wireless)"

1.3.3. Step 2: Download CDK Software

Before you can download CDK software, you need to either register with the Red Hat Developer Program site or login to the Red Hat customer portal with Red Hat subscription credentials. Then go to one of the following two sites and download the software associated with your operating system:

Copy the downloaded minishift file to a directory in your $PATH and make it executable. The downloaded minishift executable is named cdk-3.1.0-1-minishift-darwin-amd64 (for macOS), cdk-3.1.0-1-minishift-linux-amd64 (for Linux) or cdk-3.1.0-1-minishift-windows-amd64.exe (for Windows). Assuming minishift executable is in the Downloads directory, follow the procedure for your operating system:

For Red Hat Enterprise Linux:

$ mkdir -p ~/bin
$ cp ~/Downloads/cdk-3.1.0-1-minishift* ~/bin/minishift
$ chmod +x ~/bin/minishift
$ export PATH=$PATH:$HOME/bin
$ echo ‘export PATH=$PATH:$HOME/bin’ >> ~/.bashrc

For macOS:

$ mkdir -p ~/bin
$ cp ~/Downloads/cdk-3.1.0-1-minishift* ~/bin/minishift
$ chmod +x ~/bin/minishift
$ export PATH=$PATH:$HOME/bin
$ echo export PATH=$PATH:$HOME/bin >> ~/.bash_profile

For Windows:

Create the desired directory and copy the downloaded minishift binary to the directory, renaming the binary to minishift. Add the directory path to the Windows path variable. This directory MUST be on the C: drive!

If it’s difficult to get minishift in your PATH, you can simply run it from the current directory as ./minishift (or .\minishift in some Windows shells).

1.3.4. Step 3: Set up CDK

The minishift setup-cdk command gets and configures the components needed to run Container Development Kit on your system. By default, it places Container Development Kit content in your ~/.minishift directory. One thing you should know about this directory:

  • To use a directory other than ~/.minishift, you must set the --minishift-home flag and the MINISHIFT_HOME environment variable, as described in Environment Variables.

Run the following command to set up Container Development Kit for Red Hat Enterprise Linux:

$ minishift setup-cdk
Setting up CDK 3 on host using '/home/joe/.minishift' as Minishift's home directory
Copying minishift-rhel7.iso to '/home/joe/.minishift/cache/iso/minishift-rhel7.iso'
Copying oc to '/home/joe/.minishift/cache/oc/v3.6.173.0.21/oc'
Creating configuration file '/home/joe/.minishift/config/config.json'
Creating marker file '/home/joe/.minishift/cdk'
Default add-ons anyuid, admin-user, xpaas installed
Default add-ons anyuid, admin-user, xpaas enabled
CDK 3 setup complete.

As you can see from the output, a .minishift directory is created in the user’s home directory to hold various CDK components, and appropriate files and setting are stored there.

For Windows or macOS: Running the same minishift setup-cdk command on Windows and Mac results in slightly different output, based on some different components and pathnames.

1.3.5. Step 4: Start CDK

The minishift start command launches Container Development Kit, which consists of a Red Hat Enterprise Linux virtual machine running OpenShift. Follow these steps to launch Container Development Kit.

  1. If you are using the default hypervisor for your operating system (KVM for Linux, xhyve for macOS, or Hyper-V for Windows), you can skip this step. If you have set up VirtualBox as your hypervisor, you need to configure the VirtualBox Driver. To switch the hypervisor used by Container Development Kit to VirtualBox, you have two choices.

    • Temporary: Add the --vm-driver virtualbox option to the minishift start command line to use VirtualBox immediately.
    • Persistent: To persistently change the hypervisor, run the minishift config set vm-driver virtualbox command. See the Persistent Configuration section for examples.
  2. Registration. By default, minishift start prompts you for your Red Hat account username and password. You can enter that information or choose instead to:

    • Skip registration: Add the --skip-registration option to minishift start to not register the Container Development Kit VM.
    • Register permanently: You can export registration information so that minishift picks it up automatically, each time it starts as shown here:

      For Red Hat Enterprise Linux:

      $ export MINISHIFT_USERNAME=<RED_HAT_USERNAME>
      $ export MINISHIFT_PASSWORD='<RED_HAT_PASSWORD>'
      $ echo export MINISHIFT_USERNAME=$MINISHIFT_USERNAME >> ~/.bashrc
      $ echo export MINISHIFT_PASSWORD=$MINISHIFT_PASSWORD >> ~/.bashrc

      For macOS:

      export MINISHIFT_USERNAME=‘<RED_HAT_USERNAME>’
      export MINISHIFT_PASSWORD=‘<RED_HAT_PASSWORD>’
      echo export MINISHIFT_USERNAME=$MINISHIFT_USERNAME >> ~/.bash_profile
      echo export MINISHIFT_PASSWORD=$MINISHIFT_PASSWORD >> ~/.bash_profile

      For Windows:

    Set these two variables: MINISHIFT_USERNAME=<RED_HAT_USERNAME> and MINISHIFT_PASSWORD=<RED_HAT_PASSWORD>.

  3. Run minishift start to set up and start the virtual machine with the default configuration. See the description of minishift start in the minishift start command reference to see other options to modify minishift start. Here is an example of how that would look run from a Red Hat Enterprise Linux system.

    ...
    -- Minishift VM will be configured with ...
       Memory:    4 GB
       vCPUs :    2
       Disk size: 20 GB
    -- Starting Minishift VM .......................... OK
    -- Registering machine using subscription-manager
       Registration in progress ..................... OK [42s]
    -- Checking for IP address ... OK
    -- Checking if external host is reachable from the Minishift VM ...
    ...
    Extracting
    Image pull complete
    OpenShift server started.
    The server is accessible via web console at:
        https://192.168.42.60:8443
    You are logged in as:
        User:     developer
        Password: developer
    To login as administrator:
        oc login -u system:admin
    ...
  4. Run this command to see if the virtual machine is running:

    $ minishift status
    Running

For macOS and Windows system, you see similar output from minishift start when run in a macOS terminal or Windows command prompt or PowerShell, respectively.

1.3.6. Step 5: Configure CDK

With CDK virtual machine running, you can configure and start using CDK through two primary interfaces: oc (OpenShift client binary command) or the OpenShift web console.

  • oc: Use minishift oc-env to display the command you need to type into your shell in order to add the oc binary to your PATH environment variable. The output of oc-env will differ depending on your user directory, operating system and shell type.

    For Red Hat Enterprise Linux:

    $ minishift oc-env
    export PATH="/home/joe/.minishift/cache/oc/v3.6.173.0.21:$PATH"
    # Run this command to configure your shell:
    # eval $(minishift oc-env)

    To use that information to add the PATH to the oc command permanently to the .bashrc file, type the following:

    $ echo export PATH=\"/home/joe/.minishift/cache/oc/v3.6.173.0.21:\$PATH\" >> ~/.bashrc
    $ source ~/.bashrc

    For macOS:

    $ minishift oc-env
    export PATH="/home/joe/.minishift/cache/oc/v3.6.173.0.21:$PATH"
    # Run this command to configure your shell:
    # eval $(minishift oc-env)
    $ echo export PATH=/Users/joe/.minishift/cache/oc/v3.6.173.0.21:\$PATH >> ~/.bash_profile
    $ source ~/.bash_profile

    For Windows:

    Set the oc binary path in the environment path variable.

For more information about interacting with OpenShift from the command-line interface, see the OpenShift Client Binary section.

  • OpenShift web console: To access OpenShift from the web console, you can either:

    • Run minishift console to open the OpenShift web console from your default browser or
    • Open a browser to the URL output from the minishift start command (for example, https://192.168.42.60:8443).

    From the web console screen, enter the user name (developer) and password (developer) displayed from the output.

You are now ready to start using OpenShift using either of those two interfaces.

1.3.7. Deploying a Sample Application

OpenShift provides various sample applications, such as templates, builder applications, and quickstarts. To begin creating an application, see :

The following steps describe how to deploy a sample Node.js application from the command-line.

  1. Create a Node.js example app.

    $ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp
  2. Track the build log until the app is built and deployed.

    $ oc logs -f bc/nodejs-ex
  3. Expose a route to the service.

    $ oc expose svc/nodejs-ex
  4. Access the application.

    $ minishift openshift service nodejs-ex --in-browser
  5. If you are done with the VM, use minishift stop to stop the VM temporarily, so you can return to the same state later (with minishift start).

    $ minishift stop
    Stopping local OpenShift cluster...
    Stopping "minishift"...

See minishift stop for details on managing subscriptions as you stop and start the VM.

For more information about creating applications in OpenShift, see Creating New Applications in the OpenShift documentation.

1.4. Uninstalling Container Development Kit

1.4.1. Overview

This section describes how you can uninstall the minishift binary and delete associated files.

1.4.2. Uninstalling Container Development Kit

  1. Delete CDK VM and any VM-specific files.

    $ minishift delete

    This command deletes everything in the CDK_HOME/.minishift/machines/minishift directory. Other cached data and the persistent configuration are not removed.

  2. To completely uninstall Container Development Kit, delete everything in the MINISHIFT_HOME directory (default ~/.minishift) and ~/.kube, run the following commands:

    For Red Hat Enterprise Linux and macOS:

    $ rm -rf ~/.minishift
    $ rm -rf ~/.kube

    For Windows powershell:

    Replace <MINISHIFT_HOME> with the location of your home directory.

    PS C:\> Remove-Item -Recurse -Force C:\<MINISHIFT_HOME>\.minishift\
    PS C:\> Remove-Item -Recurse -Force C:\<MINISHIFT_HOME>\.kube\

    For Windows command prompt:

    Replace <MINISHIFT_HOME> with the location of your home directory. (You may need to use the del /s command instead.)

    c:\> rm -r c:\<MINISHIFT_HOME>\.minishift
    c:\> rm -r c:\<MINISHIFT_HOME>\.kube
  3. With your hypervisor management tool, confirm that there are no remaining artifacts related to CDK VM. For example, if you use KVM, you need to run the virsh command.