Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

How to configure network attachment definitions

Network attachment definitions in OpenShift Virtualization

December 19, 2024
Bins Sam Thomas
Related topics:
ContainersVirtualization
Related products:
Red Hat OpenShift Container PlatformRed Hat OpenShift Virtualization

    Red Hat OpenShift Virtualization provides the ability to run virtual machines (VMs) alongside containers in a Kubernetes-native way. One of the key components enabling this is a NetworkAttachmentDefinition (NAD). NADs allow multiple network interfaces for VMs, enabling hybrid connectivity, virtual local area networks (VLANs), and high-performance network scenarios.

    A NAD is a Kubernetes CustomResourceDefinition (CRD) used to define additional network interfaces for pods or virtual machines. The Multus CNI plug-in, integrated with OpenShift Virtualization, makes this possible.

    Key features of NADs:

    • Multi-networking: Ability to attach multiple networks to VMs.
    • Custom networking: Define virtual local area networks (VLANs), single root input/output virtualization (SR-IOV), or MacVLAN configurations.
    • Flexible IPAM: Use DHCP, static IPs, or other methods for IP allocation.

    NAD architecture in OpenShift Virtualization

    To better understand how NADs work, let’s break down the architecture, as shown in Figure 1.

    • Primary network: Default OpenShift SDN.
    • Multus CNI: Manages secondary networks and interfaces.
    • Plug-ins: Specific configurations for MacVLAN, SR-IOV, or other setups.
    NAD architecture
    https://www.redhat.com/en/blog/demystifying-multus,
    Figure 1: NAD architecture.

    How to create and use NADs

    Let’s walk through a few examples of creating network attachment definitions.

    Example 1: MacVLAN NAD configuration

    This example sets up a MacVLAN-based secondary network for a VM. MacVLAN is often used to segment traffic within the same physical network.

    YAML: MacVLAN NAD configuration

    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
     name: macvlan-network
     namespace: my-namespace
    spec:
     config: '{
       "cniVersion": "0.3.1",
       "type": "macvlan",
       "master": "eth0",
       "mode": "bridge",
       "ipam": {
         "type": "static",
         "addresses": [
           {
             "address": "192.168.1.100/24",
             "gateway": "192.168.1.1"
           }
         ]
       }
     }

    Attach MacVLAN NAD to a VM by adding the NAD to your VM specification under networks and interfaces:

    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
     name: my-vm
     namespace: my-namespace
    spec:
     template:
       spec:
         domain:
           devices:
             interfaces:
             - name: default
               masquerade: {}
             - name: macvlan-net
               bridge: {}
         networks:
         - name: default
           pod: {}
         - name: macvlan-net
           multus:
             networkName: my-namespace/macvlan-network

    Example 2: SR-IOV NAD configuration

    SR-IOV provides near-native network performance by dedicating a virtual function (VF) from a physical network interface controller (NIC) to a VM.

    YAML: SR-IOV NAD

    apiVersion: k8s.cni.cncf.io/v1
    kind: NetworkAttachmentDefinition
    metadata:
     name: sriov-network
     namespace: my-namespace
    spec:
     config: '{
       "cniVersion": "0.3.1",
       "type": "sriov",
       "ipam": {
         "type": "host-local",
         "subnet": "192.168.2.0/24",
         "rangeStart": "192.168.2.100",
         "rangeEnd": "192.168.2.200",
         "gateway": "192.168.2.1"
       }
     }

    Attach SR-IOV NAD to a VM and update the VM specification to include the SR-IOV interface:

    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
     name: sriov-vm
     namespace: my-namespace
    spec:
     template:
       spec:
         domain:
           devices:
             interfaces:
             - name: default
               masquerade: {}
             - name: sriov-net
               bridge: {}
         networks:
         - name: default
           pod: {}
         - name: sriov-net
           multus:
             networkName: my-namespace/sriov-network

    Example 3: VLAN configuration

    VLANs allow logical segmentation of networks, which can be configured using Multus and a VLAN container network interface (CNI) plug-in. 

    YAML: VLAN NAD configuration

    apiVersion: k8s.cni.cncf.io/v1
                            kind: NetworkAttachmentDefinition
                            metadata:
                             name: vlan-network
                             namespace: my-namespace
                            spec:
                             config: '{
                               "cniVersion": "0.3.1",
                               "type": "vlan",
                               "vlanId": 100,
                               "master": "eth0",
                               "ipam": {
                                 "type": "static",
                                 "addresses": [
                                   {
                                     "address": "10.10.1.100/24",
                                     "gateway": "10.10.1.1"
                                   }
                                 ]
                               }
                             }

    Attach VLAN NAD to a VM as follows:

    apiVersion: kubevirt.io/v1
                            kind: VirtualMachine
                            metadata:
                             name: vlan-vm
                             namespace: my-namespace
                            spec:
                             template:
                               spec:
                                 domain:
                                   devices:
                                     interfaces:
                                     - name: default
                                       masquerade: {}
                                     - name: vlan-net
                                       bridge: {}
                                 networks:
                                 - name: default
                                   pod: {}
                                 - name: vlan-net
                                   multus:
                                     networkName: my-namespace/vlan-network

    Best practices for NADs

    Follow these best practices for using NADs, including namespace management, monitoring, and validation:

    1. Namespace management: Ensure NADs are created in the same namespace as the VM.
    2. Monitoring: Use tools like kubectl to check NAD status.

      kubectl get network-attachment-definitions -n my-namespace
    3. Validation: Use virtctl to validate VM networking.

    Improving network performance

    Network attachment definitions are a cornerstone of advanced networking in OpenShift Virtualization. Whether you’re configuring MacVLAN, SR-IOV, or VLANs, NADs enable flexible and high-performance network setups. These configurations make Red Hat OpenShift a powerful platform for seamlessly running VMs and containers together.

    Learn more about OpenShift Virtualization.

    Last updated: January 16, 2025

    Related Posts

    • Enable OpenShift Virtualization on Red Hat OpenShift

    • How to switch Red Hat OpenShift Virtualization from hardware virtualization to software emulation

    • Easily upgrade hosted OpenShift Virtualization clusters on hosted control planes

    • Create software templates for VMs with OpenShift Virtualization

    • Monitor OpenShift Virtualization using user-defined projects and Grafana

    Recent Posts

    • Type what you want to break: AI-assisted chaos engineering with Krkn

    • Understanding evaluation collections in EvalHub

    • An overview of confidential containers on OpenShift bare metal

    • iSCSI vs. NVMe/TCP: The ultimate storage showdown for Red Hat OpenShift Virtualization

    • Speculators v0.5.0: DFlash support and online training

    What’s up next?

    Learn how to create and manage virtual machines using Red Hat OpenShift and the Developer Sandbox in this hands-on activity.

    Start the activity
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.