18.7. 为云部署创建点火配置


要在 AWS、Azure、Google Cloud 和其他云平台上配置引导实例,您可以通过云提供商的用户数据机制传递 Ignition 配置。

先决条件

流程

  1. 创建名为 cloud-config.bu 的 Butane 配置文件:

    variant: r4e
    version: 1.5.0
    passwd:
      users:
        - name: core
          groups:
            - wheel
            - sudo
    storage:
      files:
        - path: /etc/hostname
          mode: 0644
          contents:
            inline: <hostname>
        - path: /etc/sysconfig/network-scripts/ifcfg-eth0
          mode: 0644
          contents:
            inline: |
              DEVICE=eth0
              BOOTPROTO=dhcp
              ONBOOT=yes
        - path: /etc/profile.d/cloud-env.sh
          mode: 0644
          contents:
            inline: |
              export CLOUD_PROVIDER="aws"
              export ENVIRONMENT="production"
      directories:
        - path: /var/log/applications
          mode: 0755
    systemd:
      units:
        - name: cloud-init-replacement.service
          enabled: true
          contents: |
            [Unit]
            Description=Cloud initialization tasks
            After=network-online.target
            Wants=network-online.target
            ConditionFirstBoot=yes
    
            [Service]
            Type=oneshot
           ExecStart=/bin/sh -c '/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id > /var/lib/instance-id'
            ExecStart=/usr/bin/echo "Cloud initialization complete"
    
            [Install]
            WantedBy=multi-user.target
  2. 将丁烷配置转换为 Ignition JSON 文件:

    $ butane --strict cloud-config.bu > cloud-config.ign
  3. 将具有 Ignition 配置的实例部署为用户数据。

    • 对于 AWS EC2,运行:

      $ aws ec2 run-instances --image-id <ami_id> --instance-type <instance_type> --user-data file://cloud-config.ign --key-name <key_pair_name>
    • 对于 Azure,请运行:

      $ az vm create --resource-group <resource_group> --name <vm_name> --image <ignition_image> --custom-data cloud-config.ign --admin-username core
    • 对于 Google Cloud,请运行:

      $ gcloud compute instances create <instance_name> --image <ignition_image> --metadata-from-file user-data=cloud-config.ign --machine-type <machine_type>
    • 对于 QEMU/KVM 测试,请运行:

      $ qemu-system-x86_64 \ -machine q35 \ -cpu host \ -enable-kvm \ -m 4096 \ -fw_cfg name=opt/com.coreos/config,file=<path_to_config_file> \ -drive file=bootc-image.qcow2,format=qcow2 \ -netdev user,id=net0,hostfwd=tcp::2222-:22 \ -device virtio-net-pci,netdev=net0 \
        -append "ignition.platform.id=qemu ignition.firstboot"

验证

  1. 连接到实例:

    $ ssh core@<instance_ip>
  2. 验证是否设置了云环境变量:

    $ source /etc/profile.d/cloud-env.sh
    $ echo ${CLOUD_PROVIDER}
  3. 检查点火执行状态:

    $ journalctl -t ignition --no-pager
  4. 验证是否捕获了实例 ID(AWS 示例):

    $ cat /var/lib/instance-id
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部