Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Announcement: Try the Ask AI chatbot for answers to your technical questions about Juniper products and solutions.

close
header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
Juniper Cloud-Native Router User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

L2 VLAN Sub-Interface Configuration Example

Release: JCNR 23.3
{}
Change Release
date_range 27-Nov-24

Read this topic to learn how to add a user pod with a Layer 2 VLAN sub-interface to an instance of the cloud-native router.

Overview

You can configure a user pod with a Layer 2 VLAN sub-interface and attach it to the Cloud-Native Router instance. The Juniper Cloud-Native Router must have an L2 interface configured at the time of deployment. The cRPD must be configured with the valid VLAN configuration for the fabric interface. For example:

content_copy zoom_out_map
set interfaces eth1 unit 100 vlan-id 100
Note:

Note that the unit number and the VLAN ID must match.

Your high-level tasks are:

  • Define and apply a network attachment definition (NAD)—The NAD file defines the required configuration for Multus to invoke the JCNR-CNI and create a network to attach the pod interface to.

  • Define and apply a pod YAML file to your cloud-native router cluster—The pod YAML contains the pod specifications and an annotation to the network created by the JCNR-CNI

    Note:

    Please review the Cloud-Native Router Use-Cases and Configuration Overview topic for more information on NAD and pod YAML files.

