19
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

この記事は kubernetes Advent Calendar 2025 および デジタル創作サークル UniProject Advent Calendar 2025 16 日目の記事です。

はじめに

先日、コンテナは銀の弾丸ではないという記事を出しました。

そこでもお話ししたとおり、Kubernetes のネットワークは完全に隔離されていると過信しすぎるのは NG です。

mTLS とは

mTLS とは、送信側も受信側も双方向に TLS を使うことによって、送信者証明も行おうというものです。

K8s で何も意識せずに簡単にそれを行えるのが mTLS です。

インストールしてみる

まず、Istio CLI をインストールします。

curl -L https://istio.io/downloadIstio | sh -
cd istio-1.28.1
export PATH=$PWD/bin:$PATH

これで、CLI はインストールできたました。
ここから K8s にインストールしていきます。

Istio にはサイドカーモードとアンビエントモードの 2 種類がありますが、基本的にはアンビエントモードを使用して OK です。

istioctl install --set profile=ambient --skip-confirmation

こんな感じのログが出れば OK です。

✔ Istio core installed
✔ Istiod installed
✔ CNI installed
✔ Ztunnel installed
✔ Installation complete

また、Istio は Gateway API をサポートしています。
下記コマンドで CRDs をインストールしてみましょう。

kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.4.0/experimental-install.yaml

サンプルアプリケーションを入れてみる

何やらサンプルアプリケーションがあるので、使ってみましょう。

インストールしてみる

まず Deployment から

kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f samples/bookinfo/platform/kube/bookinfo-versions.yaml

これで、このようなリソースが確認できます。

$ kubectl get pods
NAME                             READY   STATUS    RESTARTS   AGE
details-v1-cf74bb974-nw94k       1/1     Running   0          42s
productpage-v1-87d54dd59-wl7qf   1/1     Running   0          42s
ratings-v1-7c4bbf97db-rwkw5      1/1     Running   0          42s
reviews-v1-5fd6d4f8f8-66j45      1/1     Running   0          42s
reviews-v2-6f9b55c5db-6ts96      1/1     Running   0          42s
reviews-v3-7d99fd7978-dm6mx      1/1     Running   0          42s

Gateway CRUDs をインストールした場合はこちらも入れましょう。

kubectl apply -f samples/bookinfo/gateway-api/bookinfo-gateway.yaml
$ kubectl get gateway
NAME               CLASS   ADDRESS                                            PROGRAMMED   AGE
bookinfo-gateway   istio   bookinfo-gateway-istio.default.svc.cluster.local   True         42s

アクセスしてみる

ポートフォワードの設定をします。

kubectl port-forward svc/bookinfo-gateway-istio 8080:80

これで、http://localhost:8080/productpageにアクセスすると、このような画面が見えると思います。

bookinfo-browser.png

Istio を有効化する

Istio の mTLS は名前空間ごとに有効化できます。
有効化してみましょう。

kubectl label namespace default istio.io/dataplane-mode=ambient

確認してみる

Prometheus と Kiali をインストールすることにより、Web 上でデータの流れを確認できます。

kubectl apply -f samples/addons/prometheus.yaml
kubectl apply -f samples/addons/kiali.yaml
istioctl dashboard kiali

このコマンドで、アクセスを発生させ続けることにより、確認しやすくなります。

for i in $(seq 1 100); do curl -sSI -o /dev/null http://localhost:8080/productpage; done

おそらくこんな画面が見えるかと思います。

kiali-ambient-bookinfo.png

また、それぞれのサービスをクリックすると、こんな感じで、mTLS が有効化されていることも確認できます。

kiali-tcp-traffic.png

最後に

今回は Kubernetes で mTLS をする方法を試してみました。

また、当サークルでは ProxmoxVE や Kubernetes を運用しています。
もし興味がありましたら、下記 URL へ飛んでいただければと思います!

⭐︎ 公式 HP ↓

⭐︎ Discord ↓

19
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?