Is this a BUG REPORT or FEATURE REQUEST? (choose one):
Feature Request
It appears right now there is only a way to label all nodes with a particular label using node_lables. It would be nice to also be able to label each node, or each group with a label.
For example, I want to label my nodes with gpu_enabled: true, if they have GPUs physically installed, in order to run the nvidia daemonset. I would also want to label each node with the type of GPU installed, and I'd like to be able to do something like this
`[kube-node]
gpu
[gpu label:gpu_enabled=true]
k80
p100
[k80 label:accelerator=k80]
HOST1
[p100 label:accelerator=p100]
HOST2`
Environment:
printf "$(uname -srm)\n$(cat /etc/os-release)\n"):Linux 4.4.0-109-generic x86_64
NAME="Ubuntu"
VERSION="16.04.3 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.3 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
ansible --version):Kubespray version (commit) (git rev-parse --short HEAD):
69ea28e1
Actually node_labels is a simple variable which can be defined in group_vars or/and hostvars as well as for all nodes, it depends on the file variables files you use.
I currently define it a per-host basis through a dynamic json inventory generator that defines _meta.hostvars.[host].node_labels
@mirwan do you know how I'd set that in a hosts.ini file? I tried the following, but it didn't seem to work.
NODE14 ansible_host=192.168.1.14 ip=192.168.1.14 node_labels=[gpu:true]
I was unable to get this done using the ini format, so I changed to using the yaml format as described by ansible's documentation.
If you are using python3:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_python_version.html#dict-iteritems
In Python2, dictionaries have iterkeys(), itervalues(), and iteritems() methods. These methods have been removed in Python3. Playbooks and Jinja2 templates should use dict.keys(), dict.values(), and dict.items() in order to be compatible with both Python2 and Python3
For python3 need to change:
https://github.com/kubernetes-incubator/kubespray/blob/master/roles/kubernetes/node/templates/kubelet.standard.env.j2#L99
from {% for labelname, labelvalue in node_labels.iteritems() %}
to {% for labelname, labelvalue in node_labels.items() %}
this ini works.
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
master-1 ip=10.10.10.12
master-2 ip=10.10.10.10
master-3 ip=10.10.10.7
ctrl-1 ip=10.10.10.18
ctrl-2 ip=10.10.10.19
ctrl-3 ip=10.10.10.20
com-1 ip=10.10.10.17
com-2 ip=10.10.10.4
[kube-master]
master-1
master-2
master-3
[etcd]
master-1
master-2
master-3
[kube-node]
ctrl-1
ctrl-2
ctrl-3
com-1
com-2
[k8s-cluster:children]
kube-master
kube-node
[controller-node]
ctrl-1
ctrl-2
ctrl-3
[compute-node]
com-1
com-2
[controller-node:vars]
node_labels={"openstack-control-plane":"enabled", "openvswitch":"enabled"}
[compute-node:vars]
node_labels={"openstack-compute-node":"enabled", "openvswitch":"enabled"}
Most helpful comment
this ini works.