Configuration Example

  1. Here is an example NAD to create a Layer 2 VLAN sub-interface:
    content_copy zoom_out_map
    apiVersion: "k8s.cni.cncf.io/v1"
    kind: NetworkAttachmentDefinition
    metadata:
      name: vswitch-bd201-sub      
    spec:
      config: '{
        "cniVersion":"0.4.0",
        "name": "vswitch-bd201-sub",
        "capabilities":{"ips":true},
        "plugins": [
          {
            "type": "jcnr",
            "args": {
              "instanceName": "vswitch",               
              "instanceType": "virtual-switch",        
              "bridgeDomain": "bd201",                
              "bridgeVlanId": "201",                  
              "parentInterface": "net1",                
              "interface": "net1.201"                 
            },
            "ipam": {
              "type": "static",
              "capabilities":{"ips":true},
              "addresses":[
                {
                  "address":"10.3.0.1/24",
                  "gateway":"10.3.0.254"
                },
                {
                  "address":"2001:db8:3003::10.3.0.1/120",
                  "gateway":"2001:db8:3003::10.3.0.1"
                }
              ]
            },
            "kubeConfig":"/etc/kubernetes/kubelet.conf"
          }
        ]
      }'
    The NAD defines a bridge domain bd201 and a sub-interface net1.201 with a parent interface net1. The pod will be attached in the virtual-switch instance.. It also defines a static IP address to be assigned to the pod interface.
  2. Apply the NAD manifest to create the network.
    content_copy zoom_out_map
    kubectl apply -f nad_l2_vlan_subinterface.yaml 
    networkattachmentdefinition.k8s.cni.cncf.io/vswitch-bd201-sub created
  3. Verify the NAD is created.
    content_copy zoom_out_map
    [root@jcnr-01]# kubectl get net-attach-def
    NAME                 AGE
    vswitch-bd201-sub    43s
  4. Here is an example yaml to create a pod attached to the vswitch-bd201-sub network:
    content_copy zoom_out_map
    apiVersion: v1
    kind: Pod
    metadata:
      name:   pod1
      annotations:
        k8s.v1.cni.cncf.io/networks: "vswitch-bd201-sub"              
    spec:
      containers:
        - name: pod1
          image: ubuntu:latest
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: false
          resources:
            requests:
              memory: 2Gi
            limits:
              hugepages-1Gi: 2Gi
          env:
            - name: KUBERNETES_POD_UID
              valueFrom:
                fieldRef:
                   fieldPath: metadata.uid
          volumeMounts:
            - name: dpdk
              mountPath: /dpdk
              subPathExpr: $(KUBERNETES_POD_UID)
            - mountPath: /dev/hugepages
              name: hugepage
      volumes:
        - name: dpdk
          hostPath:
            path: /var/run/jcnr/containers
        - name: hugepage
          emptyDir:
            medium: HugePages
    The pod attaches to the router instance using the k8s.v1.cni.cncf.io/networks annotation.
  5. Apply the pod manifest.
    content_copy zoom_out_map
    [root@jcnr-01]# kubectl apply -f pod_access_mode.yaml 
    pod/pod1 created
  6. Verify the pod is running.
    content_copy zoom_out_map
    [root@jcnr-01 ~]# kubectl get pods 
    NAME   READY   STATUS    RESTARTS   AGE
    pod1   1/1     Running   0          40s
  7. Describe the pod to verify a secondary interface is created and attached to the vswitch-bd201-sub network. (The output is trimmed for brevity).
    content_copy zoom_out_map
    [root@jcnr-01 ~]# kubectl describe pod pod1
    Name:         pod1
    Namespace:    default
    Priority:     0
    Node:         jcnr-01/10.100.20.25
    Start Time:   Mon, 26 Jun 2023 09:53:31 -0400
    Labels:       <none>
    Annotations:  cni.projectcalico.org/containerID: 58642dd26f85769e14d302153357e84e6900398532d1b82b50a845ac1ede051a
                  cni.projectcalico.org/podIP: 
                  cni.projectcalico.org/podIPs: 
                  jcnr.juniper.net/dpdk-interfaces:
                    [
                        {
                            "name": "net1",
                            "vhost-adaptor-path": "/dpdk/vhost-net1.sock",
                            "vhost-adaptor-mode": "client",
                            "ipv4-address": "10.3.0.1/24",
                            "ipv6-address": "2001:db8:3003::a03:1/120",
                            "mac-address": "02:00:00:84:DC:42",
                            "vlan-id": "201"
                        }
                    ]
                  k8s.v1.cni.cncf.io/network-status:
                    [{
                        "name": "k8s-pod-network",
                        "ips": [
                            "10.233.91.97"
                        ],
                        "default": true,
                        "dns": {}
                    },{
                        "name": "default/vswitch-bd201-sub",
                        "interface": "net1",
                        "ips": [
                            "10.3.0.1",
                            "2001:db8:3003::a03:1"
                        ],
                        "mac": "02:00:00:84:DC:42",
                        "dns": {}
                    }]
    ...
  8. Verify the vRouter has the corresponding interface created. Access the vRouter CLI and issue the vif --list command.
    content_copy zoom_out_map
    vif0/2      PMD: vhostnet1-d5eee4ec-dd7c-4e MTU: 9160
                Type:Virtual HWaddr:02:00:00:84:dc:42
                DDP: OFF SwLB: ON
                Vrf:65535 Flags:L2 QOS:-1 Ref:14
                RX queue errors to lcore 0 0 0 0 0 0 0 0 0 0 0 0 0 0
                RX packets:0  bytes:0 errors:0
                TX packets:0  bytes:0 errors:0
                Drops:0
                TX port   packets:0 errors:293
    
    vif0/3      Virtual: vhostnet1-d5eee4ec-dd7c-4e.201 Vlan(o/i)(,S): 201/201 Parent:vif0/2 MTU: 1514
                Type:Virtual(Vlan) HWaddr:02:00:00:84:dc:42
                DDP: OFF SwLB: ON
                Vrf:0 Flags:L2 QOS:-1 Ref:1
                RX queue errors to lcore 0 0 0 0 0 0 0 0 0 0 0 0 0 0
                RX packets:0  bytes:0 errors:0
                TX packets:208  bytes:17071 errors:0
                Drops:0
    Note that the interface type is Virtual and the Vlan ID set to 201. The parent interface is vif0/2. The VRF is always 0 for L2 sub-interfaces.
footer-navigation