rewrite kubelet installation for different systems

pull/1282/head
gjmzj 2023-05-02 18:26:06 +08:00
parent f2f62f347d
commit 9acff29630
4 changed files with 14 additions and 12 deletions

View File

@ -30,9 +30,7 @@ Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service] [Service]
WorkingDirectory=/var/lib/kubelet WorkingDirectory=/var/lib/kubelet
{% if ansible_distribution == "Debian" and ansible_distribution_version|int >= 10 %}
ExecStartPre=/bin/mount -o remount,rw '/sys/fs/cgroup' ExecStartPre=/bin/mount -o remount,rw '/sys/fs/cgroup'
{% endif %}
{% if KUBE_RESERVED_ENABLED == "yes" or SYS_RESERVED_ENABLED == "yes" %} {% if KUBE_RESERVED_ENABLED == "yes" or SYS_RESERVED_ENABLED == "yes" %}
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpu/podruntime.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpu/podruntime.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpuacct/podruntime.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpuacct/podruntime.slice
@ -48,11 +46,9 @@ ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/memory/system.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/pids/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/pids/system.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/systemd/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/systemd/system.slice
{% if ansible_distribution != "Debian" %}
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/podruntime.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/podruntime.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/system.slice
{% endif %} {% endif %}
{% endif %}
ExecStart={{ bin_dir }}/kubelet \ ExecStart={{ bin_dir }}/kubelet \
--config=/var/lib/kubelet/config.yaml \ --config=/var/lib/kubelet/config.yaml \
--container-runtime-endpoint=unix:///run/containerd/containerd.sock \ --container-runtime-endpoint=unix:///run/containerd/containerd.sock \

View File

@ -38,6 +38,20 @@
template: src=kubelet-config.yaml.j2 dest=/var/lib/kubelet/config.yaml template: src=kubelet-config.yaml.j2 dest=/var/lib/kubelet/config.yaml
tags: upgrade_k8s, restart_node tags: upgrade_k8s, restart_node
- name: 检查文件/run/systemd/resolve/resolv.conf
stat: path="/run/systemd/resolve/resolv.conf"
register: resolv
tags: upgrade_k8s, restart_node
- name: 替换resolvConf 配置
lineinfile:
dest: /var/lib/kubelet/config.yaml
state: present
regexp: 'resolvConf'
line: 'resolvConf: /run/systemd/resolve/resolv.conf'
when: "resolv.stat.isreg is defined"
tags: upgrade_k8s, restart_node
- name: 创建kubelet的systemd unit文件 - name: 创建kubelet的systemd unit文件
template: src=kubelet.service.j2 dest=/etc/systemd/system/kubelet.service template: src=kubelet.service.j2 dest=/etc/systemd/system/kubelet.service
tags: upgrade_k8s, restart_node tags: upgrade_k8s, restart_node

View File

@ -71,11 +71,7 @@ podPidsLimit: {{ POD_MAX_PIDS }}
port: 10250 port: 10250
# disable readOnlyPort # disable readOnlyPort
readOnlyPort: 0 readOnlyPort: 0
{% if ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int > 16 %}
resolvConf: /run/systemd/resolve/resolv.conf
{% else %}
resolvConf: /etc/resolv.conf resolvConf: /etc/resolv.conf
{% endif %}
runtimeRequestTimeout: 2m0s runtimeRequestTimeout: 2m0s
serializeImagePulls: true serializeImagePulls: true
streamingConnectionIdleTimeout: 4h0m0s streamingConnectionIdleTimeout: 4h0m0s

View File

@ -4,9 +4,7 @@ Documentation=https://github.com/GoogleCloudPlatform/kubernetes
[Service] [Service]
WorkingDirectory=/var/lib/kubelet WorkingDirectory=/var/lib/kubelet
{% if ansible_distribution == "Debian" and ansible_distribution_version|int >= 10 %}
ExecStartPre=/bin/mount -o remount,rw '/sys/fs/cgroup' ExecStartPre=/bin/mount -o remount,rw '/sys/fs/cgroup'
{% endif %}
{% if KUBE_RESERVED_ENABLED == "yes" or SYS_RESERVED_ENABLED == "yes" %} {% if KUBE_RESERVED_ENABLED == "yes" or SYS_RESERVED_ENABLED == "yes" %}
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpu/podruntime.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpu/podruntime.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpuacct/podruntime.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/cpuacct/podruntime.slice
@ -22,11 +20,9 @@ ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/memory/system.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/pids/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/pids/system.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/systemd/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/systemd/system.slice
{% if ansible_distribution != "Debian" %}
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/podruntime.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/podruntime.slice
ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/system.slice ExecStartPre=/bin/mkdir -p /sys/fs/cgroup/hugetlb/system.slice
{% endif %} {% endif %}
{% endif %}
ExecStart={{ bin_dir }}/kubelet \ ExecStart={{ bin_dir }}/kubelet \
--config=/var/lib/kubelet/config.yaml \ --config=/var/lib/kubelet/config.yaml \
--container-runtime-endpoint=unix:///run/containerd/containerd.sock \ --container-runtime-endpoint=unix:///run/containerd/containerd.sock \