Skip to content

Commit

Permalink
Merge pull request #7 from GoneLikeAir/develop
Browse files Browse the repository at this point in the history
Fix issue #5 #6 .
  • Loading branch information
GoneLikeAir authored Jan 21, 2021
2 parents d525fb8 + 1f59af2 commit 46d6482
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 51 deletions.
92 changes: 80 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ English | [中文](README.zh-CN.md)
**For more Dockin components, please visit [https://github.com/WeBankFinTech/Dockin](https://github.com/WeBankFinTech/Dockin)**

## **Dockin cni**
dockin cni used to manager pod network, interact with resource manager(rm), support:
dockin cni used to manager pod network, interact with resource manager(RM), support:
- create single network
- create multiple network
- only support dockin-ipam ipam plugin
Expand All @@ -18,9 +18,15 @@ dockin cni must work with
- dockin-ipam, used to assign ip
- bridge, used to manage network

cni configuration
--
configuration sample

## Quick Start

### 1. cni configuration
You should put cni config file to `/etc/cni/net.d` (Default config path using by kubelet. If you redirect the config path, put the config to the path that your kubelet using).

The name of config file name can named like `00-dockin-cni.json`.

configuration sample:
```
{
"cniVersion": "0.2.0",
Expand All @@ -30,7 +36,7 @@ configuration sample
"binDir": "/opt/cni/bin",
"logFile": "/data/kubernetes/dockin-cni.log",
"logLevel": "debug",
"backend": "http://localhost:8080/rm"
"backend": "http://localhost:10002/rmController/getPodMultiNetwork"
}
```
all the parameters a described as follows:
Expand All @@ -41,10 +47,24 @@ all the parameters a described as follows:
- binDir, the binary execution about bridge
- logFile, file to store the dockin-cni's log
- logLevel, log level, support error/info/debug
- backend, the rm service api address
- backend, the api address of webhook, here using the api of dockin-RM as the sample.


### 2. Network configuration

We need to create network config file as well.

#### Step1: Using webhook to get network type.
Firstly, you should have a web server(webhook) to get the pod (multi)network information, and implement an API with `podName` query parameter:
```
<IP>:<port>/<URL>?podName=
```

rm data sample
---
Here we using Dockin-RM as the sample. You can use `curl` to access RM, for example:
```
curl 127.0.0.1:10002/rmController/getPodMultiNetwork?podName=<your_pod_name>
```
If there is no error, you will get response like this. You web API must return a struct as below as well.
```
{
"code": 0,
Expand Down Expand Up @@ -81,12 +101,14 @@ in the sample:
- ifName, the network device name about this network, which will show in ifconfig or ip a
- master, weather the main network, which will show in kubectl get pods, and this must be single in a pod

network configuration
---
**What we need to pay attention to is the field `type`. In the sample, there is two types: `test` and `dockin`**

#### Step2: create network config file.

network configuration is the bridge configuration, for more details:
>https://github.com/containernetworking/plugins/tree/master/plugins/main/bridge
network configuration are json files which stored in binDir set in the cni configuration.
network configuration are json files which stored in `confDir` set in the cni configuration.
and will pass to kubelet create network.

```
Expand All @@ -103,7 +125,53 @@ and will pass to kubelet create network.
- type, only support bridge to manage network
- bridge, the bridge name about this network, multiple network can assign different bridge name

---
**Now, let's start to create network config.**

- Firstly, create config dir:

You can find the path in the `00-dockin-cni.json`
```shell
mkdir -p /etc/cni/dockin/net.d
```

- Secondly,create config file:

In the sample as above, we need to create two network config file.

1.create config for type `test`

```
touch /etc/cni/dockin/net.d/test.json
```
content:
```JSON
{
"cniVersion": "0.2.0",
"name": "test", // type
"type": "bridge",
"bridge": "br0"
}
```

2.create config for type `dockin`

```
touch /etc/cni/dockin/net.d/dockin.json
```
content:
```JSON
{
"cniVersion": "0.2.0",
"name": "dockin", // type
"type": "bridge",
"bridge": "br0"
}
```

### 3. Put executable binary to `binDir`

You can using `make` to build `dockin-cni` and `dockin-ipam`. Then put them to `binDir` in the `00-dockin-cni.json`. The binDir is `/opt/cni/bin` normally.

## **Dockin-ipam**: static IP address management plugin

### Overview
Expand Down
78 changes: 68 additions & 10 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ dockin cni 与资源管理模块(RM)进行交互,共同来管理容器网
- dockin-ipam,用于分配ip地址
- bridge, 网桥用于网络管理

cni的配置
--
配置示例
## 部署说明
### 1. cni的配置
cni配置文件需要放置到`/etc/cni/net.d`下(kubelet使用的默认配置路径。如果重定向了配置路径,请将配置文件放置到kubelet使用的路径。

配置文件的命名可以参考`00-dockin-cni.json`这样的命名方式

配置文件内容示例:
```
{
"cniVersion": "0.2.0",
Expand All @@ -30,7 +34,7 @@ cni的配置
"binDir": "/opt/cni/bin",
"logFile": "/data/kubernetes/dockin-cni.log",
"logLevel": "debug",
"backend": "http://localhost:8080/rm"
"backend": "http://localhost:10002/rmController/getPodMultiNetwork"
}
```
参数描述如下:
Expand All @@ -41,10 +45,21 @@ cni的配置
- binDir, 网桥(bridge)二进制文件所在目录
- logFile, 日志文件路径
- logLevel, 日志登记
- backend, RM模块访问地址
- backend, webhook的访问地址,这里使用dockin-RM的地址作为示例

rm 数据示例
---
### 2. 配置Network
这里同样需要创建配置network相关的配置文件。

#### Step1:使用webhook获取network类型
首先,您需要有一个web服务器提供webhook,用于获取pod的网络信息(包括单/双网卡),该web服务需要实现一个带有`podName`url参数的API。比如:
```
<IP>:<port>/<URL>?podName=
```
这里的话,可以使用Dockin-RM作为例子。可以使用`curl`命令来访问rm的以下API:
```
curl 127.0.0.1:10002/rmController/getPodMultiNetwork?podName=<your_pod_name>
```
如果没有出现错误的话,您将会得到如下格式的响应:
```
{
"code": 0,
Expand Down Expand Up @@ -81,12 +96,13 @@ rm 数据示例
- ifName, 该网络所属的网卡名称,将能够通过ifconfig命令及ip a命令查看
- master, 用于标记是否为主要网络,在使用kubectl展示信息时将会看到该网络信息,并且在一个pod中只能有一个master网卡

network 配置
---
**这里我们需要关注的是其中`type`字段. 在这个例子中,一共有两个类型: `test``dockin`**

#### Step2: 创建network配置文件
network 配置通过网桥进行管理,更多细节可参考以下链接:
>https://github.com/containernetworking/plugins/tree/master/plugins/main/bridge
网络配置通过json文件进行存储,存放在binDir中(在cni配置中),并且将会传给kubelet创建网络。
网络配置通过json文件进行存储,存放在`confDir`(在cni配置中),并且将会传给kubelet创建网络。

```
{
Expand All @@ -102,6 +118,48 @@ network 配置通过网桥进行管理,更多细节可参考以下链接:
- type, 类型,仅支持通过网桥进行网络管理
- bridge, 网桥名称,多网卡环境下可以分配不同的网桥名称

**上面对配置的内容做了简单介绍,现在来创建network配置文件.**
- 首先,先创建配置文件目录:

目录的路径可以从前面的cni配置文件中的`confDir`找到
```
mkdir -p /etc/cni/dockin/net.d
```

- 然后,创建配置文件

在上面的例子中,我们需要创建两个network配置文件
1.为类型`test`创建配置文件
```
touch /etc/cni/dockin/net.d/test.json
```
配置文件内容:
```JSON
{
"cniVersion": "0.2.0",
"name": "test", // type
"type": "bridge",
"bridge": "br0"
}
```

2.为类型`dockin`创建配置文件
```
touch /etc/cni/dockin/net.d/dockin.json
```
配置文件内容:
```JSON
{
"cniVersion": "0.2.0",
"name": "dockin", // type
"type": "bridge",
"bridge": "br0"
}
```

### 3. 将可执行文件放到`binDir`
你可以使用`make`命令完成`dockin-cni``dockin-ipam`的编译,然后将两个可执行文件放到cni配置文件中`binDir`指向的路径。通常情况下,cni的bin目录为`/opt/cni/bin`

---
## **Dockin-ipam**: 静态IP地址管理插件

Expand Down
25 changes: 11 additions & 14 deletions dockin-cni/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,33 @@ OS=linux
ARCH=amd64

default:
@go mod tidy
@go mod vendor
@mkdir build
@cd build && GOOS=${OS} GOARCH=${ARCH} go build -o ${BINARY} ../cmd
go mod tidy
go mod vendor
@mkdir -p build
cd build && GOOS=${OS} GOARCH=${ARCH} go build -o ${BINARY} ../cmd


list:
@echo ${PACKAGES}
@echo ${VETPACKAGES}
@echo ${GOFILES}
echo ${PACKAGES}
echo ${VETPACKAGES}
echo ${GOFILES}

fmt:
@gofmt -s -w ${GOFILES}
gofmt -s -w ${GOFILES}

fmt-check:
@diff=?(gofmt -s -d $(GOFILES)); \
diff=?(gofmt -s -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;

# test:
# @go test -cpu=1,2,4 -v -tags integration ./...

vet:
@go vet $(VETPACKAGES)
go vet $(VETPACKAGES)

clean:
@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi


.PHONY: default fmt fmt-check install vet clean
4 changes: 3 additions & 1 deletion dockin-cni/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ go 1.12

require (
github.com/containernetworking/cni v0.7.1
github.com/containernetworking/plugins v0.8.2
github.com/golang/protobuf v1.3.2 // indirect
github.com/google/uuid v1.1.1
github.com/kr/pretty v0.1.0 // indirect
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf
github.com/vishvananda/netns v0.0.0-20190625233234-7109fa855b0f // indirect
golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect
golang.org/x/sys v0.0.0-20190927073244-c990c680b611 // indirect
golang.org/x/text v0.3.2 // indirect
Expand Down
Loading

0 comments on commit 46d6482

Please sign in to comment.