Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

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

Share:

    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

    • Why some agentic AI developers are moving code from Python to Rust

    • Confidential VMs: The core of confidential containers

    • Benchmarking with GuideLLM in air-gapped OpenShift clusters

    • Run Qwen3-Next on vLLM with Red Hat AI: A step-by-step guide

    • How to implement observability with Python and Llama Stack

    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

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue