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?

containerlab の YAML は何を書いている?

Last updated at Posted at 2025-12-04

はじめに

containerlab は ネットワークトポロジ(配線図)を YAML で宣言的に表現し、
そのとおりに仮想ネットワークを構築するツール
です。
https://containerlab.dev/

この記事では、下記のような containerlab の設定ファイルの中で
何を定義しているのかについて見ていきます。

name: test-lab

topology:
  nodes:
    host1:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host1:/host1-folder
    host2:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host2:/host2-folder
    switch:
      kind: linux
      image: XXXXXX
      binds: 
        - ./switch:/lab-folder

  links:
    - endpoints: ["host1:eth1", "switch:eth1"]
    - endpoints: ["host2:eth1", "switch:eth2"]

containerlab YAML の構造

上記サンプルは下記のような構造になっています。

name:
topology:
  nodes:
  links:
セクション 役割
name ラボ(構成ファイル)の名前
topology.nodes 各ノードの詳細(名前、種類=kind、使うコンテナイメージ)
topology.links ノード間の接続(どのノードのどのインタフェースをつなぐか)

それぞれ掘り下げます。

1. name:ラボの名前

name: test-lab

ここで宣言する name は、生成されるコンテナやネットワーク名のプレフィックスとして利用されます。

また containerlab が自動生成したリソースには clab- が付与されるので、

clab-test-lab-host1
clab-test-lab-host2
clab-test-lab-switch

というように、「clab- + ラボ名 + ノード名」という命名になります。

2. nodes:各ノードの詳細

冒頭の例で記載した node の設定は下記のような構造になっています。

nodes:
  host1:
    kind: linux
    image: XXXXXX
    binds: 
      - ./host1:/host1-folder
キー 意味
host1 ノードの名称
kind どのようなネットワーク機器として動かすか
image そのノードが使う Docker コンテナイメージ(Docker Hub や GHCR 等を指定)
binds ホスト上のファイルやディレクトリを、コンテナ内にマウントする設定

3. links:ノード間の接続

links:
  - endpoints: ["host1:eth1", "switch:eth1"]
  - endpoints: ["host2:eth1", "switch:eth2"]
  • endpoints = どのノードの、どのインタフェース同士を接続するか

ノード同士の “仮想ケーブル接続” を定義しているイメージです。
containerlab が裏側で veth ペア を自動生成し、それぞれのノードに接続してくれます。

シンプルな例の全体図

ここまで理解できれば、冒頭の YAML が
どのような構成を表現していたかイメージできるはずです。

name: test-lab

topology:
  nodes:
    host1:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host1:/host1-folder
    host2:
      kind: linux
      image: XXXXXX
      binds: 
        - ./host2:/host2-folder
    switch:
      kind: linux
      image: XXXXXX
      binds: 
        - ./switch:/lab-folder

  links:
    - endpoints: ["host1:eth1", "switch:eth1"]
    - endpoints: ["host2:eth1", "switch:eth2"]

以下が、deploy により生成されるトポロジ図です:

containerlab-topology

以上で、containerlab の YAML がどのような役割を持っているか、
基本的な部分を理解できたと思います🙌

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?