From 583e80109f2f5d528fa76af1f4339e3107419deb Mon Sep 17 00:00:00 2001 From: Craig Tracey Date: Wed, 1 May 2019 22:05:17 -0400 Subject: [PATCH] Support kubelet environment file (#142) * Support kubelet environment file With 1.11 the kubelet packages now support an external kubelet environment file. Update the placement of this configuration from the kubelet.d directory to the /etc/{default|sysconfig}/kubelet file. Signed-off-by: Craig Tracey * Support env vars in kubelet environment file Add the capability to add environment vars to the kubelet's systemd environment file. This will let folks add arbitrary env vars for things like $HOME, etc. Signed-off-by: Craig Tracey --- ansible/roles/kubernetes-common/defaults/main.yml | 1 + ansible/roles/kubernetes-common/tasks/main.yml | 11 +++++++++-- .../kubernetes-common/templates/etc/default/kubelet | 5 +++++ .../system/kubelet.service.d/09-extra-args.conf | 2 -- 4 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 ansible/roles/kubernetes-common/templates/etc/default/kubelet delete mode 100644 ansible/roles/kubernetes-common/templates/etc/systemd/system/kubelet.service.d/09-extra-args.conf diff --git a/ansible/roles/kubernetes-common/defaults/main.yml b/ansible/roles/kubernetes-common/defaults/main.yml index 6494130..fddccdc 100644 --- a/ansible/roles/kubernetes-common/defaults/main.yml +++ b/ansible/roles/kubernetes-common/defaults/main.yml @@ -7,6 +7,7 @@ kubernetes_common_primary_interface: eth0 # kubelet_extra_args is a dict of arg:value (ie. 'node-ip: 1.1.1.1' for '--node-ip=1.1.1.1') kubernetes_common_kubelet_extra_args: {} +kubernetes_common_kubelet_env_vars: {} kubernetes_common_kubelet_config: {} kubernetes_common_kubeadm_config: diff --git a/ansible/roles/kubernetes-common/tasks/main.yml b/ansible/roles/kubernetes-common/tasks/main.yml index 605be32..4801238 100644 --- a/ansible/roles/kubernetes-common/tasks/main.yml +++ b/ansible/roles/kubernetes-common/tasks/main.yml @@ -33,11 +33,18 @@ - name: drop extra args kubelet config template: backup: True + dest: "/etc/{{ 'default' if ansible_os_family == 'Debian' else 'sysconfig' }}/kubelet" + src: etc/default/kubelet + notify: + - restart kubelet + when: kubernetes_common_primary_interface is defined or kubernetes_common_kubelet_extra_args is defined or kubernetes_common_kubelet_env_vars is defined + +- name: delete old kubelet extra args unit file + file: dest: /etc/systemd/system/kubelet.service.d/09-extra-args.conf - src: etc/systemd/system/kubelet.service.d/09-extra-args.conf + state: absent notify: - restart kubelet - when: kubernetes_common_primary_interface is defined or kubernetes_common_kubelet_extra_args is defined - name: open kubelet ports firewalld: diff --git a/ansible/roles/kubernetes-common/templates/etc/default/kubelet b/ansible/roles/kubernetes-common/templates/etc/default/kubelet new file mode 100644 index 0000000..df97049 --- /dev/null +++ b/ansible/roles/kubernetes-common/templates/etc/default/kubelet @@ -0,0 +1,5 @@ +KUBELET_EXTRA_ARGS={% if kubernetes_common_primary_interface is defined %} --node-ip={{kubernetes_node_ip}}{% endif %}{% for k, v in kubernetes_common_kubelet_extra_args.items() %} --{{k}}='{{v}}'{%- endfor %} + +{% for k, v in kubernetes_common_kubelet_env_vars.items() %} +{{k}}='{{v}}' +{% endfor %} \ No newline at end of file diff --git a/ansible/roles/kubernetes-common/templates/etc/systemd/system/kubelet.service.d/09-extra-args.conf b/ansible/roles/kubernetes-common/templates/etc/systemd/system/kubelet.service.d/09-extra-args.conf deleted file mode 100644 index e01ff32..0000000 --- a/ansible/roles/kubernetes-common/templates/etc/systemd/system/kubelet.service.d/09-extra-args.conf +++ /dev/null @@ -1,2 +0,0 @@ -[Service] -Environment="KUBELET_EXTRA_ARGS={% if kubernetes_common_primary_interface is defined %} --node-ip={{kubernetes_node_ip}}{% endif %}{% for k, v in kubernetes_common_kubelet_extra_args.items() %} --{{k}}='{{v}}'{%- endfor %}"