Chapter 4. Installing Container Development Kit on macOS

To prepare your macOS development system for running Container Development Kit, the steps are:

  1. Download and install VirtualBox.
  2. Download and install Vagrant.
  3. Download Red Hat Container Tools and the Container Development Kit Vagrant box for VirtualBox.
  4. Install additional Vagrant plugins to support Red Hat Subscription Management and other features.

4.1. Prerequisites for Installing Container Development Kit on macOS

To run Container Development Kit on a macOS system, you need:

  • An Intel-based Mac with a minimum of 4 GB of RAM running a recent, 64-bit version of macOS, such as 10.11 (El Capitan) or later.
  • A minimum of 3 GB of free disk space for virtual machine images. Note that during the setup process, you will need to be able to store multiple copies of each of the virtual machine images.
  • Adequate Internet connectivity to download 1—​2 GB of software.
  • An available Red Hat Enterprise Linux subscription with support or Red Hat Enterprise Linux Developer Suite. Note that Red Hat Enterprise Linux subscriptions with self-support do not have access to all of the necessary software for CDK in all environments.

4.2. Installing Software and Configuring the Host System

Vagrant is used to run a Red Hat Enterprise Linux virtual machine with all necessary components for the Container Development Environment. Virtualization is provided by installing VirtualBox.

Please note that Vagrant is strictly command-line oriented. All interaction with Vagrant is through the command line from a terminal prompt. Use Terminal.app from the Applications → Utilities folder or a terminal emulator of your choice for running Vagrant.

Command-line instructions use path names with a tilde, such as ~/cdk. This is a shorthand notation for a path relative to the current user’s home directory, /Users/username/cdk.

4.2.1. Additional Software Requirements for macOS

In order to run Container Development Kit, some command-line development tools are needed on your Mac. Install either Apple Command Line Development Tools or Apple Xcode.

  1. Download and install VirtualBox for macOS from http://www.virtualbox.org.

    Important

    Container Development Kit 2.3 is known to not work correctly with VirtualBox 5.1.x. If you already have VirtualBox 5.1.x installed, downgrade your installation to VirtualBox 5.0.26.

  2. Choose a location for storing VirtualBox VM images. By default, these are stored in subdirectory in your home directory (~/VirtualBox VMs). You need several gigabytes of space wherever you choose to store these images. To change the location, start VirtualBox, go to VirtualBox → Preferences → General and change Default Machine Folder to the desired location. Documentation for VirtualBox can be found on the virtualbox.org website.
  3. Download and install Vagrant from https://releases.hashicorp.com/vagrant/. Select the folder with the 1.8.1 release and download the Vagrant installation file in the .dmg format (vagrant_1.8.1.dmg). The 1.7.4 version of Vagrant is also supported for use with Red Hat Container Development Kit 2.3.

    The default is to install Vagrant in the /opt/vagrant directory. You can change this. The Vagrant installer creates a /usr/bin/vagrant symbolic link that points to /opt/vagrant/bin/vagrant, so no adjustments to the PATH environment variable are necessary.

4.3. Setting Up Container Development Kit Software Components

  1. Download the Container Development Kit software components from the Red Hat Product Downloads web site. You must log in to get access to this page. If you are on the right page, you should see "Product Variant: Red Hat Container Development Kit". You need to download the following items:

    • Red Hat Container Tools
    • RHEL 7.3 Vagrant box for VirtualBox

      Note

      The page also offers Vagrant box downloads formatted for other virtualization platforms, such as libvirt. You only need to download the box image that matches the virtualization you are using — VirtualBox.

      The following steps assume you have saved these files in your home directory in ~/Downloads. If you used a different directory, adjust the paths accordingly. You need several gigabytes of free space for the Vagrant box images.

      All of the remaining steps need to be performed using the command-line using the Terminal Application (Terminal.app). You can find Terminal.app in the Application → Utilities Folder.

  2. Unzip the ZIP file you downloaded. This should create the ~/cdk subdirectory:

    $ cd
    $ unzip ~/Downloads/cdk-2.3.0.zip
  3. Install the vagrant-registration, vagrant-service-manager, and vagrant-sshfs plugins (the plugins in the form of .gem files are included in the ZIP file).

    The installation of the first plugin may take several minutes, and Vagrant may install some additional gem files as needed.

    $ cd ~/cdk/plugins
    $ ls -1 *.gem
    $ vagrant plugin install \
      ./vagrant-registration-*.gem \
      ./vagrant-service-manager-*.gem \
      ./vagrant-sshfs-*.gem
  4. Verify the plugins are installed by running the following command:

    $ vagrant plugin list
  5. Add the Container Development Kit box to Vagrant. This is the configured virtual machine image that you downloaded in one of the previous steps.

    $ vagrant box add --name cdkv2 ~/Downloads/rhel-cdk-kubernetes-7.2*.x86_64.vagrant-virtualbox.box
    Important

    The name you assign to the box using the --name parameter in this step must correspond to the name used by the Vagrantfile used to initialize the box. By default, this is cdkv2 for the Vagrantfiles provided with Container Development Kit.

    To use a customized name for the box:

    1. Export the desired name to the BOX environment variable

      $ export BOX=<box-name>
    2. Use the name in the vagrant box add command:

      $ vagrant box add --name <box-name> \
        rhel-cdk-kubernetes-7.2-*.x86_64.vagrant-virtualbox.box
  6. Verify that the box is installed:

    $ vagrant box list
    cdkv2 (virtualbox, 0)

    The box image file will be stored in your home directory under ~/.vagrant.d. You need adequate space there, approximately 2 GB.

