optimize creating new node with playbook
This commit is contained in:
parent
fb335a15cd
commit
2151eb0b5c
@ -19,7 +19,6 @@
|
|||||||
register: grub_defaults
|
register: grub_defaults
|
||||||
when: ansible_architecture == 'x86_64'
|
when: ansible_architecture == 'x86_64'
|
||||||
|
|
||||||
|
|
||||||
- name: Load grub defaults
|
- name: Load grub defaults
|
||||||
ansible.builtin.shell: update-grub
|
ansible.builtin.shell: update-grub
|
||||||
when: grub_defaults.changed
|
when: grub_defaults.changed
|
||||||
@ -66,10 +65,18 @@
|
|||||||
state: present
|
state: present
|
||||||
filename: crio
|
filename: crio
|
||||||
|
|
||||||
- name: Install cri-o
|
- name: Install cri-o and conntrack
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: cri-o
|
name: "{{ item }}"
|
||||||
state: latest
|
state: latest
|
||||||
|
loop:
|
||||||
|
- cri-o
|
||||||
|
- conntrack
|
||||||
|
|
||||||
|
- name: Enable crio service
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: crio
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
- name: Download kubectl, kubeadm, kubelet
|
- name: Download kubectl, kubeadm, kubelet
|
||||||
ansible.builtin.get_url:
|
ansible.builtin.get_url:
|
||||||
@ -92,12 +99,18 @@
|
|||||||
- kubeadm
|
- kubeadm
|
||||||
register: kubelet
|
register: kubelet
|
||||||
|
|
||||||
- name: Restart Kubelet
|
- name: Download calicoctl
|
||||||
service:
|
ansible.builtin.get_url:
|
||||||
name: kubelet
|
url: "https://github.com/projectcalico/calico/releases/download/v3.28.1/calicoctl-linux-{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
|
||||||
enabled: true
|
dest: "/usr/bin/calicoctl"
|
||||||
state: restarted
|
mode: '0755'
|
||||||
when: kubelet.changed
|
|
||||||
|
- name: Install crictl
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
VERSION="v1.31.1"
|
||||||
|
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION/crictl-$VERSION-linux-amd64.tar.gz
|
||||||
|
sudo tar zxvf crictl-$VERSION-linux-amd64.tar.gz -C /usr/local/bin
|
||||||
|
rm -f crictl-$VERSION-linux-amd64.tar.gz
|
||||||
|
|
||||||
- name: Create /etc/systemd/system/kubelet.service
|
- name: Create /etc/systemd/system/kubelet.service
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
@ -108,25 +121,66 @@
|
|||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
After=network-online.target
|
After=network-online.target
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/local/bin/kubelet
|
ExecStart=/usr/bin/kubelet
|
||||||
Restart=always
|
Restart=always
|
||||||
StartLimitInterval=0
|
StartLimitInterval=0
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
dest: /etc/systemd/system/kubelet.service
|
dest: /etc/systemd/system/kubelet.service
|
||||||
|
register: kubelet_service
|
||||||
|
|
||||||
|
- name: Create /etc/systemd/system/kubelet.service.d
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: directory
|
||||||
|
path: /etc/systemd/system/kubelet.service.d
|
||||||
|
register: kubelet_service_directory
|
||||||
|
|
||||||
|
- name: Create /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: |
|
||||||
|
# Note: This dropin only works with kubeadm and kubelet v1.11+
|
||||||
|
[Service]
|
||||||
|
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
|
||||||
|
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
|
||||||
|
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
|
||||||
|
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
|
||||||
|
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
|
||||||
|
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
|
||||||
|
EnvironmentFile=-/etc/default/kubelet
|
||||||
|
ExecStart=
|
||||||
|
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
|
||||||
|
dest: /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
|
||||||
|
register: kubelet_service_directory_conf
|
||||||
|
|
||||||
|
- name: Enable kubelet service
|
||||||
|
ansible.builtin.systemd_service:
|
||||||
|
name: kubelet
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: true
|
||||||
|
when: kubelet_service.changed or kubelet_service_directory.changed or kubelet_service_directory_conf.changed
|
||||||
|
register: kubelet_service_reload
|
||||||
|
|
||||||
|
- name: Restart Kubelet
|
||||||
|
service:
|
||||||
|
name: kubelet
|
||||||
|
enabled: true
|
||||||
|
state: restarted
|
||||||
|
when: kubelet_service.changed or kubelet_service_reload.changed
|
||||||
|
|
||||||
- name: Reconfigure shutdownGracePeriod
|
- name: Reconfigure shutdownGracePeriod
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /var/lib/kubelet/config.yaml
|
path: /var/lib/kubelet/config.yaml
|
||||||
regexp: '^shutdownGracePeriod:'
|
regexp: '^shutdownGracePeriod:'
|
||||||
line: 'shutdownGracePeriod: 5m'
|
line: 'shutdownGracePeriod: 5m'
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Reconfigure shutdownGracePeriodCriticalPods
|
- name: Reconfigure shutdownGracePeriodCriticalPods
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
path: /var/lib/kubelet/config.yaml
|
path: /var/lib/kubelet/config.yaml
|
||||||
regexp: '^shutdownGracePeriodCriticalPods:'
|
regexp: '^shutdownGracePeriodCriticalPods:'
|
||||||
line: 'shutdownGracePeriodCriticalPods: 5m'
|
line: 'shutdownGracePeriodCriticalPods: 5m'
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
- name: Work around unattended-upgrades
|
- name: Work around unattended-upgrades
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
@ -198,9 +252,3 @@
|
|||||||
- name: Restart kube-apiserver
|
- name: Restart kube-apiserver
|
||||||
ansible.builtin.shell: "killall kube-apiserver"
|
ansible.builtin.shell: "killall kube-apiserver"
|
||||||
when: apiserver.changed
|
when: apiserver.changed
|
||||||
|
|
||||||
- name: Download calicoctl
|
|
||||||
ansible.builtin.get_url:
|
|
||||||
url: "https://github.com/projectcalico/calico/releases/download/v3.28.1/calicoctl-linux-{{ 'arm64' if ansible_architecture == 'aarch64' else 'amd64' }}"
|
|
||||||
dest: "/usr/bin/calicoctl"
|
|
||||||
mode: '0755'
|
|
||||||
|
Loading…
Reference in New Issue
Block a user