Giter Site home page Giter Site logo

momaek / cni-ipam-consul Goto Github PK

View Code? Open in Web Editor NEW

This project forked from logingood/cni-ipam-consul

0.0 0.0 0.0 10 KB

IPAM CNI plugin with Consul backend. Plugin could be used for IP allocation in container networks.

License: MIT License

Go 95.69% Shell 4.31%

cni-ipam-consul's Introduction

consul IP address manager

Consul IPAM allocates IPv4 and IPv6 addresses out of a specified address range and stores allocations in Consul KV store backend.

Plugin is based on the code of CNI IPAM host-local plugin but with different Backend type. Allocator code was taken as is, as long as this README. Main.go has slight modifications. Config.go was moved into separate module to share the configuration with backend code.

TODO

  • If network already defined from consul use it for allocation regardless setting in the client.
  • Create *Store type struct and modify interface, which will to support disk backend from CNI IPAM host-local plugin and consul backend depending on the plugin configuration. That will allow to use host-local plugin with different backends.
  • Store mac address in Consul as well. That could be useful for EVPN solution with BaGPipe CNI plugin.

Install

Option 1

Use go get for installation

go get github.com/murat1985/cni-ipam-consul

Plugin would be install into $GOBIN, e.g.:

~/bagpipe/bin/cni-ipam-consul

Option 2

The second way to install plugin altogether with other CNI plugins and IPAM plugins. Clone CNI repositority: CNI

Make sure that GOPATH environment variable is set

cd $GOPATH
git clone https://github.com/containernetworking/cni
cd cni/plugins/ipam

Clone bagpipe CNI plugin into plugins/main/cni-ipam-consul

git clone https://github.com/murat1985/cni-ipam-consul cni-ipam-consul
cd ../../

Build plugins

./build

Usage

Obtain an IP

Given the following network configuration:

{
    "name": "default",
    "ipam": {
        "type": "consul",
        "consul_addr": "127.0.0.1",
        "consul_port": "8500",
        "dc": "dc1",
        "subnet": "203.0.113.0/24"
    }
}

Using the command line interface

$ export CNI_COMMAND=ADD
$ export CNI_CONTAINERID=f81d4fae-7dec-11d0-a765-00a0c91e6bf6
$ ./consul < $conf
{
    "ip4": {
        "ip": "203.0.113.1/24"
    }
}

Backends

By default ipmanager stores IP allocations on the local filesystem using the IP address as the file name and the ID as contents. For example:

$ ls /var/lib/cni/networks/default
203.0.113.1	203.0.113.2
$ cat /var/lib/cni/networks/default/203.0.113.1
f81d4fae-7dec-11d0-a765-00a0c91e6bf6

Configuration Files

{
	"name": "ipv6",
    "ipam": {
        "type": "consul",
        "consul_addr": "127.0.0.1",
        "consul_port": "8500",
        "dc": "dc1",
        "subnet": "3ffe:ffff:0:01ff::/64",
        "range-start": "3ffe:ffff:0:01ff::0010",
        "range-end": "3ffe:ffff:0:01ff::0020",
        "routes": [
          { "dst": "3ffe:ffff:0:01ff::1/64" }
        ]
}
}
{
  "name": "ipv4",
	"ipam": {
    "type": "consul",
    "consul_addr": "127.0.0.1",
    "consul_port": "8500",
    "dc": "dc1",
    "subnet": "203.0.113.1/24",
    "range-start": "203.0.113.10",
    "range-end": "203.0.113.20",
    "routes": [
      { "dst": "203.0.113.0/24" }
    ]
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.