Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ai_cording_with_k8s_knowledge.pdf

 ai_cording_with_k8s_knowledge.pdf

2026/10/06 Kubernetes Novice Tokyo #42
AIコーディングで活きたKubernetesの知識

セッション動画
https://k8s-novice-jp.connpass.com/event/405343/
https://www.youtube.com/live/mneDZUdBPhY?si=WhUcUF77wSxA7xWm&t=5102

Avatar for mochizuki875

mochizuki875

October 06, 2026

More Decks by mochizuki875

Other Decks in Technology

Transcript

  1. 導入 しかしLLMへのリクエストにファイルを直接渡すことができない。 マルチモーダル対応モデルにファイル情報を渡すには、ファイル形式に応じた変換を行う必要がある。 ✔ PDF, O ceファイル: ファイルを画像化&Base64エンコードしたものをimage̲urlとして送信 ✔ TEXT,

    HTMLファイルなど: ファイルからテキストを抽出して送信 POST /v1/responses POST /v1/chat/completions TEXT { "type": "image̲url", "image̲url": { "url": "data:image/png;base64,iVBORw0KGgoAAA..." } } GPUサーバー Client/SDK 偶然家にあったDGX Spark→ ffi https://docs.vllm.ai/en/stable/serving/online̲serving/
  2. OpenAI公式ではFiles APIというAPIが提供されており、 直接アップロードしたファイルを推論に利用できる。 POST /v1/ les Files API le̲id le̲id

    POST /v1/responses + Client/SDK request le̲id request Responses API le̲idに紐づくファイル情報 を取得して推論を実行 fi https://developers.openai.com/api/reference/resources/ les fi fi fi fi fi 導入
  3. 課題1: LFGでの対応 KubernetesのReplicaSet Controllerの実装 LFGの実装 func (rsc *ReplicaSetController) worker(ctx context.Context)

    { for rsc.processNextWorkItem(ctx) { } } func (service *Service) worker(ctx context.Context, id int) { for service.processNextJob(ctx) { } } func (rsc *ReplicaSetController) processNextWorkItem(ctx context.Context) bool { key, quit := rsc.queue.Get() // Queueからアイテムを取り出す if quit { return false } defer rsc.queue.Done(key) func (service *Service) processNextJob(ctx context.Context) bool { job, quit := service.queue.Get(ctx) // Queueからアイテムを取り出す if quit { return false } err := rsc.syncHandler(ctx, key) // Reconcile処理を実行 if err == nil { rsc.queue.Forget(key) return true } utilruntime.HandleError(fmt.Errorf("sync %q failed with %v", key, err)) rsc.queue.AddRateLimited(key) return true } err := service.processJob(ctx, job) // Convert処理を実行 service.handleErr(ctx, err, job) return true }
  4. 課題2: 様々なファイル形式の変換処理 ✅ Files APIにアップロードされるファイル形式は様々 ✅ ファイル形式によってアーティファクトへの変換ロジックが異なる ✅ 既存変換ロジックの見直しや新しい拡張子を追加する毎にLFG本体を変更する必要がある switch

    format { case "pdf": // PDFファイル用の変換処理 case "docx": // Wordファイル用の変換処理 case "xlsx": // Excel用の変換処理 ... TEXT Files API アーティファクトに変換 Convert ファイル形式に応じた変換処理を実行
  5. 課題2のヒント: SchedulerにおけるScheduling Framework Filterフェーズの例 ✅ スケジュール対象Podに対しKubernetesクラスタのNodeからスケジュール先となり得るNodeを選択 ✅ 様々なFilterロジックがプラグインとして登録されており固有のFiltering処理を担う ✅ SchedulerとPluginの間に共通の規則(Interface)を設けることで処理を呼び出す側と処理を実装する側の責務を分離

    Filter NodeName Plugin 処理を呼び出す NodeUnschedulable Plugin 共通規則 Node Filterという (FilterPlugin Interface) スケジュール対象Pod TaintToleration Plugin スケジュール先 Nodeの候補 NodeA nity Plugin ・ ・ ・ Filterという 処理を実装 ffi 登録されたプラグインを 順番に実行
  6. 課題2のヒント: SchedulerにおけるScheduling Framework Filterフェーズの例 ✅ スケジュール対象Podに対しKubernetesクラスタのNodeからスケジュール先となり得るNodeを選択 ✅ 様々なFilterロジックがプラグインとして登録されており固有のFiltering処理を担う ✅ SchedulerとPluginの間に共通の規則(Interface)を設けることで処理を呼び出す側と処理を実装する側の責務を分離

    参考にした部分 Filter NodeName Plugin 処理を呼び出す NodeUnschedulable Plugin 共通規則 Node Filterという (FilterPlugin Interface) スケジュール対象Pod TaintToleration Plugin スケジュール先 Nodeの候補 NodeA nity Plugin ・ ・ ・ Filterという 処理を実装 ffi 登録されたプラグインを 順番に実行
  7. 課題2: LFGでの対応 LFGでもScheduling Frameworkを参考に以下のように実装 ✅ 共通の規則であるDocumentConverter Interfaceを定義 ✅ 拡張子に応じた変換処理を実装したConverterをプラグイン形式で登録 ✅

    ファイル拡張子に応じたConverterを選択して変換処理を実行 Converter Convertという 処理を呼び出す PdfConverter or DocxConverter 共通規則 変換対象ファイル (DocumentConverter Interface) ファイル形式に適した Converterを選択 or XlsxConverter or PptxConverter ・ ・ ・ Convertという 処理を実装 TEXT アーティファクトに変換
  8. 課題2: LFGでの対応 KubernetesのReplicaSet Controllerの実装 LFGの実装 SchedulerにおけるFilter処理の呼び出し LFGにおけるConvert処理の呼び出し func (f *frameworkImpl)

    runFilterPlugin(...) *fwk.Status { ... status := pl.Filter(ctx, state, pod, nodeInfo) // Filter処理の呼び出し ... } func (service *Service) convert(ctx context.Context, job conversionJob) error { ... ̲, err = documentConverter.Convert(ctx, source, lepath.Join( lepath.Dir(source), "derived"), converter.Options{...}) // Convert処理の呼び出し ... FilterPlugin Interfaceの定義 DocumentConverter Interfaceの定義 type FilterPlugin interface { ... type DocumentConverter interface { ... // Filterの共通規則 Filter(ctx context.Context, state CycleState, pod *v1.Pod, nodeInfo NodeInfo) *Status // Convertの共通規則 Convert(ctx context.Context, source, outputDir string, options Options) (Result, error) Filter処理の実装 Convert処理の実装 NodeName Plugin PdfConverter func (pl *NodeName) Filter(ctx context.Context, ̲ fwk.CycleState, pod *v1.Pod, nodeInfo fwk.NodeInfo) *fwk.Status { // NodeNameを満たすNodeを選択する処理 } func (documentConverter pdfConverter) Convert(ctx context.Context, source, outputDir string, options Options) (Result, error) { // PDF形式のファイルを変換する処理 } NodeUnschedulable Plugin DocumentConverter func (pl *NodeUnschedulable) Filter(ctx context.Context, ̲ fwk.CycleState, pod *v1.Pod, nodeInfo fwk.NodeInfo) *fwk.Status { // スケジュール不可(e.g. cordon)なNodeを除外する処理 } func (documentConverter docxConverter) Convert(ctx context.Context, source, outputDir string, options Options) (Result, error) { // DOCX形式のファイルを変換する処理 } fi } fi }