Skip to content

Commit 20f8177

Browse files
committed
Parameterize kubelet root directory(/var/lib/kubelet)
1 parent e332375 commit 20f8177

File tree

18 files changed

+56
-48
lines changed

18 files changed

+56
-48
lines changed

roles/container-engine/cri-o/templates/crio.conf.j2

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,15 @@ insecure_registries = {{ crio_insecure_registries }}
327327
default_transport = "docker://"
328328

329329
# The path to a file containing credentials necessary for pulling images from
330-
# secure registries. The file is similar to that of /var/lib/kubelet/config.json
330+
# secure registries. The file is similar to that of {{kubelet_root_dir}}/config.json
331331
global_auth_file = "/etc/crio/config.json"
332332

333333
# The image used to instantiate infra containers.
334334
# This option supports live configuration reload.
335335
pause_image = "{{ crio_pause_image }}"
336336

337337
# The path to a file containing credentials specific for pulling the pause_image from
338-
# above. The file is similar to that of /var/lib/kubelet/config.json
338+
# above. The file is similar to that of {{kubelet_root_dir}}/config.json
339339
# This option supports live configuration reload.
340340
pause_image_auth_file = ""
341341

roles/kubernetes-apps/container_engine_accelerator/nvidia_gpu/templates/k8s-device-plugin-nvidia-daemonset.yml.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
volumes:
3535
- name: device-plugin
3636
hostPath:
37-
path: /var/lib/kubelet/device-plugins
37+
path: {{kubelet_root_dir}}/device-plugins
3838
- name: dev
3939
hostPath:
4040
path: /dev

roles/kubernetes-apps/csi_driver/aws_ebs/templates/aws-ebs-csi-nodeservice.yml.j2

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
value: unix:/csi/csi.sock
3838
volumeMounts:
3939
- name: kubelet-dir
40-
mountPath: /var/lib/kubelet
40+
mountPath: {{kubelet_root_dir}}
4141
mountPropagation: "Bidirectional"
4242
- name: plugin-dir
4343
mountPath: /csi
@@ -69,7 +69,7 @@ spec:
6969
- name: ADDRESS
7070
value: /csi/csi.sock
7171
- name: DRIVER_REG_SOCK_PATH
72-
value: /var/lib/kubelet/plugins/ebs.csi.aws.com/csi.sock
72+
value: {{kubelet_root_dir}}/plugins/ebs.csi.aws.com/csi.sock
7373
volumeMounts:
7474
- name: plugin-dir
7575
mountPath: /csi
@@ -85,15 +85,15 @@ spec:
8585
volumes:
8686
- name: kubelet-dir
8787
hostPath:
88-
path: /var/lib/kubelet
88+
path: {{kubelet_root_dir}}
8989
type: Directory
9090
- name: plugin-dir
9191
hostPath:
92-
path: /var/lib/kubelet/plugins/ebs.csi.aws.com/
92+
path: {{kubelet_root_dir}}/plugins/ebs.csi.aws.com/
9393
type: DirectoryOrCreate
9494
- name: registration-dir
9595
hostPath:
96-
path: /var/lib/kubelet/plugins_registry/
96+
path: {{kubelet_root_dir}}/plugins_registry/
9797
type: Directory
9898
- name: device-dir
9999
hostPath:

roles/kubernetes-apps/csi_driver/azuredisk/templates/azure-csi-azuredisk-node.yml.j2

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ spec:
6565
- name: ADDRESS
6666
value: /csi/csi.sock
6767
- name: DRIVER_REG_SOCK_PATH
68-
value: /var/lib/kubelet/plugins/disk.csi.azure.com/csi.sock
68+
value: {{kubelet_root_dir}}/plugins/disk.csi.azure.com/csi.sock
6969
volumeMounts:
7070
- name: socket-dir
7171
mountPath: /csi
@@ -120,7 +120,7 @@ spec:
120120
volumeMounts:
121121
- mountPath: /csi
122122
name: socket-dir
123-
- mountPath: /var/lib/kubelet/
123+
- mountPath: {{kubelet_root_dir}}/
124124
mountPropagation: Bidirectional
125125
name: mountpoint-dir
126126
- mountPath: /etc/kubernetes/
@@ -139,15 +139,15 @@ spec:
139139
memory: 20Mi
140140
volumes:
141141
- hostPath:
142-
path: /var/lib/kubelet/plugins/disk.csi.azure.com
142+
path: {{kubelet_root_dir}}/plugins/disk.csi.azure.com
143143
type: DirectoryOrCreate
144144
name: socket-dir
145145
- hostPath:
146-
path: /var/lib/kubelet/
146+
path: {{kubelet_root_dir}}/
147147
type: DirectoryOrCreate
148148
name: mountpoint-dir
149149
- hostPath:
150-
path: /var/lib/kubelet/plugins_registry/
150+
path: {{kubelet_root_dir}}/plugins_registry/
151151
type: DirectoryOrCreate
152152
name: registration-dir
153153
- secret:

roles/kubernetes-apps/csi_driver/cinder/templates/cinder-csi-nodeplugin.yml.j2

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
- name: ADDRESS
3232
value: /csi/csi.sock
3333
- name: DRIVER_REG_SOCK_PATH
34-
value: /var/lib/kubelet/plugins/cinder.csi.openstack.org/csi.sock
34+
value: {{kubelet_root_dir}}/plugins/cinder.csi.openstack.org/csi.sock
3535
- name: KUBE_NODE_NAME
3636
valueFrom:
3737
fieldRef:
@@ -81,7 +81,7 @@ spec:
8181
- name: socket-dir
8282
mountPath: /csi
8383
- name: kubelet-dir
84-
mountPath: /var/lib/kubelet
84+
mountPath: {{kubelet_root_dir}}
8585
mountPropagation: "Bidirectional"
8686
- name: pods-probe-dir
8787
mountPath: /dev
@@ -107,15 +107,15 @@ spec:
107107
volumes:
108108
- name: socket-dir
109109
hostPath:
110-
path: /var/lib/kubelet/plugins/cinder.csi.openstack.org
110+
path: {{kubelet_root_dir}}/plugins/cinder.csi.openstack.org
111111
type: DirectoryOrCreate
112112
- name: registration-dir
113113
hostPath:
114-
path: /var/lib/kubelet/plugins_registry/
114+
path: {{kubelet_root_dir}}/plugins_registry/
115115
type: Directory
116116
- name: kubelet-dir
117117
hostPath:
118-
path: /var/lib/kubelet
118+
path: {{kubelet_root_dir}}
119119
type: Directory
120120
- name: pods-probe-dir
121121
hostPath:

roles/kubernetes-apps/csi_driver/gcp_pd/templates/gcp-pd-csi-node.yml.j2

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
args:
2626
- "--v=5"
2727
- "--csi-address=/csi/csi.sock"
28-
- "--kubelet-registration-path=/var/lib/kubelet/plugins/pd.csi.storage.gke.io/csi.sock"
28+
- "--kubelet-registration-path={{kubelet_root_dir}}/plugins/pd.csi.storage.gke.io/csi.sock"
2929
lifecycle:
3030
preStop:
3131
exec:
@@ -52,7 +52,7 @@ spec:
5252
- "--run-controller-service=false"
5353
volumeMounts:
5454
- name: kubelet-dir
55-
mountPath: /var/lib/kubelet
55+
mountPath: {{kubelet_root_dir}}
5656
mountPropagation: "Bidirectional"
5757
- name: plugin-dir
5858
mountPath: /csi
@@ -73,15 +73,15 @@ spec:
7373
volumes:
7474
- name: registration-dir
7575
hostPath:
76-
path: /var/lib/kubelet/plugins_registry/
76+
path: {{kubelet_root_dir}}/plugins_registry/
7777
type: Directory
7878
- name: kubelet-dir
7979
hostPath:
80-
path: /var/lib/kubelet
80+
path: {{kubelet_root_dir}}
8181
type: Directory
8282
- name: plugin-dir
8383
hostPath:
84-
path: /var/lib/kubelet/plugins/pd.csi.storage.gke.io/
84+
path: {{kubelet_root_dir}}/plugins/pd.csi.storage.gke.io/
8585
type: DirectoryOrCreate
8686
- name: device-dir
8787
hostPath:

roles/kubernetes-apps/csi_driver/upcloud/templates/upcloud-csi-node.yml.j2

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
- name: ADDRESS
2828
value: /csi/csi.sock
2929
- name: DRIVER_REG_SOCK_PATH
30-
value: /var/lib/kubelet/plugins/storage.csi.upcloud.com/csi.sock
30+
value: {{kubelet_root_dir}}/plugins/storage.csi.upcloud.com/csi.sock
3131
- name: KUBE_NODE_NAME
3232
valueFrom:
3333
fieldRef:
@@ -70,7 +70,7 @@ spec:
7070
- name: plugin-dir
7171
mountPath: /csi
7272
- name: pods-mount-dir
73-
mountPath: /var/lib/kubelet
73+
mountPath: {{kubelet_root_dir}}
7474
# needed so that any mounts setup inside this container are
7575
# propagated back to the host machine.
7676
mountPropagation: "Bidirectional"
@@ -81,15 +81,15 @@ spec:
8181
volumes:
8282
- name: registration-dir
8383
hostPath:
84-
path: /var/lib/kubelet/plugins_registry/
84+
path: {{kubelet_root_dir}}/plugins_registry/
8585
type: DirectoryOrCreate
8686
- name: plugin-dir
8787
hostPath:
88-
path: /var/lib/kubelet/plugins/storage.csi.upcloud.com
88+
path: {{kubelet_root_dir}}/plugins/storage.csi.upcloud.com
8989
type: DirectoryOrCreate
9090
- name: pods-mount-dir
9191
hostPath:
92-
path: /var/lib/kubelet
92+
path: {{kubelet_root_dir}}
9393
type: Directory
9494
- name: device-dir
9595
hostPath:

