Contenu connexe
Similaire à Container Storage Interface のすべて (20)
Container Storage Interface のすべて
- 4. 発表の流れ
▌PV, PVC, SC のおさらい
▌CSIの概要
▌CSI・CSIドライバの構造
▌最小限のCSIドライバの実装
▌CSIドライバのテスト
▌オプション機能の拡張方法
▌ドキュメント・参考情報
▌まとめ
4
- 5. metadata:
name: pv01
spec:
capacity: ...
storageClassName: sc01
PV: Persistent Volume
metadata:
name: sc01
provisioner: ...
parameters: ...
SC: Storage Class
metadata:
name: pvc01
spec:
resources: ...
storageClassName: sc01
PVC: Persistent Volume Claim
PV, PVC, SC のおさらい
5
metadata:
name: pod01
spec:
containers:
volumes:
- name: volume01
persistentVolumeClaim:
claimName: pvc01
1. PodおよびPodが利用する
volumeをPVCとして定義
0. (前準備)
SCでPVをグループ分け
することが可能
ストレージ
システム
2. Podから利用可能なvolume (ファイルシステムまたはRawブロックデバイス)
ごとにPVを定義し、関連付ける
4. PVCに関連付けられた
PVのvolumeを用い、
Podが起動
3. PVCで定義した条件に
マッチするPVがPVCに
関連付けられる
- 13. apiVersion: v1
kind: Pod
metadata:
name: pod-name
spec:
containers:
- image: container1:latest
name: container-1
volumeMounts:
- mountPath: /mnt/share
name: shared-volume
- image: container2:latest
name: container-2
volumeMounts:
- mountPath: /mnt/share
name: shared-volume
volumes:
- name: shared-volume
emptyDir: {}
sidecarのおさらい
▌複数のコンテナを内包するPod
▌コンテナ間で、Volumeの共有や
Volume内の Unix Domain
Socket (USD) を利用した通信
が可能
13
Pod
Container#2Container#1
Container#1
Container#2
Volume
- 15. Kubernetes の Node
CSIに関するコンポーネントの連携
15
Controller Plugin の Pod
(Deployment/StatefulSet)
Controller Plugin コンテナ
・ Controller サービス
・ Identity サービス
K8s CSI の sidecar コンテナ
Node Plugin の Pod
(DaemonSet)
Node Plugin コンテナ
・ Node サービス
・ Identity サービス
K8s CSI の sidecar コンテナ
API
Server
gRPC
Unix Domain Socket
gRPC
Unix Domain Socket
Kubelet
Volume Volume詳しくは、CSI Volume Plugins in Kubernetes Design Doc を参照
作成
利用
- 20. 生成されたスケルトンについて
▌csi.pb.goが生成される
▌Identity, Controller, Node の各サービスで実装するべきプロシー
ジャが定義されている。
20
type IdentityServer interface {
GetPluginInfo(context.Context, *GetPluginInfoRequest) (*GetPluginInfoResponse, error)
...
type ControllerServer interface {
CreateVolume(context.Context, *CreateVolumeRequest) (*CreateVolumeResponse, error)
...
type NodeServer interface {
NodeStageVolume(context.Context, *NodeStageVolumeRequest) (*NodeStageVolumeResponse, ...
...
- 22. func (ns *nodeServer) NodeGetCapabilities(ctx context.Context,
req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
return &csi.NodeGetCapabilitiesResponse{
Capabilities: []*csi.NodeServiceCapability{
{
Type: &csi.NodeServiceCapability_Rpc{
Rpc: &csi.NodeServiceCapability_RPC{
Type: csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
},
},
},
...
},
}, nil
}
Capabilityの設定例
22https://github.com/kubernetes-csi/csi-driver-host-path/blob/v1.3.0/pkg/hostpath/nodeserver.go#L279-L299
CSIドライバで提供する機能に応じ、
capabilityを列挙する
- 25. CSIDriverの例
▌CSIドライバの存在と機能を Kubernetes に伝える
25
apiVersion: storage.k8s.io/v1beta1
kind: CSIDriver
metadata:
name: topolvm.cybozu.com
spec:
attachRequired: true
podInfoOnMount: true
volumeLifecycleModes:
- Persistent
- Ephemeral
該当CSIドライバが提供している機能についての定義
https://github.com/cybozu-go/topolvm/blob/v0.4.8/deploy/manifests/controller.yaml#L2-L11
該当CSIドライバが Kubernetes に要求する
挙動についての定義
- 27. CSI Driver Sanity Tester
▌Kubernetes プロジェクトから提供されるCSIドライバのテストツール。
⚫ https://github.com/kubernetes-csi/csi-
test/tree/master/pkg/sanity
▌CSIドライバを起動した状態で、gRPC の応答が正しく実装されているか
をテストしてくれる。
▌コマンドラインから起動 / Ginkgo (Go言語のTesting Framework)
から利用。
27
Tip: 手戻りをなくすため、最初からテストを実行できるようにする。
- 28. Sanity Testerの利用例
28
var _ = Describe("TopoLVM", func() {
Context("CSI sanity", func() {
... テスト対象のCSIドライバを起動しておく
sanity.GinkgoTest(&sanity.Config{
Address: "/tmp/topolvm/worker1/plugins/topolvm.cybozu.com/node/csi-topolvm.sock",
ControllerAddress: "/tmp/topolvm/worker1/plugins/topolvm.cybozu.com/controller/csi-topolvm.sock",
TargetPath: "/tmp/topolvm/worker1/plugins/topolvm.cybozu.com/node/mountdir",
StagingPath: "/tmp/topolvm/worker1/plugins/topolvm.cybozu.com/node/stagingdir",
TestVolumeSize: 1073741824,
IDGen: &sanity.DefaultIDGenerator{},
})
})
})
https://github.com/cybozu-go/topolvm/blob/v0.4.8/e2e/suite_test.go#L99-L137
Controller と Node の両方のエンドポイントに
アクセス可能な環境で実行
- 29. Sanity Tester 以外のテスト
▌Sanity Testerだけでは全てのテストをカバーしているわけではない。
▌実際にストレージが使えるかのE2Eテストを行っていない。
⚫ Cybozuで開発しているCSIドライバ (TopoLVM) では、 kindを利用したE2E
テストを別途実施している。
▌個々のCSIドライバの実装に関する単体テストも必要に応じて追加する。
29
- 31. Volume Expansion 機能を提供する
▌定義するCapabilities
⚫ EXPAND_VOLUME (ControllerCapabilities)
⚫ EXPAND_VOLUME (NodeCapabilities)
▌実装するメソッド
⚫ ControllerExpandVolume (Controllerサービス)
⚫ NodeExpandVolume (Nodeサービス)
▌Sidecarとして external-resizer を追加
▌StorageClass に allowVolumeExpansion を定義
31
- 32. ControllerExpandVolumeの例
▌サイズの変更が可能かどうかを判定する。
requestGb, err := convertRequestCapacity(req.GetCapacityRange().GetRequiredBytes(),
req.GetCapacityRange().GetLimitBytes())
...
if requestGb <= currentGb {
return &csi.ControllerExpandVolumeResponse{
CapacityBytes: currentGb << 30,
NodeExpansionRequired: true,
}, nil
}
...
if capacity < (requestGb<<30 - currentGb<<30) {
return nil, status.Error(codes.Internal, "not enough space")
}
...
return &csi.ControllerExpandVolumeResponse{
CapacityBytes: requestGb << 30,
NodeExpansionRequired: true,
}, nil
領域の縮小が要求される場合もある
領域の拡張を許容する場合
NodeExpansionRequired が true の場合、
Node の NodeExpandVolume (次スライド) が呼ばれる
https://github.com/cybozu-go/topolvm/blob/v0.4.8/driver/controller.go#L310-L376 32
- 34. Dynamic Provisioning 機能を提供する
▌定義するCapabilities
⚫ CREATE_DELETE_VOLUME (ControllerCapabilities)
▌実装するメソッド
⚫ CreateVolume (Controllerサービス)
⚫ DeleteVolume (Controllerサービス)
▌Sidecarとして external-provisioner を追加
▌StorageClass の provisioner と、GetPluginInfo で戻すnameの
値を同じにしておく。
34
詳しい実装はTopoLVMを参照
- 40. ドキュメント
▌Container Storage Interface (CSI) のspec
https://github.com/container-storage-interface/spec/
▌CSI Volume Plugins in Kubernetes Design Doc
https://github.com/kubernetes/community/blob/master/contribut
ors/design-proposals/storage/container-storage-interface.md
▌Kubernetes CSI Developer Documentation
https://kubernetes-csi.github.io/docs/introduction.html
▌各sidecarのREADME.mdにオプションなどが記載されている
40