Windows+VirtualBoxでminikubeを動かす

# VirtualBox で minikube を動かす

minikubeのドキュメントをもとに操作すると何が起こるか、を残す。

## バージョン

このバージョンを前提に構成する。

* VirtualBox: 5.2.20
* kubectl: v1.13.3

## 構成

構成すると、次のようになった。

* Windows
   * VirtualBox
      * VM: minikube
   * kubectl

## ネットワーク構成

構成すると、次のようになった。

```
  internet
    |
  router
    |
  --o-o--
      |
    Windows ----.
      |         |
      |       router(nat)
      |         |
      |       --o-o------ 10.0.2.0/24
      |           | .15
      |         eth0
      |       minikube
      |         eth1
      |           | .100
    --o-----------o------ 192.168.99.0/24
```

## 仮想マシン

構成すると、次のようになった。

### ハードウェア

* VM: minikube
   * vMEM: 2048MB
   * vCPU: 2
   * ストレージ
      * SATA port0: boot2docker.iso
      * SATA port1: disk.vmdk (20GB)
   * ネットワーク
      * アダプタ1: NAT
      * アダプタ2: ホストオンリーアダプタ
   * 共有フォルダ
      * c/Users

### パスワード

* username: docker
* password: tcuser

## 仮想マシンOS

構成すると、次のようになった。

### ストレージ構成

```
$ cat /etc/fstab
# <file system> <mount pt>      <type>  <options>       <dump>  <pass>
/dev/root       /               ext2    rw,noauto       0       1
proc            /proc           proc    defaults        0       0
devpts          /dev/pts        devpts  defaults,gid=5,mode=620 0       0
sysfs           /sys            sysfs   defaults        0       0

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        908M     0  908M   0% /dev
tmpfs           996M     0  996M   0% /dev/shm
tmpfs           996M   17M  979M   2% /run
tmpfs           996M     0  996M   0% /sys/fs/cgroup
tmpfs           996M   20K  996M   1% /tmp
/dev/sda1        17G  937M   15G   7% /mnt/sda1
/c/Users        118G   94G   24G  80% /c/Users:w
```

## 手順

### コンテナを動かして、ブラウザで見る

管理者権限

```powershell
choco install kubernetes-cli
cd $HOME
mkdir .kube
cd $HOME/.kube
New-Item config -type file

choco install minikube kubernetes-cli
```

一般ユーザ:

```powershell
minikube --vm-driver=virtualbox start
```

ログ

```
o   minikube v0.34.0 on windows (amd64)
>   Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
@   Downloading Minikube ISO ...
 181.48 MB / 181.48 MB [============================================] 100.00% 0s
-   "minikube" IP address is 192.168.99.100
-   Configuring Docker as the container runtime ...
-   Preparing Kubernetes environment ...
@   Downloading kubelet v1.13.3
@   Downloading kubeadm v1.13.3
-   Pulling images required by Kubernetes v1.13.3 ...
-   Launching Kubernetes v1.13.3 using kubeadm ...
-   Configuring cluster permissions ...
-   Verifying component health .....
+   kubectl is now configured to use "minikube"
=   Done! Thank you for using minikube!
```

```powershell
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
kubectl expose deployment hello-minikube --type=NodePort
kubectl get pod
minikube service hello-minikube --url
  # --> http://192.168.99.100:30930
Invoke-Webrequest http://192.168.99.100:30930
```

```
StatusCode        : 200
StatusDescription : OK
Content           :

                    Hostname: hello-minikube-6fd785d459-h2llx

                    Pod Information:
                        -no pod information available-

                    Server values:
                        server_version=nginx: 1.13.3 - lua: 10008

                    Request Information:
                        client_address=172.17.0....
RawContent        : HTTP/1.1 200 OK
                    Transfer-Encoding: chunked
                    Connection: keep-alive
                    Content-Type: text/plain
                    Date: Sat, 16 Feb 2019 06:27:14 GMT
                    Server: echoserver



                    Hostname: hello-minikube-6fd785d459-h2llx

                    P...
Forms             : {}
Headers           : {[Transfer-Encoding, chunked], [Connection, keep-alive], [Content-Type, t
                    ext/plain], [Date, Sat, 16 Feb 2019 06:27:14 GMT]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 517
```

### 仮想マシンにSSHログインする

```
ssh docker@192.168.99.100
tcuser
sudo whoami
  # --> root
```

### 仮想マシン minikube をシャットダウンする

```powershell
kubectl delete services hello-minikube
kubectl delete deployment hello-minikube
minikube stop
```

## kubectl の機能を一覧する

```
# kubectl
kubectl controls the Kubernetes cluster manager.

Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Take a replication controller, service, deployment or pod and expose it as a new Kubernetes Service
  run            Run a particular image on the cluster
  set            Set specific features on objects

Basic Commands (Intermediate):
  explain        Documentation of resources
  get            Display one or many resources
  edit           Edit a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout        Manage the rollout of a resource
  scale          Set a new size for a Deployment, ReplicaSet, Replication
Controller, or Job
  autoscale      Auto-scale a Deployment, ReplicaSet, or ReplicationController

Cluster Management Commands:
  certificate    Modify certificate resources.
  cluster-info   Display cluster info
  top            Display Resource (CPU/Memory/Storage) usage.
  cordon         Mark node as unschedulable
  uncordon       Mark node as schedulable
  drain          Drain node in preparation for maintenance
  taint          Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe       Show details of a specific resource or group of resources
  logs           Print the logs for a container in a pod
  attach         Attach to a running container
  exec           Execute a command in a container
  port-forward   Forward one or more local ports to a pod
  proxy          Run a proxy to the Kubernetes API server
  cp             Copy files and directories to and from containers.
  auth           Inspect authorization

Advanced Commands:
  diff           Diff live version against would-be applied version
  apply          Apply a configuration to a resource by filename or stdin
  patch          Update field(s) of a resource using strategic merge patch
  replace        Replace a resource by filename or stdin
  wait           Experimental: Wait for a specific condition on one or many resources.
  convert        Convert config files between different API versions

Settings Commands:
  label          Update the labels on a resource
  annotate       Update the annotations on a resource
  completion     Output shell completion code for the specified shell (bash or zsh)

Other Commands:
  api-resources  Print the supported API resources on the server
  api-versions   Print the supported API versions on the server, in the form of "group/version"
  config         Modify kubeconfig files
  plugin         Provides utilities for interacting with plugins.
  version        Print the client and server version information

Usage:
  kubectl [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).
```

## 参考資料

Running Kubernetes Locally via Minikube
https://kubernetes.io/docs/setup/minikube/

How do I ssh into the VM for Minikube?
https://stackoverflow.com/questions/38870277/how-do-i-ssh-into-the-vm-for-minikube

<!-- vim:set ft=markdown: -->