--bip=172.17.18.1/24
通过如上方式,Flannel就控制了每个Node上的docker0地址段的地址,从而保障了所有Pod的IP地址在同一个水平网络中且不产生冲突。
Flannel完美地实现了对Kubernetes网络的支持,但是它引入了多个网络组件,在网络通信时需要转到flannel0网络接口,再转到用户态的flanneld程序,到对端后还需要走这个过程的反过程,所以也会引入一些网络的时延损耗。
另外,Flannel模型默认采用了UDP作为底层传输协议,UDP本身是非可靠协议,虽然两端的TCP实现了可靠传输,但在大流量、高并发的应用场景下还建议多次测试。
1 kind: ConfigMap
2 apiVersion: v1
3 metadata:
4 name: calico-config
5 namespace: kube-system
6 data:
7 typha_service_name: "none"
8 calico_backend: "bird"
9 veth_mtu: "1440"
10 cni_network_config: |-
11 {
12 "name": "k8s-pod-network",
13 "cniVersion": "0.3.0",
14 "plugins": [
15 {
16 "type": "calico",
17 "log_level": "info",
18 "datastore_type": "kubernetes",
19 "nodename": "__KUBERNETES_NODE_NAME__",
20 "mtu": __CNI_MTU__,
21 "ipam": {
22 "type": "calico-ipam"
23 },
24 "policy": {
25 "type": "k8s"
26 },
27 "kubernetes": {
28 "kubeconfig": "__KUBECONFIG_FILEPATH__"
29 }
30 },
31 {
32 "type": "portmap",
33 "snat": true,
34 "capabilities": {"portMappings": true}
35 }
36 ]
37 }
1 apiVersion: v1
2 kind: Secret
3 type: Opaque
4 metadata:
5 name: calico-etcd-secrets
6 namespace: kube-system
7 data:
8 # Populate the following with etcd TLS configuration if desired, but leave blank if
9 # not using TLS for etcd.
10 # The keys below should be uncommented and the values populated with the base64
11 # encoded contents of each file that would be associated with the TLS data.
12 # Example command for encoding a file contents: cat | base64 -w 0
13 # 如果配置了TLS ,则需要设置相应的证书和密钥文件路径
14 # etcd-key: null
15 # etcd-cert: null
16 # etcd-ca: null
1 kind: DaemonSet
2 apiVersion: extensions/v1beta1
3 metadata:
4 name: calico-node
5 namespace: kube-system
6 labels:
7 k8s-app: calico-node
8 spec:
9 selector:
10 matchLabels:
11 k8s-app: calico-node
12 updateStrategy:
13 type: RollingUpdate
14 rollingUpdate:
15 maxUnavailable: 1
16 template:
17 metadata:
18 labels:
19 k8s-app: calico-node
20 annotations:
21 scheduler.alpha.kubernetes.io/critical-pod: ''
22 spec:
23 nodeSelector:
24 beta.kubernetes.io/os: linux
25 hostNetwork: true
26 tolerations:
27 - effect: NoSchedule
28 operator: Exists
29 - key: CriticalAddonsOnly
30 operator: Exists
31 - effect: NoExecute
32 operator: Exists
33 serviceAccountName: calico-node
34 terminationGracePeriodSeconds: 0
35 initContainers:
36 - name: upgrade-ipam
37 image: calico/cni:v3.6.0
38 command: ["/opt/cni/bin/calico-ipam", "-upgrade"]
39 env:
40 - name: KUBERNETES_NODE_NAME
41 valueFrom:
42 fieldRef:
43 fieldPath: spec.nodeName
44 - name: CALICO_NETWORKING_BACKEND
45 valueFrom:
46 configMapKeyRef:
47 name: calico-config
48 key: calico_backend
49 volumeMounts:
50 - mountPath: /var/lib/cni/networks
51 name: host-local-net-dir
52 - mountPath: /host/opt/cni/bin
53 name: cni-bin-dir
54 - name: install-cni
55 image: calico/cni:v3.6.0
56 command: ["/install-cni.sh"]
57 env:
58 - name: CNI_CONF_NAME
59 value: "10-calico.conflist"
60 - name: CNI_NETWORK_CONFIG
61 valueFrom:
62 configMapKeyRef:
63 name: calico-config
64 key: cni_network_config
65 - name: KUBERNETES_NODE_NAME
66 valueFrom:
67 fieldRef:
68 fieldPath: spec.nodeName
69 - name: CNI_MTU
70 valueFrom:
71 configMapKeyRef:
72 name: calico-config
73 key: veth_mtu
74 - name: SLEEP
75 value: "false"
76 volumeMounts:
77 - mountPath: /host/opt/cni/bin
78 name: cni-bin-dir
79 - mountPath: /host/etc/cni/net.d
80 name: cni-net-dir
81 containers:
82 - name: calico-node
83 image: calico/node:v3.6.0
84 env:
85 - name: DATASTORE_TYPE
86 value: "kubernetes"
87 - name: WAIT_FOR_DATASTORE
88 value: "true"
89 - name: NODENAME
90 valueFrom:
91 fieldRef:
92 fieldPath: spec.nodeName
93 - name: CALICO_NETWORKING_BACKEND
94 valueFrom:
95 configMapKeyRef:
96 name: calico-config
97 key: calico_backend
98 - name: CLUSTER_TYPE
99 value: "k8s,bgp"
100 - name: IP
101 value: "autodetect"
102 - name: IP_AUTODETECTION_METHOD
103 value: "can-reach=172.24.8.2"
104 - name: CALICO_IPV4POOL_IPIP
105 value: "Always"
106 - name: FELIX_IPINIPMTU
107 valueFrom:
108 configMapKeyRef:
109 name: calico-config
110 key: veth_mtu
111 - name: CALICO_IPV4POOL_CIDR
112 value: "10.10.0.0/16"
113 - name: CALICO_DISABLE_FILE_LOGGING
114 value: "true"
115 - name: FELIX_DEFAULTENDPOINTTOHOSTACTION
116 value: "ACCEPT"
117 - name: FELIX_IPV6SUPPORT
118 value: "false"
119 - name: FELIX_LOGSEVERITYSCREEN
120 value: "info"
121 - name: FELIX_HEALTHENABLED
122 value: "true"
123 securityContext:
124 privileged: true
125 resources:
126 requests:
127 cpu: 250m
128 livenessProbe:
129 httpGet:
130 path: /liveness
131 port: 9099
132 host: localhost
133 periodSeconds: 10
134 initialDelaySeconds: 10
135 failureThreshold: 6
136 readinessProbe:
137 exec:
138 command:
139 - /bin/calico-node
140 - -bird-ready
141 - -felix-ready
142 periodSeconds: 10
143 volumeMounts:
144 - mountPath: /lib/modules
145 name: lib-modules
146 readOnly: true
147 - mountPath: /run/xtables.lock
148 name: xtables-lock
149 readOnly: false
150 - mountPath: /var/run/calico
151 name: var-run-calico
152 readOnly: false
153 - mountPath: /var/lib/calico
154 name: var-lib-calico
155 readOnly: false
156 volumes:
157 - name: lib-modules
158 hostPath:
159 path: /lib/modules
160 - name: var-run-calico
161 hostPath:
162 path: /var/run/calico
163 - name: var-lib-calico
164 hostPath:
165 path: /var/lib/calico
166 - name: xtables-lock
167 hostPath:
168 path: /run/xtables.lock
169 type: FileOrCreate
170 - name: cni-bin-dir
171 hostPath:
172 path: /opt/cni/bin
173 - name: cni-net-dir
174 hostPath:
175 path: /etc/cni/net.d
176 - name: host-local-net-dir
177 hostPath:
178 path: /var/lib/cni/networks
1 apiVersion: extensions/v1beta1
2 kind: Deployment
3 metadata:
4 name: calico-kube-controllers
5 namespace: kube-system
6 labels:
7 k8s-app: calico-kube-controllers
8 annotations:
9 scheduler.alpha.kubernetes.io/critical-pod: ''
10 spec:
11 replicas: 1
12 strategy:
13 type: Recreate
14 template:
15 metadata:
16 name: calico-kube-controllers
17 namespace: kube-system
18 labels:
19 k8s-app: calico-kube-controllers
20 spec:
21 nodeSelector:
22 beta.kubernetes.io/os: linux
23 tolerations:
24 - key: CriticalAddonsOnly
25 operator: Exists
26 - key: node-role.kubernetes.io/master
27 effect: NoSchedule
28 serviceAccountName: calico-kube-controllers
29 containers:
30 - name: calico-kube-controllers
31 image: calico/kube-controllers:v3.6.0
32 env:
33 - name: ENABLED_CONTROLLERS
34 value: node
35 - name: DATASTORE_TYPE
36 value: kubernetes
37 readinessProbe:
38 exec:
39 command:
40 - /usr/bin/check-status
41 - -r