Chapter 1. Getting Started with Container Development Kit

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

1.1. Introducing Red Hat Container Development Kit

Red Hat Container Development Kit provides a platform for developing containerized applications. It is a set of tools that 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.
  • Container Development Kit is available for the Microsoft Windows, macOS, and Linux operating systems, thus allowing developers to use their preferred 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. Understanding Container Development Kit Documentation

1.2. Preparing to Install CDK

1.2.1. Overview

The following section describes how to install CDK and the required dependencies.

These are the basic steps for setting up CDK on your personal system:

  1. Set up your virtualization environment
  2. Download CDK software for your operating system from the Red Hat Container Development Kit Download page
  3. Install CDK
  4. Set up and start CDK
  5. Configure CDK so you can use it efficiently

The setup procedure should be run as a regular user with 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 CDK.

1.2.2. Prerequisites

CDK 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 CDK. Once the hypervisor is up and running, additional setup is required for CDK to work with that hypervisor.

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

macOS
Linux
Windows
All Platforms

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

1.3. Setting Up the Virtualization Environment

1.3.1. Overview

Follow the appropriate procedure to set up the hypervisor for your particular operating system. CDK uses libmachine and its driver plug-in architecture to provide a consistent way to manage the CDK VM.

Some hypervisors require manual installation of the driver plug-in. CDK embeds the VirtualBox driver plug-in, so no additional steps are required to configure it. However, VirtualBox will need to be identified to CDK via the --vm-driver virtualbox flag or persistant configuration settings. See Setting Up CDK to Use VirtualBox for more information.

See the appropriate section for your hypervisor and operating system:

1.3.2. Setting Up the KVM Driver

CDK is currently tested against docker-machine-driver-kvm version 0.7.0.

  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:

    # yum install libvirt qemu-kvm
  3. As root, add yourself to the libvirt group:

    # usermod -a -G libvirt <username>
  4. Update your current session to apply the group change:

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

    # systemctl start libvirtd
    # systemctl enable libvirtd

1.3.2.1. Next Steps

Proceed to Installing CDK once your hypervisor has been installed and configured.

1.3.3. Setting Up the xhyve Driver

CDK is currently tested against docker-machine-driver-xhyve version 0.3.3.

To 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 recommended, as 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.3/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 the 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 binary is compiled against a specific version of macOS. The driver may fail to work after a 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.3.1. Next Steps

Proceed to Installing CDK once your hypervisor has been installed and configured.

1.3.4. Setting Up the Hyper-V Driver

To use CDK with Hyper-V:

  1. Install Hyper-V.
  2. Add the user to the local Hyper-V Administrators group.

    Note

    This is required to allow the user to create and delete virtual machines with the Hyper-V Management API. For more information, see Hyper-V commands must be run as an Administrator.

  3. Add an External Virtual Switch.
  4. Verify that you pair the virtual switch with a network card (wired or wireless) that is connected to the network.
  5. Set the environment variable HYPERV_VIRTUAL_SWITCH to the name of the external virtual switch you want to use for CDK.

    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"

    PowerShell, however, requires the quotes:

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

    Using set in Command Prompt or $env in PowerShell will only affect the currently running shell session. You may use the setx utility to persist this environment variable across shell instances and system restarts. Quotes must be used with setx for both Command Prompt and PowerShell. For example:

    C:\> setx HYPERV_VIRTUAL_SWITCH "External (Wireless)"

1.3.4.1. Next Steps

Proceed to Installing CDK once your hypervisor has been installed and configured.

1.3.5. Setting Up CDK to Use VirtualBox

VirtualBox must be manually installed in order to use the embedded VirtualBox drivers. VirtualBox version 5.1.12 or later is required. Ensure that you download and install VirtualBox before using the embedded drivers.

VirtualBox must be identified to CDK through either the --vm-driver virtualbox flag or persistant configuration options.

1.3.5.1. Use VirtualBox Temporarily

The --vm-driver virtualbox flag will need to be given on the command line each time the minishift start command is run. For example:

$ minishift start --vm-driver virtualbox

1.3.5.2. Use VirtualBox Permanently

Setting the vm-driver option as a persistent configuration option allows you to run minishift start without explicitly passing the --vm-driver virtualbox flag each time. You may set the vm-driver persistent configuration option as follows:

$ minishift config set vm-driver virtualbox
Note

