kakakakakku blog

Weekly Tech Blog: Keep on Learning!

HashiCorp Learn の Consul コース「Getting Started with Kubernetes」を実施した

引き続き Consul を検証している.前回の記事では「HashiCorp Learn Platform」を活用して,Consul の「Getting Started」を実施したので,今回は「Getting Started with Kubernetes」を実施した.Consul に限らず,Kubernetes と Envoy を使ったマイクロサービスを試すことができる点もメリットだと思う.興味がある人は是非やってみると良いのでは!とは言え,Consul 要素は少ないようにも感じた.

kakakakakku.hatenablog.com

「HashiCorp Learn Platform」には,Consul 以外にも Vault / Terraform / Nomad のコンテンツがあるので,継続的に学んでいく.

learn.hashicorp.com

HashiCorp Learn 画面

画面は前回と同じで,基本的に動画を見ながら受講する.コマンドをコピーするときは下部にあるスクリプトを使う.

f:id:kakku22:20190330180924p:plain

Learn how to deploy a service mesh with HashiCorp Consul : Getting Started with Kubernetes

今回実施した「Getting Started with Kubernetes」は,前回実施した「Getting Started」と比較すると内容は軽く,計2ステップある.

  • 1 : Consul Installation to Minikube via Helm (8 min)
    • 実際に動画を観ると 9 min を超えているし,実際に動作確認をしながら進めるため,1時間ぐらいを想定しておくと良さそう
  • 2 : Deploy Consul with Kubernetes (8 min)

1 : Consul Installation to Minikube via Helm

learn.hashicorp.com

Prerequisites

Minikube と Helm をインストールしておく.今回は brew を使う.

$ brew cask install minikube
$ brew install kubernetes-cli
$ brew install kubernetes-helm

kubernetes.io

Task 1: Start Minikube and Install Consul with Helm

Step 1: Start Minikube

まず,Minikube を使って VirtualBox 上に Kubernetes を起動する.起動後に minikube dashboard を実行すると,Kubernetes Dashboard にアクセスできる.

$ minikube start --memory 8192
$ minikube dashboard

f:id:kakku22:20190330180954p:plain

Step 2: Install the Consul Helm Chart to the Cluster

今回は HashiCorp Training でも使われている「hashicorp/demo-consul-101」を使う.

github.com

さらに Consul Helm Chart を使う.Helm Charts の stable にもあるけど,どう違うんだろう.

github.com

最後に helm install を実行する.

$ git clone https://github.com/hashicorp/demo-consul-101.git
$ cd demo-consul-101/k8s
$ helm init
$ git clone https://github.com/hashicorp/consul-helm.git
$ helm install -f helm-consul-values.yaml --name hedgehog ./consul-helm

Task 2: Deploy a Consul-aware Application to the Cluster

Step 1: View the Consul Web UI

minikube service list を実行すると,起動しているサービスを確認できる.

$ minikube service list
|-------------|--------------------------------------|-----------------------------|
|  NAMESPACE  |                 NAME                 |             URL             |
|-------------|--------------------------------------|-----------------------------|
| default     | hedgehog-consul-connect-injector-svc | No node port                |
| default     | hedgehog-consul-dns                  | No node port                |
| default     | hedgehog-consul-server               | No node port                |
| default     | hedgehog-consul-ui                   | http://192.168.99.100:30367 |
| default     | kubernetes                           | No node port                |
| kube-system | kube-dns                             | No node port                |
| kube-system | kubernetes-dashboard                 | No node port                |
| kube-system | tiller-deploy                        | No node port                |
|-------------|--------------------------------------|-----------------------------|

サービス一覧から hedgehog-consul-ui を起動すると,Consul Web UI にアクセスできる.

$ minikube service hedgehog-consul-ui

f:id:kakku22:20190330181043p:plain

Step 2: Deploy Custom Applications

アプリケーションを2種類起動する.

  • Counting Service
  • Dashboard Service
$ kubectl create -f 04-yaml-connect-envoy
pod/counting created
pod/dashboard created
service/dashboard-service-load-balancer created

f:id:kakku22:20190330181103p:plain

Step 3: View the Web Application

起動した Dashboard Service に接続するために,ポートフォワードを設定する.既に http://localhost:9002 にアクセスできるようになっている.ちなみに Counting Service と Dashboard Service は Envoy を経由した構成になっている.

$ kubectl port-forward dashboard 9002:9002
Forwarding from 127.0.0.1:9002 -> 9002
Forwarding from [::1]:9002 -> 9002

f:id:kakku22:20190330184535p:plain

Task 3: Use Consul Connect

最後に Consul Intentions を設定する.まず,全サービスのアクセスを拒否する.

f:id:kakku22:20190330181145p:plain

すると,Dashboard Service から Counting Service にアクセスできず,Unreachable エラーになる.

f:id:kakku22:20190330181202p:plain

次に Dashboard Service から Counting Service にアクセスできるように許可すると,正常にアクセスできるようになった.

f:id:kakku22:20190330181226p:plain

2 : Deploy Consul with Kubernetes

Consul Helm Chart を使って Kubernetes 上に Consul をデプロイする.「Consul Installation to Minikube via Helm」と重複する箇所も多く,一通り実施はしたけど,割愛する.

learn.hashicorp.com

まとめ

  • HashiCorp プロダクトを学ぶなら「HashiCorp Learn Platform」を活用する
  • 今回は「Learn how to deploy a service mesh with HashiCorp Consul」「Getting Started with Kubernetes」を実施した
  • Minikube で起動した Kubernetes 上にマイクロサービスを起動して Consul Connect で制御できるようになった

参考記事

www.consul.io