2020-09-08 20:16:17 +03:00
---
2021-03-09 13:38:09 +02:00
title: "Deployment and usage"
2020-09-08 20:16:17 +03:00
layout: default
sort: 3
---
2021-03-09 13:38:09 +02:00
# Deployment and usage
2021-02-25 13:49:02 +02:00
2020-09-08 20:16:17 +03:00
{: .no_toc }
2021-03-09 13:38:09 +02:00
## Table of contents
2021-02-25 13:49:02 +02:00
2020-09-08 20:16:17 +03:00
{: .no_toc .text-delta }
1. TOC
{:toc}
---
## Requirements
1. Linux (x86_64/Arm64/Arm)
2020-10-01 15:37:34 +03:00
1. [kubectl ](https://kubernetes.io/docs/tasks/tools/install-kubectl )
2020-09-08 20:16:17 +03:00
(properly set up and configured to work with your Kubernetes cluster)
2021-03-09 13:02:07 +02:00
## Image variants
NFD currently offers two variants of the container image. The "full" variant is
currently deployed by default.
### Full
This image is based on
[debian:buster-slim ](https://hub.docker.com/_/debian ) and contains a full Linux
system for running shell-based nfd-worker hooks and doing live debugging and
diagnosis of the NFD images.
### Minimal
This is a minimal image based on
[gcr.io/distroless/base ](https://github.com/GoogleContainerTools/distroless/blob/master/base/README.md )
and only supports running statically linked binaries.
The container image tag has suffix `-minimal`
(e.g. `{{ site.container_image }}-minimal` )
2020-10-01 15:37:34 +03:00
## Deployment options
### Operator
2020-10-01 17:09:33 +03:00
Deployment using the
[Node Feature Discovery Operator][nfd-operator]
is recommended to be done via
[operatorhub.io ](https://operatorhub.io/operator/nfd-operator ).
1. You need to have
[OLM][OLM]
installed. If you don't, take a look at the
[latest release ](https://github.com/operator-framework/operator-lifecycle-manager/releases/latest )
for detailed instructions.
1. Install the operator:
2021-02-25 13:49:02 +02:00
```bash
kubectl create -f https://operatorhub.io/install/nfd-operator.yaml
```
2020-10-01 17:09:33 +03:00
1. Create NodeFeatureDiscovery resource (in `nfd` namespace here):
2021-02-25 13:49:02 +02:00
```bash
cat < < EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: nfd
---
apiVersion: nfd.kubernetes.io/v1alpha1
kind: NodeFeatureDiscovery
metadata:
name: my-nfd-deployment
namespace: nfd
EOF
```
2020-10-01 15:37:34 +03:00
2021-03-10 14:06:49 +02:00
In order to deploy the [minimal ](#minimal ) image you need to add
```yaml
image: {{ site.container_image }}-minimal
```
to the metadata of NodeFeatureDiscovery object above.
2021-03-09 13:38:09 +02:00
### Deployment templates
2020-10-01 15:37:34 +03:00
The template specs provided in the repo can be used directly:
```bash
2020-10-08 20:15:26 +03:00
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-master.yaml.template
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-worker-daemonset.yaml.template
2020-10-01 15:37:34 +03:00
```
This will required RBAC rules and deploy nfd-master (as a deployment) and
nfd-worker (as a daemonset) in the `node-feature-discovery` namespace.
Alternatively you can download the templates and customize the deployment
2021-03-10 14:06:49 +02:00
manually. For example, to deploy the [minimal ](#minimal ) image.
2020-10-01 15:37:34 +03:00
2021-03-09 13:38:09 +02:00
#### Master-worker pod
2020-10-01 15:37:34 +03:00
You can also run nfd-master and nfd-worker inside the same pod
```bash
2020-10-08 20:15:26 +03:00
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-daemonset-combined.yaml.template
2020-10-01 15:37:34 +03:00
```
This creates a DaemonSet runs both nfd-worker and nfd-master in the same Pod.
In this case no nfd-master is run on the master node(s), but, the worker nodes
are able to label themselves which may be desirable e.g. in single-node setups.
2021-03-09 13:38:09 +02:00
#### Worker one-shot
2020-10-01 15:37:34 +03:00
Feature discovery can alternatively be configured as a one-shot job.
The Job template may be used to achieve this:
```bash
NUM_NODES=$(kubectl get no -o jsonpath='{.items[*].metadata.name}' | wc -w)
2020-10-08 20:15:26 +03:00
curl -fs https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-worker-job.yaml.template | \
2020-10-01 15:37:34 +03:00
sed s"/NUM_NODES/$NUM_NODES/" | \
kubectl apply -f -
```
The example above launces as many jobs as there are non-master nodes. Note that
this approach does not guarantee running once on every node. For example,
tainted, non-ready nodes or some other reasons in Job scheduling may cause some
node(s) will run extra job instance(s) to satisfy the request.
2021-04-13 10:09:43 +03:00
### Deployment with Helm
2020-12-16 17:27:31 +00:00
Node Feature Discovery Helm chart allow to easily deploy and manage NFD.
#### Prerequisites
[Helm package manager ](https://helm.sh/ ) should be installed.
2021-02-25 13:49:02 +02:00
#### Deployment
2020-12-16 17:27:31 +00:00
2021-03-16 08:00:45 +02:00
To install the latest stable version:
```bash
export NFD_NS=node-feature-discovery
2021-04-13 10:09:43 +03:00
helm repo add nfd https://kubernetes-sigs.github.io/node-feature-discovery/charts
2021-03-16 08:00:45 +02:00
helm repo update
helm install nfd/node-feature-discovery --namespace $NFD_NS --create-namespace --generate-name
```
To install the latest development version you need to clone the NFD Git
repository and install from there.
2020-12-16 17:27:31 +00:00
```bash
git clone https://github.com/kubernetes-sigs/node-feature-discovery/
cd node-feature-discovery/deployment
export NFD_NS=node-feature-discovery
helm install node-feature-discovery ./node-feature-discovery/ --namespace $NFD_NS --create-namespace
```
2021-03-16 08:00:45 +02:00
See the [configuration ](#configuration ) section below for instructions how to
alter the deployment parameters.
2020-12-16 17:27:31 +00:00
2021-03-10 14:06:49 +02:00
In order to deploy the [minimal ](#minimal ) image you need to override the image
tag:
```bash
helm install node-feature-discovery ./node-feature-discovery/ --set image.tag={{ site.release }}-minimal --namespace $NFD_NS --create-namespace
```
2020-12-16 17:27:31 +00:00
#### Configuration
You can override values from `values.yaml` and provide a file with custom values:
```bash
export NFD_NS=node-feature-discovery
2021-03-16 08:00:45 +02:00
helm install nfd/node-feature-discovery -f < path / to / custom / values . yaml > --namespace $NFD_NS --create-namespace
2020-12-16 17:27:31 +00:00
```
To specify each parameter separately you can provide them to helm install command:
```bash
export NFD_NS=node-feature-discovery
2021-03-16 08:00:45 +02:00
helm install nfd/node-feature-discovery --set nameOverride=NFDinstance --set master.replicaCount=2 --namespace $NFD_NS --create-namespace
2020-12-16 17:27:31 +00:00
```
2021-03-09 13:38:09 +02:00
#### Uninstalling the chart
2020-12-16 17:27:31 +00:00
To uninstall the `node-feature-discovery` deployment:
```bash
export NFD_NS=node-feature-discovery
helm uninstall node-feature-discovery --namespace $NFD_NS
```
2021-02-25 13:49:02 +02:00
The command removes all the Kubernetes components associated with the chart and
deletes the release.
2020-12-16 17:27:31 +00:00
2021-03-09 13:38:09 +02:00
#### Chart parameters
2020-12-16 17:27:31 +00:00
In order to tailor the deployment of the Node Feature Discovery to your cluster needs
We have introduced the following Chart parameters.
##### General parameters
| Name | Type | Default | description |
| ---- | ---- | ------- | ----------- |
2021-03-10 14:16:49 +02:00
| `image.repository` | string | `{{ site.container_image | split: ":" | first }}` | NFD image repository |
2021-03-10 14:10:23 +02:00
| `image.tag` | string | `{{ site.release }}` | NFD image tag |
2020-12-16 17:27:31 +00:00
| `image.pullPolicy` | string | `Always` | Image pull policy |
| `imagePullSecrets` | list | [] | ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec. If specified, these secrets will be passed to individual puller implementations for them to use. For example, in the case of docker, only DockerConfig type secrets are honored. [https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod ](More info ) |
| `serviceAccount.create` | bool | true | Specifies whether a service account should be created |
| `serviceAccount.annotations` | dict | {} | Annotations to add to the service account |
| `serviceAccount.name` | string | | The name of the service account to use. If not set and create is true, a name is generated using the fullname template |
| `rbac` | dict | | RBAC [parameteres ](https://kubernetes.io/docs/reference/access-authn-authz/rbac/ ) |
| `nameOverride` | string | | Override the name of the chart |
| `fullnameOverride` | string | | Override a default fully qualified app name |
##### Master pod parameters
2021-03-18 15:31:41 +00:00
| Name | Type | Default | description |
| ---- | ---- | ------- | ----------- |
2020-12-16 17:27:31 +00:00
| `master.*` | dict | | NFD master deployment configuration |
2021-02-19 14:24:43 +02:00
| `master.instance` | string | | Instance name. Used to separate annotation namespaces for multiple parallel deployments |
2020-12-16 17:27:31 +00:00
| `master.replicaCount` | integer | 1 | Number of desired pods. This is a pointer to distinguish between explicit zero and not specified |
| `master.podSecurityContext` | dict | {} | SecurityContext holds pod-level security attributes and common container settings |
| `master.service.type` | string | ClusterIP | NFD master service type |
| `master.service.port` | integer | port | NFD master service port |
| `master.resources` | dict | {} | NFD master pod [resources management ](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ ) |
| `master.nodeSelector` | dict | {} | NFD master pod [node selector ](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector ) |
| `master.tolerations` | dict | _Scheduling to master node is disabled_ | NFD master pod [tolerations ](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/ ) |
| `master.annotations` | dict | {} | NFD master pod [metadata ](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ ) |
| `master.affinity` | dict | | NFD master pod required [node affinity ](https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/ ) |
##### Worker pod parameters
2021-03-18 15:31:41 +00:00
| Name | Type | Default | description |
| ---- | ---- | ------- | ----------- |
2020-12-16 17:27:31 +00:00
| `worker.*` | dict | | NFD master daemonset configuration |
| `worker.configmapName` | string | `nfd-worker-conf` | NFD worker pod ConfigMap name |
| `worker.config` | string | `` | NFD worker service configuration |
| `worker.podSecurityContext` | dict | {} | SecurityContext holds pod-level security attributes and common container settings |
| `worker.securityContext` | dict | {} | Container [security settings ](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod ) |
| `worker.resources` | dict | {} | NFD worker pod [resources management ](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ ) |
| `worker.nodeSelector` | dict | {} | NFD worker pod [node selector ](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#nodeselector ) |
| `worker.tolerations` | dict | {} | NFD worker pod [node tolerations ](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/ ) |
| `worker.annotations` | dict | {} | NFD worker pod [metadata ](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ ) |
2021-03-09 13:38:09 +02:00
### Build your own
2020-10-01 15:37:34 +03:00
If you want to use the latest development version (master branch) you need to
build your own custom image.
2020-11-02 10:48:17 +02:00
See the [Developer Guide ](../advanced/developer-guide ) for instructions how to
2020-10-01 15:37:34 +03:00
build images and deploy them on your cluster.
2020-09-08 20:16:17 +03:00
## Usage
2020-10-20 20:50:46 +03:00
### NFD-Master
2020-09-08 20:16:17 +03:00
2020-10-20 20:50:46 +03:00
NFD-Master runs as a deployment (with a replica count of 1), by default
2020-09-08 20:16:17 +03:00
it prefers running on the cluster's master nodes but will run on worker
nodes if no master nodes are found.
For High Availability, you should simply increase the replica count of
2020-10-01 15:37:34 +03:00
the deployment object. You should also look into adding
[inter-pod ](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity )
2020-09-08 20:16:17 +03:00
affinity to prevent masters from running on the same node.
However note that inter-pod affinity is costly and is not recommended
in bigger clusters.
2020-10-20 20:50:46 +03:00
NFD-Master listens for connections from nfd-worker(s) and connects to the
2020-09-08 20:16:17 +03:00
Kubernetes API server to add node labels advertised by them.
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.
2020-10-20 20:50:46 +03:00
### NFD-Worker
2020-09-08 20:16:17 +03:00
2020-10-01 15:37:34 +03:00
NFD-Worker is preferably run as a Kubernetes DaemonSet. This assures
re-labeling on regular intervals capturing changes in the system configuration
and mames sure that new nodes are labeled as they are added to the cluster.
Worker connects to the nfd-master service to advertise hardware features.
2020-09-08 20:16:17 +03:00
When run as a daemonset, nodes are re-labeled at an interval specified using
2021-02-24 14:29:07 +02:00
the `-sleep-interval` option. In the
2021-02-25 13:49:02 +02:00
[template ](https://github.com/kubernetes-sigs/node-feature-discovery/blob/{{site.release}}/nfd-worker-daemonset.yaml.template#L26 )
2020-09-08 20:16:17 +03:00
the default interval is set to 60s which is also the default when no
2021-02-24 14:29:07 +02:00
`-sleep-interval` is specified. Also, the configuration file is re-read on
2020-09-08 20:16:17 +03:00
each iteration providing a simple mechanism of run-time reconfiguration.
2021-03-09 13:38:09 +02:00
### Communication security with TLS
2020-09-08 20:16:17 +03:00
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.
2021-02-24 14:29:07 +02:00
TLS authentication is enabled by specifying `-ca-file` , `-key-file` and
`-cert-file` args, on both the nfd-master and nfd-worker instances.
2020-09-08 20:16:17 +03:00
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
2021-02-24 14:29:07 +02:00
the nfd-worker has been signed by the specified root certificate (-ca-file).
Additional hardening can be enabled by specifying -verify-node-name in
2020-09-08 20:16:17 +03:00
nfd-master args, in which case nfd-master verifies that the NodeName presented
2021-04-20 09:44:32 +01:00
by nfd-worker matches the Common Name (CN) or a Subject Alternative Name (SAN)
of its certificate.
2020-09-08 20:16:17 +03:00
2020-11-10 09:12:34 +02:00
#### Automated TLS certificate management using cert-manager
[cert-manager ](https://cert-manager.io/ ) can be used to automate certificate
management between nfd-master and the nfd-worker pods. The instructions below describe
steps how to set up cert-manager's
[CA Issuer ](https://cert-manager.io/docs/configuration/ca/ ) to
sign `Certificate` requests for NFD components in `node-feature-discovery` namespace.
```bash
$ kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.2.0/cert-manager.yaml
$ make yamls
$ openssl genrsa -out ca.key 2048
$ openssl req -x509 -new -nodes -key ca.key -subj "/CN=nfd-ca" -days 10000 -out ca.crt
$ sed s"/tls.key:.*/tls.key: $(cat ca.key|base64 -w 0)/" -i nfd-cert-manager.yaml
$ sed s"/tls.crt:.*/tls.crt: $(cat ca.crt|base64 -w 0)/" -i nfd-cert-manager.yaml
$ kubectl apply -f nfd-cert-manager.yaml
```
Finally, deploy `nfd-master.yaml` and `nfd-worker-daemonset.yaml` with the Secrets
(`nfd-master-cert` and `nfd-worker-cert` ) mounts enabled.
2021-03-09 13:38:09 +02:00
## Worker configuration
2020-09-08 20:16:17 +03:00
2021-02-05 12:06:43 +02:00
NFD-Worker supports dynamic configuration through a configuration file. The
default location is `/etc/kubernetes/node-feature-discovery/nfd-worker.conf` ,
2021-02-24 14:29:07 +02:00
but, this can be changed by specifying the`-config` command line flag.
2021-02-05 12:06:43 +02:00
Configuration file is re-read whenever it is modified which makes run-time
re-configuration of nfd-worker straightforward.
2020-09-08 20:16:17 +03:00
Worker configuration file is read inside the container, and thus, Volumes and
VolumeMounts are needed to make your configuration available for NFD. The
preferred method is to use a ConfigMap which provides easy deployment and
2020-11-18 11:35:20 +02:00
re-configurability.
2020-10-01 15:37:34 +03:00
2020-11-18 11:35:20 +02:00
The provided nfd-worker deployment templates create an empty configmap and
mount it inside the nfd-worker containers. Configuration can be edited with:
2020-10-01 15:37:34 +03:00
2021-02-25 13:49:02 +02:00
```bash
2020-11-18 11:35:20 +02:00
kubectl -n ${NFD_NS} edit configmap nfd-worker-conf
```
2020-09-08 20:16:17 +03:00
2021-02-05 12:06:43 +02:00
See
[nfd-worker configuration file reference ](../advanced/worker-configuration-reference.md )
for more details.
2020-09-08 20:16:17 +03:00
The (empty-by-default)
2021-02-25 13:49:02 +02:00
[example config ](https://github.com/kubernetes-sigs/node-feature-discovery/blob/{{site.release}}/nfd-worker.conf.example )
2020-11-18 11:35:20 +02:00
contains all available configuration options and can be used as a reference
for creating creating a configuration.
2020-09-08 20:16:17 +03:00
2021-02-24 14:29:07 +02:00
Configuration options can also be specified via the `-options` command line
2020-09-08 20:16:17 +03:00
flag, in which case no mounts need to be used. The same format as in the config
file must be used, i.e. JSON (or YAML). For example:
2020-10-01 15:37:34 +03:00
2021-02-25 13:49:02 +02:00
```bash
2021-02-24 14:29:07 +02:00
-options='{"sources": { "pci": { "deviceClassWhitelist": ["12"] } } }'
2020-09-08 20:16:17 +03:00
```
2020-10-01 15:37:34 +03:00
2020-09-08 20:16:17 +03:00
Configuration options specified from the command line will override those read
from the config file.
2021-03-09 13:38:09 +02:00
## Using node labels
2020-09-08 20:16:17 +03:00
Nodes with specific features can be targeted using the `nodeSelector` field. The
following example shows how to target nodes with Intel TurboBoost enabled.
```yaml
apiVersion: v1
kind: Pod
metadata:
labels:
env: test
name: golang-test
spec:
containers:
- image: golang
name: go1
nodeSelector:
feature.node.kubernetes.io/cpu-pstate.turbo: 'true'
```
For more details on targeting nodes, see
2020-11-02 10:48:17 +02:00
[node selection ](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ ).
2020-09-08 20:16:17 +03:00
## Uninstallation
2021-03-09 13:38:09 +02:00
### Operator was used for deployment
2020-10-01 17:09:33 +03:00
If you followed the deployment instructions above you can simply do:
```bash
kubectl -n nfd delete NodeFeatureDiscovery my-nfd-deployment
```
Optionally, you can also remove the namespace:
```bash
kubectl delete ns nfd
```
See the [node-feature-discovery-operator][nfd-operator] and [OLM][OLM] project
documentation for instructions for uninstalling the operator and operator
lifecycle manager, respectively.
### Manual
2020-12-03 14:36:42 +02:00
Simplest way is to invoke `kubectl delete` on the deployment files you used.
Beware that this will also delete the namespace that NFD is running in. For
example:
```bash
kubectl delete -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-worker-daemonset.yaml.template
kubectl delete -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-master.yaml.template
```
Alternatively you can delete create objects one-by-one, depending on the type
of deployment, for example:
2020-10-01 17:09:33 +03:00
```bash
NFD_NS=node-feature-discovery
kubectl -n $NFD_NS delete ds nfd-worker
kubectl -n $NFD_NS delete deploy nfd-master
kubectl -n $NFD_NS delete svc nfd-master
kubectl -n $NFD_NS delete sa nfd-master
kubectl delete clusterrole nfd-master
kubectl delete clusterrolebinding nfd-master
```
2021-03-09 13:38:09 +02:00
### Removing feature labels
2020-10-01 17:09:33 +03:00
2021-02-24 14:29:07 +02:00
NFD-Master has a special `-prune` command line flag for removing all
2020-10-01 17:09:33 +03:00
nfd-related node labels, annotations and extended resources from the cluster.
```bash
2020-10-08 20:15:26 +03:00
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-prune.yaml.template
2020-10-01 17:09:33 +03:00
kubectl -n node-feature-discovery wait job.batch/nfd-prune --for=condition=complete & & \
2020-12-03 14:41:54 +02:00
kubectl delete -f kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/node-feature-discovery/{{ site.release }}/nfd-prune.yaml.template
2020-10-01 17:09:33 +03:00
```
**NOTE:** You must run prune before removing the RBAC rules (serviceaccount,
clusterrole and clusterrolebinding).
<!-- Links -->
[nfd-operator]: https://github.com/kubernetes-sigs/node-feature-discovery-operator
[OLM]: https://github.com/operator-framework/operator-lifecycle-manager