Skip to content

Commit

Permalink
集成使用离线docker镜像安装网络插件
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmzj committed Jun 26, 2018
1 parent c4775cc commit 837b579
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 22 deletions.
6 changes: 4 additions & 2 deletions roles/calico/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ FELIX_LOG_LVL: "warning"
#IP_AUTODETECTION_METHOD: "interface=eth0"
IP_AUTODETECTION_METHOD: "can-reach={{ MASTER_IP }}"

# 镜像版本
calico_node_ver: "v3.0.6"

calico_cni_ver: "v2.0.5"

calico_kube_controller_ver: "v2.0.4"

# 离线镜像tar包
calico_offline: "calico_{{ calico_node_ver }}.tar"
34 changes: 27 additions & 7 deletions roles/calico/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
file: name={{ item }} state=directory
with_items:
- /etc/calico/ssl
- /opt/kube/kube-system/calico
- /etc/cni/net.d
- /opt/kube/kube-system/calico
- /opt/kube/images

- name: 复制CA 证书到calico 证书目录
copy: src={{ ca_dir }}/ca.pem dest=/etc/calico/ssl/ca.pem
Expand All @@ -27,16 +29,34 @@
- name: 准备 calico rbac文件
template: src=calico-rbac.yaml.j2 dest=/opt/kube/kube-system/calico/calico-rbac.yaml

- name: 获取所有已经创建的POD信息
command: "{{ bin_dir }}/kubectl get daemonset -n kube-system"
register: pod_info
run_once: true
# 【可选】推送离线docker 镜像,可以忽略执行错误
- name: 尝试推送离线docker 镜像(若执行失败,可忽略)
copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }}
with_items:
- "pause_3.1.tar"
- "{{ calico_offline }}"
ignore_errors: true

- name: 获取目录下离线镜像信息
command: "ls /opt/kube/images"
register: image_info

# 如果目录下有离线镜像,就把它导入到node节点上
- name: 导入 calico的离线镜像(若执行失败,可忽略)
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ calico_offline }}"
when: 'calico_offline in image_info.stdout'
ignore_errors: true

# 如果目录下有离线镜像,就把它导入到node节点上
- name: 导入 pause的离线镜像(若执行失败,可忽略)
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/pause_3.1.tar"
when: '"pause_3" in image_info.stdout'
ignore_errors: true

# 只需单节点执行一次
- name: 运行 calico网络
shell: "{{ bin_dir }}/kubectl create -f /opt/kube/kube-system/calico/ && sleep 5"
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/calico/ && sleep 5"
run_once: true
when: '"calico-node" not in pod_info.stdout'

# 删除原有cni配置
- name: 删除默认cni配置
Expand Down
3 changes: 3 additions & 0 deletions roles/flannel/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ install_cni_image: "jmgao1983/flannel:v0.10.0-amd64"

#flanneld_image: "quay.io/coreos/flannel:v0.10.0-amd64"
flanneld_image: "jmgao1983/flannel:v0.10.0-amd64"

# 离线镜像tar包
flannel_offline: "flannel_v0.10.0-amd64.tar"
33 changes: 26 additions & 7 deletions roles/flannel/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with_items:
- /etc/cni/net.d
- /opt/kube/kube-system/flannel
- /opt/kube/images

- name: 下载flannel cni plugins
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
Expand All @@ -16,19 +17,37 @@
- name: 准备 flannel DaemonSet yaml文件
template: src=kube-flannel.yaml.j2 dest=/opt/kube/kube-system/flannel/kube-flannel.yaml

- name: 获取所有已经创建的POD信息
command: "{{ bin_dir }}/kubectl get daemonset -n kube-system"
register: pod_info
run_once: true
# 【可选】推送离线docker 镜像,可以忽略执行错误
- name: 尝试推送离线docker 镜像(若执行失败,可忽略)
copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }}
with_items:
- "pause_3.1.tar"
- "{{ flannel_offline }}"
ignore_errors: true

- name: 获取目录下离线镜像信息
command: "ls /opt/kube/images"
register: image_info

# 如果目录下有离线镜像,就把它导入到node节点上
- name: 导入 flannel的离线镜像(若执行失败,可忽略)
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ flannel_offline }}"
when: 'flannel_offline in image_info.stdout'
ignore_errors: true

# 如果目录下有离线镜像,就把它导入到node节点上
- name: 导入 pause的离线镜像(若执行失败,可忽略)
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/pause_3.1.tar"
when: '"pause_3" in image_info.stdout'
ignore_errors: true

# 只需单节点执行一次
- name: 运行 flannel网络
shell: "{{ bin_dir }}/kubectl create -f /opt/kube/kube-system/flannel/ && sleep 5"
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/flannel/ && sleep 5"
run_once: true
when: '"flannel" not in pod_info.stdout'

# 删除原有cni配置
- name: 删除默认cni配置
- name: 删除默认cni配置
file: path=/etc/cni/net.d/10-default.conf state=absent

# 等待网络插件部署成功,视下载镜像速度而定
Expand Down
2 changes: 2 additions & 0 deletions roles/kube-router/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ FIREWALL_ENABLE: "true"
IMAGE: "cloudnativelabs/kube-router"
PullPolicy: "IfNotPresent"

# kube-router 离线镜像tar包
kuberouter_offline: "kube-router_v0.2.0-beta.7.tar"
31 changes: 25 additions & 6 deletions roles/kube-router/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with_items:
- /etc/cni/net.d
- /opt/kube/kube-system/kube-router
- /opt/kube/images

- name: 下载cni plugins
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
Expand Down Expand Up @@ -32,16 +33,34 @@
template: src=kuberouter-all.yaml.j2 dest=/opt/kube/kube-system/kube-router/kuberouter.yaml
when: 'SERVICE_PROXY == "IPVS"'

- name: 获取所有已经创建的POD信息
command: "{{ bin_dir }}/kubectl get daemonset -n kube-system"
register: pod_info
run_once: true
# 【可选】推送离线docker 镜像,可以忽略执行错误
- name: 尝试推送离线docker 镜像(若执行失败,可忽略)
copy: src={{ base_dir }}/down/{{ item }} dest=/opt/kube/images/{{ item }}
with_items:
- "pause_3.1.tar"
- "{{ kuberouter_offline }}"
ignore_errors: true

- name: 获取目录下离线镜像信息
command: "ls /opt/kube/images"
register: image_info

# 如果目录下有离线镜像,就把它导入到node节点上
- name: 导入 kube-router的离线镜像(若执行失败,可忽略)
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ kuberouter_offline }}"
when: 'kuberouter_offline in image_info.stdout'
ignore_errors: true

# 如果目录下有离线镜像,就把它导入到node节点上
- name: 导入 pause的离线镜像(若执行失败,可忽略)
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/pause_3.1.tar"
when: '"pause_3" in image_info.stdout'
ignore_errors: true

# 只需单节点执行一次
- name: 运行 kube-router DaemonSet
shell: "{{ bin_dir }}/kubectl create -f /opt/kube/kube-system/kube-router/ && sleep 5"
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/kube-router/ && sleep 5"
run_once: true
when: '"kube-router" not in pod_info.stdout'

# 删除原有cni配置
- name: 删除默认cni配置
Expand Down

0 comments on commit 837b579

Please sign in to comment.