terraform libvirt 桥接网络出现问题

发布于 2025-01-09 00:14:36 字数 2452 浏览 0 评论 0原文

周一早上 terraform 专家面临的挑战;-)

在使用桥接网络时,我在使用 libvirt 提供程序创建 KVM 主机时遇到问题。 网络接口无法接收 dhcp 信息。然而,具有相同桥接网络的 virt-install 可以正常工作。 DHCP/DNS 服务器位于网络本地,我没有使用内置 DHCP 服务器。

下面是创建网络和来宾的 terraform...

# create KVM bridge network 
resource "libvirt_network" "kvm_network" {
  name = "kvmnet"
  mode = "bridge"
  bridge = "br0"
  autostart = "true"
}

# create kvm volume
resource "libvirt_volume" "generic-kvm-volume" {  
  name = "debian-141"
  pool = "tf"                                     
  source = "/var/kvm/images/debian11.img"
}                                                 

# Define KVM domain to create                     
resource "libvirt_domain" "generic-kvm-domain" {  
  name = "debian"
  vcpu = 1
  memory = 1024
                                                  
  network_interface {                             
    network_name   = "kvmnet"                    
    mac            = "de:3d:c0:a8:0a:8d"
  }                                               
  disk {                                          
    file = "/var/kvm/tf/debian-141"    
  }                                                
  console {                                        
    type = "pty"                                   
    target_type = "serial"                         
    target_port = "0"                              
  }                                                
  graphics {                                       
    type = "spice"                                 
    listen_type = "address"                        
    autoport = true                                
  }                                                
}                                                  

如果我注释“# Define KVM domain to create”块并重新运行 terraform apply 以仅删除来宾,然后通过以下方式创建域virt-install (使用 terraform 定义的网络和卷)界面出现并按预期分配 IP/域名。

virt-install \                   
  --name debian-14 \             
  --memory 1024 \                
  --vcpus 2 \                    
  --disk /var/kvm/tf/debian-141 \
  --import \                     
  --network network=kvmnet \     
  --mac=de:3d:c0:a8:0a:8d \      
  --os-variant debian10          

这暗示了 terraform 配置的最后一个块,因为物理桥/terraform 桥似乎正在按预期工作。

注意:

  • wait_for_lease = true 超时
  • 我已经查看了两个实例的 kvmnetxml,它们是相同的。

所以希望 terraform 专家能够对周一早上的挑战发表评论;-)

monday morning challenge for terraform experts ;-)

I have a problem in creating a KVM host with libvirt provider, when using a bridged network.
The network interface cannot receive dhcp info. However a virt-install with same bridged network works ok. The DHCP/DNS server is local on the network, I am not using the builtin DHCP server.

Below is the terraform to create network and guest....

# create KVM bridge network 
resource "libvirt_network" "kvm_network" {
  name = "kvmnet"
  mode = "bridge"
  bridge = "br0"
  autostart = "true"
}

# create kvm volume
resource "libvirt_volume" "generic-kvm-volume" {  
  name = "debian-141"
  pool = "tf"                                     
  source = "/var/kvm/images/debian11.img"
}                                                 

# Define KVM domain to create                     
resource "libvirt_domain" "generic-kvm-domain" {  
  name = "debian"
  vcpu = 1
  memory = 1024
                                                  
  network_interface {                             
    network_name   = "kvmnet"                    
    mac            = "de:3d:c0:a8:0a:8d"
  }                                               
  disk {                                          
    file = "/var/kvm/tf/debian-141"    
  }                                                
  console {                                        
    type = "pty"                                   
    target_type = "serial"                         
    target_port = "0"                              
  }                                                
  graphics {                                       
    type = "spice"                                 
    listen_type = "address"                        
    autoport = true                                
  }                                                
}                                                  

If I comment the "# Define KVM domain to create" block and re-run terraform apply to remove only the guest and then create a domain via virt-install (using the terraform defined network and volume) the interface comes up and is allocated the IP/Domain name as intended.

virt-install \                   
  --name debian-14 \             
  --memory 1024 \                
  --vcpus 2 \                    
  --disk /var/kvm/tf/debian-141 \
  --import \                     
  --network network=kvmnet \     
  --mac=de:3d:c0:a8:0a:8d \      
  --os-variant debian10          

this alludes to the last block of terraform config as physical bridge/terraform bridge seems to be working as intended.

Notes:

  • wait_for_lease = true times out
  • I have looked at the xml for kvmnet for both instances and these are identical.

so hopefully a terraform expert can comment on this monday morning challenge ;-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南七夏 2025-01-16 00:14:37

更新/解决方案:声明machine = "pc-q35-5.2"解决了这个问题。之前未设置,默认为 pc-i440fx-5.2。

UPDATE / SOLUTION: Declaring machine = "pc-q35-5.2" resolved this problem. It was previously not set and defaulting to pc-i440fx-5.2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文