nekop's blog

OpenShift / JBoss / WildFly / Infinispanの中の人 http://twitter.com/nekop

minishiftでOpenShift Origin v3.7.0を利用する

OpenShift 全部俺 Advent Calendar 2017

11/29日US時間にOpenShift Origin 3.7とOpenShift Container Platform 3.7がリリースされたので、minishift v1.9.0を使ってOpenShift Origin v3.7.0をセットアップしたいと思います。

minishiftはシングルノーVMのOpenShift環境を起動するツールです。以下のインストールガイドに記述されているように、VMを立ち上げるので事前にOS毎に異なるそれのセットアップが必要です。

https://docs.openshift.org/latest/minishift/getting-started/installing.html

Linux(Fedora 26)のKVMを利用するセットアップだとこのような感じです。例ではバイナリは/usr/binに直接置いています。WindowsMacの人は上のURLからそれぞれのセットアップを参照してください。

curl -LO https://github.com/minishift/minishift/releases/download/v1.9.0/minishift-1.9.0-linux-amd64.tgz
sudo tar xf minishift-1.9.0-linux-amd64.tgz --strip=1 -C /usr/bin minishift-1.9.0-linux-amd64/minishift
sudo 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
sudo chmod +x /usr/local/bin/docker-machine-driver-kvm
sudo dnf install libvirt qemu-kvm -y
sudo usermod -a -G libvirt <username>
newgrp libvirt

これでminishiftを実行するとOpenShift Origin v3.7.0環境が立ち上がります。

$ minishift start --openshift-version v3.7.0 --iso-url centos --cpus 4 --memory 4GB --disk-size 40GB
-- Checking if requested hypervisor 'kvm' is supported on this platform ... OK
-- Checking if KVM driver is installed ... 
   Driver is available at /usr/local/bin/docker-machine-driver-kvm ... 
   Checking driver binary is executable ... OK
-- Checking if Libvirt is installed ... OK
-- Checking if Libvirt default network is present ... OK
-- Checking if Libvirt default network is active ... OK
-- Checking the ISO URL ... OK
-- Starting profile 'minishift'
-- Starting local OpenShift cluster using 'kvm' hypervisor ...
-- Minishift VM will be configured with ...
   Memory:    4 GB
   vCPUs :    4
   Disk size: 40 GB

   Downloading ISO 'https://github.com/minishift/minishift-centos-iso/releases/download/v1.3.0/minishift-centos7.iso'
 323.00 MiB / 323.00 MiB [=============================================================================================================================================================================] 100.00% 0s
-- Starting Minishift VM ............... OK
-- Checking for IP address ... OK
-- Checking if external host is reachable from the Minishift VM ... 
   Pinging 8.8.8.8 ... OK
-- Checking HTTP connectivity from the VM ... 
   Retrieving http://minishift.io/index.html ... OK
-- Checking if persistent storage volume is mounted ... OK
-- Checking available disk space ... 1% used OK
-- Downloading OpenShift binary 'oc' version 'v3.7.0'
 38.51 MiB / 38.51 MiB [===============================================================================================================================================================================] 100.00% 0s-- Downloading OpenShift v3.7.0 checksums ... OK
-- OpenShift cluster will be configured with ...
   Version: v3.7.0
-- Checking `oc` support for startup flags ... 
   host-config-dir ... OK
   host-data-dir ... OK
   host-pv-dir ... OK
   host-volumes-dir ... OK
   version ... OK
   routing-suffix ... OK
Starting OpenShift using openshift/origin:v3.7.0 ...
Pulling image openshift/origin:v3.7.0
Pulled 1/4 layers, 26% complete
Pulled 2/4 layers, 74% complete
Pulled 3/4 layers, 85% complete
Pulled 4/4 layers, 100% complete
Extracting
Image pull complete
OpenShift server started.

The server is accessible via web console at:
    https://192.168.42.225:8443

You are logged in as:
    User:     developer
    Password: <any value>

To login as administrator:
    oc login -u system:admin

ocコマンドを利用するにはeval $(minishift oc-env)source <(oc completion bash)を実行してカレントシェルに反映する、という方法もあるのですが、面倒なので/usr/binに放り込んでしまいます。

$ eval $(minishift oc-env)
$ source <(oc completion bash)
$ sudo cp ~/.minishift/cache/oc/v3.7.0/linux/oc /usr/bin/
$ sudo sh -c "oc completion bash > /etc/bash_completion.d/oc"
$ oc whoami
developer
$ oc status 
In project My Project (myproject) on server https://192.168.42.225:8443

You have no services, deployment configs, or build configs.
Run 'oc new-app' to create an application.

minishiftはデフォルトで軽量のDockerホストOSであるboot2dockerのVMを立ち上げますが、SELinuxが無効になっていて動作が異なる部分があるなどコンテナ動作環境としては微妙なので--iso-url centosを指定して起動しています。

minishiftのヘルプを以下に記載しておきます。

$ minishift version
minishift v1.9.0+a511b25

$ minishift help
Minishift is a command-line tool that provisions and manages single-node OpenShift clusters optimized for development workflows.

Usage:
  minishift [command]

