Skip to content

qiankunli/static-ipam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CNI IPAM 插件实现/CNI IPAM plugin

支持指定ip/You can request a specific IP address through Kubernetes annotations

代码拷贝自已有的 cni ipam 实现——static

copy from CNI static ipam plugin

配置/Example configurations

ipam/static

set kubeconfig in k8s.go

const kubeconfig  = `
set your own kubeconfig
`
func NewClient() (*kubernetes.Clientset, error) {
    //kubeconfig, err := ioutil.ReadFile("./kube-config")
    //if err != nil {
    //	return nil, err
    //}
    restConf, err := clientcmd.RESTConfigFromKubeConfig([]byte(kubeconfig))
    if err != nil {
        return nil, err
    }
    return kubernetes.NewForConfig(restConf)
}

k8s 网络配置 /etc/cni/net.d/network.json

{
    "cniVersion": "0.3.1",
    "name": "macnet",
    "type": "macvlan",
    "master": "eno3.96",
    "ipam": {

        "type": "static-ipam",
                "addresses": [
                    {
                            "address": "172.31.204.19/16",    // return default ip if there is error
                            "gateway": "172.31.0.1"
                    }
                ],
        "routes": [
            { "dst": "0.0.0.0/0" }
        ]
    }
}

k8s deployment.yaml

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      appName: hello-world
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        appName: hello-world
        type: web
      name: hello-world
      annotations:
        static-ipam.ipv4: "172.31.204.12"
      ...

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages