From d1e66f9cc8982df71b8c7130f679744226b406b9 Mon Sep 17 00:00:00 2001 From: Rong Zhang Date: Mon, 4 Jun 2018 16:26:47 +0800 Subject: [PATCH] Add label to kubelet env for kubeadm deploy cluster (#2841) --- .../node/templates/kubelet.kubeadm.env.j2 | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/roles/kubernetes/node/templates/kubelet.kubeadm.env.j2 b/roles/kubernetes/node/templates/kubelet.kubeadm.env.j2 index fa2db11f4..4ca17ef53 100644 --- a/roles/kubernetes/node/templates/kubelet.kubeadm.env.j2 +++ b/roles/kubernetes/node/templates/kubelet.kubeadm.env.j2 @@ -65,8 +65,28 @@ KUBELET_HOSTNAME="--hostname-override={{ kube_override_hostname }}" {% endif %} {% set kubelet_args_dns %}{{ kubelet_args_cluster_dns }} --cluster-domain={{ dns_domain }} --resolv-conf={{ kube_resolv_conf }}{% endset %} +{# Kubelet node labels #} +{% set role_node_labels = [] %} +{% if inventory_hostname in groups['kube-master'] %} +{% set dummy = role_node_labels.append('node-role.kubernetes.io/master=true') %} +{% if not standalone_kubelet|bool %} +{% set dummy = role_node_labels.append('node-role.kubernetes.io/node=true') %} +{% endif %} +{% else %} +{% set dummy = role_node_labels.append('node-role.kubernetes.io/node=true') %} +{% endif %} +{% if inventory_hostname in groups['kube-ingress']|default([]) %} +{% set dummy = role_node_labels.append('node-role.kubernetes.io/ingress=true') %} +{% endif %} +{% set inventory_node_labels = [] %} +{% if node_labels is defined %} +{% for labelname, labelvalue in node_labels.iteritems() %} +{% set dummy = inventory_node_labels.append('%s=%s'|format(labelname, labelvalue)) %} +{% endfor %} +{% endif %} +{% set all_node_labels = role_node_labels + inventory_node_labels %} -KUBELET_ARGS="{{ kubelet_args_base }} {{ kubelet_args_dns }} {{ kube_reserved }} {% if kubelet_custom_flags is string %} {{kubelet_custom_flags}} {% else %}{% for flag in kubelet_custom_flags %} {{flag}} {% endfor %}{% endif %}" +KUBELET_ARGS="{{ kubelet_args_base }} {{ kubelet_args_dns }} {{ kube_reserved }} --node-labels={{ all_node_labels | join(',') }} {% if kubelet_custom_flags is string %} {{kubelet_custom_flags}} {% else %}{% for flag in kubelet_custom_flags %} {{flag}} {% endfor %}{% endif %}" {% if kube_network_plugin is defined and kube_network_plugin in ["calico", "canal", "flannel", "weave", "contiv", "cilium"] %} KUBELET_NETWORK_PLUGIN="--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin" {% elif kube_network_plugin is defined and kube_network_plugin == "cloud" %}