此内容没有您所选择的语言版本。
Chapter 5. Installing Container Development Kit on macOS
To prepare your macOS development system for running Container Development Kit, the steps are:
- Download and install VirtualBox.
- Download and install Vagrant.
- Download Red Hat Container Tools and the Container Development Kit Vagrant box for VirtualBox.
- Install additional Vagrant plugins to support Red Hat Subscription Management and other features.
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.
5.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
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
.
5.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.
Download and install VirtualBox for macOS from http://www.virtualbox.org.
ImportantContainer Development Kit 2.4 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.
-
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 VirtualBoxPreferences General and change Default Machine Folder to the desired location. Documentation for VirtualBox can be found on the virtualbox.org website. 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.4.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 thePATH
environment variable are necessary.
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
NoteThe 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.
Unzip the ZIP file you downloaded. This should create the
~/cdk
subdirectory:cd unzip ~/Downloads/cdk-2.4.0.zip
$ cd $ unzip ~/Downloads/cdk-2.4.0.zip
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
vagrant-registration
,vagrant-service-manager
, andvagrant-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.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note that the vagrant-sshfs
plugin is dependent upon sftp-server.
Verify the plugins are installed by running the following command:
vagrant plugin list
$ vagrant plugin list
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
$ vagrant box add --name cdkv2 ~/Downloads/rhel-cdk-kubernetes-7.2*.x86_64.vagrant-virtualbox.box
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ImportantThe 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 iscdkv2
for the Vagrantfiles provided with Container Development Kit.To use a customized name for the box:
Export the desired name to the
BOX
environment variableexport BOX=<box-name>
$ export BOX=<box-name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the name in the
vagrant box add
command:vagrant box add --name <box-name> rhel-cdk-kubernetes-7-*.x86_64.vagrant-virtualbox.box
$ vagrant box add --name <box-name> rhel-cdk-kubernetes-7-*.x86_64.vagrant-virtualbox.box
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verify that the box is installed:
vagrant box list
$ vagrant box list cdkv2 (virtualbox, 0)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The box image file will be stored in your home directory under
~/.vagrant.d
. You need adequate space there, approximately 2 GB.
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).
Currently, only HTTP and HTTPS proxy servers are supported.
5.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>"
$ export PROXY="<proxy-server>:<port>"
$ export PROXY_USER="<username>"
$ export PROXY_PASSWORD="<password>"
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:
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
Vagrant.configure(2) do |config| config.servicemanager.proxy = '<proxy server>:<port>' config.servicemanager.proxy_user = '<proxy username>' config.servicemanager.proxy_password = '<proxy password>' end
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# 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
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# prevent the automatic start of openshift via service-manager by just enabling Docker config.servicemanager.services = "docker, openshift"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# 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
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
# prevent the automatic start of openshift via service-manager by just enabling Docker config.servicemanager.services = "docker, kubernetes"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To set the IP address used by the Vagrant box, set the PUBLIC_ADDRESS variable in the Vagrantfile for that box:
The private network IP of the VM. You will use this IP to connect to OpenShift. PUBLIC_ADDRESS="10.1.2.2"
# The private network IP of the VM. You will use this IP to connect to OpenShift.
# PUBLIC_ADDRESS="10.1.2.2"
PUBLIC_ADDRESS="x.x.x.x"
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, ordocker
,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.
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.
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
$ cd ~/cdk/components/rhel/rhel-ose/ $ vagrant up
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To use a different version of OpenShift Container Platform than the default (3.4.0.40), edit the
IMAGE_TAG
parameter in therhel-ose
Vagrantfile before runningvagrant 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"
IMAGE_TAG="v3.3.1.5"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start Container Development Kit with single-node Kubernetes as follows:
cd ~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/ vagrant up
$ cd ~/cdk/components/rhel/misc/rhel-k8s-singlenode-setup/ $ vagrant up
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
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:
==> 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:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 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
$ cd ~/cdk/components/rhel/rhel-ose/ $ vagrant status
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
If the machine state shows as running, you are ready to start using your Container Development Environment.