0
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?

PodにIstioのサイドカーを注入してみる

0
Posted at

はじめに

1つ前の記事でkindで作成したKubernetesクラスタにIstioをインストールしてみました。

次はPodを作成して、Istioのサイドカーを注入してみます。

環境情報

Component Version
PC M1 MacBook Pro
OS macOS 26.6.2
Rancher Desktop 1.24.0
kind 0.33.0
Kubernetes v1.37.0
Istio 1.30.4
Helm v4.2.3

手順

予め以下の記事を参考にKubernetesクラスタへIstioをインストール済みであることとします。

Istioのソースコードのダウンロード

サンプルのマニフェストを使うので、Istio 1.30.4のソースコードをダウンロードしておきます。

istio-injection=enabled のラベルによるサイドカーの自動注入

defalut Namespaceに istio-injection=enabled ラベルをつけて、サイドカーの自動注入を有効化してみます。

kubectl label namespace default istio-injection=enabled --overwrite

--overwrite は既に同じラベルがあった場合に上書きするオプションです。ラベルが未定義であれば不要なオプションです。

curl Deploymentを作成してみます。

cd /path/to/istio-1.30.4
kubectl apply -f samples/curl/curl.yaml

Podを取得すると、コンテナが2つReadyになっていることがわかります。

❯ kubectl get pod
NAME                    READY   STATUS    RESTARTS   AGE
curl-76c6cddfb7-s5dx6   2/2     Running   0          13m

コンテナとinitコンテナの一覧を表示すると以下のようになります。

❯ kubectl get pod curl-76c6cddfb7-s5dx6 -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}{"---¥n"}{range .spec.initContainers[*]}{.name}{"\n"}{end}'
curl
---
istio-init
istio-proxy

istio-initはネットワークの初期化を行い終わったら終了するので、現在Running状態のコンテナはcurlとistio-proxyの2つです。

片付け

自動注入の片付けをします。

作成したリソースを削除し、default Namespaceからistio-injection=enabled ラベルを削除します。

kubectl delete -f samples/curl/curl.yaml
kubectl label ns default istio-injection-

istioctl kube-inject によるサイドカーの手動注入

istioctl kube-inject によるサイドカーの手動注入をやってみます。

istio-injection=enabled ラベルによるサイドカーの自動注入と違い、マニフェストを修正してサイドカーを注入します。

curlのサンプルマニフェストから、サイドカーを注入したマニフェストを生成しapplyします。

istioctl kube-inject -f samples/curl/curl.yaml -o samples/curl/curl-inject.yaml
kubectl apply -f samples/curl/curl-inject.yaml

自動注入のときと同じようにサイドカーが注入されています。

❯ kubectl get pod
NAME                    READY   STATUS    RESTARTS   AGE
curl-574ff9ccc4-xjmsg   2/2     Running   0          9s
❯ kubectl get pod curl-574ff9ccc4-xjmsg -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}{"---\n"}{range .spec.initContainers[*]}{.name}{"\n"}{end}'
curl
---
istio-init
istio-proxy

istioctl experimental check-inject によるサイドカーの注入状況確認

istioctl experimental check-inject` は、サイドカーが自動注入されているか確認するコマンドです。

試しに、手動注入したcurl Deploymentで確認してみます。

❯ istioctl experimental check-inject deployment/curl -n default
WEBHOOK                 REVISION  INJECTED      REASON
istio-sidecar-injector  default   ✘             No matching namespace labels (istio.io/rev=default, istio-injection=enabled) or pod labels (istio.io/rev=default, sidecar.istio.io/inject=true)

NamespaceやPodのラベルで判断しているらしく、手動注入した場合ではOKになりませんでした。

もう一度、サイドカーの自動注入してみます。

kubectl delete -f samples/curl/curl-inject.yaml
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/curl/curl.yaml

今度は自動注入がされていると判断されました。

❯ istioctl experimental check-inject deployment/curl -n default
WEBHOOK                 REVISION  INJECTED      REASON
istio-sidecar-injector  default   ✔             Namespace label istio-injection=enabled matches

最後に

Istioのサイドカーの自動注入と手動注入の違い、またそれぞれの注入方法によっての istioctl experimental check-inject の挙動の違いを確認することができました。

参考情報

0
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
0
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?