Available Commands:
  addons      Manages Minishift add-ons.
  config      Modifies Minishift configuration properties.
  console     Opens or displays the OpenShift Web Console URL.
  delete      Deletes the Minishift VM.
  docker-env  Sets Docker environment variables.
  help        Help about any command
  hostfolder  Manages host folders for the OpenShift cluster.
  ip          Gets the IP address of the running cluster.
  logs        Gets the logs of the running OpenShift cluster.
  oc-env      Sets the path of the 'oc' binary.
  openshift   Interacts with your local OpenShift cluster.
  profile     Manages Minishift profiles.
  ssh         Log in to or run a command on a Minishift VM with SSH.
  start       Starts a local OpenShift cluster.
  status      Gets the status of the local OpenShift cluster.
  stop        Stops the running local OpenShift cluster.
  update      Updates Minishift to the latest version.
  version     Gets the version of Minishift.

Flags:
      --alsologtostderr                  log to standard error as well as files
  -h, --help                             help for minishift
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory
      --logtostderr                      log to standard error instead of files
      --profile string                   Profile name (default "minishift")
      --show-libmachine-logs             Show logs from libmachine.
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
  -v, --v Level                          log level for V logs
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

Use "minishift [command] --help" for more information about a command.

$ minishift start --help
Starts a local single-node OpenShift cluster.

All flags of this command can also be configured by setting corresponding environment variables or persistent configuration options.
For the former prefix the flag with MINISHIFT_, uppercase characters and replace '-' with '_', for example MINISHIFT_VM_DRIVER.
For the latter see 'minishift config -h'.

Usage:
  minishift start [flags]

Flags:
  -a, --addon-env stringSlice           Specify key-value pairs to be added to the add-on interpolation context.
      --cpus int                        Number of CPU cores to allocate to the Minishift VM. (default 2)
      --disk-size string                Disk size to allocate to the Minishift VM. Use the format <size><unit>, where unit = MB or GB. (default "20GB")
      --docker-env stringSlice          Environment variables to pass to the Docker daemon. Use the format <key>=<value>.
      --docker-opt stringSlice          Specify arbitrary flags to pass to the Docker daemon in the form <flag>=<value>.
  -h, --help                            help for start
      --host-config-dir string          Location of the OpenShift configuration on the Docker host. (default "/var/lib/minishift/openshift.local.config")
      --host-data-dir string            Location of the OpenShift data on the Docker host. If not specified, etcd data will not be persisted on the host. (default "/var/lib/minishift/hostdata")
      --host-only-cidr string           The CIDR to be used for the minishift VM. (Only supported with VirtualBox driver.) (default "192.168.99.1/24")
      --host-pv-dir string              Directory on Docker host for OpenShift persistent volumes (default "/var/lib/minishift/openshift.local.pv")
      --host-volumes-dir string         Location of the OpenShift volumes on the Docker host. (default "/var/lib/minishift/openshift.local.volumes")
      --http-proxy string               HTTP proxy in the format http://<username>:<password>@<proxy_host>:<proxy_port>. Overrides potential HTTP_PROXY setting in the environment.
      --https-proxy string              HTTPS proxy in the format https://<username>:<password>@<proxy_host>:<proxy_port>. Overrides potential HTTPS_PROXY setting in the environment.
      --insecure-registry stringSlice   Non-secure Docker registries to pass to the Docker daemon. (default )
      --iso-url string                  Location of the minishift ISO. Can be an URL, file URI or one of the following short names: [b2d centos]. (default "b2d")
      --logging                         Install logging (experimental)
      --memory string                   Amount of RAM to allocate to the Minishift VM. Use the format <size><unit>, where unit = MB or GB. (default "2GB")
      --metrics                         Install metrics (experimental)
      --no-proxy string                 List of hosts or subnets for which no proxy should be used.
  -e, --openshift-env stringSlice       Specify key-value pairs of environment variables to set on the OpenShift container.
      --openshift-version string        The OpenShift version to run, eg. v3.6.0 (default "v3.6.0")
      --password string                 Password for the virtual machine registration.
      --public-hostname string          Public hostname of the OpenShift cluster.
      --registry-mirror stringSlice     Registry mirrors to pass to the Docker daemon.
      --routing-suffix string           Default suffix for the server routes.
      --server-loglevel int             Log level for the OpenShift server.
      --skip-registration               Skip the virtual machine registration.
      --skip-registry-check             Skip the Docker daemon registry check.
      --username string                 Username for the virtual machine registration.
      --vm-driver string                The driver to use for the Minishift VM. Possible values: [virtualbox kvm] (default "kvm")

Global Flags:
      --alsologtostderr                  log to standard error as well as files
      --log_backtrace_at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log_dir string                   If non-empty, write log files in this directory (default "")
      --logtostderr                      log to standard error instead of files
      --profile string                   Profile name (default "minishift")
      --show-libmachine-logs             Show logs from libmachine.
      --stderrthreshold severity         logs at or above this threshold go to stderr (default 2)
  -v, --v Level                          log level for V logs
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging

Red Hat Container Development Kitにもminishiftが含まれています。こちらは別の機会に。

Resources