---
- name: 添加Kubernetes国内YUM源
  yum_repository:
    name: kubernetes
    description: Kubernetes
    baseurl: "{{ mirror_k8s }}/core/stable/v1.29/rpm/"
    gpgkey: 
      - "{{ mirror_k8s }}/core/stable/v1.29/rpm/repodata/repomd.xml.key"
    gpgcheck: yes
    enabled: yes
  become: yes

- name: 安装kubelet kubeadm kubectl
  yum:
    name:
      - kubelet-{{ kube_version }}
      - kubeadm-{{ kube_version }}
      - kubectl-{{ kube_version }}
    state: present
  become: yes

- name: 配置kubelet
  copy:
    content: |
      apiVersion: kubelet.config.k8s.io/v1beta1
      kind: KubeletConfiguration
      cgroupDriver: systemd
      systemReserved:
        cpu: {{ system_reserved.cpu }}
        memory: {{ system_reserved.memory }}
      kubeReserved:
        cpu: {{ kube_reserved.cpu }}
        memory: {{ kube_reserved.memory }}
      evictionHard:
        memory.available: "200Mi"
        nodefs.available: "10%"
        nodefs.inodesFree: "5%"
    dest: /var/lib/kubelet/config.yml
    mode: '0644'
  become: yes
  
- name: 上传kubelet配置文件
  copy:
    src: "{{ role_path }}/files/kubelet"
    dest: /etc/sysconfig/kubelet
    mode: '0644'
    backup: yes
  become: yes

- name: 启动kubelet
  systemd:
    name: kubelet
    state: started
    enabled: yes
    daemon_reload: yes
  become: yes

