将 AWS EBS 挂载到 CoreOS

Mounting AWS EBS into CoreOS

我已经启动了一个带有 100Gb EBS 的 EC2 实例作为 https://coreos.com/os/docs/latest/booting-on-ec2.html 文档。

#cloud-config
coreos:
  units:
    - name: media-ephemeral.mount
      command: start
      content: |
        [Mount]
        What=/dev/xvdb
        Where=/media/ephemeral
        Type=ext4
    - name: format-ephemeral.service
      command: start
      content: |
        [Unit]
        Description=Formats the ephemeral drive
        [Service]
        Type=oneshot
        RemainAfterExit=yes
        ExecStart=/usr/sbin/wipefs -f /dev/xvdb
        ExecStart=/usr/sbin/mkfs.btrfs -f /dev/xvdb
    - name: var-lib-docker.mount
      command: start
      content: |
        [Unit]
        Description=Mount ephemeral to /var/lib/docker
        Requires=format-ephemeral.service
        After=format-ephemeral.service
        Before=docker.service
        [Mount]
        What=/dev/xvdb
        Where=/var/lib/docker
        Type=btrfs

如果我 运行 以上,EBS 已正确挂载,但在系统重启时,卷不是持久的

使用

storage:
  filesystems:
    - name: ephemeral1
      mount:
        device: /dev/xvdb
        format: ext4
        wipe_filesystem: true
systemd:
  units:
    - name: media-ephemeral.mount
      enable: true
      contents: |
        [Unit]
        Before=local-fs.target
        [Mount]
        What=/dev/xvdb
        Where=/media/ephemeral
        Type=ext4
        [Install]
        WantedBy=local-fs.target
    - name: var-lib-docker.mount
      enable: true
      contents: |
        [Unit]
        Description=Mount ephemeral to /var/lib/docker
        Before=local-fs.target
        [Mount]
        What=/dev/xvdb
        Where=/var/lib/docker
        Type=ext4
        [Install]
        WantedBy=local-fs.target
    - name: docker.service
      dropins:
        - name: 10-wait-docker.conf
          contents: |
            [Unit]
            After=var-lib-docker.mount
            Requires=var-lib-docker.mount

根据文档,我得到

core@ip-10-1-2-188 ~ $ sudo /usr/bin/coreos-cloudinit --from-file storage1.conf
2019/01/15 17:09:28 Checking availability of "local-file"
2019/01/15 17:09:28 Fetching user-data from datasource of type "local-file"
2019/01/15 17:09:28 line 2: warning: unrecognized key "storage"
2019/01/15 17:09:28 line 9: warning: unrecognized key "systemd"
2019/01/15 17:09:28 Fetching meta-data from datasource of type "local-file"
2019/01/15 17:09:28 Parsing user-data as cloud-config
2019/01/15 17:09:28 Merging cloud-config from meta-data and user-data
2019/01/15 17:09:28 Updated /etc/environment
2019/01/15 17:09:28 Ensuring runtime unit file "etcd.service" is unmasked
2019/01/15 17:09:28 Ensuring runtime unit file "etcd2.service" is unmasked
2019/01/15 17:09:28 Ensuring runtime unit file "fleet.service" is unmasked
2019/01/15 17:09:28 Ensuring runtime unit file "locksmithd.service" is unmasked

core@ip-10-1-2-188 ~ $ cat /etc/os-release
NAME="Container Linux by CoreOS"
ID=coreos
VERSION=1967.3.0
VERSION_ID=1967.3.0
BUILD_ID=2019-01-08-0044
PRETTY_NAME="Container Linux by CoreOS 1967.3.0 (Rhyolite)"
ANSI_COLOR="38;5;75"
HOME_URL="https://coreos.com/"
BUG_REPORT_URL="https://issues.coreos.com"
COREOS_BOARD="amd64-usr"

在 CoreOS 上挂载 EBS 卷的正确方法是什么?

非常感谢任何建议

看来你错过了一步。 [cloud-configs 已经被弃用很长一段时间了。您正确地将云配置转换为 container linux config (CLC) file, but missed using config transpiler (CT) to then render an ignition sequence. You can check this by running your config through the online validator。 运行通过配置转译器配置 CLC 后,我得到以下内容,验证正确:

{
  "ignition": {
    "config": {},
    "timeouts": {},
    "version": "2.1.0"
  },
  "networkd": {},
  "passwd": {},
  "storage": {
    "filesystems": [
      {
        "mount": {
          "device": "/dev/xvdb",
          "format": "ext4",
          "wipeFilesystem": true
        },
        "name": "ephemeral1"
      }
    ]
  },
  "systemd": {
    "units": [
      {
        "contents": "[Unit]\nBefore=local-fs.target\n[Mount]\nWhat=/dev/xvdb\nWhere=/media/ephemeral\nType=ext4\n[Install]\nWantedBy=local-fs.target\n",
        "enable": true,
        "name": "media-ephemeral.mount"
      },
      {
        "contents": "[Unit]\nDescription=Mount ephemeral to /var/lib/docker\nBefore=local-fs.target\n[Mount]\nWhat=/dev/xvdb\nWhere=/var/lib/docker\nType=ext4\n[Install]\nWantedBy=local-fs.target\n",
        "enable": true,
        "name": "var-lib-docker.mount"
      },
      {
        "dropins": [
          {
            "contents": "[Unit]\nAfter=var-lib-docker.mount\nRequires=var-lib-docker.mount\n",
            "name": "10-wait-docker.conf"
          }
        ],
        "name": "docker.service"
      }
    ]
  }
}

此外,重要的是要注意 there are other differences as wellignitioncoreos-cloud-init 之间。其中最重要的是 点火仅 运行 一次 。因此,对于擦除该临时磁盘的内容之类的事情,您不应期望 wipe_filesystem: true 每次启动都是 运行。

尝试使用此配置启动机器。您应该会得到预期的结果。