1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-07 01:07:05 +00:00
node-feature-discovery/master/advanced/developer-guide.html

78 lines
28 KiB
HTML
Raw Normal View History

<!DOCTYPE html> <html lang="en" dir="auto"> <head><meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5, user-scalable=no"> <meta name="description" content="Developer guide Table of contents Building from source Download the source code Docker build Deployment Building locally Customizing the build Test..."> <meta name="revised" content=""> <meta name="author" content="Kubernetes SIGs"> <meta name="generator" content="rundocs/jekyll-rtd-theme v2.0.10"><meta name="theme-color" content="#2980b9"> <title>Developer guide · Node Feature Discovery</title> <meta name="twitter:title" content="Developer guide · Node Feature Discovery"> <meta name="twitter:description" content="Developer guide Table of contents Building from source Download the source code Docker build Deployment Building locally Customizing the build Test..."> <meta name="twitter:card" content="summary"> <meta name="twitter:site" content="@Kubernetes SIGs"> <meta name="twitter:url" content="https://kubernetes-sigs.github.com/node-feature-discovery/master/advanced/developer-guide.html"> <meta name="twitter:creator" content="@rundocs/jekyll-rtd-theme v2.0.10"> <meta property="og:title" content="Developer guide · Node Feature Discovery"> <meta property="og:description" content="Developer guide Table of contents Building from source Download the source code Docker build Deployment Building locally Customizing the build Test..."> <meta property="og:locale" content="en"> <meta property="og:url" content="https://kubernetes-sigs.github.com/node-feature-discovery/master/advanced/developer-guide.html"> <meta property="og:type" content="article"> <meta property="article:author" content="Kubernetes SIGs"> <meta property="article:published_time" content="2016-07-23T00:07:52-05:00"> <meta property="article:modified_time" content="2021-10-26T10:29:06-05:00"> <script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "mainEntityOfPage": { "@type": "WebPage", "@id": "https://kubernetes-sigs.github.com/node-feature-discovery/master/advanced/developer-guide.html" }, "headline": "Developer guide · Node Feature Discovery", "image": [], "author": { "@type": "Person", "name": "Kubernetes SIGs" }, "datePublished": "2016-07-23T00:07:52-05:00", "dateModified": "2021-10-26T10:29:06-05:00", "publisher": { "@type": "Organization", "name": "Kubernetes SIGs", "logo": { "@type": "ImageObject", "url": "https://avatars.githubusercontent.com/u/36015203?v=4" } }, "description": "Developer guide Table of contents Building from source Download the source code Docker build Deployment Building locally Customizing the build Test..." } </script> <link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="next" href="https://kubernetes-sigs.github.com/node-feature-discovery/master/advanced/master-commandline-reference.html"><link rel="canonical" href="https://kubernetes-sigs.github.com/node-feature-discovery/master/advanced/developer-guide.html"><link rel="icon" type="image/svg+xml" href="/node-feature-discovery/master/assets/images/favicon.svg"><link rel="icon" type="image/png" href="/node-feature-discovery/master/assets/images/favicon-16x16.png" sizes="16x16"> <link rel="icon" type="image/png" href="/node-feature-discovery/master/assets/images/favicon-32x32.png" sizes="32x32"> <link rel="icon" type="image/png" href="/node-feature-discovery/master/assets/images/favicon-96x96.png" sizes="96x96"><link rel="mask-icon" href="/node-feature-discovery/master/assets/images/favicon.svg" color="#2980b9"><link rel="apple-touch-icon" href="/node-feature-discovery/master/assets/images/apple-touch-icon-300x300.jpg"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@2.0.10/assets/css/theme.min.css"><script> window.ui = { title: "Node Feature Discovery", baseurl: "/node-feature-discovery/master", i18n: { search_results: "Search Results", search_results_found: "Search finished, found # page(s) matching the search query.", search_results_not_found: "Your search did not match any documents, pl
<span class="nb">cd </span>node-feature-discovery
</code></pre> </div></div> <h3 id="docker-build">Docker build</h3> <h4 id="build-the-container-image">Build the container image</h4> <p>See <a href="#customizing-the-build">customizing the build</a> below for altering the container image registry, for example.</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make
</code></pre> </div></div> <h4 id="push-the-container-image">Push the container image</h4> <p>Optional, this example with Docker.</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>docker push &lt;IMAGE_TAG&gt;
</code></pre> </div></div> <h4 id="change-the-job-spec-to-use-your-custom-image-optional">Change the job spec to use your custom image (optional)</h4> <p>To use your published image from the step above instead of the <code class="language-plaintext highlighter-rouge notranslate">k8s.gcr.io/nfd/node-feature-discovery</code> image, edit <code class="language-plaintext highlighter-rouge notranslate">image</code> attribute in the spec template(s) to the new location (<code class="language-plaintext highlighter-rouge notranslate">&lt;registry-name&gt;/&lt;image-name&gt;[:&lt;version&gt;]</code>).</p> <h3 id="deployment">Deployment</h3> <p>The <code class="language-plaintext highlighter-rouge notranslate">yamls</code> makefile generates a <code class="language-plaintext highlighter-rouge notranslate">kustomization.yaml</code> matching your locally built image and using the <code class="language-plaintext highlighter-rouge notranslate">deploy/overlays/default</code> deployment. See <a href="#customizing-the-build">build customization</a> below for configurability, e.g. changing the deployment namespace.</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code><span class="nv">K8S_NAMESPACE</span><span class="o">=</span>my-ns make yamls
kubectl apply <span class="nt">-k</span> <span class="nb">.</span>
</code></pre> </div></div> <p>You can use alternative deployment methods by modifying the auto-generated kustomization file. For example, deploying worker and master in the same pod by pointing to <code class="language-plaintext highlighter-rouge notranslate">deployment/overlays/default-combined</code>.</p> <h3 id="building-locally">Building locally</h3> <p>You can also build the binaries locally</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make build
</code></pre> </div></div> <p>This will compile binaries under <code class="language-plaintext highlighter-rouge notranslate">bin/</code></p> <h3 id="customizing-the-build">Customizing the build</h3> <p>There are several Makefile variables that control the build process and the name of the resulting container image. The following are targeted targeted for build customization and they can be specified via environment variables or makefile overrides.</p> <table> <thead> <tr> <th>Variable</th> <th>Description</th> <th>Default value</th> </tr> </thead> <tbody> <tr> <td>HOSTMOUNT_PREFIX</td> <td>Prefix of system directories for feature discovery (local builds)</td> <td>/ (<em>local builds</em>) /host- (<em>container builds</em>)</td> </tr> <tr> <td>IMAGE_BUILD_CMD</td> <td>Command to build the image</td> <td>docker build</td> </tr> <tr> <td>IMAGE_BUILD_EXTRA_OPTS</td> <td>Extra options to pass to build command</td> <td><em>empty</em></td> </tr> <tr> <td>IMAGE_PUSH_CMD</td> <td>Command to push the image to remote registry</td> <td>docker push</td> </tr> <tr> <td>IMAGE_REGISTRY</td> <td>Container image registry to use</td> <td>k8s.gcr.io/nfd</td> </tr> <tr> <td>IMAGE_TAG_NAME</td> <td>Container image tag name</td> <td>&lt;nfd version&gt;</td> </tr> <tr> <td>IMAGE_EXTRA_TAG_NAMES</td> <td>Additional container image tag(s) to create when building image</td> <td><em>empty</em></td> </tr> <tr> <td>K8S_NAMESPACE</td> <td>nfd-master and nfd-worker namespace</td> <td>kube-system</td> </tr> <tr> <td>KUBECONFIG</td> <td>Kubeconfig for running e2e-tests</td> <td><em>empty</em></td> </tr> <tr> <td>E2E_TEST_CONFIG</td> <td>Parameterization file of e2e-tests (see <a href="https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/test/e2e/e2e-test-config.example.yaml">example</a>)</td> <td><em>empty</em></td> </tr> <tr> <td>OPENSHIFT</td> <td>Non-empty value enables OpenShift specific support (currently only effective in e2e tests)</td> <td><em>empty</em></td> </tr> <tr> <td>BASE_IMAGE_FULL</td> <td>Container base image for target image full (target full)</td> <td>debian:buster-slim</td> </tr> <tr> <td>BASE_IMAGE_MINIMAL</td> <td>Container base image for target image minimal (target minimal)</td> <td>gcr.io/distroless/base</td> </tr> </tbody> </table> <p>For example, to use a custom registry:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make <span class="nv">IMAGE_REGISTRY</span><span class="o">=</span>&lt;my custom registry uri&gt;
</code></pre> </div></div> <p>Or to specify a build tool different from Docker, It can be done in 2 ways:</p> <ol> <li> <p>via environment</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code> <span class="nv">IMAGE_BUILD_CMD</span><span class="o">=</span><span class="s2">"buildah bud"</span> make
</code></pre> </div> </div> </li> <li> <p>by overriding the variable value</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code> make <span class="nv">IMAGE_BUILD_CMD</span><span class="o">=</span><span class="s2">"buildah bud"</span>
</code></pre> </div> </div> </li> </ol> <h3 id="testing">Testing</h3> <p>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:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make <span class="nb">test</span>
</code></pre> </div></div> <p>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:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make e2e-test <span class="nv">KUBECONFIG</span><span class="o">=</span><span class="nv">$HOME</span>/.kube/config
</code></pre> </div></div> <h2 id="running-locally">Running locally</h2> <p>You can run NFD locally, either directly on your host OS or in containers for testing and development purposes. This may be useful e.g. for checking features-detection.</p> <h3 id="nfd-master">NFD-Master</h3> <p>When running as a standalone container labeling is expected to fail because Kubernetes API is not available. Thus, it is recommended to use <code class="language-plaintext highlighter-rouge notranslate">-no-publish</code> command line flag. E.g.</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span><span class="nb">export </span><span class="nv">NFD_CONTAINER_IMAGE</span><span class="o">=</span>gcr.io/k8s-staging-nfd/node-feature-discovery:master
<span class="nv">$ </span>docker run <span class="nt">--rm</span> <span class="nt">--name</span><span class="o">=</span>nfd-test <span class="k">${</span><span class="nv">NFD_CONTAINER_IMAGE</span><span class="k">}</span> nfd-master <span class="nt">-no-publish</span>
2019/02/01 14:48:21 Node Feature Discovery Master &lt;NFD_VERSION&gt;
2019/02/01 14:48:21 gRPC server serving on port: 8080
</code></pre> </div></div> <p>Command line flags of nfd-master:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>docker run <span class="nt">--rm</span> <span class="k">${</span><span class="nv">NFD_CONTAINER_IMAGE</span><span class="k">}</span> nfd-master <span class="nt">-help</span>
Usage of nfd-master:
<span class="nt">-ca-file</span> string
Root certificate <span class="k">for </span>verifying connections
<span class="nt">-cert-file</span> string
Certificate used <span class="k">for </span>authenticating connections
<span class="nt">-extra-label-ns</span> value
Comma separated list of allowed extra label namespaces
<span class="nt">-instance</span> string
Instance name. Used to separate annotation namespaces <span class="k">for </span>multiple parallel deployments.
<span class="nt">-key-file</span> string
Private key matching <span class="nt">-cert-file</span>
<span class="nt">-kubeconfig</span> string
Kubeconfig to use
<span class="nt">-label-whitelist</span> value
Regular expression to filter label names to publish to the Kubernetes API server. NB: the label namespace is omitted i.e. the filter is only applied to the name part after <span class="s1">'/'</span><span class="nb">.</span>
<span class="nt">-no-publish</span>
Do not publish feature labels
<span class="nt">-port</span> int
Port on which to listen <span class="k">for </span>connections. <span class="o">(</span>default 8080<span class="o">)</span>
<span class="nt">-prune</span>
Prune all NFD related attributes from all nodes of the cluaster and exit.
<span class="nt">-resource-labels</span> value
Comma separated list of labels to be exposed as extended resources.
<span class="nt">-verify-node-name</span>
Verify worker node name against the worker<span class="s1">'s TLS certificate. Only takes effect when TLS authentication has been enabled.
-version
Print version and exit.
</span></code></pre> </div></div> <h3 id="nfd-worker">NFD-Worker</h3> <p>In order to run nfd-worker as a "stand-alone" container against your standalone nfd-master you need to run them in the same network namespace:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>docker run <span class="nt">--rm</span> <span class="nt">--network</span><span class="o">=</span>container:nfd-test <span class="k">${</span><span class="nv">NFD_CONTAINER_IMAGE</span><span class="k">}</span> nfd-worker
2019/02/01 14:48:56 Node Feature Discovery Worker &lt;NFD_VERSION&gt;
...
</code></pre> </div></div> <p>If you just want to try out feature discovery without connecting to nfd-master, pass the <code class="language-plaintext highlighter-rouge notranslate">-no-publish</code> flag to nfd-worker.</p> <p>Command line flags of nfd-worker:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code><span class="nv">$ </span>docker run <span class="nt">--rm</span> <span class="k">${</span><span class="nv">NFD_CONTAINER_IMAGE</span><span class="k">}</span> nfd-worker <span class="nt">-help</span>
Usage of nfd-worker:
<span class="nt">-ca-file</span> string
Root certificate <span class="k">for </span>verifying connections
<span class="nt">-cert-file</span> string
Certificate used <span class="k">for </span>authenticating connections
<span class="nt">-config</span> string
Config file to use. <span class="o">(</span>default <span class="s2">"/etc/kubernetes/node-feature-discovery/nfd-worker.conf"</span><span class="o">)</span>
<span class="nt">-key-file</span> string
Private key matching <span class="nt">-cert-file</span>
<span class="nt">-label-whitelist</span> value
Regular expression to filter label names to publish to the Kubernetes API server. NB: the label namespace is omitted i.e. the filter is only applied to the name part after <span class="s1">'/'</span><span class="nb">.</span> DEPRECATED: This parameter should be <span class="nb">set </span>via the config file.
<span class="nt">-no-publish</span>
Do not publish discovered features, disable connection to nfd-master.
<span class="nt">-oneshot</span>
Do not publish feature labels
<span class="nt">-options</span> string
Specify config options from <span class="nb">command </span>line. Config options are specified <span class="k">in </span>the same format as <span class="k">in </span>the config file <span class="o">(</span>i.e. json or yaml<span class="o">)</span><span class="nb">.</span> These options
<span class="nt">-server</span> string
NFD server address to connecto to. <span class="o">(</span>default <span class="s2">"localhost:8080"</span><span class="o">)</span>
<span class="nt">-server-name-override</span> string
Hostname expected from server certificate, useful <span class="k">in </span>testing
<span class="nt">-sleep-interval</span> duration
Time to <span class="nb">sleep </span>between re-labeling. Non-positive value implies no re-labeling <span class="o">(</span>i.e. infinite <span class="nb">sleep</span><span class="o">)</span><span class="nb">.</span> DEPRECATED: This parameter should be <span class="nb">set </span>via the config file
<span class="nt">-sources</span> value
Comma separated list of feature sources. Special value <span class="s1">'all'</span> enables all feature sources. DEPRECATED: This parameter should be <span class="nb">set </span>via the config file
<span class="nt">-version</span>
Print version and exit.
</code></pre> </div></div> <p><strong>NOTE</strong> 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 <code class="language-plaintext highlighter-rouge notranslate">--volume</code> options in order for them to work correctly when run stand-alone directly with <code class="language-plaintext highlighter-rouge notranslate">docker run</code>. See the <a href="https://github.com/kubernetes-sigs/node-feature-discovery/blob/master/deployment/components/common/worker-mounts.yaml">default deployment</a> for up-to-date information about the required volume mounts.</p> <h2 id="documentation">Documentation</h2> <p>All documentation resides under the <a href="https://github.com/kubernetes-sigs/node-feature-discovery/tree/master/docs">docs</a> directory in the source tree. It is designed to be served as a html site by <a href="https://pages.github.com/">GitHub Pages</a>.</p> <p>Building the documentation is containerized in order to fix the build environment. The recommended way for developing documentation is to run:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make site-serve
</code></pre> </div></div> <p>This will build the documentation in a container and serve it under <a href="http://localhost:4000/">localhost:4000/</a> making it easy to verify the results. Any changes made to the <code class="language-plaintext highlighter-rouge notranslate">docs/</code> will automatically re-trigger a rebuild and are reflected in the served content and can be inspected with a simple browser refresh.</p> <p>In order to just build the html documentation run:</p> <div class="language-bash highlighter-rouge notranslate"><div class="highlight"><pre class="highlight"><code>make site-build
</code></pre> </div></div> <p>This will generate html documentation under <code class="language-plaintext highlighter-rouge notranslate">docs/_site/</code>.</p> <!-- Links --> </div> </div> <div class="navigation-bottom d-flex flex-justify-between py-3" role="navigation" aria-label="footer navigation"> <div class="prev"></div> <div class="next"><a href="/node-feature-discovery/master/advanced/master-commandline-reference.html" class="btn" title="Master cmdline reference" accesskey="n" rel="next"> Next <i class="fa fa-arrow-circle-right"></i> </a></div> </div><hr> <div class="copyright text-center text-gray" role="contentinfo"> <i class="fa fa-copyright"></i> <span class="time">2016-2021,</span> <a class="text-gray" href="https://github.com/kubernetes-sigs" rel="noreferrer" target="_blank">Kubernetes SIGs</a> Revision <a class="text-gray" href="https://github.com/kubernetes-sigs/node-feature-discovery/commit/" title="" rel="noreferrer" target="_blank"></a> <br> <div class="generator"> Built with <a href="https://pages.github.com" rel="noreferrer" target="_blank" title="github-pages v209">GitHub Pages</a> using a <a href="https://github.com/rundocs/jekyll-rtd-theme" rel="noreferrer" target="_blank" title="rundocs/jekyll-rtd-theme v2.0.10">theme</a> provided by <a href="https://rundocs.io" rel="noreferrer" target="_blank">RunDocs</a>. </div> </div> </div> </div> <div class="addons-wrap d-flex flex-column overflow-y-auto"> <div class="status d-flex flex-justify-between p-2"> <div class="title p-1"> <i class="fa fa-book"></i> Node Feature Discovery </div> <div class="branch p-1"> <span class="name"> master </span> <i class="fa fa-caret-down"></i> </div> </div> <div class="addons d-flex flex-column height-full p-2 d-none"> <dl id="versions"> <dt>Versions</dt> <script src="/node-feature-discovery/versions.js"></script> <script> var dt = document.getElementById('versions'); var items = getVersionListItems(); for (var i=0; i < items.length; i++) { var dd = document.createElement('dd'); var a = dd.appendChild(document.createElement('a')); a.appendChild(document.createTextNode(items[i].name)); a.href = items[i].url; dt.appendChild(dd); } </script> </dl> <dl> <dt>GitHub</dt> <dd> <a href="https://github.com/kubernetes-sigs/node-feature-discovery" title="Stars: 349"> <i class="fa fa-github"></i> Homepage </a> </dd> <dd> <a href="https://github.com/kubernetes-sigs/node-feature-discovery/issues" title="Open issues: 34"> <i class="fa fa-question-circle-o"></i> Issues </a> </dd> <dd> <a href="https://github.com/kubernetes-sigs/node-feature-discovery/zipball/gh-pages" title="Size: 80637 Kb"> <i class="fa fa-download"></i> Download </a> </dd> </dl> <hr> <div class="license f6 pb-2"> This <a href="/node-feature-discovery/master/" title="Node Feature Discovery">Software</a> is under the terms of <a href="https://github.com/kubernetes-sigs/node-feature-discovery">Apache License 2.0</a>. </div> </div> </div> <script src="https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@2.0.10/assets/js/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@2.0.10/assets/js/theme.min.js"></script> </body> </html>