Skip to content

Commit 828de9d

Browse files
committed
增加网络插件kube-ovn支持
1 parent b4e373b commit 828de9d

File tree

7 files changed

+543
-1
lines changed

7 files changed

+543
-1
lines changed

06.network.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
- { role: cilium, when: "CLUSTER_NETWORK == 'cilium'" }
88
- { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" }
99
- { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" }
10+
- { role: kube-ovn, when: "CLUSTER_NETWORK == 'kube-ovn'" }

90.setup.yml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- { role: cilium, when: "CLUSTER_NETWORK == 'cilium'" }
6969
- { role: flannel, when: "CLUSTER_NETWORK == 'flannel'" }
7070
- { role: kube-router, when: "CLUSTER_NETWORK == 'kube-router'" }
71+
- { role: kube-ovn, when: "CLUSTER_NETWORK == 'kube-ovn'" }
7172

7273
# to install cluster-addons
7374
- hosts:

99.clean.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@
133133
- "/var/lib/cni/"
134134
- "/var/lib/kube-router/"
135135
- "/opt/kube/kube-system/"
136+
- "/var/run/openvswitch/"
137+
- "/etc/origin/openvswitch/"
138+
- "/etc/openvswitch/"
139+
- "/var/log/openvswitch/"
136140

137141
- name: cleanup iptables
138142
shell: "iptables -F && iptables -X \
@@ -149,7 +153,9 @@
149153
ip link del dummy0; \
150154
ip link del kube-ipvs0; \
151155
ip link del cilium_net; \
152-
ip link del cilium_vxlan"
156+
ip link del cilium_vxlan; \
157+
ip link del ovn0; \
158+
ip link del ovs-system"
153159
ignore_errors: true
154160

155161
- name: cleanup networks2

roles/kube-ovn/defaults/main.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 选择 OVN DB and OVN Control Plane 节点,默认为第一个master节点
2+
OVN_DB_NODE: "{{ groups['kube-master'][0] }}"
3+
4+
# 离线镜像tar包
5+
kube_ovn_offline: "kube_ovn_0.4.0.tar"

roles/kube-ovn/tasks/main.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
- block:
2+
- name: 在deploy 节点创建相关目录
3+
file: name=/opt/kube/kube-ovn state=directory
4+
5+
- name: 配置 kube-ovn.yaml 文件
6+
template: src=kube-ovn.yaml.j2 dest=/opt/kube/kube-ovn/kube-ovn.yaml
7+
8+
- name: 配置 ovn.yaml 文件
9+
template: src=ovn.yaml.j2 dest=/opt/kube/kube-ovn/ovn.yaml
10+
11+
delegate_to: "{{ groups.deploy[0] }}"
12+
run_once: true
13+
14+
- name: 创建相关目录
15+
file: name={{ item }} state=directory
16+
with_items:
17+
- /etc/cni/net.d
18+
- /opt/kube/images
19+
20+
# 【可选】推送离线镜像,可以忽略执行错误
21+
- block:
22+
- name: 检查是否已下载离线kube_ovn镜像
23+
command: "ls {{ base_dir }}/down"
24+
register: download_info
25+
connection: local
26+
run_once: true
27+
28+
- name: 尝试推送离线docker 镜像(若执行失败,可忽略)
29+
copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }}
30+
when: 'item in download_info.stdout'
31+
with_items:
32+
- "pause_3.1.tar"
33+
- "{{ kube_ovn_offline }}"
34+
ignore_errors: true
35+
36+
- name: 获取kube_ovn离线镜像推送情况
37+
command: "ls /opt/kube/images"
38+
register: image_info
39+
40+
# 如果目录下有离线镜像,就把它导入到node节点上
41+
- name: 导入 kube_ovn的离线镜像(若执行失败,可忽略)
42+
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ item }}"
43+
with_items:
44+
- "pause_3.1.tar"
45+
- "{{ kube_ovn_offline }}"
46+
ignore_errors: true
47+
when: "item in image_info.stdout and CONTAINER_RUNTIME == 'docker'"
48+
49+
- name: 导入 kube_ovn的离线镜像(若执行失败,可忽略)
50+
shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ item }}"
51+
with_items:
52+
- "pause_3.1.tar"
53+
- "{{ kube_ovn_offline }}"
54+
ignore_errors: true
55+
when: "item in image_info.stdout and CONTAINER_RUNTIME == 'containerd'"
56+
57+
# 只需单节点执行一次
58+
- name: 运行 kube-ovn网络
59+
shell: "{{ bin_dir }}/kubectl label node {{ OVN_DB_NODE }} kube-ovn/role=master --overwrite && \
60+
{{ bin_dir }}/kubectl apply -f /opt/kube/kube-ovn/ovn.yaml && sleep 5 && \
61+
{{ bin_dir }}/kubectl apply -f /opt/kube/kube-ovn/kube-ovn.yaml"
62+
delegate_to: "{{ groups.deploy[0] }}"
63+
run_once: true
64+
65+
# 删除原有cni配置
66+
- name: 删除默认cni配置
67+
file: path=/etc/cni/net.d/10-default.conf state=absent
68+
69+
# 等待网络插件部署成功,视下载镜像速度而定
70+
- name: 轮询等待kube-ovn 运行,视下载镜像速度而定
71+
shell: "{{ bin_dir }}/kubectl get pod -n kube-ovn -o wide|grep 'kube-ovn-cni'|grep ' {{ inventory_hostname }} '|awk '{print $3}'"
72+
register: pod_status
73+
until: pod_status.stdout == "Running"
74+
delegate_to: "{{ groups.deploy[0] }}"
75+
retries: 15
76+
delay: 8
77+
ignore_errors: true
78+
+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
kind: Deployment
3+
apiVersion: apps/v1
4+
metadata:
5+
name: kube-ovn-controller
6+
namespace: kube-ovn
7+
annotations:
8+
kubernetes.io/description: |
9+
kube-ovn controller
10+
spec:
11+
replicas: 2
12+
selector:
13+
matchLabels:
14+
app: kube-ovn-controller
15+
strategy:
16+
rollingUpdate:
17+
maxSurge: 0%
18+
maxUnavailable: 100%
19+
type: RollingUpdate
20+
template:
21+
metadata:
22+
labels:
23+
app: kube-ovn-controller
24+
component: network
25+
type: infra
26+
spec:
27+
tolerations:
28+
- operator: Exists
29+
effect: NoSchedule
30+
affinity:
31+
podAntiAffinity:
32+
requiredDuringSchedulingIgnoredDuringExecution:
33+
- labelSelector:
34+
matchLabels:
35+
app: kube-ovn-controller
36+
topologyKey: kubernetes.io/hostname
37+
serviceAccountName: ovn
38+
hostNetwork: true
39+
containers:
40+
- name: kube-ovn-controller
41+
image: "index.alauda.cn/alaudak8s/kube-ovn-controller:v0.4.0"
42+
imagePullPolicy: IfNotPresent
43+
command:
44+
- /kube-ovn/start-controller.sh
45+
args:
46+
- --default-cidr=10.16.0.0/16
47+
- --node-switch-cidr=100.64.0.0/16
48+
env:
49+
- name: POD_NAME
50+
valueFrom:
51+
fieldRef:
52+
fieldPath: metadata.name
53+
- name: KUBE_NAMESPACE
54+
valueFrom:
55+
fieldRef:
56+
fieldPath: metadata.namespace
57+
nodeSelector:
58+
beta.kubernetes.io/os: "linux"
59+
60+
---
61+
kind: DaemonSet
62+
apiVersion: apps/v1
63+
metadata:
64+
name: kube-ovn-cni
65+
namespace: kube-ovn
66+
annotations:
67+
kubernetes.io/description: |
68+
This daemon set launches the kube-ovn cni daemon.
69+
spec:
70+
selector:
71+
matchLabels:
72+
app: kube-ovn-cni
73+
updateStrategy:
74+
type: RollingUpdate
75+
template:
76+
metadata:
77+
labels:
78+
app: kube-ovn-cni
79+
component: network
80+
type: infra
81+
spec:
82+
tolerations:
83+
- operator: Exists
84+
effect: NoSchedule
85+
serviceAccountName: ovn
86+
hostNetwork: true
87+
hostPID: true
88+
initContainers:
89+
- name: install-cni
90+
image: "index.alauda.cn/alaudak8s/kube-ovn-cni:v0.4.0"
91+
imagePullPolicy: IfNotPresent
92+
command: ["/kube-ovn/install-cni.sh"]
93+
volumeMounts:
94+
- mountPath: /etc/cni/net.d
95+
name: cni-conf
96+
- mountPath: /opt/cni/bin
97+
name: cni-bin
98+
containers:
99+
- name: cni-server
100+
image: "index.alauda.cn/alaudak8s/kube-ovn-cni:v0.4.0"
101+
imagePullPolicy: IfNotPresent
102+
securityContext:
103+
runAsUser: 0
104+
privileged: true
105+
env:
106+
- name: POD_IP
107+
valueFrom:
108+
fieldRef:
109+
fieldPath: status.podIP
110+
- name: KUBE_NODE_NAME
111+
valueFrom:
112+
fieldRef:
113+
fieldPath: spec.nodeName
114+
volumeMounts:
115+
- mountPath: /run/openvswitch
116+
name: host-run-ovs
117+
nodeSelector:
118+
beta.kubernetes.io/os: "linux"
119+
volumes:
120+
- name: host-run-ovs
121+
hostPath:
122+
path: /run/openvswitch
123+
- name: cni-conf
124+
hostPath:
125+
path: /etc/cni/net.d
126+
- name: cni-bin
127+
hostPath:
128+
path: {{ bin_dir }}

0 commit comments

Comments
 (0)