The vm-driver persistent configuration option must be supplied before minishift start has been run. If you have already run minishift start, ensure that you run minishift delete, set the configuration with minishift config set vm-driver virtualbox, then run minishift start in order to make use of the VirtualBox driver.

1.3.5.3. Next Steps

Proceed to Installing CDK once your hypervisor has been installed and configured.

1.4. Installing CDK

  1. Download the archive for your operating system from the Red Hat Container Development Kit Download page and extract its contents.
  2. Copy the contents of the directory to your preferred location.
  3. Add the minishift binary to your PATH environment variable.
Note
  • On the Windows operating system, due to issue #236, you need to execute the CDK binary from your local C:\ drive. You cannot run CDK from a network drive.
  • CDK will use any SSH binary found on the PATH in preference to internal SSH code. Ensure that any SSH binary in the system PATH does not generate warning messages as this will cause installation problems such as issue #1923.

1.5. CDK Quickstart

1.5.1. Overview

This section contains a brief demo of CDK and of the provisioned OpenShift cluster. For details on the usage of CDK, see the Basic Usage section.

The interaction with OpenShift is with the command line tool oc which is copied to your host. For more information on how CDK can assist you in interacting with and configuring your local OpenShift instance, see the OpenShift Client Binary section.

For more information about the OpenShift cluster architecture, see Architecture Overview in the OpenShift documentation.

The following steps describe how to get started with CDK on a Linux operating system with the KVM hypervisor driver.

1.5.2. Setting up CDK

The minishift setup-cdk command gets and configures the components needed to run CDK on your system. By default, minishift setup-cdk places CDK content in your ~/.minishift directory (%USERPROFILE%/.minishift on Windows).

Important

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

Run the following command to set up CDK for Red Hat Enterprise Linux:

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

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

1.5.3. Starting CDK

  1. By default, minishift start prompts you for your Red Hat Subscription Manager 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 CDK VM.
    • Register permanently: You can export registration information to environment variables 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:

      Using Command Prompt:

      C:\> set MINISHIFT_USERNAME='<RED_HAT_USERNAME>'
      C:\> set MINISHIFT_PASSWORD='<RED_HAT_PASSWORD>'
      C:\> setx MINISHIFT_USERNAME %MINISHIFT_USERNAME%
      C:\> setx MINISHIFT_PASSWORD %MINISHIFT_PASSWORD%

      Using PowerShell:

      PS> $env:MINISHIFT_USERNAME = '<RED_HAT_USERNAME>'
      PS> $env:MINISHIFT_PASSWORD = '<RED_HAT_PASSWORD>'
      PS> setx MINISHIFT_USERNAME $env:MINISHIFT_USERNAME
      PS> setx MINISHIFT_PASSWORD $env:MINISHIFT_PASSWORD
  2. Run the minishift start command:

    $ minishift start
    -- Starting profile 'minishift'
    ...
    -- 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]
    ...
    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: <any value>
    
    To login as administrator:
        oc login -u system:admin
    ...
    Note
    • The IP is dynamically generated for each OpenShift cluster. To check the IP, run the minishift ip command.
    • By default, CDK uses the driver most relevant to the host OS. To use a different driver, set the --vm-driver flag in minishift start. For example, to use VirtualBox instead of KVM on Linux operating systems, run minishift start --vm-driver=virtualbox.
    • While CDK starts it runs several checks to make sure that the CDK VM and the OpenShift cluster are able to start correctly. If any startup checks fail, see the Troubleshooting Getting Started topic for information about possible causes and solutions.

    For more information about minishift start options, see the minishift start command reference.

  3. 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 OS and shell type.

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

For more information about interacting with OpenShift with the command line interface and the Web console, see the OpenShift Client Binary section.

1.5.4. Deploying a Sample Application

OpenShift provides various sample applications, such as templates, builder applications, and quickstarts. The following steps describe how to deploy a sample Node.js application from the command line.

  1. Create a Node.js example application:

    $ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp
  2. Track the build log until the application 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. To stop CDK, use the following command:

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

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

1.6. Uninstalling CDK

1.6.1. Overview

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

1.6.2. Uninstalling CDK

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

    $ minishift delete

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

  2. To completely uninstall CDK, delete everything in the MINISHIFT_HOME directory (default ~/.minishift) and ~/.kube:

    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 the CDK VM. For example, if you use KVM, you need to run the virsh command.