vmware-archive/wardroom

Allow kubelet env vars to be set in inventory

Opened this issue · 1 comments

For private docker registries that require credentials for all pulled images, kubelet needs to have access to docker credentials to pull all images in all namespaces, including for system pods, pause image, etc. Kubelet HOME defaults to "/", so docker registries are expected in the non-standard location of "/.docker", unexpected as kubelet is running as root. One way to solve is to make sure HOME is set to "/root", so method of being able to specify env vars is desired, for this or any other requirement to set env.

Related issues:

For the 1.11.x branch, the following allows a user to add kubernetes_common_kubelet_env_vars dictionary, values are added to /etc/default/kubelet. ( @craigtracey )

diff --git a/ansible/roles/kubernetes-common/defaults/main.yml b/ansible/roles/kubernetes-common/defaults/main.yml
index 27b4044..152fc73 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 d136091..6873ad2 100644
--- a/ansible/roles/kubernetes-common/tasks/main.yml
+++ b/ansible/roles/kubernetes-common/tasks/main.yml
@@ -36,7 +36,7 @@
     src: etc/default/kubelet
   notify:
     - restart kubelet
-  when: kubernetes_common_primary_interface is defined or kubernetes_common_kubelet_extra_args is defined
+  when: kubernetes_common_primary_interface is defined or kubernetes_common_kubelet_extra_args is defined or kubernetes_common_kubelet_env_vars 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
index 32821b4..1f26c58 100644
--- a/ansible/roles/kubernetes-common/templates/etc/default/kubelet
+++ b/ansible/roles/kubernetes-common/templates/etc/default/kubelet
@@ -1 +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 %}