// kubelet -> generic runtime -> runtime shim -> network plugin // docker/non-cri implementations have a passthrough UpdatePodCIDR if err := kl.getRuntime().UpdatePodCIDR(cidr); err != nil { return true, fmt.Errorf("failed to update pod CIDR: %v", err) } kl.runtimeState.setPodCIDR(cidr) return true, nil }
将pod的cidr传递给runtime shim, 同时更新到runtimeState
runtime更新配置
pkg/kubelet/kuberuntime/kuberuntime_manager.go
1 2 3 4 5 6 7 8 9 10 11 12
func (m *kubeGenericRuntimeManager) UpdatePodCIDR(podCIDR string) error { // TODO(#35531): do we really want to write a method on this manager for each // field of the config? klog.InfoS("Updating runtime config through cri with podcidr", "CIDR", podCIDR) // 调用底层运行时, 更新runtime的配置 return m.runtimeService.UpdateRuntimeConfig( &runtimeapi.RuntimeConfig{ NetworkConfig: &runtimeapi.NetworkConfig{ PodCidr: podCIDR, }, }) }
// 将最外层的cniVersion和name注入到每个cni plugin中 // Ensure every config uses the same name and version orig, err = InjectConf(orig, inject) if err != nil { return nil, err }
rc := make(map[string]interface{}) for capability, supported := range orig.Network.Capabilities { if !supported { continue } if data, ok := rt.CapabilityArgs[capability]; ok { rc[capability] = data } }
// port mappings are a cni capability-based args, rather than parameters // to a specific plugin portMappings, err := plugin.host.GetPodPortMappings(podSandboxID.ID) if err != nil { return nil, fmt.Errorf("could not retrieve port mappings: %v", err) } portMappingsParam := make([]cniPortMapping, 0, len(portMappings)) for _, p := range portMappings { if p.HostPort <= 0 { continue } portMappingsParam = append(portMappingsParam, cniPortMapping{ HostPort: p.HostPort, ContainerPort: p.ContainerPort, Protocol: strings.ToLower(string(p.Protocol)), HostIP: p.HostIP, }) } rt.CapabilityArgs = map[string]interface{}{ portMappingsCapability: portMappingsParam, }
other
todo
总结
node-ipam-controller(controller-manager) => node(pod cidr,可allcate多个) => runtime shim => cni管理器 => specific cni plugin(配置文件设置是否开启) => pod netns eth