CoreOS 配置工具 Ignition 官方示例

时间:2022-04-29
本文章向大家介绍CoreOS 配置工具 Ignition 官方示例,主要内容包括常用配置举例、网络配置、用户、systemd unit、文件、示例文件、相关链接、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

CoreOS 配置工具已由 Ignition 代替 cloud-config

GitHub:https://github.com/coreos/ignition

使用 Ignition 需要两步:

  • 第一步编写 Container Linux Config ( yaml 格式 )
  • 第二步使用 container-linux-config-transpilerContainer Linux Config 转化为 Ignition Config (json 格式)
$ ct-v0.5.0-x86_64-apple-darwin -in-file ignition.yaml  > ignition.json

container-linux-config-transpiler 安装方法:

https://github.com/coreos/container-linux-config-transpiler/releases 下载二进制文件移入 PATH,并赋予可执行权限之后即可使用。

官方文档:https://coreos.com/os/docs/latest/overview-of-ct.html

常用配置举例

etcd

etcd:
  name:                        coreos3
  discovery: https://discovery.etcd.io/249ea9815631abc753fe4a4743f147d2
  advertise_client_urls:       http://192.168.57.102:2379
  initial_advertise_peer_urls: http://192.168.57.102:2380
  listen_client_urls:          http://192.168.57.102:2379,http://0.0.0.0:4001
  listen_peer_urls:            http://0.0.0.0:2380

网络配置

通过与网络接口名称( enp0s3 等)匹配来设置静态或动态 IP 地址

networkd:
   units:
     - name: 10-static.network
       contents: |
         [Match]
         Name=enp0s3

         [Network]
         Address=192.168.57.102/24
     - name: 20-dhcp.network
       contents: |
         [Match]
         Name=enp0s8

         [Network]
         DHCP=yes

用户

passwd:
  users:
    - name: core
      ssh_authorized_keys:
        - ssh-rsa SSH_PUB
      groups:
        - wheel
        - sudo
        - docker

systemd unit

systemd:
  units:
    - name: settimezone.service
      enable: true
      contents: |
        [Unit]
        Description=Set the time zone

        [Service]
        ExecStart=/usr/bin/timedatectl set-timezone  PRC
        RemainAfterExit=yes
        Type=oneshot

文件

storage:
  files:
    - filesystem: "root"
      path:       "/etc/hostname"
      mode:       0644
      contents:
        inline: coreos3
    - filesystem: "root"
      path:       "/etc/resolv.conf"
      mode:       0644
      contents:
        inline: |
          nameserver 114.114.114.114

示例文件

https://github.com/khs1994-docker/coreos/blob/master/disk/ignition-1.example.yaml

相关链接