roles/kubernetes-apps/csi_driver/vsphere/templates/vsphere-csi-node.yml.j2

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
- name: ADDRESS
4949
value: /csi/csi.sock
5050
- name: DRIVER_REG_SOCK_PATH
51-
value: /var/lib/kubelet/plugins/csi.vsphere.vmware.com/csi.sock
51+
value: {{kubelet_root_dir}}/plugins/csi.vsphere.vmware.com/csi.sock
5252
volumeMounts:
5353
- name: plugin-dir
5454
mountPath: /csi
@@ -58,7 +58,7 @@ spec:
5858
exec:
5959
command:
6060
- /csi-node-driver-registrar
61-
- --kubelet-registration-path=/var/lib/kubelet/plugins/csi.vsphere.vmware.com/csi.sock
61+
- --kubelet-registration-path={{kubelet_root_dir}}/plugins/csi.vsphere.vmware.com/csi.sock
6262
- --mode=kubelet-registration-probe
6363
initialDelaySeconds: 3
6464
- name: vsphere-csi-node
@@ -104,7 +104,7 @@ spec:
104104
- name: plugin-dir
105105
mountPath: /csi
106106
- name: pods-mount-dir
107-
mountPath: /var/lib/kubelet
107+
mountPath: {{kubelet_root_dir}}
108108
# needed so that any mounts setup inside this container are
109109
# propagated back to the host machine.
110110
mountPropagation: "Bidirectional"
@@ -142,15 +142,15 @@ spec:
142142
volumes:
143143
- name: registration-dir
144144
hostPath:
145-
path: /var/lib/kubelet/plugins_registry
145+
path: {{kubelet_root_dir}}/plugins_registry
146146
type: Directory
147147
- name: plugin-dir
148148
hostPath:
149-
path: /var/lib/kubelet/plugins/csi.vsphere.vmware.com
149+
path: {{kubelet_root_dir}}/plugins/csi.vsphere.vmware.com
150150
type: DirectoryOrCreate
151151
- name: pods-mount-dir
152152
hostPath:
153-
path: /var/lib/kubelet
153+
path: {{kubelet_root_dir}}
154154
type: Directory
155155
- name: device-dir
156156
hostPath:

roles/kubernetes/control-plane/tasks/kubeadm-setup.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
- name: Kubeadm | Check if kubeadm has already run
1414
stat:
15-
path: "/var/lib/kubelet/config.yaml"
15+
path: "{{kubelet_root_dir}}/config.yaml"
1616
get_attributes: false
1717
get_checksum: false
1818
get_mime: false

roles/kubernetes/control-plane/tasks/kubelet-fix-client-cert-rotation.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
lineinfile:
44
path: "{{ kube_config_dir }}/kubelet.conf"
55
regexp: '^ client-certificate-data: '
6-
line: ' client-certificate: /var/lib/kubelet/pki/kubelet-client-current.pem'
6+
line: " client-certificate: {{kubelet_root_dir}}/pki/kubelet-client-current.pem"
77
backup: true
88
notify:
99
- "Control plane | reload kubelet"
@@ -12,7 +12,7 @@
1212
lineinfile:
1313
path: "{{ kube_config_dir }}/kubelet.conf"
1414
regexp: '^ client-key-data: '
15-
line: ' client-key: /var/lib/kubelet/pki/kubelet-client-current.pem'
15+
line: " client-key: {{kubelet_root_dir}}/pki/kubelet-client-current.pem"
1616
backup: true
1717
notify:
1818
- "Control plane | reload kubelet"

roles/kubernetes/node/defaults/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ loadbalancer_apiserver_pod_name: "{% if loadbalancer_apiserver_type == 'nginx' %
110110
# A port range to reserve for services with NodePort visibility.
111111
# Inclusive at both ends of the range.
112112
kube_apiserver_node_port_range: "30000-32767"
113-
113+
kubelet_root_dir: /var/lib/kubelet
114114
# Configure the amount of pods able to run on single node
115115
# default is equal to application default
116116
kubelet_max_pods: 110

roles/kubernetes/node/tasks/loadbalancer/kube-vip.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
- name: Kube-vip | Check if kubeadm has already run
1717
stat:
18-
path: "/var/lib/kubelet/config.yaml"
18+
path: "{{kubelet_root_dir}}/config.yaml"
1919
get_attributes: false
2020
get_checksum: false
2121
get_mime: false

roles/kubernetes/node/templates/kubelet.env.v1beta1.j2

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ KUBELET_HOSTNAME="--hostname-override={{ kube_override_hostname }}"
1212
--kubeconfig={{ kube_config_dir }}/kubelet.conf \
1313
{# end kubeadm specific settings #}
1414
--runtime-cgroups={{ kubelet_runtime_cgroups }} \
15+
--root-dir={{ kubelet_root_dir }} \
1516
{% endset %}
1617

1718
KUBELET_ARGS="{{ kubelet_args_base }} {{ kubelet_custom_flags | join(' ') }}"

roles/kubernetes/preinstall/tasks/0020-set_facts.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,5 @@
148148

149149
- name: Set alternate flexvolume path
150150
set_fact:
151-
kubelet_flexvolumes_plugins_dir: /var/lib/kubelet/volumeplugins
151+
kubelet_flexvolumes_plugins_dir: "{{kubelet_root_dir}}/volumeplugins"
152152
when: not usr.stat.writeable

roles/kubernetes/preinstall/tasks/0040-verify-settings.yml

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@
107107
- kube_network_plugin not in ['calico', 'none']
108108
- ipv4_stack | bool
109109

110+
- name: "Kubelet: check root-dir is not set as custom-flag too"
111+
assert:
112+
that: "{{item.split('=')[0] != '--root-dir'}}"
113+
fail_msg: "kubelet root dir is set via `kubelet_root_dir` variable. Remove it from the kubelet_custom_flags and set the new var"
114+
loop: "{{kubelet_custom_flags | d([])}}"
115+
110116
- name: Stop if ip var does not match local ips
111117
assert:
112118
that: (ip in ansible_all_ipv4_addresses) or (ip in ansible_all_ipv6_addresses)

roles/kubespray-defaults/defaults/main/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ kubelet_rotate_server_certificates: false
565565
# If set to true, kubelet errors if any of kernel tunables is different than kubelet defaults
566566
kubelet_protect_kernel_defaults: true
567567

568+
kubelet_root_dir: /var/lib/kubelet
568569
# Set additional sysctl variables to modify Linux kernel variables, for example:
569570
# additional_sysctl:
570571
# - { name: kernel.pid_max, value: 131072 }

roles/network_plugin/kube-ovn/templates/cni-kube-ovn.yml.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ spec:
517517
path: /lib/modules
518518
- name: shared-dir
519519
hostPath:
520-
path: /var/lib/kubelet/pods
520+
path: {{kubelet_root_dir}}/pods
521521
- name: systemid
522522
hostPath:
523523
path: /etc/origin/openvswitch

roles/reset/tasks/main.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
- services
160160

161161
- name: Reset | gather mounted kubelet dirs
162-
shell: set -o pipefail && mount | grep /var/lib/kubelet/ | awk '{print $3}' | tac
162+
shell: set -o pipefail && mount | grep {{kubelet_root_dir}}/ | awk '{print $3}' | tac
163163
args:
164164
executable: /bin/bash
165165
check_mode: false
@@ -241,23 +241,23 @@
241241
- enable_nodelocaldns | default(false) | bool
242242
- nodelocaldns_device.stat.exists
243243

244-
- name: Reset | Check whether /var/lib/kubelet directory exists
244+
- name: Reset | Check whether {{kubelet_root_dir}} directory exists
245245
stat:
246-
path: /var/lib/kubelet
246+
path: "{{kubelet_root_dir}}"
247247
get_attributes: false
248248
get_checksum: false
249249
get_mime: false
250250
register: var_lib_kubelet_directory
251251

252-
- name: Reset | Find files/dirs with immutable flag in /var/lib/kubelet
253-
command: lsattr -laR /var/lib/kubelet/
252+
- name: Reset | Find files/dirs with immutable flag in {{kubelet_root_dir}}
253+
command: lsattr -laR {{kubelet_root_dir}}/
254254
become: true
255255
register: var_lib_kubelet_files_dirs_w_attrs
256256
changed_when: false
257257
no_log: true
258258
when: var_lib_kubelet_directory.stat.exists
259259

260-
- name: Reset | Remove immutable flag from files/dirs in /var/lib/kubelet
260+
- name: Reset | Remove immutable flag from files/dirs in {{kubelet_root_dir}}
261261
file:
262262
path: "{{ filedir_path }}"
263263
state: touch
@@ -277,7 +277,7 @@
277277
state: absent
278278
with_items:
279279
- "{{ kube_config_dir }}"
280-
- /var/lib/kubelet
280+
- {{kubelet_root_dir}}
281281
- "{{ containerd_storage_dir }}"
282282
- "{{ ansible_env.HOME | default('/root') }}/.kube"
283283
- "{{ ansible_env.HOME | default('/root') }}/.helm"

0 commit comments

Comments
 (0)