将AWS EBS挂载到CoreOS

时间:2019-01-15 17:16:52

标签: amazon-ec2 coreos

我已经使用https://coreos.com/os/docs/latest/booting-on-ec2.html文档启动了具有100Gb EBS的EC2实例。

#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卷的正确方法是什么?

任何建议都值得赞赏

1 个答案:

答案 0 :(得分:0)

您似乎错过了一步。 [cloud-configs已经过时了很长一段时间。您已正确地将该云配置转换为container linux config(CLC)文件,但是错过了使用config transpiler(CT)来呈现点火序列的信息。您可以通过online validator运行配置来进行检查。通过config transpiler运行该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"
      }
    ]
  }
}

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

尝试使用此配置引导计算机。您应该会得到预期的结果。