标签:namespace port led 部署 null ase pip 资源 screen
部署calico网络Calico组件:
Felix:Calico agent 运行在每台node上,为容器设置网络信息:IP,路由规则,iptable规则等
etcd:calico后端存储
BIRD: BGP Client: 负责把Felix在各node上设置的路由信息广播到Calico网络 , 通过BGP协议来着
BGP Route Reflector: 大规则集群的分级路由分发。
calico: calico命令行管理工具
为Node节点部署calico网络,参照官方文档:https://docs.projectcalico.org/v2.6/getting-started/kubernetes/installation/hosted/hosted ,步骤如下:
1,下载部署的yaml文件:
wget https://docs.projectcalico.org/v2.6/getting-started/kubernetes/installation/rbac.yaml wget https://docs.projectcalico.org/v2.6/getting-started/kubernetes/installation/hosted/calico.yaml
2,对于RBAC文件,不用做修改,直接创建即可:
root@calico:/data/calico.yaml# kubectl create -f calico-rbac.yaml clusterrole "calico-kube-controllers" created clusterrolebinding "calico-kube-controllers" created clusterrole "calico-node" created clusterrolebinding "calico-node" created
3,配置calico
calico# vim calico.yaml data: # Configure this with the location of your etcd cluster. etcd_endpoints: "https://10.3.1.15:2379,https://10.3.1.16:2379,https://10.3.1.17:2379" # If you're using TLS enabled etcd uncomment the following. # You must also populate the Secret below with these files. etcd_ca: "/calico-secrets/etcd-ca" etcd_cert: "/calico-secrets/etcd-cert" etcd_key: "/calico-secrets/etcd-key" apiVersion: v1 kind: Secret type: Opaque metadata: name: calico-etcd-secrets namespace: kube-system data: etcd-key: (cat /etc/kubernetes/ssl/etcd-key.pem | base64 | tr -d '\n') #将输出结果填写在这里 etcd-cert: (cat /etc/kubernetes/ssl/etcd.pem | base64 | tr -d '\n') #将输出结果填写在这里 etcd-ca: (cat /etc/kubernetes/ssl/ca.pem | base64 | tr -d '\n') #将输出结果填写在这里 #如果etcd没用启用tls则为null #上面是必须要修改的参数,文件中有一个参数是设置pod network地址的,根据实际情况做修改: - name: CALICO_IPV4POOL_CIDR value: "192.168.0.0/16"
calico-node服务的主要参数:
CALICO_IPV4POOL_CIDR: Calico IPAM的IP地址池,Pod的IP地址将从该池中进行分配
CALICO_IPV4POOL_IPIP:是否启用IPIP模式,启用IPIP模式时,Calico将在node上创建一个tunl0的虚拟隧道。
FELIX_LOGSEVERITYSCREEN: 日志级别
FELIX_IPV6SUPPORT : 是否启用IPV6
4,创建:
calico# kubectl create -f calico.yaml configmap "calico-config" created secret "calico-etcd-secrets" created daemonset "calico-node" created deployment "calico-kube-controllers" created deployment "calico-policy-controller" created serviceaccount "calico-kube-controllers" created serviceaccount "calico-node" created
创建的资源如下:
DaemonSet: name: calico-node 这个pod里运行两个容器 hostNetwork: true serviceAccountName: calico-node 两个容器: name: calico-node image: quay.io/calico/node:v2.6.5 - name: install-cni image: quay.io/calico/cni:v1.11.2 command: ["/install-cni.sh"] calico-node: calico服务程序,用于设置Pod的网络资源,保证pod的网络与各Node互联互通,它还需要以HostNetwork模式运行,直接使用宿主机网络。 install-cni : 在各Node上安装CNI二进制文件到/opt/cni/bin目录下,并安装相应的网络配置文件到/etc/cni/net.d目录下 Deployment name ---calico-kube-controllers replicas: 1 #网络策略控制器 serviceAccountName: calico-kube-controllers containers: - name: calico-kube-controllers image: quay.io/calico/kube-controllers:v1.0.2
calico# kubectl get deployment,pod -n kube-system NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/calico-kube-controllers 1 1 1 1 4m deploy/calico-policy-controller 0 0 0 0 4m NAME READY STATUS RESTARTS AGE po/calico-kube-controllers-56d9f8c44c-6hftd 1/1 Running 0 4m po/calico-node-6k827 2/2 Running 0 4m po/calico-node-wfbpz 2/2 Running 0 4m #calico-node用的是daemonset,会在每个node上启动一个
5,设置各node上Kubelet服务的启动参数: --network-plugin=cni, 可能还要加上这两个参数:
--cni-conf-dir CNI插件的配置文件目录,默认为/etc/cni/net.d 该目录下的配置文件内容需要符合CNI规范
--cni-bin-dir: CNI插件的可执行文件目录,默认为/opt/cni/bin
设置 master上的kube-apiserver服务的启动参数: --allow-privileged=true (因为calico-node需要以特权模式运行在各node上)
设置好后,重新启动kubelet。
这样通过calico就完成了Node间容器网络的设置 ,在后续的pod创建过程中,Kubelet将通过CNI接口调用 calico进行Pod的网络设置
包括IP地址,路由规则,Iptables规则
6,验证各Node间网络联通性:
kubelet启动后主机上就生成了一个tunl0接口。 #第一台Node查看: root@node1# ip route 192.168.77.192/26 via 10.3.1.17 dev tunl0 proto bird onlink #第二台Node查看: root@node2# ip route 192.168.150.192/26 via 10.3.1.16 dev tunl0 proto bird onlink #每台node上都自动设置了到其它node上pod网络的路由,去往其它节点的路都是通过tunl0接口。
标签:namespace port led 部署 null ase pip 资源 screen
原文地址:http://blog.51cto.com/newfly/2062210