Windowsãèµ·åããã¨4ã5åã§ãã«ã¼ã¹ã¯ãªã¼ã³ãGunziã§ããã¨ã¦ãã¤ããã
ãçä¼ã¿ä¸ã«ãããã³ã«ã»ã¹ã¿ãã¯èªä½ããã¦ã ãã¶ã¢ããã¼ã·ã§ã³ãå復ããã®ã§ã
ãã°ããk8sã®ãããã¯ã¼ã¯é¨åã®æ¢æ¤ããããã¨æãç«ã¡ãã¨ããããcni-pluginãããããããã®ã§ãä½ã£ã¦ã¿ããã¨ã«ããã
è²ã
ãã£ã¦ã¿ãçµæãããããããªãã£ãã®ã§ãããèãflannelã®ã½ã¼ã¹ãèªãã§ä»ã®CNIãã©ã°ã¤ã³ãã©ã®ããã«åä½ãã¦ããã®ãï¼
ãã¾ãã¯èª¿ã¹ã¤ã¤ãèªä½CNIãã©ã°ã¤ã³ãã£ã¬ã³ã¸ããããã¨ã«ããã
ãã ãåæç¥èããããã«å¤ãã説æãæãã¦ãããè¥å¹²ééãã¦ããå¯è½æ§ãé«ãã®ã§ããäºæ¿ããã ãããã
ã¨ããããæãåãã
ã©ãããShellã§èªä½ãã人ããããããªã®ã§ãèªå®
ã«k8sã®ç°å¢ãæ§ç¯ãã¦ãã£ã¦ã¿ãã
www.altoros.com
ãã¼ãéã®éä¿¡ã¯ãã¾ããããªãã£ããåä¸ãã¼ãå
ã®éä¿¡ã¯ãã¾ãã§ããã
ã©ãããå
¥åèªä½ã¯æ¨æºå
¥åã§åãåãé¢ä¿ä¸ãçè«ä¸ã¯ã©ããªè¨èªã§ãæ§ããªãããã ã
ã³ã¼ããèªãã¨ã©ãããpodã«ä»®æ³ããã¯ãåºãã¦ä½æãããããã¯ã¼ã¯åå空éã«æ¥ç¶ãã¦ããããã ã£ããä½ããã¦åãã¦ããã¯ãªãã¨ãªãæ´ããã
ã¨ããããã§ããã¤ããªããªã®ãã«ã¤ãã¦ã®è©±ã
å
¬å¼ããã¥ã¡ã³ãã¯ãã¡ãã
Network Plugins
ããããããâ¦
è²ã
ãªè³æãã½ã¼ã¹ã³ã¼ããèªã¿æ¼ã£ãã¨ãããã³ã³ããã®ãããã¯ã¼ã¯ãä½æã»åé¤ããããã®ä»çµã¿ããããContainerNetworkingInterfaceã ãããããããããã
ããæãã«k8sãããã¯ã¼ã¯ã®ä»çµã¿ã®å
¨ä½ã解説ãã¦ããæ¥æ¬èªè³æããã£ãã®ã§ãã°ã°ãã¤ã¤ããã¡ãã§å
¨ä½åãå¦ã°ãã¦ããã£ããè¦åãçºè»ã§å§ããã®ã§ãæ¦è¦ãæ´ãã®ã«ã¨ã¦ãè¯ãã£ãã
speakerdeck.com
cni-plugin ã¯ä»æ§ã«ããå®è£
ããã³ãã³ãã決ã¾ã£ã¦ãããããã¯cni-pluginã®ä»æ§æ¸ã§ããã®ä»æ§æ¸ã«ããCNI operationsã®é
ç®ãå®è£
ããå¿
è¦ã®ããã³ãã³ãã«ãªãã
ä»æ§æ¸ã«ããã°
ã®3ã¤ãå®è£
ããå¿
è¦ããããããããã¯flannelã®cni-pluginã«ãããADD,DELCHECKã«å¯¾å¿ãã¦ããã³ãã³ãã®é¨åãèªãã§ãããã¨æãã
ãªãflannelãã¨ããã¨ãæåãªã¤ã¡ã¼ã¸ãå¼·ããã·ã¹ãã èªä½ãã¨ã¦ãã·ã³ãã«ãªã®ã§åèã«ããã®ã«åãã¦ããã¨æã£ãããã ãã¯ã©ã¹ã¿ã¼ãããã¯ã¼ã¯ã®ä»çµã¿ãã·ã³ãã«ãªã®ã§ãå®éã«ä½æããéã«ã¯åèã«ããã
å®è£
ãèªãã§ã¿ã
ã¨ããããã§flannelã®cni-pluginã®ã½ã¼ã¹ã³ã¼ããå®éã«èªãã§ã¿ãã
èªãã§æã£ããã¨ããå¦çã«ã¤ãã¦ã³ã¡ã³ããæãæãã«æ®ãã¦ããã®ã§ãããæãã«ã¿ãªãããèªã¿ã¨ã£ã¦ããã ããã°ã¨æãã
github.com
cmdAdd()
cmdAdd()ã¯ã³ã³ããããããã¯ã¼ã¯ã«è¿½å ããã
flannelã§ã¯cmdAdd()âdoCmdAddâdelegateCmdAddã®é ã§å¦çãã¦ããã
delegateCmdAddã§ã¯invoke.DelegateAddãå¼ã³åºãã¦ããã
ããã±ã¼ã¸ã«èª¬æãããããã®é¢æ°ã¯CNI ADDããããã¯JSONã³ã³ãã£ã°ã使ç¨ãã¦æå®ãããdelegate pluginãå¼ã³åºãã¦ããã
ããã©ã«ãã§ã¯ããªãã¸ãã©ã°ã¤ã³ã®ãããæ§ææã«æå®ãããããªãã¸ãã©ã°ã¤ã³ã®ADDã³ãã³ããå®è¡ãã¦ããã
âbridgeâ以å¤ãæå®ããã¦ããå ´åã¯ããããå¼ã³åºããã¯ããå¤åã
delegateAddã®ååã®éããæå¾ã«invoke.DelegateAddãå¼ã³ãããªãã¸ãã©ã°ã¤ã³ã®ADDãå®è¡ãã¦ããã
invoke package - github.com/containernetworking/cni/pkg/invoke - Go Packages
func cmdAdd(args *skel.CmdArgs) error {
n, err := loadFlannelNetConf(args.StdinData)
if err != nil {
return fmt.Errorf("loadFlannelNetConf failed: %w", err)
}
fenv, err := loadFlannelSubnetEnv(n.SubnetFile)
if err != nil {
return fmt.Errorf("loadFlannelSubnetEnv failed: %w", err)
}
if n.Delegate == nil {
n.Delegate = make(map[string]interface{})
} else {
if hasKey(n.Delegate, "type") && !isString(n.Delegate["type"]) {
return fmt.Errorf("'delegate' dictionary, if present, must have (string) 'type' field")
}
if hasKey(n.Delegate, "name") {
return fmt.Errorf("'delegate' dictionary must not have 'name' field, it'll be set by flannel")
}
if hasKey(n.Delegate, "ipam") {
return fmt.Errorf("'delegate' dictionary must not have 'ipam' field, it'll be set by flannel")
}
}
if n.RuntimeConfig != nil {
n.Delegate["runtimeConfig"] = n.RuntimeConfig
}
return doCmdAdd(args, n, fenv)
}
func doCmdAdd(args *skel.CmdArgs, n *NetConf, fenv *subnetEnv) error {
n.Delegate["name"] = n.Name
if !hasKey(n.Delegate, "type") {
n.Delegate["type"] = "bridge"
}
if !hasKey(n.Delegate, "ipMasq") {
ipmasq := !*fenv.ipmasq
n.Delegate["ipMasq"] = ipmasq
}
if !hasKey(n.Delegate, "mtu") {
mtu := fenv.mtu
n.Delegate["mtu"] = mtu
}
if n.Delegate["type"].(string) == "bridge" {
if !hasKey(n.Delegate, "isGateway") {
n.Delegate["isGateway"] = true
}
}
if n.CNIVersion != "" {
n.Delegate["cniVersion"] = n.CNIVersion
}
ipam, err := getDelegateIPAM(n, fenv)
if err != nil {
return fmt.Errorf("failed to assemble Delegate IPAM: %w", err)
}
n.Delegate["ipam"] = ipam
fmt.Fprintf(os.Stderr, "\n%#v\n", n.Delegate)
return delegateAdd(args.ContainerID, n.DataDir, n.Delegate)
}
func delegateAdd(cid, dataDir string, netconf map[string]interface{}) error {
netconfBytes, err := json.Marshal(netconf)
fmt.Fprintf(os.Stderr, "delegateAdd: netconf sent to delegate plugin:\n")
os.Stderr.Write(netconfBytes)
if err != nil {
return fmt.Errorf("error serializing delegate netconf: %v", err)
}
if err = saveScratchNetConf(cid, dataDir, netconfBytes); err != nil {
return err
}
result, err := invoke.DelegateAdd(context.TODO(), netconf["type"].(string), netconfBytes, nil)
if err != nil {
err = fmt.Errorf("failed to delegate add: %w", err)
return err
}
return result.Print()
}
cmdDel()
ADDã¨åãå¼æ°ã渡ããã³ã³ãããåé¤ããã
æå¾ã«delegateDelãå¼ã³åºãã¦ããªãã¸ã¤ã³ã¿ã¼ãã§ã¼ã¹ãåé¤ãã¦ããã
doCmdAdd()ã§saveScratchNetConf()ãå¼ã³ãä¸æçã«ä¿åãããã¼ã¿ãåé¤ããã¨ããã¾ã§ãã¯ã³ã»ããã
func cmdDel(args *skel.CmdArgs) error {
nc, err := loadFlannelNetConf(args.StdinData)
if err != nil {
return err
}
if nc.RuntimeConfig != nil {
if nc.Delegate == nil {
nc.Delegate = make(map[string]interface{})
}
nc.Delegate["runtimeConfig"] = nc.RuntimeConfig
}
return doCmdDel(args, nc)
}
func consumeScratchNetConf(containerID, dataDir string) (func(error), []byte, error) {
path := filepath.Join(dataDir, containerID)
cleanup := func(err error) {
if err == nil {
_ = os.Remove(path)
}
}
netConfBytes, err := os.ReadFile(path)
return cleanup, netConfBytes, err
}
func doCmdDel(args *skel.CmdArgs, n *NetConf) error {
cleanup, netConfBytes, err := consumeScratchNetConf(args.ContainerID, n.DataDir)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
defer func() {
cleanup(err)
}()
nc := &types.NetConf{}
if err = json.Unmarshal(netConfBytes, nc); err != nil {
fmt.Fprintf(os.Stderr, "failed to parse netconf: %v", err)
return nil
}
return invoke.DelegateDel(context.TODO(), nc.Type, netConfBytes, nil)
}
cmdCheck()
func cmdCheck(args *skel.CmdArgs) error {
TODO
return nil
}
ã¾ã¨ãã¦ããªãã¤
ãã¾ãã«ãããããªãã®ã§ã¨ããããä»ã®CNIãã©ã°ã¤ã³èª¿ã¹ããâ¦ã¨æããflannel-io/cni-plugin ãèªãã§æ£è§£ã ã£ããããªãç解ãé²ãã ã
containernetworkingã®ããã±ã¼ã¸ã«ããinvokeããªãå¼ã³åºãã¦ããã®ãï¼ã«ã¤ãã¦èª¿ã¹ãã¨ãããã©ãããã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ä½æããã¦ããããã®ã ã£ããããã
www.cni.dev
flannelã¯å段ã§è¨è¨ãã¡ã¤ã«ã®ãã¼ã¹âããªãã¼ã·ã§ã³ãè¡ããå®è¡æã«åé¡ã®ãªãå½¢å¼ã«ãã¦ãããã¨ãããã¨ãç解ã§ããã
åèã«ãã¤ã¤ãå°ããCNIãã©ã°ã¤ã³ãã¾ãã¯ä½ã£ã¦ã¿ããã¨æãã
ä½è«ã ããk8sãåºãå½åããããã¯ã¼ã¯ã¯ããã¾ã§èªç±ã§ã¯ãªãã£ããããã
çµããã«
k8sã¯è»½ãåå¼·ã¯ããããå®éã«ã³ã¢ãªé¨åï¼ã¨ãã£ã¦ãããã¯ããããªããï¼ã«è¿ãã¨ããã«è§¦ãããã¨ãã§ãã¦ã¨ã¦ãé¢ç½ãã
k8sã®ãããã¯ã¼ã¯ã¯ã©ããããã©ã¬ãã«ã«ãã¡ããã¡ãã§ãããã¨ãããã¨ãç¥ã£ã¦ãããªã触ãå§ããã®ã§ãã ãã¶ããããªãã¨ãããå¤ãã¦ã¨ã¦ãè¯ãã
ãã ãCNIãã©ã°ã¤ã³ãèªä½ãã¦ã人ããªããªãããããããã°ãã»ã¨ãã©è¦ã¤ãããªãã£ããã¯ã©ã¹ã¿ã¼ãããã¯ã¼ã¯ã®èªä½ã¯â¦ã¨æã£ããã©æµç³ã«ãã¾ãããªããããªæ°ãããã
ã¨ããããä»æ§æ¸ãOSSã«ãªã£ã¦ããå種CNIãã©ã°ã¤ã³ã®ã½ã¼ã¹ã³ã¼ãã¨ãã£ãããã¬ãã¸ã¨ããã¥ã¡ã³ããããã
èªãã°ã©ãã¨ã§ããªãã®ã§ãè³çã§ããããï¼ã¨ãããã¨ãããã£ããã²ã¨ã¾ãç¶ãã¦ã¿ãã