LoginSignup
3
4

More than 3 years have passed since last update.

minikube構築時のメモ

Posted at

いい加減kubenetesを触りたかったけれど、ホストマシンをあんまり汚したくなかったので仮想マシン上に構築した際のメモ。

minikubeをvirtualbox+vagrant上のCentOSにインストールして動かすのに結構苦戦したので記録として残す。

実行環境

  • macOS 10.14.6 (Mojave)
  • virtualbox 6.1.12
  • vagrant 2.2.10

構築した環境

  • CentOS 7.5
  • docker 19.03.12
  • minikube 1.13.0

作業手順

基本的には公式の「Minikubeのインストール」に従った。

以下手順は全てrootユーザーで実行。

構築前準備

いきなりよくわからなくて困った。

$ grep -E --color 'vmx|svm' /proc/cpuinfo

これ実行してなんかしらの結果が返ってこないとminikubeは動かせないらしい。何も返ってこない。

解決策

どうやら、VM内でVMを作成できるような設定(Nested Virtualization)を許可しないとならないらしい。

virtualboxv6.1以降から対応してるらしい。よかった。

ということでVagrantfileに以下の項目を追記し、vagrant reloadを実行。

  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.customize ["modifyvm", :id, "--nested-hw-virt", "on"]
  end

さっきのコマンドを実行。

[root@kube ~]# grep -E --color 'vmx|svm' /proc/cpuinfo
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow flexpriority fsgsbase avx2 invpcid rdseed clflushopt flush_l1d
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq vmx ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch tpr_shadow flexpriority fsgsbase avx2 invpcid rdseed clflushopt flush_l1d

いけた。

dockerのインストール

nonedriverでminikubeを動かすことにする。

ということでdockerのドキュメントに従いdockerをインストール。

$ yum install docker-ce docker-ce-cli containerd.io

kubectlのインストール

公式ドキュメントに従い、バイナリをダウンロードして構築する。

minikubeのインストール

公式ドキュメントに従い、スタンドアロンバイナリをダウンロードして構築する。

minikube実行

minikubeバイナリをインストールして、以下のコマンドを実行。

$ minikube start --vm-driver=none
😄  minikube v1.13.0 on Centos 7.5.1804
✨  Using the none driver based on user configuration

❌  Exiting due to GUEST_MISSING_CONNTRACK: Sorry, Kubernetes 1.19.0 requires conntrack to be installed in root's path

なにやらエラーとなった。

解決策

どうやらk8s v1.18以降はconntrackなるものをインストールしないとならないらしい。

それは失礼しました。ということでインストール。

$ yum install conntrack -y

再度minikube実行

晴れて開始コマンドを実行。

$ minikube start --vm-driver=none
stderr:
W0906 11:40:23.265166   14424 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
    [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
    [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
    [WARNING Swap]: running with swap on is not supported. Please disable swap
    [WARNING FileExisting-socat]: socat not found in system path
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher


😿  If the above advice does not help, please let us know:
👉  https://github.com/kubernetes/minikube/issues/new/choose

🤔???

ものすごいたくさん警告が出た。正直この時点でやっぱ辞めようかという気になってきた。

仕方ないんで一つ一つ解決していく。

docker周りの警告を解決していく

まず、dockerのエラーに対処する。

[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/

どうやらdockerのcgroup driverをsystemdにしろと言ってるらしい。

というか、対処法が公式ドキュメントのCRIのインストールに書いてあったので、そっくりそのまま従う。

$ cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF
$ mkdir -p /etc/systemd/system/docker.service.d
$ systemctl daemon-reload
$ systemctl restart docker

あと、どうやらdockerをenableにしないといけないらしいので、やっておく。

[WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
$ systemctl enable docker

swap周りの警告を解決していく

次はswapに問題があるようなので、対処していく。

若干へっぴり腰でメモリの設定に触れる。

[WARNING Swap]: running with swap on is not supported. Please disable swap

kubeadmのドキュメントに注意書きがあった。

どうやら、kubeadmの要件に、swapメモリが無効になっている必要があるとのこと。そういえばminikube起動時にkubeadmも入ってきたっけ。

ということで、こちらのQiita記事を参考にして、swapメモリを無効化する。

$ swapoff -a

socatをインストールする

[WARNING FileExisting-socat]: socat not found in system path

socatなるパッケージをインストールして対応する。

$ yum install -y socat

bridge周りのエラーを解決していく

最後はこれである。

[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1

どうやら、bridgeアダプターの設定を有効にしてあげないとならないらしい。

Oracleのドキュメントによると、docker infoとか実行すると有効化してないと警告が出るとのこと。

ということで/etc/sysctl.confを編集し、以下を追加。

net.bridge.bridge-nf-call-iptables = 1
$ sysctl -p

を実行して、net.bridge.bridge-nf-call-iptables = 1が返ってくることを確認。

再びminikube実行

エラーに対応したので、再びコマンドを実行。

minikube start --vm-driver=none

実行結果である。

😄  minikube v1.13.0 on Centos 7.5.1804
✨  Using the none driver based on existing profile

🧯  The requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2342MiB). You may face stability issues.
💡  Suggestion: Start minikube with less memory allocated: 'minikube start --memory=2200mb'

👍  Starting control plane node minikube in cluster minikube
🔄  Restarting existing none bare metal machine for "minikube" ...
ℹ️  OS release is CentOS Linux 7 (Core)
🐳  Preparing Kubernetes v1.19.0 on Docker 19.03.12 ...
🤹  Configuring local host environment ...

❗  The 'none' driver is designed for experts who need to integrate with an existing VM
💡  Most users should use the newer 'docker' driver instead, which does not require root!
📘  For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/

❗  kubectl and minikube configuration will be stored in /root
❗  To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:

    ▪ sudo mv /root/.kube /root/.minikube $HOME
    ▪ sudo chown -R $USER $HOME/.kube $HOME/.minikube

💡  This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
🔎  Verifying Kubernetes components...
🌟  Enabled addons: default-storageclass, storage-provisioner
🏄  Done! kubectl is now configured to use "minikube" by default

動いた!!

これでminikubeを弄れる。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4