Calico BGP 网络(v2.6.x)
基于版本为 Calico v2.6.x「当前官方最新版本为 v3.0 Calico Reference」
calicoctl
calicoctl 是 calico 网络命令行管理工具。
概览
# calicoctl --help
Usage:
calicoctl [options] <command> [<args>...]
create Create a resource by filename or stdin.
// 从标准输入或者文件创建资源
replace Replace a resource by filename or stdin.
// 从标准输入或者文件更新资源
apply Apply a resource by filename or stdin. This creates a resource
if it does not exist, and replaces a resource if it does exists.
// 从标准输入或者文件应用资源,如果资源存在则更新「Replace」,不在则创建 「Create」
delete Delete a resource identified by file, stdin or resource type and
name.
// 从文件、标准输出或者资源类型和名字删除资源
get Get a resource identified by file, stdin or resource type and
name.
// 通过文件、标准输入或者资源类型和名字获取定义的资源
config Manage system-wide and low-level node configuration options.
// 管理系统层和较低级别的节点配置选项
ipam IP address management.
// IP 地址管理
node Calico node management.
// Calico 节点管理
version Display the version of calicoctl.
// 显示 calicoctl 版本
Options:
-h --help Show this screen.
-l --log-level=<level> Set the log level (one of panic, fatal, error,
warn, info, debug) [default: panic]
// 设置日志级别create
v3.0 中新增了
-n --namespace=<NS>选项
replace
使用选项同 create,replace 用于更新,如果资源对象不存在则抛错。
apply
使用选项同 create,apply 执行时如果资源不存在则创建该资源对象,如果存在则更新。
delete
get
get默认 get 命令输出格式为 ps
wide 格式输出会更详细,会输出资源的一些附加列
custom-columns 可以自定义输出列
yaml/json 以 yaml 或者 json 格式输出
如果节点没有运行 etcd,那么需要通过 ETCD_ENDPOINTS 指定 etcd 地址,否则将无法操作:
config
config目前 calicoctl config 只有 logLevel 可以单独设置节点,其它如 nodeToNodeMesh、asNumber、ipip 配置的都是全局选项。默认安装之后 nodeToNodeMesh 为开启状态,如果需要和内部交换机打通,需要通过如下命令关闭该选项:
ipam
ipam目前 calicoctl ipam 的地址管理相对 v2.0 以下的版本,功能还是比较弱的,有 release 和 show 两个命令。
calico ipam release 用于从 Calico 清除未被正常回收的地址
calico ipam show 用于获取指定 ip 地址使用情况
node
node获取 Calico 节点状态信息:
calicoctl node run calico 节点启动参数选项:
注:经测试,此处
--name选项必须为主机名,否则和 bgppeer 的node字段匹配不上,bgppeer 的node字段必须为主机名,后续还需进一步测试。
资源类型
资源结构概览:
bgpPeer
配置 Calico 集群节点,支持如下别名:bgppeer、bgppeers、bgpp、bgpps、bp、bps
v3.0
apiVersion已变更为projectcalico.org/v3
Field
Description
Accepted Values
Schema
scope
Determines the Calico nodes to which this peer applies.
global, node
string
node
Must be specified if scope is node, and must be omitted when scope is global.
The hostname of the node to which this peer applies.
string
peerIP
The IP address of this peer.
Valid IPv4 or IPv6 address.
string
此处 node 官档标明为主机名,另外实际测试中如果此处指定 calico node 启动时指定的节点名「非主机名」时,跨容器路由会有问题,所以此处必须标注为主机名。
关于 BGP 的一些术语:
在 BGP 网络中,所有参与 BGP 进程的路由器都称为 BGP-speaking 路由器(BGP-speaking 可以看成是 BGP 会话的意思)
对于活动的 BGP-speaking设备,称为 peer设备,它与其他 BGP-speaking 设备之间有一个活动的 TCP 连接。BGP speaker是指本地 BGP 路由器,而 peer(对等,或者对端)是指任何其他 BGP-speaking 网络设备
当 BGP peer 路由器位于不同 AS 中时,它们之间互称对方为外部 peer,当它们位于同一个 AS 中时,则称为内部 peer
当在 peer 设备间(也就是相互直接连接的 BGP 路由器之间)建立了 TCP 连接,每个 BGP peer 就会立即与对端交换所有的路由表,也就是完整的 BGP 路由表
Host Endpoint Resource (hostEndpoint)
Host Endpoint 资源表示运行 Calico 主机关联接口,每个主机的 endpoint 包括针对该接口设置 labels 和 profiles,用以应用相关策略。
IP Pool Resource(ipPool)
定义 Calico IP 地址资源池,除了 ipPool 还有以下别名:ippool、ippools、ipp、ipps、pool、pools
ipip:ipip tunneling configuration for this pool. If not specified, ipip tunneling is disabled for this pool. 在公有云平台跨主机通信需要添加这一选项
nat-outgoing:When enabled, packets sent from calico networked containers in this pool to destinations outside of this pool will be masqueraded。简单说,使得容器可以访问外网
如果直接和内网交换机打通,则去除
nat-outgoing选项,否则容器访问外部网络还是以 nat 方式出去的。如果 ip 池启用了
ipip,建议同时也开启nat-outgoing。否则当工作负载和运行 Calico 的主机之间没有nat-outgoing路由时启用ipip是不对称的,并且可能导致流量由于 RPF 检查失败而被过滤。
Node Resource (node)
定义节点资源,除了 node,还可以使用 nodes、no、nos
默认启动 Calico node 实例,会自动创建一个使用主机名的节点资源。
获取节点信息:
Policy Resource(policy) 和 Profile Resource(profile)
关于规则的设置,当前还没有实际使用,具体可参考官网内容 Policy Resource (policy) 和 Profile Resource(profile)。
最后更新于
这有帮助吗?