Skip to content

Latest commit

 

History

History
97 lines (81 loc) · 4.11 KB

06-6.calico.md

File metadata and controls

97 lines (81 loc) · 4.11 KB

tags: worker, calico

06-6. 部署 calico 网络

kubernetes 要求集群内各节点(包括 master 节点)能通过 Pod 网段互联互通。

calico 使用 IPIP 或 BGP 技术(默认为 IPIP)为各节点创建一个可以互通的 Pod 网络。

如果使用 flannel,请参考附件 E.部署flannel网络.md(flannel 与 docker 结合使用)

注意:如果没有特殊指明,本文档的所有操作均在 zhangjun-k8s01 节点上执行。

安装 calico 网络插件

cd /opt/k8s/work
curl https://docs.projectcalico.org/manifests/calico.yaml -O

修改配置:

$ cp calico.yaml calico.yaml.orig
zhangjun@zj-pc16:~$ diff -U 5 calico.yaml.orig calico.yaml
--- calico.yaml.orig    2021-06-02 21:04:31.000000000 +0800
+++ calico.yaml 2021-06-02 21:08:14.000000000 +0800
@@ -3678,12 +3678,14 @@
                   name: calico-config
                   key: veth_mtu
             # The default IPv4 pool to create on startup if none exists. Pod IPs will be
             # chosen from this range. Changing this value after installation will have
             # no effect. This should fall within `--cluster-cidr`.
-            # - name: CALICO_IPV4POOL_CIDR
-            #   value: "192.168.0.0/16"
+            - name: CALICO_IPV4POOL_CIDR
+              value: "172.30.0.0/16"
+            - name: IP_AUTODETECTION_METHOD
+              value: "interface=eth.*"
             # Disable file logging so `kubectl logs` works.
             - name: CALICO_DISABLE_FILE_LOGGING
               value: "true"
             # Set Felix endpoint to host default action to ACCEPT.
             - name: FELIX_DEFAULTENDPOINTTOHOSTACTION
@@ -3759,11 +3761,11 @@
             path: /sys/fs/
             type: DirectoryOrCreate
         # Used to install CNI.
         - name: cni-bin-dir
           hostPath:
-            path: /opt/cni/bin
+            path: /opt/k8s/bin
         - name: cni-net-dir
           hostPath:
             path: /etc/cni/net.d
         # Used to access CNI logs.
         - name: cni-log-dir
  • 将 Pod 网段地址修改为 172.30.0.0/16;
  • calico 自动探查互联网卡,如果有多快网卡,则可以配置用于互联的网络接口命名正则表达式,如上面的 eth.*(根据自己服务器的网络接口名修改);

运行 calico 插件:

$ kubectl apply -f  calico.yaml
  • calico 插架以 daemonset 方式运行在所有的 K8S 节点上。

查看 calico 运行状态

$ kubectl get pods -n kube-system -o wide
NAME                                      READY   STATUS    RESTARTS   AGE     IP               NODE              NOMINATED NODE   READINESS GATES
calico-kube-controllers-77c4b7448-99lfq   1/1     Running   0          2m11s   172.30.184.128   zhangjun-k8s-03   <none>           <none>
calico-node-dxnjs                         1/1     Running   0          2m11s   172.27.137.229   zhangjun-k8s-02   <none>           <none>
calico-node-rknzz                         1/1     Running   0          2m11s   172.27.138.239   zhangjun-k8s-03   <none>           <none>
calico-node-rw84c                         1/1     Running   0          2m11s   172.27.138.251   zhangjun-k8s-01   <none>           <none>

使用 crictl 命令查看 calico 使用的镜像:

$ crictl  images
IMAGE                                                     TAG                 IMAGE ID            SIZE
docker.io/calico/cni                                      v3.12.0             cb6799752c46c       66.5MB
docker.io/calico/node                                     v3.12.0             fc05bc4225f39       89.7MB
docker.io/calico/pod2daemon-flexvol                       v3.12.0             98793d0a88c82       37.5MB
registry.cn-beijing.aliyuncs.com/images_k8s/pause-amd64   3.1                 21a595adc69ca       326kB
  • 如果 crictl 输出为空或执行失败,则有可能是缺少配置文件 /etc/crictl.yaml 导致的,该文件的配置如下:

    $ cat /etc/crictl.yaml
    runtime-endpoint: unix:///run/containerd/containerd.sock
    image-endpoint: unix:///run/containerd/containerd.sock
    timeout: 10
    debug: false