Skip to content

Instantly share code, notes, and snippets.

@LionelJouin
Created January 10, 2024 18:53
Show Gist options
  • Save LionelJouin/c653ff77d1c7eda6d9b9b7bf3ad7de47 to your computer and use it in GitHub Desktop.
Save LionelJouin/c653ff77d1c7eda6d9b9b7bf3ad7de47 to your computer and use it in GitHub Desktop.
Kubernetes Multi-Network

Kubernetes Multi-Network

Implementation

Build instructions (On Kind)

# Clone the kubernetes fork
git clone -b multi-network [email protected]:LionelJouin/kubernetes.git

# Check and generate files (If any API changes is done)
./hack/update-all.sh

# Build Kind images
kind build node-image . --image kindest/node:multi-network

Kind Config (Follow this for local registry: https://kind.sigs.k8s.io/docs/user/local-registry/):

---
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  ipFamily: dual
  kubeProxyMode: ipvs
featureGates:
  "MultiNetwork": true
runtimeConfig:
  "api/alpha": "true"
nodes:
- role: control-plane
  image: kindest/node:multi-network
- role: worker
  image: kindest/node:multi-network
# Clone the Multus fork
git clone -b multi-network [email protected]:LionelJouin/multus-cni.git

# Build Multus
docker build -t localhost:5000/k8snetworkplumbingwg/multus-cni:snapshot-thick-multi-network -f images/Dockerfile.thick .
docker push localhost:5000/k8snetworkplumbingwg/multus-cni:snapshot-thick-multi-network

# Install multus
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/e2e/templates/cni-install.yml.j2 
kubectl apply -f deployments/multus-daemonset-thick.yml

Examples

NetworkAttachmentDefinition

---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: macvlan-nad
  namespace: default
spec:
  config: '{
      "cniVersion": "0.3.0",
      "type": "macvlan",
      "master": "eth0",
      "mode": "bridge",
      "ipam": {
        "type": "host-local",
        "ranges": [
          [ { "subnet": "169.254.100.0/24" } ],
          [ { "subnet": "100:100::/64" } ]
        ]
      }
    }'

PodNetwork

---
apiVersion: networking.k8s.io/v1alpha1
kind: PodNetwork
metadata:
  name: dataplane
spec:
  enabled: true
  provider: k8s.cni.cncf.io/multus
  parametersRefs:
  - group: "k8s.cni.cncf.io/v1"
    kind: NetworkAttachmentDefinition
    namespace: default
    name: macvlan-nad

Pod with the PodNetwork

---
apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
spec:
  networks:
  - podNetworkName: dataplane
    interfaceName: net1
  containers:
    - name: ubuntu
      image: lioneljouin/example-application:latest # Ubuntu images with more tools
      command:
        - /bin/bash
        - -c
      args:
        - sleep infinity

Deployment with the PodNetwork

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ubuntu-server
  labels:
    app: ubuntu-server
spec:
  replicas: 2
  selector:
    matchLabels:
      app: ubuntu-server
  template:
    metadata:
      labels:
        app: ubuntu-server
    spec:
      networks:
      - podNetworkName: dataplane
        interfaceName: net1
      containers:
        - name: ubuntu
          image: lioneljouin/example-application:latest # Ubuntu images with more tools
          command:
            - /bin/bash
            - -c
          args:
            - nc -l -k -p 5000

Service selecting the deployment (Only default PodIPs will be added to the endpoints and endpointslice)

---
apiVersion: v1
kind: Service
metadata:
  name: ubuntu-service
spec:
  selector:
    app: ubuntu-server
  type: ClusterIP
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 5000

Uncertainties

  1. How to handle HostNetwork in networks and PodIPs?
  2. How to fix this conversion: https://github.com/kubernetes/kubernetes/blob/v1.29.0/pkg/apis/core/v1/conversion.go#L259
  3. pkg/kubelet/stats/helper.go#36 could be solved if the default network interface is known
  4. Should the Default network be recognized by its name?
  5. is isDefaultGW4 and isDefaultGW6 set to true on default network?
  6. What should be the Provider and parametersRefs in default PodNetwork?
  7. How to handle multiple parametersRefs?

References

plwhite implementation:

mskrocki implementation:

KEP:

Planning:

DRA PR (as example):

Service CIDR (as example):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment