Docker
kubernetes
Kind

いわゆる Kubernetes in Docker。(いわゆるもくそも、だから名前が "kind")

たくさんのクラスタがDockerコンテナ1つで上がる!?感じ。

Learningに使えるかという点で評価してみる。

とりあえずはセットアップと軽めのApp立ち上げ確認。


Pre Setup


  • GCPにて、約メモリ8GB積んだCentOS7 x86_64を用意

  • git

  • docker 18.09.5

  • kubectl 1.14.1


Install Golang

よしなに、

# curl -LO https://dl.google.com/go/go1.12.4.linux-amd64.tar.gz

# tar zxf go1.12.4.linux-amd64.tar.gz
# mv go /usr/local/bin/


Install kind

# export GOPATH=/usr/local/bin/go/bin

# export PATH=$PATH:$GOPATH
# go get -u sigs.k8s.io/kind

そこそこかかる

# export KINDPATH=/usr/local/bin/go/bin/bin

# export PATH=$PATH:$KINDPATH

# kind create cluster
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.13.4) 🖼
✓ Preparing nodes 📦
✓ Creating kubeadm config 📜
✓ Starting control-plane 🕹️
Cluster creation complete. You can now use the cluster with:

export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
kubectl cluster-info

そこそこかかる

docker コマンドうってみると・・・・

# docker container ls

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7f23eb8af62 kindest/node:v1.13.4 "/usr/local/bin/entr…" About a minute ago Up About a minute 34487/tcp, 127.0.0.1:34487->6443/tcp kind-control-plane

# kind get kubeconfig-path

/root/.kube/kind-config-kind
# export KUBECONFIG="$(kind get kubeconfig-path)"
# kubectl cluster-info
Kubernetes master is running at https://localhost:37608
KubeDNS is running at https://localhost:37608/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

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


Wordpressあげてみる

https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/#add-resource-configs-for-mysql-and-wordpress

# kubectl get secrets

NAME TYPE DATA AGE
default-token-bkh8n kubernetes.io/service-account-token 3 36m
mysql-pass-59cdgt95hd Opaque 1 14m

# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Bound pvc-a8f2baf5-5f5b-11e9-989b-0242a2b9ea4d 20Gi RWO standard 15m
wp-pv-claim Bound pvc-a8f6eb33-5f5b-11e9-989b-0242a2b9ea4d 20Gi RWO standard 15m

# kubectl get pods
NAME READY STATUS RESTARTS AGE
wordpress-c6b7fcdd-sfc8d 1/1 Running 0 15m
wordpress-mysql-b4447dd8-xr668 1/1 Running 0 15m

# kubectl get services wordpress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 10.101.188.12 <pending> 80:32617/TCP 15m

ちゃんとあがっとるので、そとからアクセスできるようにポートフォワード

# kubectl port-forward --address 0.0.0.0 svc/wordpress 80:80

=>ブラウザで確認、ばっちりあがる!


もいっちょクラスタCreate

# kind create cluster --name tk

Creating cluster "tk" ...
✓ Ensuring node image (kindest/node:v1.13.4) 🖼
✓ Preparing nodes 📦
✓ Creating kubeadm config 📜
✓ Starting control-plane 🕹️
Cluster creation complete. You can now use the cluster with:

export KUBECONFIG="$(kind get kubeconfig-path --name="tk")"
kubectl cluster-info

# kind get clusters
tk
kind

追加されてる!ので宛先を変えて、再度Wordpress

# export KUBECONFIG="$(kind get kubeconfig-path --name="tk")"

# kubectl cluster-info
Kubernetes master is running at https://localhost:33629
KubeDNS is running at https://localhost:33629/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

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

なにがちがうって、さっきとちゃんとMasterの宛先ポートが違う。

同じYAML使ってWordpress上げて、ポートフォワーディングして、ブラウザアクセス。

ばっちりあがった。

が・・・クラスタが2つで外からのアクセスをそれぞれのクラスタのPodにアクセスするようにするのは!?

ちゃんと確認・・・これから。


クラスタ・消す

kind delete cluster --name kind

すぐ消える


Ref