kubeasz/roles/kube-node/tasks/main.yml

129 lines
4.2 KiB
YAML
Raw Normal View History

- 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
- 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:
- 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
2022-12-19 20:33:56 +08:00
- name: 添加 kubectl 自动补全
lineinfile:
dest: ~/.bashrc
state: present
regexp: 'kubectl completion'
line: 'source <(kubectl completion bash) # generated by kubeasz'
##----------kubelet 配置部分--------------
# 创建 kubelet 相关证书及 kubelet.kubeconfig
- import_tasks: create-kubelet-kubeconfig.yml
2022-11-26 10:56:52 +08:00
tags: force_change_certs
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的配置文件
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
tags: upgrade_k8s, restart_node
2017-11-11 19:14:21 +08:00
- name: 开机启用kubelet 服务
shell: systemctl enable kubelet
ignore_errors: true
- name: 开启kubelet 服务
shell: systemctl daemon-reload && systemctl restart kubelet
2022-11-26 10:56:52 +08:00
tags: upgrade_k8s, restart_node, force_change_certs
2017-11-11 19:14:21 +08:00
##-------kube-proxy部分----------------
- name: 分发 kube-proxy.kubeconfig配置文件
copy: src={{ cluster_dir }}/kube-proxy.kubeconfig dest=/etc/kubernetes/kube-proxy.kubeconfig
2022-11-26 10:56:52 +08:00
tags: force_change_certs
2019-05-28 23:46:22 +08:00
- name: 替换 kube-proxy.kubeconfig 的 apiserver 地址
lineinfile:
dest: /etc/kubernetes/kube-proxy.kubeconfig
regexp: "^ server"
line: " server: {{ KUBE_APISERVER }}"
2022-11-26 10:56:52 +08:00
tags: force_change_certs
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
- name: 创建kube-proxy 服务文件
2017-11-11 19:14:21 +08:00
template: src=kube-proxy.service.j2 dest=/etc/systemd/system/kube-proxy.service
tags: reload-kube-proxy, restart_node, upgrade_k8s
2017-11-11 19:14:21 +08:00
- name: 开机启用kube-proxy 服务
shell: systemctl enable kube-proxy
ignore_errors: true
- name: 开启kube-proxy 服务
shell: systemctl daemon-reload && systemctl restart kube-proxy
2022-11-26 10:56:52 +08:00
tags: reload-kube-proxy, upgrade_k8s, restart_node, force_change_certs
2017-11-12 09:16:20 +08:00
# 设置k8s_nodename 在/etc/hosts 地址解析
- name: 设置k8s_nodename 在/etc/hosts 地址解析
lineinfile:
dest: /etc/hosts
state: present
regexp: "{{ K8S_NODENAME }}"
line: "{{ inventory_hostname }} {{ K8S_NODENAME }}"
delegate_to: "{{ item }}"
with_items: "{{ groups.kube_master }}"
when: "inventory_hostname != K8S_NODENAME"
2021-01-07 09:30:50 +08:00
# 轮询等待kube-proxy启动完成
- name: 轮询等待kube-proxy启动
shell: "systemctl is-active kube-proxy.service"
2021-01-07 09:30:50 +08:00
register: kubeproxy_status
until: '"active" in kubeproxy_status.stdout'
2021-01-07 09:30:50 +08:00
retries: 4
delay: 2
2022-11-26 10:56:52 +08:00
tags: reload-kube-proxy, upgrade_k8s, restart_node, force_change_certs
2021-01-07 09:30:50 +08:00
2019-05-28 23:46:22 +08:00
# 轮询等待kubelet启动完成
- name: 轮询等待kubelet启动
shell: "systemctl is-active kubelet.service"
register: kubelet_status
until: '"active" in kubelet_status.stdout'
2021-01-07 09:30:50 +08:00
retries: 4
delay: 2
2022-11-26 10:56:52 +08:00
tags: reload-kube-proxy, upgrade_k8s, restart_node, force_change_certs
- name: 轮询等待node达到Ready状态
2023-01-15 21:41:45 +08:00
shell: "{{ base_dir }}/bin/kubectl get node {{ K8S_NODENAME }}|awk 'NR>1{print $2}'"
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
2022-11-26 10:56:52 +08:00
tags: upgrade_k8s, restart_node, force_change_certs
connection: local
2018-05-22 15:57:44 +08:00
2023-01-15 21:41:45 +08:00
- block:
- name: Setting worker role name
shell: "{{ base_dir }}/bin/kubectl label node {{ K8S_NODENAME }} kubernetes.io/role=node --overwrite"
- name: Setting master role name
shell: "{{ base_dir }}/bin/kubectl label node {{ K8S_NODENAME }} kubernetes.io/role=master --overwrite"
when: "inventory_hostname in groups['kube_master']"
- name: Making master nodes SchedulingDisabled
shell: "{{ base_dir }}/bin/kubectl cordon {{ K8S_NODENAME }} "
when: "inventory_hostname not in groups['kube_node']"
2018-05-22 15:57:44 +08:00
ignore_errors: true
connection: local