Kubespray: Label individual nodes/groups

Created on 5 Jun 2018  路  5Comments  路  Source: kubernetes-sigs/kubespray

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:

  • Cloud provider or hardware configuration:
    Bare Metal
  • OS (printf "$(uname -srm)\n$(cat /etc/os-release)\n"):
    Darwin 17.5.0 x86_64 - ansible-playbook host

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

  • Version of Ansible (ansible --version):
    ansible 2.5.4

Kubespray version (commit) (git rev-parse --short HEAD):
69ea28e1

Most helpful comment

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"}

All 5 comments

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"}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

zouyee picture zouyee  路  3Comments

sermilrod picture sermilrod  路  4Comments

lacebal picture lacebal  路  3Comments

butuzov picture butuzov  路  4Comments

mattdornfeld picture mattdornfeld  路  4Comments