2021-01-19 17:41:00 +08:00
|
|
|
|
- name: 创建kube_node 相关目录
|
2018-01-02 22:12:51 +08:00
|
|
|
|
file: name={{ item }} state=directory
|
|
|
|
|
with_items:
|
|
|
|
|
- /var/lib/kubelet
|
|
|
|
|
- /var/lib/kube-proxy
|
|
|
|
|
- /etc/cni/net.d
|
|
|
|
|
|
|
|
|
|
- name: 下载 kubelet,kube-proxy 二进制和基础 cni plugins
|
2017-11-11 19:14:21 +08:00
|
|
|
|
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
|
|
|
|
|
with_items:
|
2019-02-01 13:45:46 +08:00
|
|
|
|
- kubectl
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- kubelet
|
|
|
|
|
- kube-proxy
|
2018-01-02 22:12:51 +08:00
|
|
|
|
- bridge
|
|
|
|
|
- host-local
|
|
|
|
|
- loopback
|
2018-05-11 11:07:14 +08:00
|
|
|
|
tags: upgrade_k8s
|
2018-03-14 16:53:21 +08:00
|
|
|
|
|
2019-05-29 20:45:25 +08:00
|
|
|
|
- name: 替换 kubeconfig 的 apiserver 地址
|
|
|
|
|
lineinfile:
|
|
|
|
|
dest: /root/.kube/config
|
|
|
|
|
regexp: "^ server"
|
|
|
|
|
line: " server: {{ KUBE_APISERVER }}"
|
|
|
|
|
|
2018-03-16 18:23:34 +08:00
|
|
|
|
##----------kubelet 配置部分--------------
|
2020-01-29 18:05:58 +08:00
|
|
|
|
# 创建 kubelet 相关证书及 kubelet.kubeconfig
|
|
|
|
|
- import_tasks: create-kubelet-kubeconfig.yml
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2018-01-02 22:12:51 +08:00
|
|
|
|
- name: 准备 cni配置文件
|
|
|
|
|
template: src=cni-default.conf.j2 dest=/etc/cni/net.d/10-default.conf
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2021-01-22 23:54:12 +08:00
|
|
|
|
- name: 注册变量 DNS_SVC_IP
|
|
|
|
|
shell: echo {{ SERVICE_CIDR }}|cut -d/ -f1|awk -F. '{print $1"."$2"."$3"."$4+2}'
|
|
|
|
|
register: DNS_SVC_IP
|
|
|
|
|
|
|
|
|
|
- name: 设置变量 CLUSTER_DNS_SVC_IP
|
|
|
|
|
set_fact: CLUSTER_DNS_SVC_IP={{ DNS_SVC_IP.stdout }}
|
|
|
|
|
|
2021-04-19 00:00:55 +08:00
|
|
|
|
- block:
|
|
|
|
|
- name: 获取docker版本信息
|
|
|
|
|
shell: "{{ base_dir }}/bin/dockerd --version|cut -d' ' -f3"
|
|
|
|
|
register: docker_ver
|
|
|
|
|
|
|
|
|
|
- name: 转换docker版本信息为浮点数
|
|
|
|
|
set_fact:
|
|
|
|
|
DOCKER_VER: "{{ docker_ver.stdout.split('.')[0]|int + docker_ver.stdout.split('.')[1]|int/100 }}"
|
|
|
|
|
connection: local
|
|
|
|
|
run_once: true
|
|
|
|
|
tags: upgrade_k8s, restart_node
|
|
|
|
|
when: "CONTAINER_RUNTIME == 'docker'"
|
|
|
|
|
|
2019-07-13 11:01:08 +08:00
|
|
|
|
- name: 创建kubelet的配置文件
|
|
|
|
|
template: src=kubelet-config.yaml.j2 dest=/var/lib/kubelet/config.yaml
|
|
|
|
|
tags: upgrade_k8s, restart_node
|
|
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- name: 创建kubelet的systemd unit文件
|
|
|
|
|
template: src=kubelet.service.j2 dest=/etc/systemd/system/kubelet.service
|
2019-07-04 14:25:32 +08:00
|
|
|
|
tags: upgrade_k8s, restart_node
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2018-04-10 18:33:24 +08:00
|
|
|
|
- name: 开机启用kubelet 服务
|
|
|
|
|
shell: systemctl enable kubelet
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2017-12-05 21:31:28 +08:00
|
|
|
|
- name: 开启kubelet 服务
|
2018-04-10 18:33:24 +08:00
|
|
|
|
shell: systemctl daemon-reload && systemctl restart kubelet
|
2018-05-20 00:17:59 +08:00
|
|
|
|
tags: upgrade_k8s, restart_node
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
|
|
##-------kube-proxy部分----------------
|
2019-05-28 23:46:22 +08:00
|
|
|
|
- name: 替换 kube-proxy.kubeconfig 的 apiserver 地址
|
|
|
|
|
lineinfile:
|
|
|
|
|
dest: /etc/kubernetes/kube-proxy.kubeconfig
|
|
|
|
|
regexp: "^ server"
|
2019-05-29 20:45:25 +08:00
|
|
|
|
line: " server: {{ KUBE_APISERVER }}"
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2021-01-10 21:25:05 +08:00
|
|
|
|
- name: 创建kube-proxy 配置
|
|
|
|
|
template: src=kube-proxy-config.yaml.j2 dest=/var/lib/kube-proxy/kube-proxy-config.yaml
|
|
|
|
|
tags: reload-kube-proxy, restart_node, upgrade_k8s
|
|
|
|
|
|
2017-12-05 21:31:28 +08:00
|
|
|
|
- name: 创建kube-proxy 服务文件
|
2017-11-11 19:14:21 +08:00
|
|
|
|
template: src=kube-proxy.service.j2 dest=/etc/systemd/system/kube-proxy.service
|
2019-07-04 14:25:32 +08:00
|
|
|
|
tags: reload-kube-proxy, restart_node, upgrade_k8s
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2018-04-10 18:33:24 +08:00
|
|
|
|
- name: 开机启用kube-proxy 服务
|
|
|
|
|
shell: systemctl enable kube-proxy
|
|
|
|
|
ignore_errors: true
|
|
|
|
|
|
2017-12-05 21:31:28 +08:00
|
|
|
|
- name: 开启kube-proxy 服务
|
2018-04-10 18:33:24 +08:00
|
|
|
|
shell: systemctl daemon-reload && systemctl restart kube-proxy
|
2018-05-20 00:17:59 +08:00
|
|
|
|
tags: reload-kube-proxy, upgrade_k8s, restart_node
|
2017-11-12 09:16:20 +08:00
|
|
|
|
|
2021-01-07 09:30:50 +08:00
|
|
|
|
# 轮询等待kube-proxy启动完成
|
|
|
|
|
- name: 轮询等待kube-proxy启动
|
2021-05-28 10:11:35 +08:00
|
|
|
|
shell: "systemctl is-active kube-proxy.service"
|
2021-01-07 09:30:50 +08:00
|
|
|
|
register: kubeproxy_status
|
2021-05-28 10:11:35 +08:00
|
|
|
|
until: '"active" in kubeproxy_status.stdout'
|
2021-01-07 09:30:50 +08:00
|
|
|
|
retries: 4
|
|
|
|
|
delay: 2
|
|
|
|
|
tags: reload-kube-proxy, upgrade_k8s, restart_node
|
|
|
|
|
|
2019-05-28 23:46:22 +08:00
|
|
|
|
# 轮询等待kubelet启动完成
|
2018-03-22 22:41:43 +08:00
|
|
|
|
- name: 轮询等待kubelet启动
|
2021-05-28 10:11:35 +08:00
|
|
|
|
shell: "systemctl is-active kubelet.service"
|
2018-03-22 22:41:43 +08:00
|
|
|
|
register: kubelet_status
|
2021-05-28 10:11:35 +08:00
|
|
|
|
until: '"active" in kubelet_status.stdout'
|
2021-01-07 09:30:50 +08:00
|
|
|
|
retries: 4
|
2018-03-22 22:41:43 +08:00
|
|
|
|
delay: 2
|
2019-06-01 09:24:43 +08:00
|
|
|
|
tags: reload-kube-proxy, upgrade_k8s, restart_node
|
2018-03-22 22:41:43 +08:00
|
|
|
|
|
2018-03-24 09:25:20 +08:00
|
|
|
|
- name: 轮询等待node达到Ready状态
|
2018-06-09 22:19:20 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl get node {{ inventory_hostname }}|awk 'NR>1{print $2}'"
|
2018-03-24 09:25:20 +08:00
|
|
|
|
register: node_status
|
2018-03-25 18:28:49 +08:00
|
|
|
|
until: node_status.stdout == "Ready" or node_status.stdout == "Ready,SchedulingDisabled"
|
2018-06-18 00:04:00 +08:00
|
|
|
|
retries: 8
|
|
|
|
|
delay: 8
|
2018-05-20 00:17:59 +08:00
|
|
|
|
tags: upgrade_k8s, restart_node
|
2018-05-22 15:57:44 +08:00
|
|
|
|
|
|
|
|
|
- name: 设置node节点role
|
2018-06-09 22:19:20 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl label node {{ inventory_hostname }} kubernetes.io/role=node --overwrite"
|
2018-05-22 15:57:44 +08:00
|
|
|
|
ignore_errors: true
|
2021-01-19 20:20:05 +08:00
|
|
|
|
|
|
|
|
|
- block:
|
|
|
|
|
- name: 获取已下载离线镜像信息
|
|
|
|
|
command: "ls {{ base_dir }}/down"
|
|
|
|
|
register: download_info
|
|
|
|
|
connection: local
|
|
|
|
|
|
|
|
|
|
- name: 尝试推送离线dnscache镜像(若执行失败,可忽略)
|
|
|
|
|
copy: src={{ base_dir }}/down/{{ dnscache_offline }} dest=/opt/kube/images/{{ dnscache_offline }}
|
|
|
|
|
when: 'dnscache_offline in download_info.stdout'
|
|
|
|
|
|
|
|
|
|
- name: 获取dnscache离线镜像推送情况
|
|
|
|
|
command: "ls /opt/kube/images"
|
|
|
|
|
register: image_info
|
|
|
|
|
|
|
|
|
|
- name: 导入dnscache的离线镜像(若执行失败,可忽略)
|
|
|
|
|
shell: "{{ bin_dir }}/docker load -i /opt/kube/images/{{ dnscache_offline }}"
|
|
|
|
|
when: 'dnscache_offline in image_info.stdout and CONTAINER_RUNTIME == "docker"'
|
|
|
|
|
|
|
|
|
|
- name: 导入dnscache的离线镜像(若执行失败,可忽略)
|
|
|
|
|
shell: "{{ bin_dir }}/ctr -n=k8s.io images import /opt/kube/images/{{ dnscache_offline }}"
|
|
|
|
|
when: 'dnscache_offline in image_info.stdout and CONTAINER_RUNTIME == "containerd"'
|
|
|
|
|
when: "ENABLE_LOCAL_DNS_CACHE|bool"
|