Configure Network

Configure Network #

In most cases, Kubernetes networking relies on network plugins, such as the commonly used flannel, calico, and weave.

To demonstrate the basic Pod network, we’ll temporarily skip these classic plugins and instead set up routing manually. Instructions for installing network plugins will be provided in later sections.

As shown in the diagram, each Node is assigned a unique Pod subnet. We’ll manually add routing configurations to the Pod subnet on both the Master and Node nodes.


flowchart LR
A[master
primary: 10.192.56.10]
subgraph NODES
direction TB
B[node01
primary: 10.192.56.11
Pod CIDR: 10.244.1.0/24]
C[node02
primary: 10.192.56.12
Pod CIDR: 10.244.2.0/24]
end
A <---> B & C

    B <---> C

Add CNI Configuration #

Create directory for CNI configurations.

# Same on both nodes
mkdir /etc/cni/net.d/
# Same on both nodes
mkdir /etc/cni/net.d/

Create the subnet configuration file at /etc/cni/net.d/10-bridge.conf and add the following configurations.

The setup differs slightly between the two nodes:

  • On node01, assign 10.244.1.0/24
  • On node02, assign 10.244.2.0/24

Different contents on the two nodes

{
  "cniVersion": "1.0.0",
  "name": "bridge-network",
  "type": "bridge",
  "bridge": "cni0",
  "isGateway": true,
  "ipMasq": true,
  "ipam": {
    "type": "host-local",
    "ranges": [
      [
        {
          "subnet": "10.244.1.0/24"
        }
      ]
    ],
    "routes": [
      {
        "dst": "0.0.0.0/0"
      }
    ]
  }
}

Different contents on the two nodes

{
  "cniVersion": "1.0.0",
  "name": "bridge-network",
  "type": "bridge",
  "bridge": "cni0",
  "isGateway": true,
  "ipMasq": true,
  "ipam": {
    "type": "host-local",
    "ranges": [
      [
        {
          "subnet": "10.244.2.0/24"
        }
      ]
    ],
    "routes": [
      {
        "dst": "0.0.0.0/0"
      }
    ]
  }
}

Create the loopback configuration file at /etc/cni/net.d/99-loopback.conf. The configuration is the same on both nodes.

{
  "cniVersion": "1.1.0",
  "name": "loopback",
  "type": "loopback"
}

Add Routing #

Finally, set up the routing on each of the three machines.

ip route add 10.244.1.0/24 via 192.168.56.11
ip route add 10.244.2.0/24 via 192.168.56.12
ip route add 10.244.2.0/24 via 192.168.56.12
ip route add 10.244.1.0/24 via 192.168.56.11

Then we can Run Pods

comments powered by Disqus