Phase 3: Kubernetes
1. イメージのビルドとロード
クラスターの確認 #
ワークショップインスタンスには K3d がプリインストールされています。動作していることを確認します
bash
kubectl get nodestext
NAME STATUS ROLES AGE VERSION
k3d-shw-ece9-cluster-agent-0 Ready <none> 4h6m v1.33.4+k3s1
k3d-shw-ece9-cluster-agent-1 Ready <none> 4h6m v1.33.4+k3s1
k3d-shw-ece9-cluster-server-0 Ready control-plane,master 4h6m v1.33.4+k3s1アプリケーションイメージのビルド #
K8s マニフェストはローカルでビルドされたイメージを参照します。02-obi-docker/ ソースからビルドします
bash
cd ~/workshop/obi/03-obi-k8s
docker build -t obi-workshop-frontend:latest ../02-obi-docker/frontend
docker build -t obi-workshop-order-processor:latest ../02-obi-docker/order-processor
docker build -t obi-workshop-payment-service:latest ../02-obi-docker/payment-servicetext
[+] Building 8.2s (10/10) FINISHED
=> => naming to docker.io/library/obi-workshop-frontend:latest
[+] Building 12.1s (11/11) FINISHED
=> => naming to docker.io/library/obi-workshop-order-processor:latest
[+] Building 11.8s (11/11) FINISHED
=> => naming to docker.io/library/obi-workshop-payment-service:latestK3d へのイメージのインポート #
K3d は Docker ではなく containerd を使用するため、イメージをクラスターにインポートする必要があります。まず、クラスター名を確認します
bash
k3d cluster listtext
NAME SERVERS AGENTS LOADBALANCER
shw-ece9-cluster 1/1 2/2 true次にイメージをインポートします。CLUSTER_NAME は env で利用可能なはずですが、設定されていない場合は以下を試してください
text
export CLUSTER_NAME=$(k3d cluster list -o json | jq -r '.[].name')bash
k3d image import -c $CLUSTER_NAME \
obi-workshop-frontend:latest \
obi-workshop-order-processor:latest \
obi-workshop-payment-service:latesttext
INFO[0000] Importing image(s) into cluster 'shw-ece9-cluster'
INFO[0000] Starting new tools node...
INFO[0000] Starting node 'k3d-shw-ece9-cluster-tools'
INFO[0000] Saving 3 image(s) from runtime...
INFO[0003] Importing images into nodes...
INFO[0003] Importing images from tarball '/k3d/images/k3d-shw-ece9-cluster-images-20260227211818.tar' into node 'k3d-shw-ece9-cluster-server-0'...
INFO[0003] Importing images from tarball '/k3d/images/k3d-shw-ece9-cluster-images-20260227211818.tar' into node 'k3d-shw-ece9-cluster-agent-1'...
INFO[0003] Importing images from tarball '/k3d/images/k3d-shw-ece9-cluster-images-20260227211818.tar' into node 'k3d-shw-ece9-cluster-agent-0'...
INFO[0015] Removing the tarball(s) from image volume...
INFO[0016] Removing k3d-tools node...
INFO[0020] Successfully imported image(s)
INFO[0020] Successfully imported 3 image(s) into 1 cluster(s)ヒント
上記のスクリプトはクラスター名を自動的に検出します。複数の K3d クラスターがある場合は、明示的に指定できます
bash
k3d image import -c shw-ece9-cluster obi-workshop-frontend:latest obi-workshop-order-processor:latest obi-workshop-payment-service:latest
