LoginSignup
0
0

More than 5 years have passed since last update.

LinuxKitでスタティックIPアドレスを設定

Last updated at Posted at 2017-11-01

結論

onbootでlinuxkit/ipコンテナを使いましょう。

StaticIPの設定方法

詳細は以下のIssueを参照。

このIssueには実際に動かせるサンプルyamlが載っていませんので作成してみました。

サンプルでは以下のように指定しています。

  • IPアドレス: 192.0.2.101
  • デフォルトゲートウェイ: 192.0.2.1
  • ネームサーバ:
    • 8.8.8.8
    • 8.8.4.4
static_ip_example.yml
kernel:
  image: linuxkit/kernel:4.9.59
  cmdline: "console=tty0 console=ttyS0 console=ttyAMA0"
init:
  - linuxkit/init:42a92119e1ca10380e0d33e26c0cbcf85b9b3558
  - linuxkit/runc:817fdc592eac6cb7804fa1721a43a7f6e23fb50f
  - linuxkit/containerd:82be2bbb7cf83bab161ffe2a64624ba1107725ff
  - linuxkit/ca-certificates:af4880e78edc28743f7c5e262678c67c6add4c26
onboot:
  - name: sysctl
    image: linuxkit/sysctl:a9ad57ed738a31ea9380cd73236866c312b35489
  - name: rngd1
    image: linuxkit/rngd:842e5e8ece7934f0cab9fd0027b595ff3471e5b9
    command: ["/sbin/rngd", "-1"]
  - name: ip
    image: linuxkit/ip:54971b6664cb7b52912e909a8f6a45e5a5c94506
    command: ["ip", "-b", "/root/ip-command"]
    binds:
      - /root/ip-command:/root/ip-command
  - name: resolv
    image: alpine:3.6
    command: ["/bin/sh", "-c", "cat /root/resolv.conf > /etc/resolv.conf" ]
    binds:
      - /root/resolv.conf:/root/resolv.conf
      - /etc/resolv.conf:/etc/resolv.conf
services:
  - name: getty
    image: linuxkit/getty:626ccc8e1766c40447f29a790d3a7cfff126f2a2
    env:
     - INSECURE=true
  - name: rngd
    image: linuxkit/rngd:842e5e8ece7934f0cab9fd0027b595ff3471e5b9
  - name: sshd
    image: linuxkit/sshd:f55ec010619e19178d5daecb4e595e84ecbf7d67
files:
  - path: root/.ssh/authorized_keys
    source: id_rsa.pub
    mode: "0600"
    optional: true
  - path: root/ip-command
    contents: |
      addr add 192.0.2.101/24 dev eth0
      link set eth0 up
      route add default via 192.0.2.1 dev eth0
  - path: root/resolv.conf
    contents: |
      nameserver 8.8.8.8
      nameserver 8.8.4.4
      search localdomain
trust:
  org:
    - linuxkit

filesセクションでipコマンドで実行する内容が記載されているファイルをアップロードし、それをonbootに記述したlinuxkit/ipコンテナで実行しています。

今回はyaml中にIPアドレスを直書きしてますが、linuxkit/metadataコンテナで各クラウド上のメタデータサービスを利用するということも可能ですので色々運用に合わせて工夫が必要そうです。

以上です。

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