だいごろうのブログ

熊本出身で大阪、東京、パリを転勤して、今は福岡でデータエンジニアです

[MEMO] katacodaでService Mesh with Istio: ver2 Istioctl

istioctl

どうやらこのコマンドがistioの味噌みたい。 この章ではistioctl kube-injectをメインに勉強。

Deploy.yamlにkube-injectコマンドすることで、SideCarなどの設定を自動で入れてくれるみたい。

istioctl kube-inject -f {YAML}

こんな感じでおしゃれに渡してる。

kubectl apply -f <(istioctl kube-inject -f Deployment.yml) -n namespace

Kubernetesでやってみる

Katacodaの中身がocコマンドつまりredhatのopenshiftなので、minikube立ててローカルでkubernetesでやってみた。

とりあえず、Istioをkubenetesにapplyとistioctlインストールしておく

curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.2 sh -
cd istio-1.2.2
export PATH=$PWD/bin:$PATH

kubectl create namespace istio-system
for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -n istio-system -f $i; done
 kubectl apply -f install/kubernetes/istio-demo.yaml
# 準備
git clone https://github.com/redhat-developer-demos/istio-tutorial/
minikube start
kubectl create namespace istio-tutorial


cd istio-tutorial
cd customer/kubernetes/

## istioctl kube-injectを確かめておこう
istioctl kube-inject -f Deployment.yml

## kubectlにappyする
kubectl apply -f <(istioctl kube-inject -f Deployment.yml) -n istio-tutorial
kubectl get all -n istio-tutorial
less kubernetes/Deployment.yml

# 既存がClusterIPで外部から見れないので、NodePortも作る
cp Service.yml Servicenp.yml
vi Servicenp.yml
diff Service.yml Servicenp.yml
4c4
<   name: customer
---
>   name: customernp
6c6
<     app: customer
---
>     app: customernp
7a8
>   type: NodePort

kubectl apply -f Service.yml -n istio-tutorial
kubectl apply -f Servicenp.yml -n istio-tutorial


## アクセスしたいので, ip portを調べる
kubectl get service/customernp -n istio-tutorial  -owide

# nodeのIPがわからんかったから、 cluster-infoから引っ張ってくる
kubectl cluster-info
curl https://192.168.99.100:32318

## ほかもapply
## curlのレスポンスが変わっていくのが確認できる
cd ../../preference/kubernetes/
kubectl apply -f <(istioctl kube-inject -f Deployment.yml) -n istio-tutorial
kubectl apply -f Service.yml -n istio-tutorial
curl http://192.168.99.100:32318

cd ../../recommendation/kubernetes/
kubectl apply -f <(istioctl kube-inject -f Deployment.yml) -n istio-tutorial
kubectl apply -f Service.yml -n istio-tutorial
curl http://192.168.99.100:32318

最終的にはこんな感じ

kubectl get all -n istio-tutorial
NAME                                     READY   STATUS    RESTARTS   AGE
pod/customer-59975dcff6-7k8rr            2/2     Running   0          27m
pod/preference-v1-8578c48ff-mjhln        2/2     Running   0          9m7s
pod/recommendation-v1-85474b59d5-5hhg4   2/2     Running   1          7m15s

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/customer         ClusterIP   10.106.206.127   <none>        8080/TCP         19m
service/customernp       NodePort    10.111.254.169   <none>        8080:32318/TCP   20m
service/preference       ClusterIP   10.102.211.153   <none>        8080/TCP         8m57s
service/recommendation   ClusterIP   10.105.191.131   <none>        8080/TCP         7m11s

NAME                                READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/customer            1/1     1            1           27m
deployment.apps/preference-v1       1/1     1            1           9m7s
deployment.apps/recommendation-v1   1/1     1            1           7m15s

NAME                                           DESIRED   CURRENT   READY   AGE
replicaset.apps/customer-59975dcff6            1         1         1       27m
replicaset.apps/preference-v1-8578c48ff        1         1         1       9m7s
replicaset.apps/recommendation-v1-85474b59d5   1         1         1       7m15s

どんな感じで、コードの方は定義されてんやろう。どうやって、istioを利用してるんだろう。

customer -> preferenceで名前解決してるところはどうやら単純に、preferenceをhostとして指定するだけみたい。

preferences.api.url=http://preference:8080

https://github.com/redhat-developer-demos/istio-tutorial/blob/master/customer/java/springboot/src/main/resources/application.properties

同じnamespaceのserviceにservice名でアクセスできる感じかな。あとでもっと理解する必要ありそう。ただ、docker-composeと同じように名前をつけれるので、ローカルではdocker-composeで開発して、kubernetesデプロイ時にはistioに名前解決させるで良さそう。

ingress gateway

よく考えたら、serviceのnodeport使わなくても、 ingress gatewayからアクセスとかできるんじゃないかな。ちょっと検証してみよう。ただ、長くなってきたから、別のブログポストにまとめます。

TBD

まとめ

istioのサポートがアツい。kubernetesへの導入の簡単さ、違和感なくkubernetesを使えてる感じ。すごい。

あとで読む。 https://istio.io/docs/concepts/traffic-management/