Kubernetes在1.13版本开始支持kubernetes.io/ingress-bandwidth和kubernetes.io/egress-bandwidth注解,对POD的上行和下行流量进行控制。在1.15版本以后已经集成在kubernetes版本当中,可以通过kubelet设置cni插件的形式支持该特性,在/etc/cni.d/中配置支持Bandwidth功能,以下以Calico为例添加bandwidth支持。同时需要在opt/cni/bin下安装bandwidth插件,插件项目地址:https://github.com/containernetworking/plugins.
- 在kubesphere上确认kubelet启动命令中包含–network-plugin=cni,地址在systemd配置/etc/systemd/system/kubectl.service
- 查看kubelet systemd配置文件启动项目中–cni-conf-dir –cni-bin-dir中的配置路径,kubesphere默认配置路径为/etc/cni/net.d和/opt/cni/bin目录
- 修改/etc/cni/net.d下的配置文件,启动bandwidth配置,修改文件为10-calico.conflist
{
"name": "cni0",
"cniVersion":"0.3.1",
"plugins":[
{
"nodename": "master1",
"type": "calico",
"log_level": "info",
"etcd_endpoints": "https://172.28.13.73:2379,https://172.28.13.74:2379,https://172.28.13.80:2379",
"etcd_cert_file": "/etc/calico/certs/cert.crt",
"etcd_key_file": "/etc/calico/certs/key.pem",
"etcd_ca_cert_file": "/etc/calico/certs/ca_cert.crt",
"ipam": {
"type": "calico-ipam",
"assign_ipv4": "true",
"ipv4_pools": ["10.233.64.0/18"]
},
"policy": {
"type": "k8s"
},
"kubernetes": {
"kubeconfig": "/etc/cni/net.d/calico-kubeconfig"
}
},
{
"type":"portmap",
"capabilities":{
"portMappings":true
}
},
_**{
"type":"bandwidth",
"capabilities":{
"bandwidth":true
}**_
}
]
}
- 从github上下载插件的源码运行build_linux.sh进行编译得到bandwidth运行文件,将文件拷贝到/opt/cni/bin下
- 重启kubelet服务 systemctl restart kubelet启用bandwidth功能