Config Multus CNI
===
# prepare
* 我們先設定go的環境
```shell=
# 首先下載 golang 的 binary 檔:
$ wget https://dl.google.com/go/go1.11.5.linux-amd64.tar.gz
#解壓下載回來的壓縮檔, 並把 binary 檔放到 /usr/local:
$ sudo tar -xvf go1.11.5.linux-amd64.tar.gz
$ sudo mv go /usr/local
#設定 Golang 的環境變數, 一般需要設定 GOROOT, GOPATH 及 PATH, 開啟 .profile 檔:
$ vi ~/.profile
# 加入以下內容:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
$ source ~/.profile
```
* [啟動SRIOV](https://hackmd.mcl.math.ncu.edu.tw/OYqamCBcTtSfTBrcjwcO3w)
# 創建順序
```shell=
#先抓安裝檔
$ git clone https://github.com/intel/multus-cni.git
$ cd multus-cni
$ ./build
$ cp bin/multus /opt/cni/bin
#Copy the multus Configuration file from the Deployments folder to the CNI Configuration diectory
$ cp deployments/cni-conf.json /etc/cni/net.d/
#Configure Kubernetes network CRD with Multus
$ kubectl create -f image/ multus-daemonset.yaml
```

* 需要先Create CRD Netwrok Object specification
```yaml=
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: network-attachment-definitions.k8s.cni.cncf.io
spec:
group: k8s.cni.cncf.io
version: v1
scope: Namespaced
names:
plural: network-attachment-definitions
singular: network-attachment-definition
kind: NetworkAttachmentDefinition
shortNames:
- net-attach-def
validation:
openAPIV3Schema:
properties:
spec:
properties:
config:
type: string
```
2. Run the following kubectl command
* 我們可以看到一個新的自定義的資源:(network-attachment-definitions)

* 之後新開發的資源類型都是: NetworkAttachmentDefinition
EX:
```yaml=
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: flannel-conf
spec:
config: '{
"cniVersion": "0.3.0",
"type": "flannel",
"ipam": {
"type": "host-local",
"subnet": "10.56.217.0/24",
"routes": [{
"dst": "0.0.0.0/0"
}],
"delegate": {
"isDefaultGateway": true
}
}’
```
* 拿到的列表 這些都是可以使用的CNI

* 撰寫macvlan
```yaml=
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: macvlan
spec:
config: '{
"name": "mynet",
"type": "macvlan",
"master": "eth0",
"ipam": {
"type": "host-local",
"subnet": "10.56.217.0/24",
}
}'
```
* 撰寫mulit-pod yaml
```yaml=
apiVersion: v1
kind: Pod
metadata:
name: samplepod
annotations:
k8s.v1.cni.cncf.io/networks: macvlan-conf
spec:
containers:
- name: samplepod
command: ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"]
image: dougbtv/centos-network
```
* create 之後

# Build SRIOV CNI
```shell=
$ git clone https://github.com/intel/sriov-cni.git
$ cd sriov-cni
$ make
$ cp build/sriov /opt/cni/bin
```