Skip to content

Instantly share code, notes, and snippets.

@qinqon
Last active February 1, 2024 07:38
Show Gist options
  • Select an option

  • Save qinqon/a8820632923211d6e155704d052a94d2 to your computer and use it in GitHub Desktop.

Select an option

Save qinqon/a8820632923211d6e155704d052a94d2 to your computer and use it in GitHub Desktop.

This is the nad + vmi

---
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
  name: l2-network
spec:
  config: |2
    {
            "cniVersion": "0.3.1",
            "name": "l2-network",
            "type": "ovn-k8s-cni-overlay",
            "topology":"layer2",
            "subnets": "192.168.66.0/24",
            "netAttachDefName": "default/l2-network"
    }
---
---
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
  name: worker1
spec:
  architecture: amd64
  domain:
    devices:
      disks:
      - disk:
          bus: virtio
        name: containerdisk
      - disk:
          bus: virtio
        name: cloudinitdisk
      interfaces:
      - bridge: {}
        name: multus
      rng: {}
    machine:
      type: q35
    resources:
      requests:
        memory: 512Mi
  networks:
  - multus:
      networkName: l2-network
    name: multus
  nodeSelector:
    node-role.kubernetes.io/worker: ""
  terminationGracePeriodSeconds: 5
  volumes:
  - containerDisk:
      image: quay.io/fedora/fedora-coreos-kubevirt:stable
    name: containerdisk
  - cloudInitConfigDrive:
      userData: '{"ignition":{"version":"3.3.0"},"passwd":{"users":[{"name":"core","passwordHash":"$y$j9T$b7RFf2LW7MUOiF4RyLHKA0$T.Ap/uzmg8zrTcUNXyXvBvT26UgkC6zZUVg3UKXeEp5"}]}}'
    name: cloudinitdisk

Status after vmi ready

# oc get vmi
NAME      AGE    PHASE     IP             NODENAME                             READY
worker1   145m   Running   192.168.66.4   hypershift-ctlplane-2.qinqon.local   True

Then endpointslices and services are created

---
apiVersion: v1
kind: Service
metadata:
  name: vm-service
spec:
  type: NodePort
  ports:
    - protocol: TCP
      port: 22
---
apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
  name: vm-service
  labels:
    kubernetes.io/service-name: vm-service
addressType: IPv4
ports:
  - name: ssh
    protocol: TCP
    port: 22
endpoints:
  - addresses:
      - "192.168.66.4"
    conditions:
      ready: true

And after that the following changes at ovn

connect the L2 switch to the ovn_cluster_router

ovn-nbctl lrp-add ovn_cluster_router rtos-l2.network_ovn_layer2_switch 0a:58:0b:84:00:01 192.168.66.1/24
ovn-nbctl lrp-set-gateway-chassis rtos-l2.network_ovn_layer2_switch ddb55de1-d826-48c8-aeb5-0fe53c5a1fc5
ovn-nbctl lsp-add l2.network_ovn_layer2_switch stor-l2.network_ovn_layer2_switch
ovn-nbctl lsp-set-type stor-l2.network_ovn_layer2_switch router
ovn-nbctl lsp-set-addresses stor-l2.network_ovn_layer2_switch router
ovn-nbctl lsp-set-options stor-l2.network_ovn_layer2_switch router-port=rtos-l2.network_ovn_layer2_switch

add routes to send n/s traffic to the gw router

ovn-nbctl --policy src-ip lr-route-add ovn_cluster_router 192.168.66.0/24 100.64.0.4

Configure nating and inbound routing at gw router

lr-nat-add GR_hypershift-ctlplane-2.qinqon.local snat 192.168.122.36 192.168.66.4
lr-route-add GR_hypershift-ctlplane-2.qinqon.local 192.168.66.0/24 100.64.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment