kindでelasticsearchを動かす

Kubernetes IN Docker(kind)を使えば、helmとかで簡単にk8sにelasticsearchを動かせるかなと思い、試してみる。

elasticsearchのhelmチャートはhelm/stableとelasticの2種類あるが、現時点ではelasticの方は動かなかった…。elasticの方にはexamplesにはkindの例があるのだが、これもダメなので、がんばって調べないと動かせなそうなので、一旦、これは見送って、素直にhelm/stableを試す。

kindやhelmなどの必要なものは入れてある前提で、まずは、kindでk8sのクラスタを作成する。

$ kind create cluster 
 Creating cluster "kind" …
  ✓ Ensuring node image (kindest/node:v1.15.3) 🖼
  ✓ Preparing nodes 📦 
  ✓ Creating kubeadm config 📜 
  ✓ Starting control-plane 🕹️ 
  ✓ Installing CNI 🔌 
  ✓ Installing StorageClass 💾 
 Cluster creation complete. You can now use the cluster with:

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

という感じでクラスタが簡単にできる。kindでいろいろな設定でクラスタを作ることもできるらしい。何も指定しなければ、kindという名前のクラスタができる。

$ export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
$ kubectl cluster-info
 Kubernetes master is running at https://127.0.0.1:36777
 KubeDNS is running at https://127.0.0.1:36777/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

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

KUBECONIGを設定すれば、kubectlコマンドが利用できる。あとはhelmを使うので、tillerに権限を付けて初期化しておく。

$ kubectl -n kube-system create serviceaccount tiller
 serviceaccount/tiller created
$ kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
 clusterrolebinding.rbac.authorization.k8s.io/tiller created
$ helm init --service-account=tiller --wait
 $HELM_HOME has been configured at /home/shinsuke/.helm.

 Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.

 Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
 To prevent this, run helm init with the --tiller-tls-verify flag.
 For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation

これ以降は普通にhelmでインストールすれば良い。

$ helm install --name my-release stable/elasticsearch
...
 From outside the cluster, run these commands in the same shell:

 export POD_NAME=$(kubectl get pods --namespace default -l "app=elasticsearch,component=client,release=my-release" -o jsonpath="{.items[0].metadata.name}")
 echo "Visit http://127.0.0.1:9200 to use Elasticsearch"
 kubectl port-forward --namespace default $POD_NAME 9200:9200 

という感じで、上記にあるようにkubectl port-forwardを実行すれば、localhost:9200でアクセスして確認することができる。

k8sのクラスタを破棄するには

$ kind delete cluster

とすれば削除できる。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です