GKEあるけど、KubernetesクラスタをGCEで立ててみたかった日記

# はじめに
* ちょっとやってみようと思ったんです。
* ただちょっと想像と違いました。(いい意味でも悪い意味でも)

# さあ、やってみよう

* こんなページを発見 
    * [Running Kubernetes on Google Compute Engine](https://kubernetes.io/docs/setup/turnkey/gce/)

* そしたらこんなことが書いてあった。「GKE楽だよ。そっち使いなー」
    * そうじゃないんです。自分で作りたいんです

> If you want a simplified getting started experience and GUI for managing clusters, please consider trying Google Kubernetes Engine for hosted cluster installation and management.


# せっかくだからCloud shell を使ってみよう

* ..便利だ！

![image.png](https://qiita-image-store.s3.amazonaws.com/0/108052/41725628-713f-971f-5587-72e59148c600.png)

* まずは以下のbashを実行

```
curl -sS https://get.k8s.io | bash
```

```
xxxxxxx@cloudshell:~ (your-project)$ curl -sS https://get.k8s.io | bash
Downloading kubernetes release v1.13.2
  from https://dl.k8s.io/v1.13.2/kubernetes.tar.gz
  to /home/xxxxxxx/kubernetes.tar.gz
Is this ok? [Y]/n
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   161  100   161    0     0    247      0 --:--:-- --:--:-- --:--:--   247
100 1910k  100 1910k    0     0  1714k      0  0:00:01  0:00:01 --:--:-- 7405k
Unpacking kubernetes release v1.13.2
Kubernetes release: v1.13.2
Server: linux/amd64  (to override, set KUBERNETES_SERVER_ARCH)
Client: linux/amd64  (autodetected)

Will download kubernetes-server-linux-amd64.tar.gz from https://dl.k8s.io/v1.13.2
Will download and extract kubernetes-client-linux-amd64.tar.gz from https://dl.k8s.io/v1.13.2
Is this ok? [Y]/n

[..]

sha1sum(kubernetes-client-linux-amd64.tar.gz)=dd4f7830499f9ddfbbc6c86daacc891e9630f39c

ˆExtracting /home/xxxxxxx/kubernetes/client/kubernetes-client-linux-amd64.tar.gz into /home/xxxxxxx/kubernetes/platforms/linux/amd64
Add '/home/xxxxxxx/kubernetes/client/bin' to your PATH to use newly-installed binaries.
```

* ファイルが展開されていますね。 `./kubernetes`

```
xxxxxxx@cloudshell:~ (your-project)$ ls
kubernetes  kubernetes.tar.gz
```

* ふむふむ。`kube-up.sh` を叩くと

```
cd kubernetes
cluster/kube-up.sh
```

```
xxxxxxx@cloudshell:~ (your-project)$ cd kubernetes/
xxxxxxx@cloudshell:~/kubernetes (your-project)$ cluster/kube-up.sh
... Starting cluster in us-central1-b using provider gce
... calling verify-prereqs
... calling verify-kube-binaries
... calling verify-release-tars
... calling kube-up
Project: your-project
Network Project: your-project
Zone: us-central1-b
BucketNotFoundException: 404 gs://kubernetes-staging-xxxxxxxx bucket does not exist.
Creating gs://kubernetes-staging-xxxxxxxx
Creating gs://kubernetes-staging-xxxxxxxx/...
+++ Staging server tars to Google Storage: gs://kubernetes-staging-xxxxxxxx/kubernetes-devel
+++ kubernetes-server-linux-amd64.tar.gz uploaded (sha1 = b48b9e180f45775a6fbab30c5c1fd8ef986e6c3c)
+++ kubernetes-manifests.tar.gz uploaded (sha1 = 845007b37264049c938b1dad35b73164f01a69ea)
INSTANCE_GROUPS=
```

* おや？

![image.png](https://qiita-image-store.s3.amazonaws.com/0/108052/3fa695c4-75d9-63c2-a72a-f496cb62cd56.png)

* おやおや？ (確信)

![image.png](https://qiita-image-store.s3.amazonaws.com/0/108052/22135cfe-fabf-baf8-b4e9-0c7ffc62425b.png)


* できちゃいました。 kubectl が叩けましたね。

```
xxxxxxx@cloudshell:~ ()$ kubectl cluster-info
Kubernetes master is running at https://xx.xx.xx.xx
GLBCDefaultBackend is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
Heapster is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubernetes-dashboard is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
Metrics-server is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
```

# まとめ
* kubernetesのクラスタ、たった数コマンドでできちゃいました。
* もっとこう、各サーバに入って、あれこれインストールして、NW設定して、、っていうのがやりたかったんだ！
* ただ、GKEとちがって、master Nodeが触れるところにあるので、じっくり中身を見させてもらいます
    * 後半に続きます！

# 補足：ログを見てみる

* いろいろやっていそうなので、あとでじっくり作られたリソースと見比べて見てみます。

```
xxxxxxx@cloudshell:~/kubernetes (your-project)$ cluster/kube-up.sh
... Starting cluster in us-central1-b using provider gce
... calling verify-prereqs
... calling verify-kube-binaries
... calling verify-release-tars
... calling kube-up
Project: your-project
Network Project: your-project
Zone: us-central1-b
BucketNotFoundException: 404 gs://kubernetes-staging-yyyyyyy bucket does not exist.
Creating gs://kubernetes-staging-yyyyyyy
Creating gs://kubernetes-staging-yyyyyyy/...
+++ Staging server tars to Google Storage: gs://kubernetes-staging-yyyyyyy/kubernetes-devel
+++ kubernetes-server-linux-amd64.tar.gz uploaded (sha1 = b48b9e180f45775a6fbab30c5c1fd8ef986e6c3c)
+++ kubernetes-manifests.tar.gz uploaded (sha1 = 845007b37264049c938b1dad35b73164f01a69ea)
INSTANCE_GROUPS=
NODE_NAMES=
Looking for already existing resources
Found existing network default in AUTO mode.
Creating firewall...
IP aliases are disabled.
.Creating firewall...
......Found subnet for region us-central1 in network default: default
Starting master and configuring firewalls
..Creating firewall...
........Creating firewall...
...........Created [https://www.googleapis.com/compute/v1/projects/your-project/zones/us-central1-b/disks/kubernetes-master-pd].
..NAME                  ZONE           SIZE_GB  TYPE    STATUS
kubernetes-master-pd  us-central1-b  20       pd-ssd  READY

New disks are unformatted. You must format and mount a disk before it
can be used. You can find instructions on how to do this at:

[..]

もっとログ

```