2016-07-23 05:13:48 +00:00
# Node feature discovery for [Kubernetes](https://kubernetes.io)
2019-05-16 19:49:47 +00:00
[![Build Status ](https://api.travis-ci.org/kubernetes-sigs/node-feature-discovery.svg?branch=master )](https://travis-ci.org/kubernetes-sigs/node-feature-discovery)
2018-11-28 11:51:43 +00:00
[![Go Report Card ](https://goreportcard.com/badge/github.com/kubernetes-sigs/node-feature-discovery )](https://goreportcard.com/report/github.com/kubernetes-sigs/node-feature-discovery)
2016-09-23 21:08:03 +00:00
2016-07-26 05:44:45 +00:00
- [Overview ](#overview )
2016-08-31 00:04:43 +00:00
- [Command line interface ](#command-line-interface )
- [Feature discovery ](#feature-discovery )
- [Feature sources ](#feature-sources )
- [Feature labels ](#feature-labels )
- [Getting started ](#getting-started )
- [System requirements ](#system-requirements )
- [Usage ](#usage )
2016-07-12 23:44:03 +00:00
- [Building from source ](#building-from-source )
2016-08-31 00:04:43 +00:00
- [Targeting nodes with specific features ](#targeting-nodes-with-specific-features )
- [References ](#references )
2016-07-26 05:44:45 +00:00
- [License ](#license )
2016-09-23 18:08:40 +00:00
- [Demo ](#demo )
2016-07-26 05:44:45 +00:00
## Overview
This software enables node feature discovery for Kubernetes. It detects
hardware features available on each node in a Kubernetes cluster, and advertises
those features using node labels.
2019-02-01 15:08:39 +00:00
NFD consists of two software components:
1. **nfd-master** is responsible for labeling Kubernetes node objects
2. **nfd-worker** is detects features and communicates them to nfd-master.
One instance of nfd-worker is supposed to be run on each node of the cluster
2016-12-08 22:21:53 +00:00
2016-08-31 00:04:43 +00:00
## Command line interface
2019-02-01 15:08:39 +00:00
You can run NFD in stand-alone Docker containers e.g. for testing
purposes. This is useful for checking features-detection.
2018-02-23 10:53:22 +00:00
2019-02-01 15:08:39 +00:00
### NFD-Master
When running as a standalone container labeling is expected to fail because
2019-05-16 19:49:47 +00:00
Kubernetes API is not available. Thus, it is recommended to use `--no-publish`
2019-02-01 15:08:39 +00:00
command line flag. E.g.
```
$ docker run --rm --name=nfd-test < NFD_CONTAINER_IMAGE > nfd-master --no-publish
2019/02/01 14:48:21 Node Feature Discovery Master < NFD_VERSION >
2019/02/01 14:48:21 gRPC server serving on port: 8080
```
Command line flags of nfd-master:
2016-10-26 00:05:55 +00:00
```
2019-02-01 15:08:39 +00:00
$ docker run --rm < NFD_CONTAINER_IMAGE > nfd-master --help
...
nfd-master.
Usage:
nfd-master [--no-publish] [--label-whitelist=< pattern > ] [--port=< port > ]
[--ca-file=< path > ] [--cert-file=< path > ] [--key-file=< path > ]
2019-04-05 22:31:40 +00:00
[--verify-node-name] [--extra-label-ns=< list > ]
2019-02-01 15:08:39 +00:00
nfd-master -h | --help
nfd-master --version
Options:
2019-04-05 22:31:40 +00:00
-h --help Show this screen.
--version Output version and exit.
--port=< port > Port on which to listen for connections.
[Default: 8080]
--ca-file=< path > Root certificate for verifying connections
[Default: ]
--cert-file=< path > Certificate used for authenticating connections
[Default: ]
--key-file=< path > Private key matching --cert-file
[Default: ]
--verify-node-name Verify worker node name against CN from the TLS
certificate. Only has effect when TLS authentication
has been enabled.
--no-publish Do not publish feature labels
--label-whitelist=< pattern > Regular expression to filter label names to
publish to the Kubernetes API server. [Default: ]
--extra-label-ns=< list > Comma separated list of allowed extra label namespaces
[Default: ]
2019-02-01 15:08:39 +00:00
```
### NFD-Worker
2019-05-16 19:49:47 +00:00
In order to run nfd-worker as a "stand-alone" container against your
2019-02-01 15:08:39 +00:00
standalone nfd-master you need to run them in the same network namespace:
```
$ docker run --rm --network=container:nfd-test < NFD_CONTAINER_IMAGE > nfd-worker
2019/02/01 14:48:56 Node Feature Discovery Worker < NFD_VERSION >
...
```
If you just want to try out feature discovery without connecting to nfd-master,
pass the `--no-publish` flag to nfd-worker.
Command line flags of nfd-worker:
```
$ docker run --rm < CONTAINER_IMAGE_ID > nfd-worker --help
...
nfd-worker.
2016-10-26 00:05:55 +00:00
Usage:
2019-02-01 15:08:39 +00:00
nfd-worker [--no-publish] [--sources=< sources > ] [--label-whitelist=< pattern > ]
2018-07-06 11:11:07 +00:00
[--oneshot | --sleep-interval=< seconds > ] [--config=< path > ]
2019-02-01 15:08:39 +00:00
[--options=< config > ] [--server=< server > ] [--server-name-override=< name > ]
[--ca-file=< path > ] [--cert-file=< path > ] [--key-file=< path > ]
nfd-worker -h | --help
nfd-worker --version
2016-10-26 00:05:55 +00:00
Options:
-h --help Show this screen.
--version Output version and exit.
2018-07-06 11:11:07 +00:00
--config=< path > Config file to use.
2019-02-01 15:08:39 +00:00
[Default: /etc/kubernetes/node-feature-discovery/nfd-worker.conf]
2018-09-21 08:26:57 +00:00
--options=< config > Specify config options from command line. Config
options are specified in the same format as in the
config file (i.e. json or yaml). These options
will override settings read from the config file.
[Default: ]
2019-02-01 15:08:39 +00:00
--ca-file=< path > Root certificate for verifying connections
[Default: ]
--cert-file=< path > Certificate used for authenticating connections
[Default: ]
--key-file=< path > Private key matching --cert-file
[Default: ]
--server=< server > NFD server address to connecto to.
[Default: localhost:8080]
--server-name-override=< name > Name (CN) expect from server certificate, useful
in testing
[Default: ]
2016-10-26 00:05:55 +00:00
--sources=< sources > Comma separated list of feature sources.
2019-02-19 08:52:46 +00:00
[Default: cpu,iommu,kernel,local,memory,network,pci,storage,system]
2016-10-26 00:05:55 +00:00
--no-publish Do not publish discovered features to the
cluster-local Kubernetes API server.
--label-whitelist=< pattern > Regular expression to filter label names to
publish to the Kubernetes API server. [Default: ]
2018-04-11 16:33:06 +00:00
--oneshot Label once and exit.
--sleep-interval=< seconds > Time to sleep between re-labeling. Non-positive
value implies no re-labeling (i.e. infinite
sleep). [Default: 60s]
2016-10-26 00:05:55 +00:00
```
2018-08-17 10:24:38 +00:00
**NOTE** Some feature sources need certain directories and/or files from the
host mounted inside the NFD container. Thus, you need to provide Docker with the
correct `--volume` options in order for them to work correctly when run
stand-alone directly with `docker run` . See the
2019-05-16 19:49:47 +00:00
[template spec ](https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/nfd-worker-daemonset.yaml.template )
2018-08-17 10:24:38 +00:00
for up-to-date information about the required volume mounts.
2016-08-31 00:04:43 +00:00
## Feature discovery
2016-07-26 05:44:45 +00:00
### Feature sources
2016-07-19 22:35:42 +00:00
The current set of feature sources are the following:
2018-07-17 09:26:11 +00:00
- CPU
2018-07-24 15:24:45 +00:00
- IOMMU
2018-07-09 13:27:24 +00:00
- Kernel
2018-02-20 12:42:36 +00:00
- Memory
2017-11-28 14:47:11 +00:00
- Network
2018-10-19 13:45:50 +00:00
- PCI
2018-07-24 15:24:45 +00:00
- Storage
2018-07-10 09:00:02 +00:00
- System
2019-02-19 10:55:12 +00:00
- Local (hooks for user-specific features)
2016-07-26 05:44:45 +00:00
### Feature labels
The published node labels encode a few pieces of information:
2018-11-20 13:57:57 +00:00
- Namespace, i.e. `feature.node.kubernetes.io`
2019-02-19 08:52:46 +00:00
- The source for each label (e.g. `cpu` ).
2016-07-26 05:44:45 +00:00
- The name of the discovered feature as it appears in the underlying
2019-02-19 08:52:46 +00:00
source, (e.g. `cpuid.AESNI` from cpu).
2018-06-21 16:02:30 +00:00
- The value of the discovered feature.
2016-07-26 05:44:45 +00:00
2018-10-02 13:18:04 +00:00
Feature label names adhere to the following pattern:
```
2018-11-30 08:10:02 +00:00
< namespace > /< source name > -< feature name > [.< attribute name > ]
2018-10-02 13:18:04 +00:00
```
The last component (i.e. `attribute-name` ) is optional, and only used if a
feature logically has sub-hierarchy, e.g. `sriov.capable` and
`sriov.configure` from the `network` source.
2016-07-26 05:44:45 +00:00
```json
{
2018-07-17 09:26:11 +00:00
"feature.node.kubernetes.io/cpu-< feature-name > ": "true",
2018-11-30 08:10:02 +00:00
"feature.node.kubernetes.io/iommu-< feature-name > ": "true",
2018-12-20 11:32:31 +00:00
"feature.node.kubernetes.io/kernel-< feature name > ": "< feature value > ",
2018-11-30 08:10:02 +00:00
"feature.node.kubernetes.io/memory-< feature-name > ": "true",
"feature.node.kubernetes.io/network-< feature-name > ": "true",
"feature.node.kubernetes.io/pci-< device label > .present": "true",
"feature.node.kubernetes.io/storage-< feature-name > ": "true",
2018-07-10 09:00:02 +00:00
"feature.node.kubernetes.io/system-< feature name > ": "< feature value > ",
2019-03-28 00:16:54 +00:00
"feature.node.kubernetes.io/< file name > -< feature name > ": "< feature value > "
2016-07-26 05:44:45 +00:00
}
```
2016-08-31 00:04:43 +00:00
The `--sources` flag controls which sources to use for discovery.
2019-05-16 19:49:47 +00:00
_Note: Consecutive runs of nfd-worker will update the labels on a
2016-10-28 21:40:22 +00:00
given node. If features are not discovered on a consecutive run, the corresponding
label will be removed. This includes any restrictions placed on the consecutive run,
such as restricting discovered features with the --label-whitelist option._
2018-07-17 09:26:11 +00:00
### CPU Features
2019-02-19 08:52:46 +00:00
| Feature name | Attribute | Description |
| ----------------------- | ------------------ | ----------------------------- |
| cpuid | < cpuid flag> | CPU capability is supported
2019-08-22 07:18:04 +00:00
| hardware_multithreading | < br > | Hardware multithreading, such as Intel HTT, enabled (number of logical CPUs is greater than physical CPUs)
2019-02-19 08:52:46 +00:00
| power | sst_bf.enabled | Intel SST-BF ([Intel Speed Select Technology][intel-sst] - Base frequency) enabled
2019-08-29 13:11:27 +00:00
| [pstate][intel-pstate] | turbo | Set to 'true' if turbo frequencies are enabled in Intel pstate driver, set to 'false' if they have been disabled.
2019-02-19 08:52:46 +00:00
| [rdt][intel-rdt] | RDTMON | Intel RDT Monitoring Technology
| < br > | RDTCMT | Intel Cache Monitoring (CMT)
| < br > | RDTMBM | Intel Memory Bandwidth Monitoring (MBM)
| < br > | RDTL3CA | Intel L3 Cache Allocation Technology
| < br > | RDTL2CA | Intel L2 Cache Allocation Technology
| < br > | RDTMBA | Intel Memory Bandwidth Allocation (MBA) Technology
2019-05-13 14:10:55 +00:00
The (sub-)set of CPUID attributes to publish is configurable via the
`attributeBlacklist` and `attributeWhitelist` cpuid options of the cpu source.
If whitelist is specified, only whitelisted attributes will be published. With
blacklist, only blacklisted attributes are filtered out. `attributeWhitelist`
has priority over `attributeBlacklist` . For examples and more information
about configurability, see [Configuration Options ](#configuration-options ).
By default, the following CPUID flags have been blacklisted:
BMI1, BMI2, CLMUL, CMOV, CX16, ERMS, F16C, HTT, LZCNT, MMX, MMXEXT, NX, POPCNT,
RDRAND, RDSEED, RDTSCP, SGX, SSE, SSE2, SSE3, SSE4.1, SSE4.2 and SSSE3.
2019-02-19 08:52:46 +00:00
**NOTE** The cpuid features advertise *supported* CPU capabilities, that is, a
capability might be supported but not enabled.
#### X86 CPUID Attributes (Partial List)
| Attribute | Description |
| --------- | ---------------------------------------------------------------- |
| ADX | Multi-Precision Add-Carry Instruction Extensions (ADX)
| AESNI | Advanced Encryption Standard (AES) New Instructions (AES-NI)
| AVX | Advanced Vector Extensions (AVX)
| AVX2 | Advanced Vector Extensions 2 (AVX2)
#### Arm64 CPUID Attribute (Partial List)
| Attribute | Description |
| --------- | ---------------------------------------------------------------- |
| AES | Announcing the Advanced Encryption Standard
| EVSTRM | Event Stream Frequency Features
| FPHP | Half Precision(16bit) Floating Point Data Processing Instructions
| ASIMDHP | Half Precision(16bit) Asimd Data Processing Instructions
| ATOMICS | Atomic Instructions to the A64
| ASIMRDM | Support for Rounding Double Multiply Add/Subtract
| PMULL | Optional Cryptographic and CRC32 Instructions
| JSCVT | Perform Conversion to Match Javascript
| DCPOP | Persistent Memory Support
2018-04-10 06:05:39 +00:00
2018-07-24 15:24:45 +00:00
### IOMMU Features
| Feature name | Description |
| :------------: | :---------------------------------------------------------------------------------: |
| enabled | IOMMU is present and enabled in the kernel
2018-07-09 13:27:24 +00:00
### Kernel Features
2018-07-06 11:11:07 +00:00
| Feature | Attribute | Description |
| ------- | ------------------- | -------------------------------------------- |
| config | < option name> | Kernel config option is enabled (set 'y' or 'm').< br > Default options are `NO_HZ` , `NO_HZ_IDLE` , `NO_HZ_FULL` and `PREEMPT`
2018-12-20 11:32:31 +00:00
| selinux | enabled | Selinux is enabled on the node
2018-07-06 11:11:07 +00:00
| version | full | Full kernel version as reported by `/proc/sys/kernel/osrelease` (e.g. '4.5.6-7-g123abcde')
| < br > | major | First component of the kernel version (e.g. '4')
| < br > | minor | Second component of the kernel version (e.g. '5')
| < br > | revision | Third component of the kernel version (e.g. '6')
Kernel config file to use, and, the set of config options to be detected are
configurable.
See [configuration options ](#configuration-options ) for more information.
2018-07-09 13:27:24 +00:00
2019-02-19 10:55:12 +00:00
### Memory Features
| Feature | Attribute | Description |
| ------- | --------- | ------------------------------------------------------ |
| numa | < br > | Multiple memory nodes i.e. NUMA architecture detected
| nv | present | NVDIMM device(s) are present
2019-05-29 11:45:27 +00:00
| nv | dax | NVDIMM region(s) configured in DAX mode are present
2019-02-19 10:55:12 +00:00
### Network Features
| Feature | Attribute | Description |
| ------- | ---------- | ----------------------------------------------------- |
| sriov | capable | [Single Root Input/Output Virtualization][sriov] (SR-IOV) enabled Network Interface Card(s) present
| < br > | configured | SR-IOV virtual functions have been configured
### PCI Features
2020-02-14 11:22:12 +00:00
| Feature | Attribute | Description |
| -------------------- | ------------- | ----------------------------------------- |
| < device label> | present | PCI device is detected
| < device label> | sriov.capable | [Single Root Input/Output Virtualization][sriov] (SR-IOV) enabled PCI device present
2019-02-19 10:55:12 +00:00
`<device label>` is composed of raw PCI IDs, separated by underscores.
The set of fields used in `<device label>` is configurable, valid fields being
`class` , `vendor` , `device` , `subsystem_vendor` and `subsystem_device` .
Defaults are `class` and `vendor` . An example label using the default
label fields:
```
feature.node.kubernetes.io/pci-1200_8086.present=true
```
Also the set of PCI device classes that the feature source detects is
configurable. By default, device classes (0x)03, (0x)0b40 and (0x)12, i.e.
GPUs, co-processors and accelerator cards are detected.
See [configuration options ](#configuration-options )
for more information on NFD config.
### Storage Features
| Feature name | Description |
| :--------------: | :---------------------------------------------------------------------------------: |
| nonrotationaldisk | Non-rotational disk, like SSD, is present in the node
### System Features
| Feature | Attribute | Description |
| ----------- | ---------------- | --------------------------------------------|
| os_release | ID | Operating system identifier
| < br > | VERSION_ID | Operating system version identifier (e.g. '6.7')
| < br > | VERSION_ID.major | First component of the OS version id (e.g. '6')
| < br > | VERSION_ID.minor | Second component of the OS version id (e.g. '7')
### Feature Detector Hooks (User-specific Features)
2018-07-13 12:55:28 +00:00
2019-03-28 00:16:54 +00:00
NFD has a special feature source named *local* which is designed for getting the
labels from user-specific feature detector. It provides a mechanism for users to
2018-07-13 12:55:28 +00:00
implement custom feature sources in a pluggable way, without modifying nfd
source code or Docker images. The local feature source can be used to advertise
new user-specific features, and, for overriding labels created by the other
feature sources.
2019-03-28 00:16:54 +00:00
The *local* feature source gets its labels by two different ways:
* It tries to execute files found under `/etc/kubernetes/node-feature-discovery/source.d/`
2020-02-11 14:24:28 +00:00
directory. The hook files must be executable and they are supposed to print all
discovered features in `stdout` , one per line. With ELF binaries static
linking is recommended as the selection of system libraries available in the
NFD release image is very limited. Other runtimes currently supported by the
NFD stock image are bash and perl.
2019-03-28 00:16:54 +00:00
* It reads files found under `/etc/kubernetes/node-feature-discovery/features.d/`
directory. The file content is expected to be similar to the hook output (described above).
2018-07-13 12:55:28 +00:00
2019-03-28 00:16:54 +00:00
These directories must be available inside the Docker image so Volumes and
2019-04-20 00:21:38 +00:00
VolumeMounts must be used if standard NFD images are used. The given template
files mount by default the `source.d` and the `features.d` directories
respectively from `/etc/kubernetes/node-feature-discovery/source.d/` and
`/etc/kubernetes/node-feature-discovery/features.d/` from the host. You should
update them to match your needs.
2018-11-26 12:18:05 +00:00
2019-03-28 00:16:54 +00:00
In both cases, the labels can be binary or non binary, using either `<name>` or
`<name>=<value>` format.
Unlike the other feature sources, the name of the file, instead of the name of
2018-11-26 12:18:05 +00:00
the feature source (that would be `local` in this case), is used as a prefix in
2019-03-28 00:16:54 +00:00
the label name, normally. However, if the `<name>` of the label starts with a
slash (`/`) it is used as the label name as is, without any additional prefix.
This makes it possible for the user to fully control the feature label names,
e.g. for overriding labels created by other feature sources.
2018-11-26 12:18:05 +00:00
2019-04-05 22:31:40 +00:00
You can also override the default namespace of your labels using this format:
`<namespace>/<name>[=<value>]` . You must whitelist your namespace using the
`--extra-label-ns` option on the master. In this case, the name of the
file will not be added to the label name. For example, if you want to add the
label `my.namespace.org/my-label=value` , your hook output or file must contains
`my.namespace.org/my-label=value` and you must add
`--extra-label-ns=my.namespace.org` on the master command line.
2019-03-28 00:16:54 +00:00
2018-07-13 12:55:28 +00:00
`stderr` output of the hooks is propagated to NFD log so it can be used for
debugging and logging.
2020-02-11 14:24:28 +00:00
#### Injecting Labels from Other Pods
One use case for the hooks and/or feature files is detecting features in other
Pods outside NFD, e.g. in Kubernetes device plugins. It is possible to mount
the `source.d` and/or `features.d` directories common with the NFD Pod and
deploy the custom hooks/features there. NFD will periodically scan the
directories and run any hooks and read any feature files it finds. The
[example nfd-worker deployment template ](https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/nfd-worker-daemonset.yaml.template#L69 )
contains `hostPath` mounts for `sources.d` and `features.d` directories. By
using the same mounts in the secondary Pod (e.g. device plugin) you have
created a shared area for delivering hooks and feature files to NFD.
#### A Hook Example
2018-07-13 12:55:28 +00:00
User has a shell script
`/etc/kubernetes/node-feature-discovery/source.d/my-source` which has the
following `stdout` output:
```
MY_FEATURE_1
2018-09-21 12:16:41 +00:00
MY_FEATURE_2=myvalue
2018-11-26 12:18:05 +00:00
/override_source-OVERRIDE_BOOL
2019-03-28 00:16:54 +00:00
/override_source-OVERRIDE_VALUE=123
2019-04-05 22:31:40 +00:00
override.namespace/value=456
2019-03-28 00:16:54 +00:00
```
which, in turn, will translate into the following node labels:
```
feature.node.kubernetes.io/my-source-MY_FEATURE_1=true
feature.node.kubernetes.io/my-source-MY_FEATURE_2=myvalue
feature.node.kubernetes.io/override_source-OVERRIDE_BOOL=true
feature.node.kubernetes.io/override_source-OVERRIDE_VALUE=123
2019-04-05 22:31:40 +00:00
override.namespace/value=456
2019-03-28 00:16:54 +00:00
```
2020-02-11 14:24:28 +00:00
#### A File Example
2019-03-28 00:16:54 +00:00
User has a file
`/etc/kubernetes/node-feature-discovery/features.d/my-source` which contains the
following lines:
```
MY_FEATURE_1
MY_FEATURE_2=myvalue
/override_source-OVERRIDE_BOOL
2018-11-26 12:18:05 +00:00
/override_source-OVERRIDE_VALUE=123
2019-04-05 22:31:40 +00:00
override.namespace/value=456
2018-07-13 12:55:28 +00:00
```
which, in turn, will translate into the following node labels:
```
feature.node.kubernetes.io/my-source-MY_FEATURE_1=true
2018-09-21 12:16:41 +00:00
feature.node.kubernetes.io/my-source-MY_FEATURE_2=myvalue
2018-11-26 12:18:05 +00:00
feature.node.kubernetes.io/override_source-OVERRIDE_BOOL=true
feature.node.kubernetes.io/override_source-OVERRIDE_VALUE=123
2019-04-05 22:31:40 +00:00
override.namespace/value=456
2018-07-13 12:55:28 +00:00
```
2019-01-18 11:23:23 +00:00
NFD tries to run any regular files found from the hooks directory. Any
additional data files your hook might need (e.g. a configuration file) should
be placed in a separate directory in order to avoid NFD unnecessarily trying to
execute these. You can use a subdirectory under the hooks directory, for
example `/etc/kubernetes/node-feature-discovery/source.d/conf/` .
2018-07-13 12:55:28 +00:00
**NOTE!** NFD will blindly run any executables placed/mounted in the hooks
directory. It is the user's responsibility to review the hooks for e.g.
possible security implications.
2020-02-11 12:31:10 +00:00
**NOTE!** Be careful when creating and/or updating hook or feature files while
NFD is running. In order to avoid race conditions you should write into a
temporary file (outside the `source.d` and `features.d` directories), and,
atomically create/update the original file by doing a filesystem move
operation.
2016-11-14 23:05:45 +00:00
## Getting started
2019-05-08 11:31:55 +00:00
For a stable version with ready-built images see the
2019-11-21 08:51:37 +00:00
[latest released version ](https://github.com/kubernetes-sigs/node-feature-discovery/tree/v0.5.0 ) ([release notes](https://github.com/kubernetes-sigs/node-feature-discovery/releases/latest)).
2019-05-08 11:31:55 +00:00
If you want to use the latest development version (master branch) you need to
[build your own custom image ](#building-from-source ).
2016-11-14 23:05:45 +00:00
### System requirements
2016-07-12 23:44:03 +00:00
2018-04-10 06:05:39 +00:00
1. Linux (x86_64/Arm64)
2019-05-08 11:44:16 +00:00
1. [kubectl][kubectl-setup] (properly set up and configured to work with your
2016-07-19 22:35:42 +00:00
Kubernetes cluster)
2019-05-08 11:44:16 +00:00
1. [Docker][docker-down] (only required to build and push docker images)
2016-07-12 23:44:03 +00:00
### Usage
2019-02-01 15:08:39 +00:00
#### nfd-master
2019-05-28 14:13:52 +00:00
Nfd-master runs as a DaemonSet, by default in the master node(s)
only. You can use the template spec provided to deploy nfd-master, or
use `nfd-master.yaml` generated by `Makefile` . The latter includes
`image:` and `namespace:` definitions that match the latest built
image. Example:
```
make IMAGE_TAG=< IMAGE_TAG >
docker push < IMAGE_TAG >
2019-05-08 11:31:55 +00:00
kubectl create -f nfd-master.yaml
2019-02-01 15:08:39 +00:00
```
Nfd-master listens for connections from nfd-worker(s) and connects to the
2019-05-28 14:13:52 +00:00
Kubernetes API server to add node labels advertised by them.
2019-02-01 15:08:39 +00:00
If you have RBAC authorization enabled (as is the default e.g. with clusters
initialized with kubeadm) you need to configure the appropriate ClusterRoles,
ClusterRoleBindings and a ServiceAccount in order for NFD to create node
labels. The provided template will configure these for you.
#### nfd-worker
Nfd-worker is preferably run as a Kubernetes DaemonSet. There is an
2019-05-28 14:13:52 +00:00
example spec (`nfd-worker-daemonset.yaml.template`) that can be used
as a template, or, as is when just trying out the service. Similarly
to nfd-master above, the `Makefile` also generates
`nfd-worker-daemonset.yaml` from the template that you can use to
deploy the latest image. Example:
```
make IMAGE_TAG=< IMAGE_TAG >
docker push < IMAGE_TAG >
2019-05-08 11:31:55 +00:00
kubectl create -f nfd-worker-daemonset.yaml
2018-04-11 16:33:06 +00:00
```
2019-02-01 15:08:39 +00:00
Nfd-worker connects to the nfd-master service to advertise hardware features.
2018-06-14 16:08:25 +00:00
2018-04-11 16:33:06 +00:00
When run as a daemonset, nodes are re-labeled at an interval specified using
2019-02-01 15:08:39 +00:00
the `--sleep-interval` option. In the [template ](https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/nfd-worker-daemonset.yaml.template#L26 ) the default interval is set to 60s
2018-04-11 16:33:06 +00:00
which is also the default when no `--sleep-interval` is specified.
Feature discovery can alternatively be configured as a one-shot job. There is
2018-02-23 10:53:22 +00:00
an example script in this repo that demonstrates how to deploy the job in the cluster.
2016-07-12 00:30:49 +00:00
```
2019-05-28 14:13:52 +00:00
./label-nodes.sh [< IMAGE_TAG > ]
2016-07-12 00:30:49 +00:00
```
2018-02-23 10:53:22 +00:00
The label-nodes.sh script tries to launch as many jobs as there are Ready nodes.
Note that this approach does not guarantee running once on every node.
For example, if some node is tainted NoSchedule or fails to start a job for some other reason, then some other node will run extra job instance(s) to satisfy the request and the tainted/failed node does not get labeled.
2016-09-23 18:08:40 +00:00
2019-02-01 15:08:39 +00:00
#### nfd-master and nfd-worker in the same Pod
2019-05-14 17:53:57 +00:00
You can also run nfd-master and nfd-worker inside a single pod (skip the `sed`
part if running the latest released version):
2019-02-01 15:08:39 +00:00
```
2019-05-14 18:15:01 +00:00
sed -E s',^(\s*)image:.+$,\1image: < YOUR_IMAGE_REPO > :< YOUR_IMAGE_TAG > ,' nfd-daemonset-combined.yaml.template > nfd-daemonset-combined.yaml
2019-05-08 11:31:55 +00:00
kubectl apply -f nfd-daemonset-combined.yaml
2019-02-01 15:08:39 +00:00
```
Similar to the nfd-worker setup above, this creates a DaemonSet that schedules
an NFD Pod an all worker nodes, with the difference that the Pod also also
contains an nfd-master instance. In this case no nfd-master service is run on
the master node(s), but, the worker nodes are able to label themselves.
This may be desirable e.g. in single-node setups.
#### TLS authentication
NFD supports mutual TLS authentication between the nfd-master and nfd-worker
instances. That is, nfd-worker and nfd-master both verify that the other end
presents a valid certificate.
TLS authentication is enabled by specifying `--ca-file` , `--key-file` and
`--cert-file` args, on both the nfd-master and nfd-worker instances.
The template specs provided with NFD contain (commented out) example
configuration for enabling TLS authentication.
The Common Name (CN) of the nfd-master certificate must match the DNS name of
the nfd-master Service of the cluster. By default, nfd-master only check that
the nfd-worker has been signed by the specified root certificate (--ca-file).
Additional hardening can be enabled by specifying --verify-node-name in
nfd-master args, in which case nfd-master verifies that the NodeName presented
by nfd-worker matches the Common Name (CN) of its certificate. This means that
each nfd-worker requires a individual node-specific TLS certificate.
#### Usage demo
2019-05-20 15:02:39 +00:00
[![asciicast ](https://asciinema.org/a/247316.svg )](https://asciinema.org/a/247316)
2016-07-12 23:44:03 +00:00
2018-09-21 08:26:57 +00:00
### Configuration options
2018-07-06 11:11:07 +00:00
2019-02-01 15:08:39 +00:00
Nfd-worker supports a configuration file. The default location is
`/etc/kubernetes/node-feature-discovery/nfd-worker.conf` , but,
2018-07-06 11:11:07 +00:00
this can be changed by specifying the`--config` command line flag. The file is
2019-02-01 15:08:39 +00:00
read inside the container, and thus, Volumes and VolumeMounts are needed to
2018-07-06 11:11:07 +00:00
make your configuration available for NFD. The preferred method is to use a
ConfigMap.
For example, create a config map using the example config as a template:
```
2019-02-01 15:08:39 +00:00
cp nfd-worker.conf.example nfd-worker.conf
vim nfd-worker.conf # edit the configuration
kubectl create configmap nfd-worker-config --from-file=nfd-worker.conf
2018-07-06 11:11:07 +00:00
```
Then, configure Volumes and VolumeMounts in the Pod spec (just the relevant
snippets shown below):
```
...
containers:
volumeMounts:
2019-02-01 15:08:39 +00:00
- name: nfd-worker-config
2018-07-06 11:11:07 +00:00
mountPath: "/etc/kubernetes/node-feature-discovery/"
...
volumes:
2019-02-01 15:08:39 +00:00
- name: nfd-worker-config
2018-07-06 11:11:07 +00:00
configMap:
2019-02-01 15:08:39 +00:00
name: nfd-worker-config
2018-07-06 11:11:07 +00:00
...
```
You could also use other types of volumes, of course. That is, hostPath if
different config for different nodes would be required, for example.
The (empty-by-default)
2019-02-01 15:08:39 +00:00
[example config ](https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/nfd-worker.conf.example )
2018-09-21 08:26:57 +00:00
is used as a config in the NFD Docker image. Thus, this can be used as a default
2018-07-06 11:11:07 +00:00
configuration in custom-built images.
2018-09-21 08:26:57 +00:00
Configuration options can also be specified via the `--options` command line
flag, in which case no mounts need to be used. The same format as in the config
2018-09-21 10:25:47 +00:00
file must be used, i.e. JSON (or YAML). For example:
```
--options='{"sources": { "pci": { "deviceClassWhitelist": ["12"] } } }'
```
2018-09-21 08:26:57 +00:00
Configuration options specified from the command line will override those read
from the config file.
2018-09-21 10:25:47 +00:00
Currently, the only available configuration options are related to the
2019-05-13 14:10:55 +00:00
[CPU ](#cpu-features ), [PCI ](#pci-features ) and [Kernel ](#kernel-features )
feature sources.
2018-09-21 10:25:47 +00:00
2016-07-12 23:44:03 +00:00
## Building from source
2018-11-16 12:26:33 +00:00
**Download the source code:**
2016-07-12 23:44:03 +00:00
2016-07-12 00:30:49 +00:00
```
2018-11-28 11:51:43 +00:00
git clone https://github.com/kubernetes-sigs/node-feature-discovery
2016-07-12 00:30:49 +00:00
```
2018-11-16 12:26:33 +00:00
**Build the container image:**< br >
See [customizing the build ](#customizing-the-build ) below for altering the
container image registry, for example.
2016-07-12 00:30:49 +00:00
```
2016-07-12 23:44:03 +00:00
cd < project-root >
2016-07-19 22:35:42 +00:00
make
2016-07-12 00:30:49 +00:00
```
2016-07-12 23:44:03 +00:00
2018-11-16 12:26:33 +00:00
**Push the container image:**< br >
Optional, this example with Docker.
2016-07-19 22:35:42 +00:00
2018-09-12 13:40:56 +00:00
```
2019-05-28 14:13:52 +00:00
docker push < IMAGE_TAG >
2016-07-12 00:30:49 +00:00
```
2016-07-18 19:35:38 +00:00
**Change the job spec to use your custom image (optional):**
2016-07-12 23:44:03 +00:00
To use your published image from the step above instead of the
2019-02-01 15:08:39 +00:00
`quay.io/kubernetes_incubator/node-feature-discovery` image, edit `image`
attribute in the spec template(s) to the new location
(`< quay-domain-name > /< registry-user > /< image-name > [:< version > ]`).
2016-07-12 23:44:03 +00:00
2018-11-16 12:26:33 +00:00
### Customizing the Build
There are several Makefile variables that control the build process and the
name of the resulting container image.
2018-11-16 13:32:48 +00:00
| Variable | Description | Default value
| ---------------------- | -------------------------------------------- | ----------- |
| IMAGE_BUILD_CMD | Command to build the image | docker build
| IMAGE_BUILD_EXTRA_OPTS | Extra options to pass to build command | *empty*
| IMAGE_PUSH_CMD | Command to push the image to remote registry | docker push
| IMAGE_REGISTRY | Container image registry to use | quay.io/kubernetes_incubator
| IMAGE_NAME | Container image name | node-feature-discovery
| IMAGE_TAG_NAME | Container image tag name | < nfd version>
| IMAGE_REPO | Container image repository to use | < IMAGE_REGISTRY> /< IMAGE_NAME>
| IMAGE_TAG | Full image:tag to tag the image with | < IMAGE_REPO> /< IMAGE_NAME>
| K8S_NAMESPACE | nfd-master and nfd-worker namespace | kube-system
2018-11-16 15:08:51 +00:00
| KUBECONFIG | Kubeconfig for running e2e-tests | *empty*
2018-11-16 12:26:33 +00:00
For example, to use a custom registry:
```
make IMAGE_REGISTRY=< my custom registry uri >
```
Or to specify a build tool different from Docker:
```
make IMAGE_BUILD_CMD="buildah bud"
```
2019-06-27 03:31:32 +00:00
### Testing
Unit tests are automatically run as part of the container image build. You can
also run them manually in the source code tree by simply running:
```
make test
```
End-to-end tests are built on top of the e2e test framework of Kubernetes, and,
they required a cluster to run them on. For running the tests on your test
cluster you need to specify the kubeconfig to be used:
```
make e2e-test KUBECONFIG=$HOME/.kube/config
```
2016-07-14 14:56:43 +00:00
## Targeting Nodes with Specific Features
2016-07-19 22:35:42 +00:00
Nodes with specific features can be targeted using the `nodeSelector` field. The
following example shows how to target nodes with Intel TurboBoost enabled.
2016-07-14 14:56:43 +00:00
2018-09-27 11:54:45 +00:00
```yaml
apiVersion: v1
kind: Pod
metadata:
labels:
env: test
name: golang-test
spec:
containers:
- image: golang
name: go1
nodeSelector:
2019-02-19 08:52:46 +00:00
feature.node.kubernetes.io/cpu-pstate.turbo: 'true'
2016-07-14 14:56:43 +00:00
```
For more details on targeting nodes, see [node selection][node-sel].
2016-08-31 00:04:43 +00:00
## References
2016-08-01 04:35:52 +00:00
Github issues
- [#28310 ](https://github.com/kubernetes/kubernetes/issues/28310 )
- [#28311 ](https://github.com/kubernetes/kubernetes/issues/28311 )
- [#28312 ](https://github.com/kubernetes/kubernetes/issues/28312 )
[Design proposal ](https://docs.google.com/document/d/1uulT2AjqXjc_pLtDu0Kw9WyvvXm-WAZZaSiUziKsr68/edit )
2018-11-28 11:51:43 +00:00
## Governance
2016-08-31 20:19:42 +00:00
2018-11-28 11:51:43 +00:00
This is a [SIG-node ](https://github.com/kubernetes/community/blob/master/sig-node/README.md )
subproject, hosted under the
[Kubernetes SIGs ](https://github.com/kubernetes-sigs ) organization in
Github. The project was established in 2016 as a
[Kubernetes Incubator ](https://github.com/kubernetes/community/blob/master/incubator.md )
project and migrated to Kubernetes SIGs in 2018.
2016-07-14 14:56:43 +00:00
2016-07-23 05:13:48 +00:00
## License
This is open source software released under the [Apache 2.0 License ](LICENSE ).
2016-07-26 05:44:45 +00:00
2016-09-23 18:08:40 +00:00
## Demo
2019-05-28 14:13:52 +00:00
A demo on the benefits of using node feature discovery can be found in [demo ](demo/ ).
2016-09-23 18:08:40 +00:00
2016-07-26 05:44:45 +00:00
<!-- Links -->
[cpuid]: http://man7.org/linux/man-pages/man4/cpuid.4.html
[intel-rdt]: http://www.intel.com/content/www/us/en/architecture-and-technology/resource-director-technology.html
[intel-pstate]: https://www.kernel.org/doc/Documentation/cpu-freq/intel-pstate.txt
2019-04-12 11:30:53 +00:00
[intel-sst]: https://www.intel.com/content/www/us/en/architecture-and-technology/speed-select-technology-article.html
2017-11-28 14:47:11 +00:00
[sriov]: http://www.intel.com/content/www/us/en/pci-express/pci-sig-sr-iov-primer-sr-iov-technology-paper.html
2019-05-08 11:44:16 +00:00
[docker-down]: https://docs.docker.com/install
2016-07-19 22:35:42 +00:00
[golang-down]: https://golang.org/dl
[gcc-down]: https://gcc.gnu.org
2019-05-08 11:44:16 +00:00
[kubectl-setup]: https://kubernetes.io/docs/tasks/tools/install-kubectl
2016-07-19 22:35:42 +00:00
[node-sel]: http://kubernetes.io/docs/user-guide/node-selection