Minikubeをubuntu19.04にインストールした話[kvm2利用・BIOS画面でVirtualization有効化]

## はじめに
Kubernatesを扱っていく可能性が出てきたので、kubectlコマンドくらいはサラッと触っておきたいと思い、Minikubeをローカルpcに入れることにしました。

Minikubeのインストールについて調べていくと、BIOS周りの設定をする必要があることが分かります。
ビクビクしながら、インストールすることのないように備忘録として残しておきます笑。


##環境/バージョン情報
- Dell xps13 9380
- Ubuntu19.04 (Disco Dingo)
- kvm QEMU emulator version 3.1.0 (Debian 1:3.1+dfsg-2ubuntu3.5)
- minikube version: v1.5.2
- kubectl Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2"


## お話すること
- [下準備(Virtualizationの有効化)](https://qiita.com/gkzz/items/dd1dcb818612ec226cc9#下準備(Virtualizationの有効化))
- [kvm driverをインストール](https://qiita.com/gkzz/items/dd1dcb818612ec226cc9#kvm driverをインストール)
- [Minikubeをインストール](https://qiita.com/gkzz/items/dd1dcb818612ec226cc9#Minikubeをインストール)
- [Minikubeを立ち上げる](https://qiita.com/gkzz/items/dd1dcb818612ec226cc9#Minikubeを立ち上げる)
- [Minikubeを停止・削除](https://qiita.com/gkzz/items/dd1dcb818612ec226cc9#Minikubeを停止・削除)



## 下準備(Virtualizationの有効化)
- 電源ボタンを押す
- Dellのロゴが出たら、画面が変わるるまでF2キーを繰り返し押す
- BIOS設定画面で下記の *Virtualization* にチェックがついているか確認
![vt.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/341653/584fd433-ba60-f474-98b2-f3f566f9e756.jpeg)




## kvm driverをインストール
```
gkz@localhost ~ $ sudo apt install cpu-checker && sudo kvm-ok
Reading package lists... Done
Building dependency tree       
Reading state information... Done
cpu-checker is already the newest version (0.7-1.1).
cpu-checker set to manually installed.
gkz@localhost ~ $ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
gkz@localhost ~ $ sudo apt install libvirt-clients libvirt-daemon-system qemu-kvm \
>     && sudo usermod -a -G libvirt $(whoami) \
>     && newgrp libvirt
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libvirt-clients is already the newest version (5.0.0-1ubuntu2.5).
libvirt-daemon-system is already the newest version (5.0.0-1ubuntu2.5).
qemu-kvm is already the newest version (1:3.1+dfsg-2ubuntu3.5).
0 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
```


```
gkz@localhost ~ $ sudo virt-host-validate
  QEMU: Checking for hardware virtualization                                 : PASS
  QEMU: Checking if device /dev/kvm exists                                   : PASS
  QEMU: Checking if device /dev/kvm is accessible                            : PASS
  QEMU: Checking if device /dev/vhost-net exists                             : PASS

(略)

gkz@localhost ~ $ kvm --version
QEMU emulator version 3.1.0 (Debian 1:3.1+dfsg-2ubuntu3.5)
Copyright (c) 2003-2018 Fabrice Bellard and the QEMU Project developers

```

## Minikubeをインストール
```
gkz@localhost ~ $ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
>    && sudo install minikube-linux-amd64 /usr/local/bin/minikube
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 46.3M  100 46.3M    0     0  5699k      0  0:00:08  0:00:08 --:--:-- 7973k

```

## Minikubeを立ち上げる
```
gkz@localhost ~ $ minikube start --vm-driver=kvm2
😄  minikube v1.5.2 on Ubuntu 19.04
✨  Automatically selected the 'kvm2' driver (alternates: [none])
🔥  Creating kvm2 VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...
🌐  Found network options:
    ▪ NO_PROXY=localhost,127.0.0.0/8,::1
    ▪ no_proxy=localhost,127.0.0.0/8,::1
🐳  Preparing Kubernetes v1.16.2 on Docker '18.09.9' ...
    ▪ env NO_PROXY=localhost,127.0.0.0/8,::1
    ▪ env NO_PROXY=localhost,127.0.0.0/8,::1
💾  Downloading kubeadm v1.16.2
💾  Downloading kubelet v1.16.2
🚜  Pulling images ...
🚀  Launching Kubernetes ... 
⌛  Waiting for: apiserver
🏄  Done! kubectl is now configured to use "minikube"
```

### ダッシュボードを開く
```
gkz@localhost ~ $ minikube dashboard
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  Opening http://127.0.0.1:43933/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
Opening in existing browser session. 
```

### ブラウザが下記のように立ち上がります

![minikube_dashboard.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/341653/6254d909-24e9-e999-a503-778d619f2fc2.png)


### Minikubeのステータスの確認

```
# Minikubeを立ち上げる前
gkz@localhost ~ $ minikube status
host: 
kubelet: 
apiserver: 
kubeconfig: 

# Minikubeを立ち上げた後
gkz@localhost ~ $ minikube status
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
```

## Minikubeを停止・削除
```
gkz@localhost ~ $ minikube stop
✋  Stopping "minikube" in kvm2 ...
🛑  "minikube" stopped.
gkz@localhost ~ $ minikube delete
🔥  Deleting "minikube" in kvm2 ...
💔  The "minikube" cluster has been deleted.
🔥  Successfully deleted profile "minikube"

# まとめて消す方法
gkz@localhost ~ $ minikube stop; minikube delete

# Minikubeのステータスの確認
gkz@localhost ~ $ minikube status
host: 
kubelet: 
apiserver: 
kubeconfig: 
```

### Minikubeを完全に削除
```
gkz@localhost ~ $ sudo rm /usr/local/bin/minikube 
[sudo] password for gkz: 
gkz@localhost ~ $ rm -rf ~/.minikube

# 削除できているか確認
gkz@localhost ~ $ minikube start -vm-driver=kvm2
bash: /usr/local/bin/minikube: No such file or directory
gkz@localhost ~ $ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:18:23Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}
Error from server (NotFound): the server could not find the requested resource
gkz@localhost ~ $ minikube version
bash: /usr/local/bin/minikube: No such file or directory
```

### Minikubeを再インストール
``` 
gkz@localhost ~ $ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
>     && sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 46.3M  100 46.3M    0     0  5463k      0  0:00:08  0:00:08 --:--:-- 5424k
gkz@localhost ~ $ minikube version
minikube version: v1.5.2
commit: 792dbf92a1de583fcee76f8791cff12e0c9440ad-dirty
```



# 参考
- バーチャライぜーション
  - [PCでバーチャライゼーション (VT)を作動させるには?](https://support.bluestacks.com/hc/ja/articles/115003174386-PC%E3%81%A7%E3%83%90%E3%83%BC%E3%83%81%E3%83%A3%E3%83%A9%E3%82%A4%E3%82%BC%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3-VT-%E3%82%92%E4%BD%9C%E5%8B%95%E3%81%95%E3%81%9B%E3%82%8B%E3%81%AB%E3%81%AF-)
- kvm Minikubeのインストール
  - [Running Kubernetes locally on Linux with Minikube - now with Kubernetes 1.14 support](https://kubernetes.io/blog/2019/03/28/running-kubernetes-locally-on-linux-with-minikube-now-with-kubernetes-1.14-support/)

- kubectlのインストール
　- [Install and Set Up kubectl - Kubernetes](https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux)


## P.S. Twitterもやってるのでフォローしていただけると泣いて喜びます:)
[@gkzvoice](https://twitter.com/gkzvoice)

[#gkz](https://twitter.com/hashtag/gkz)