diff --git a/roles/calico/defaults/main.yml b/roles/calico/defaults/main.yml index 9146ebe..7666f2f 100644 --- a/roles/calico/defaults/main.yml +++ b/roles/calico/defaults/main.yml @@ -1,5 +1,8 @@ # 部分calico相关配置,更全配置可以去roles/calico/templates/calico.yaml.j2自定义 +# 如果 node 节点有多块网卡,请设置 true +NODE_WITH_MULTIPLE_NETWORKS: "false" + # etcd 集群服务地址列表, 根据etcd组成员自动生成 TMP_ENDPOINTS: "{% for h in groups['etcd'] %}https://{{ h }}:2379,{% endfor %}" ETCD_ENDPOINTS: "{{ TMP_ENDPOINTS.rstrip(',') }}" diff --git a/roles/calico/templates/calico.yaml.j2 b/roles/calico/templates/calico.yaml.j2 index 371ff9e..9c03ad6 100644 --- a/roles/calico/templates/calico.yaml.j2 +++ b/roles/calico/templates/calico.yaml.j2 @@ -328,10 +328,12 @@ spec: - name: ENABLED_CONTROLLERS value: policy,profile,workloadendpoint,node # if hosts have multiple net interfaces, set following two ENVs +{% if NODE_WITH_MULTIPLE_NETWORKS == 'true' %} - name: KUBERNETES_SERVICE_HOST value: "{{ MASTER_IP }}" - name: KUBERNETES_SERVICE_PORT value: "{{ KUBE_APISERVER.split(':')[2] }}" +{% end if %} volumeMounts: # Mount in the etcd TLS secrets. - mountPath: /calico-secrets diff --git a/roles/flannel/defaults/main.yml b/roles/flannel/defaults/main.yml index 2a76171..7fabe7a 100644 --- a/roles/flannel/defaults/main.yml +++ b/roles/flannel/defaults/main.yml @@ -1,5 +1,8 @@ # 部分flannel配置,详见roles/flannel/templates/kube-flannel.yaml.j2 +# 如果 node 节点有多块网卡,请设置 true +NODE_WITH_MULTIPLE_NETWORKS: "false" + # 设置flannel 后端 #FLANNEL_BACKEND: "host-gw" FLANNEL_BACKEND: "vxlan" diff --git a/roles/flannel/templates/kube-flannel.yaml.j2 b/roles/flannel/templates/kube-flannel.yaml.j2 index 302de9c..4245455 100644 --- a/roles/flannel/templates/kube-flannel.yaml.j2 +++ b/roles/flannel/templates/kube-flannel.yaml.j2 @@ -143,11 +143,14 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + # if hosts have multiple net interfaces, set following two ENVs +{% if NODE_WITH_MULTIPLE_NETWORKS == 'true' %} - name: KUBERNETES_SERVICE_HOST value: "{{ MASTER_IP }}" #value: "{{ KUBE_APISERVER.split(':')[1].lstrip('/') }}" - name: KUBERNETES_SERVICE_PORT value: "{{ KUBE_APISERVER.split(':')[2] }}" +{% end if %} volumeMounts: - name: run mountPath: /run