4.4. Setting Up Container Development Kit for Use behind an HTTP Proxy

To run the Container Development Environment behind a proxy server, you need to export the proxy server information to the Container Development Environment and then run vagrant up (see Starting the Container Development Kit Vagrant Box on macOS).

Note

Currently, only HTTP and HTTPS proxy servers are supported.

4.4.1. Setting Proxy Environment Variables Manually

Run the following commands on the host system to export environment variables with information about the proxy server. This setting only remains in effect until you restart your session:

$ export PROXY="<proxy-server>:<port>"
$ export PROXY_USER="<username>"
$ export PROXY_PASSWORD="<password>"

4.4.2. Using vagrant-service-manager to Set Proxy Environment Variables

To automatically export information about the proxy configuration to every Vagrant box that you start, use the vagrant-service-manager plugin. The following steps need to be completed:

  1. Include the following lines in your per-user Vagrantfile (~/.vagrant.d/Vagrantfile — note that you may need to create this file):

    Vagrant.configure(2) do |config|
      config.servicemanager.proxy = '<proxy server>:<port>'
      config.servicemanager.proxy_user = '<proxy username>'
      config.servicemanager.proxy_password = '<proxy password>'
    end
  2. Remove proxy-related configuration lines from the Container Development Kit Vagrantfile you intend to use.

    • To use the OpenShift Container Platform configuration, remove the following lines from the rhel-ose Vagrantfile (cdk/component/rhel/rhel-ose/Vagrantfile):

      # explicitly enable and start OpenShift
      config.vm.provision "shell", run: "always", inline: <<-SHELL
        PROXY=#{PROXY} PROXY_USER=#{PROXY_USER} PROXY_PASSWORD=#{PROXY_PASSWORD} IMAGE_TAG=#{IMAGE_TAG} /usr/bin/sccli openshift
      SHELL

      And modify the following line to include the service your Vagrantfile needs to start (openshift):

      # prevent the automatic start of openshift via service-manager by just enabling Docker
      config.servicemanager.services = "docker, openshift"
    • To use the Kubernetes configuration, remove the following lines from the rhel-k8s-singlenode-setup Vagrantfile (cdk/components/rhel/misc/rhel-k8s-singlenode-setup/Vagrantfile):

      # Explicitly enable and start kubernetes
      config.vm.provision "shell", run: "always", inline: <<-SHELL
        PROXY=#{PROXY} PROXY_USER=#{PROXY_USER} PROXY_PASSWORD=#{PROXY_PASSWORD} /usr/bin/sccli kubernetes
        echo "kubernetes single node cluster setup successfully"
      SHELL

      And modify the following line to include the service your Vagrantfile needs to start (kubernetes):

      # prevent the automatic start of openshift via service-manager by just enabling Docker
      config.servicemanager.services = "docker, kubernetes"

4.5. Starting the Container Development Kit Vagrant Box on macOS

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 Container Platform 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.
Note

You can modify the existing Vagrantfiles for your own purposes. For example, you might want to use a different IP address if it conflicts with an address on your local network.

  1. Initialize the Container Development Kit Vagrant box:

    • Start Container Development Kit with OpenShift Container Platform as follows:

      $ cd ~/cdk/components/rhel/rhel-ose/
      $ vagrant up

      To use a different version of OpenShift Container Platform than the default (v3.3.1.3), edit the IMAGE_TAG parameter in the rhel-ose Vagrantfile before running vagrant up. You can find the list of supported version tags at https://registry.access.redhat.com/v1/repositories/openshift3/ose/tags.

      For example:

      IMAGE_TAG="v3.3.1.5"
    • Start Container Development Kit with single-node Kubernetes as follows:

      $ cd ~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/
      $ vagrant up
  2. Enter the username and password you use with the Red Hat Customer Portal to register the Red Hat Enterprise Linux system running in the Vagrant box:

    ==> default: Registering box with vagrant-registration…
        default: Would you like to register the system now (default: yes)? [y|n] y
        default: Subscriber username: <username>
        default: Subscriber password:
  3. Check whether your Vagrant box is running using the vagrant status command. Note that you must be in the same directory where your Vagrantfile is located. For example:

    $ cd ~/cdk/components/rhel/rhel-ose/
    $ vagrant status

If the machine state shows as running, you are ready to start using your Container Development Environment.

4.6. Additional Resources