MicroK8sをMacOSにインストールしてみる

最近MicroK8sがMacに対応されたので、インストールしてみたいと思います。

Canonicalの軽量Kubernetes「MicroK8s」がWindowsとMacに対応。インストーラーで簡単に導入可能に

  • MicroK8sとは
  • MicroK8sをMacにインストールする

MicroK8sとは


MicroK8sとは、ワークステーションやエッジデバイスで実行できる軽量Kubernetesです。必要なパッケージやライブラリが一つのスナップとして提供されているため、インストールが簡単です。ただし、シングルノードでのみ稼働するなど制約はあります。

Linuxで稼働しますが、WindosとMacでは仮想ソフトウェアで専用のLinux仮想マシンを起動して稼働します。

MicroK8sをMacにインストールする


以下のリンク先を参考に、インストールします。

https://ubuntu.com/tutorials/install-microk8s-on-mac-os#1-overview

Homebrewをインストールする


以下のコマンドでhomebrewをインストールします。私は既にインストール済みなので、スキップします。

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

MicroK8sの前提パッケージをインストールする


まずは以下のコマンドで前提パッケージをインストールします。

$ brew install ubuntu/microk8s/microk8s

インストールしたところ、以下のエラーが発生しました。Xcodeのバージョンが古いみたいです。

Error: Your Xcode (10.0) is too outdated.
Please update to Xcode 11.3.1 (or delete it).
Xcode can be updated from the App Store.

Error: Xcode alone is not sufficient on Mojave.
Install the Command Line Tools:
  xcode-select --install

私のMacOSはバージョンがMojaveで、Xcodeのバージョンアップができなかったため、一度MacOSのバージョンをCatalina(10.15.5)にしてXcodeのバージョンを11.5にしました。

再度実行すると、以下のエラーが表示されます。

Error: You have not agreed to the Xcode license. Please resolve this by running:
  sudo xcodebuild -license accept

促されているコマンドをそのまま実行して解消しました。

$ sudo xcodebuild -license accept

改めて以下のコマンドを実行します。今度はエラーなしに完了しました。

$ brew install ubuntu/microk8s/microk8s

MicroK8sをインストールする


以下のコマンドでmicrok8sをインストールします。

$ microk8s install
VM disk size requested exceeds free space on host.
Support for 'multipass' needs to be set up. Would you like to do that it now? [y/N]: y
Updating Homebrew...
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 35, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 443429 (delta 16), reused 0 (delta 0), pack-reused 443394
Receiving objects: 100% (443429/443429), 200.17 MiB | 1.50 MiB/s, done.
Resolving deltas: 100% (314065/314065), done.
Tapped 1 command and 3570 casks (3,687 files, 214.8MB).
==> Downloading https://github.com/CanonicalLtd/multipass/releases/download/v1.2.1/multipass-1.2.1+mac-Darwin.pkg
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/114128199/fcb43c80-861f-11ea-90e8-08d13101e315?X-Am
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'multipass'.
==> Installing Cask multipass
==> Creating Caskroom at /usr/local/Caskroom
==> We'll set permissions properly so we won't need sudo in the future.
Password:
==> Running installer for multipass; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
installer: Package name is multipass
installer: Installing at base path /
installer: The install was successful.
🍺  multipass was successfully installed!
Waiting for multipass...
Launched: microk8s-vm                                                           
2020-06-07T01:23:36+09:00 INFO Waiting for restart...
microk8s (latest/stable) v1.18.2 from Canonical✓ installed
MicroK8s is up and running. See the available commands with `microk8s --help`.

これでインストールが完了しました。kubectlコマンドを実行したら動きました。

$ microk8s kubectl get nodes
NAME          STATUS   ROLES    AGE    VERSION
microk8s-vm   Ready    <none>   4m9s   v1.18.2-41+b5cdb79a4060a3

ちなみにmicrok8sを止めるときは以下のコマンドを実行します。

$ microk8s stop
Stopped.

 

以上です。なんて簡単なんでしょうか。。。