# Enable OVS

### Setting up OVS network with Pf9 DHCP Server on a PMK cluster <a href="#setting-up-ovs-network-with-pf9-dhcp-server-on-a-pmk-cluster" id="setting-up-ovs-network-with-pf9-dhcp-server-on-a-pmk-cluster"></a>

Create a PMK Cluster with the configured worker nodes in the previous section.

{% hint style="info" %}
**PMK cluster pre-requisites**

PMK cluster should have the following add-ons enabled:

* KubeVirt Add-on
* Advanced Networking Operator (Luigi) Add-on
  {% endhint %}

#### 1. Create Network Plugins Custom Resource <a href="#id-1-create-network-plugins-custom-resource" id="id-1-create-network-plugins-custom-resource"></a>

Network Plugin customer resource used to install advanced networking plugins such as ovs, sriov, dpdk, etc. and their configuration.

```
$cat <<EOF | kubectl apply -f -
apiVersion: plumber.k8s.pf9.io/v1
kind: NetworkPlugins
metadata:
  name: networkplugins-ovs
  namespace: luigi-system
spec:
  plugins:
    hostPlumber: {}            #Enabled
    multus: {}                 #Enabled
    ovs: {}                    #Enabled 
    dhcpController: {}         #Enabled
EOF
```

**DHCP controller plugin**

**DHCP controller plugin** enables running **PF9 DHCP** **server** inside pod/virtual machine to cater to the DHCP requests from virtual machine instance(not pod in case of Kubevirt). Multus network-attachment-definitions will use DHCP server to assign IPs. Pf9 DHCP server serves as an alternate to the IPAM CNIs (whereabouts, host-local), which are used as delegate from backend CNI, which gets managed/triggered at pod creation and pod deletion.

Refer for more information: <https://platform9.com/docs/kubernetes/enable-p9-dhcp>

#### 2. Create Host Network Template <a href="#id-2-create-host-network-template" id="id-2-create-host-network-template"></a>

Host Network Template is used to define configuration such as ovs-config etc. on the PMK cluster.

```
$cat <<EOF | kubectl apply -f -
apiVersion: plumber.k8s.pf9.io/v1
kind: HostNetworkTemplate
metadata:
  name: host-network-template-ovs
  namespace: luigi-system
spec:
  ovsConfig:
  - bridgeName: "br01"
    nodeInterface: "bond0.2"
EOF
```

**ovsCofig parameters:**

* **bridgeName** : User Defined name of the OVS bridge
* **nodeInterface** : Physical Network interface to be used to create ovs-bridge with.

#### 3. Create Network Attachment Definition <a href="#id-3-create-network-attachment-definition" id="id-3-create-network-attachment-definition"></a>

Network Attachment Definition is a Multus CRD used to configure additional NIC on pods and virtual machines.

```
$cat <<EOF | kubectl apply -f -
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: nad-ovs-dhcp
  annotations:
    k8s.v1.cni.cncf.io/resourceName: ovs-cni.network.kubevirt.io/br01
spec:
  config: '{
      "cniVersion": "0.3.1",
      "type": "userspace",
      "name": "nad-ovs-dhcp",
      "bridge": "br01"
    }'
EOF
```

4. Create Pf9 DHCP server

```
$cat <<EOF | kubectl apply -f -
apiVersion: dhcp.plumber.k8s.pf9.io/v1alpha1 
kind: DHCPServer
metadata:
  name: dhcpserver-pf9-ovs
spec:
  networks:
    - networkName: nad-ovs-dhcp
      interfaceIp: 192.168.15.14/24
      leaseDuration: 10m
      cidr:
        range: 192.168.15.0/24
        range_start: 192.168.15.30
        range_end: 192.168.15.100
        gateway: 192.168.15.1
EOF
```

About the fields:

* **Name**: Name of the DHCPServer. Configurations of dnsmasq will be generated in a Configmap with the same name
* **networks**: list of all networks that this pod will serve:
  * **networkName**: Name of NetworkAttachmentDefinition to provide IPs for. NAD should not have dhcp plugin enabled.
  * **interfaceIp**: IP address that the pod will be allocated. Must have prefix to ensure proper routes are added.
  * **leaseDuration**: Duration the leases offered should be valid for. Provide in valid formats for dnsmasq (eg: 10m, 5h, etc). Defaults to 1h
  * **vlanId**: Dnsmasq network identifier. Used as an identifier while restoring IPs. Optional.
  * **cidr**: range\_start, range\_end, gateway are optional. range is compulsory. If range start and end are provided, they will be used in place of the default start and end.

***At this point the PMK cluster is ready to be used for workloads such as Pods and Virtual Machines.***

#### Create a sample Virtual Machines to use the `nad-ovs-dhcp` network. <a href="#create-a-sample-virtual-machines-to-use-the-nad-ovs-dhcp-network" id="create-a-sample-virtual-machines-to-use-the-nad-ovs-dhcp-network"></a>

Let’s validate your work by creating a Virtual Machine to consume the nad-ovs-dhcp network.

```
$cat <<EOF | kubectl apply -f -
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: vm-test-ovs
  namespace: default
spec:
  running: true
  template:
    metadata:
      labels:
        debugLogs: "true"
        kubevirt.io/size: small
      annotations:
        kubevirt.io/memfd: "false"
    spec:
      terminationGracePeriodSeconds: 30
      domain:
        resources:
          requests:
            memory: 2Gi
            cpu: 1
        memory:
          hugepages:
            pageSize: "1Gi"
        devices:
          disks:
            - name: containerdisk
              disk:
                bus: virtio
            - name: cloudinitdisk
              disk:
                bus: virtio
          interfaces:
          - name: default
            masquerade: {}
          - name: vhost-user-net-1
            vhostuser: {}
      networks:
      - name: default
        pod: {}
      - name: vhost-user-net-1
        multus:
          networkName: nad-ovs-dhcp
      volumes:
        - name: containerdisk
          containerDisk:
            image: quay.io/kubevirt/fedora-cloud-container-disk-demo
        - name: cloudinitdisk
          cloudInitNoCloud:
            userData: |-
              #cloud-config
              password: fedora
              chpasswd: { expire: False }
EOF
```

### Variations of OVS networks <a href="#variations-of-ovs-networks" id="variations-of-ovs-networks"></a>

#### OVS Bonded network <a href="#ovs-bonded-network" id="ovs-bonded-network"></a>

```
$cat <<EOF | kubectl apply -f -
apiVersion: plumber.k8s.pf9.io/v1
kind: HostNetworkTemplate
metadata:
  name: host-network-template-ovs-bonded
  namespace: luigi-system
spec:
  ovsConfig:
  - bridgeName: "br01"
    nodeInterface: "bond0.2,bond0.5"
    #optional paramters
    params:
      mtuRequest: 9192
      lacp: "active"  # create ovs bond with lacp enabled
EOF
```

#### OVS with DPDK <a href="#ovs-with-dpdk" id="ovs-with-dpdk"></a>

[Enable OVS with DPDK](/managed-kubernetes/5.14/clusters/advanced-networking/enable-ovs-with-dpdk.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.platform9.com/managed-kubernetes/5.14/clusters/advanced-networking/enable-ovs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
