2018-01-02 22:12:51 +08:00
|
|
|
|
# 创建kubelet,kube-proxy工作目录和cni配置目录
|
|
|
|
|
- name: 创建kube-node 相关目录
|
|
|
|
|
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:
|
|
|
|
|
- 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
|
|
|
|
|
2018-03-16 18:23:34 +08:00
|
|
|
|
##----------kubelet 配置部分--------------
|
|
|
|
|
# kubelet 启动时向 kube-apiserver 发送 TLS bootstrapping 请求,需要绑定该角色
|
|
|
|
|
# 只需单节点执行一次
|
2018-03-14 16:53:21 +08:00
|
|
|
|
- name: get clusterrolebinding info
|
2018-03-16 18:23:34 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl get clusterrolebinding --all-namespaces"
|
2018-03-14 16:53:21 +08:00
|
|
|
|
register: clusterrolebinding_info
|
|
|
|
|
run_once: true
|
2018-01-02 22:12:51 +08:00
|
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
|
- name: kubelet-bootstrap-setting
|
2018-03-14 16:53:21 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl create clusterrolebinding kubelet-bootstrap \
|
2017-11-11 19:14:21 +08:00
|
|
|
|
--clusterrole=system:node-bootstrapper --user=kubelet-bootstrap"
|
2018-03-14 16:53:21 +08:00
|
|
|
|
run_once: True
|
|
|
|
|
when: '"kubelet-bootstrap" not in clusterrolebinding_info.stdout'
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
|
|
- name: 安装bootstrap.kubeconfig配置文件
|
2018-08-05 19:30:57 +08:00
|
|
|
|
synchronize: src=/etc/kubernetes/bootstrap.kubeconfig dest=/etc/kubernetes/bootstrap.kubeconfig
|
2018-08-11 09:14:03 +08:00
|
|
|
|
delegate_to: "{{ groups.deploy[0] }}"
|
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
|
|
|
|
|
|
|
|
|
- name: 创建kubelet的systemd unit文件
|
|
|
|
|
template: src=kubelet.service.j2 dest=/etc/systemd/system/kubelet.service
|
2018-05-20 00:17:59 +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部分----------------
|
|
|
|
|
- name: 安装kube-proxy.kubeconfig配置文件
|
2018-08-05 19:30:57 +08:00
|
|
|
|
synchronize: src=/etc/kubernetes/kube-proxy.kubeconfig dest=/etc/kubernetes/kube-proxy.kubeconfig
|
2018-08-11 09:14:03 +08:00
|
|
|
|
delegate_to: "{{ groups.deploy[0] }}"
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
2017-12-05 21:31:28 +08:00
|
|
|
|
- name: 创建kube-proxy 服务文件
|
2018-05-20 00:17:59 +08:00
|
|
|
|
tags: reload-kube-proxy, upgrade_k8s, restart_node
|
2017-11-11 19:14:21 +08:00
|
|
|
|
template: src=kube-proxy.service.j2 dest=/etc/systemd/system/kube-proxy.service
|
|
|
|
|
|
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
|
|
|
|
|
2018-03-22 22:41:43 +08:00
|
|
|
|
# 批准 node 节点,首先轮询等待kubelet启动完成
|
|
|
|
|
- name: 轮询等待kubelet启动
|
|
|
|
|
shell: "systemctl status kubelet.service|grep Active"
|
|
|
|
|
register: kubelet_status
|
|
|
|
|
until: '"running" in kubelet_status.stdout'
|
2018-03-28 17:59:26 +08:00
|
|
|
|
retries: 8
|
2018-03-22 22:41:43 +08:00
|
|
|
|
delay: 2
|
|
|
|
|
|
|
|
|
|
- name: 获取csr 请求信息
|
|
|
|
|
shell: "sleep 3 && {{ bin_dir }}/kubectl get csr"
|
|
|
|
|
register: csr_info
|
|
|
|
|
run_once: true
|
|
|
|
|
|
2018-03-16 18:23:34 +08:00
|
|
|
|
- name: approve-kubelet-csr
|
2018-03-22 22:41:43 +08:00
|
|
|
|
shell: "{{ bin_dir }}/kubectl get csr|grep 'Pending' | awk 'NR>0{print $1}'| \
|
|
|
|
|
xargs {{ bin_dir }}/kubectl certificate approve"
|
|
|
|
|
when: '"Pending" in csr_info.stdout'
|
2018-03-16 18:23:34 +08:00
|
|
|
|
run_once: true
|
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
|