本文发布于Cylon的收藏册,转载请著名原文链接~


开始前准备

确定calico数据存储

Calico同时支持kubernetes api和etcd数据存储。官方给出的建议是在本地部署中使用K8S API,仅支持Kubernetes模式。而官方给出的etcd则是混合部署(Calico作为Kubernetes和OpenStack的网络插件运行)的最佳数据存储。

使用etcd作为calico数据存储的好处:

  • 允许多平台混用calico,如Kubernetes OpenStack上运行Calico
  • Kubernetes资源与Calico资源分离
  • 一个Calico群集,该群集不仅仅包含一个Kubernetes群集,如可与多个kubernetes集群互通。

坏处:

  • 安装步骤繁琐
  • 无法使用Kubernetes RBAC对calico资源的控制
  • 无法使用Kubernetes资源对calico进行管理

下载calico部署清单

curl https://docs.projectcalico.org/manifests/calico-etcd.yaml -o calico.yaml

修改Pod CIDR

 Calico默认的Pod CIDR使用的是192.168.0.0/16,这里一般使用与controller-manager中的--cluster-cidr 保持一,取消资源清单内的 CALICO_IPV4POOL_CIDR变量的注释,并将其设置为与所选Pod CIDR相同的值。

calico的IP分配范围

 Calico IPAM从ipPool分配IP地址。修改Pod的默认IP范围则修改清单calico.yaml中的CALICO_IPV4POOL_CIDR

配置Calico的 IP in IP

默认情况下,Calico中的IPIP已经禁用,这里使用的v3.17.2 低版本默认会使用IPIP

要开启IPIP mode则需要修改配置清单内的 CALICO_IPV4POOL_IPIP 环境变量改为 always

修改secret

  # Populate the following with etcd TLS configuration if desired, but leave blank if
  # not using TLS for etcd.
  # The keys below should be uncommented and the values populated with the base64
  # encoded contents of each file that would be associated with the TLS data.
  # Example command for encoding a file contents: cat <file> | base64 -w 0
  # etcd的ca
etcd-ca: # 填写上面命令编码后的值
# etcd客户端key
etcd-key: # 填写上面命令编码后的值
# etcd客户端访问证书
etcd-cert: # 填写上面命令编码后的值

修改configMap

  etcd_endpoints: "https://10.0.0.6: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"

开始安装

kubectl apply -f calico.yaml

安装出错

/calico-secrets/etcd-cert: permission denied

2021-02-08 02:15:10.485 [INFO][1] main.go 88: Loaded configuration from environment config=&config.Config{LogLevel:"info", WorkloadEndpointWorkers:1, ProfileWorkers:1, PolicyWorkers:1, NodeWorkers:1, Kubeconfig:"", DatastoreType:"etcdv3"}
2021-02-08 02:15:10.485 [FATAL][1] main.go 101: Failed to start error=failed to build Calico client: could not initialize etcdv3 client: open /calico-secrets/etcd-cert: permission denied

找到资源清单内的对应容器(calico-kube-controllers)的配置。在卷装载中设置440将解决此问题

volumes:
# Mount in the etcd TLS secrets with mode 400.
# See https://kubernetes.io/docs/concepts/configuration/secret/
- name: etcd-certs
  secret:
  secretName: calico-etcd-secrets
  defaultMode: 0400 # 改为0440

修改calicoctl的数据源

 使用单独的etcd作为calico数据存储还需要修改calicoctl数据存储访问配置

 calicoctl 在默认情况下,查找配置文件的路径为/etc/calico/calicoctl.cfg上。可以使用--config覆盖此选项默认配置(使用中测试不成功,官方给出有这个方法)。

 如果calicoctl无法获得配置文件,将检查环境变量。

apiVersion: projectcalico.org/v3
kind: CalicoAPIConfig
metadata:
spec:
  datastoreType: etcdv3
  etcdEndpoints: "https://10.0.0.6:2379"
  etcdCACert: |
    # 这里填写etcd ca证书文件的内容,无需转码base64
  etcdCert: |
    # 这里填写etcd client证书文件的内容,无需转码base64
  etcdKey: |
    # 这里填写etcd client秘钥文件的内容,无需转码base64

reference:

Secret permission denied

configuration calicoctl

calico installation

本文发布于Cylon的收藏册,转载请著名原文链接~

链接:https://www.oomkill.com/2021/02/calico-deploy-on-hybrid-cloud/

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」 许可协议进行许可。