340 lines
16 KiB
HTML
340 lines
16 KiB
HTML
<!Doctype html>
|
|
<html id="docs">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link href='https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
|
|
<link rel="stylesheet" href="/css/styles.css"/>
|
|
<script src="/js/script.js"></script>
|
|
<script src="/js/jquery-2.2.0.min.js"></script>
|
|
<script src="/js/non-mini.js"></script>
|
|
<title>Kubernetes - Daemon Sets</title>
|
|
</head>
|
|
<body>
|
|
<div id="cellophane" onclick="kub.toggleMenu()"></div>
|
|
<header>
|
|
<a href="/" class="logo"></a>
|
|
<div class="nav-buttons" data-auto-burger="primary">
|
|
<a href="/docs" class="button" id="viewDocs">View Documentation</a>
|
|
<a href="/get-started" class="button" id="tryKubernetes">Try Kubernetes</a>
|
|
<button id="hamburger" onclick="kub.toggleMenu()" data-auto-burger-exclude><div></div></button>
|
|
</div>
|
|
|
|
<nav id="mainNav">
|
|
<main data-auto-burger="primary">
|
|
<div class="nav-box">
|
|
<h3><a href="">Get Started</a></h3>
|
|
<p>Built for a multi-cloud world, public, private or hybrid. Seamlessly roll out new features.</p>
|
|
</div>
|
|
<div class="nav-box">
|
|
<h3><a href="">Documentation</a></h3>
|
|
<p>Pellentesque in ipsum id orci porta dapibus. Nulla porttitor accumsan tincidunt. </p>
|
|
</div>
|
|
<div class="nav-box">
|
|
<h3><a href="">Community</a></h3>
|
|
<p>Vestibulum ac diam sit amet quam vehicula elementum sed sit amet dui. </p>
|
|
</div>
|
|
<div class="nav-box">
|
|
<h3><a href="">Blog</a></h3>
|
|
<p>Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Quisque velit nisi, pretium ut lacinia in. </p>
|
|
</div>
|
|
</main>
|
|
<main data-auto-burger="primary">
|
|
<div class="left">
|
|
<h5 class="github-invite">Interested in hacking on the core Kubernetes code base?</h5>
|
|
<a href="" class="button">View On Github</a>
|
|
</div>
|
|
|
|
<div class="right">
|
|
<h5 class="github-invite">Explore the community</h5>
|
|
<div class="social">
|
|
<a href="https://twitter.com/kubernetesio" class="Twitter"><span>twitter</span></a>
|
|
<a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
|
|
<a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
|
|
<a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>stackoverflow</span></a>
|
|
<a href="https://groups.google.com/forum/#!forum/google-containers" class="mailing-list"><span>Mailing List</span></a>
|
|
</div>
|
|
</div>
|
|
<div class="clear" style="clear: both"></div>
|
|
</main>
|
|
</nav>
|
|
</header>
|
|
|
|
<!-- HERO -->
|
|
<section id="hero" class="light-text">
|
|
<h1></h1>
|
|
<h5></h5>
|
|
<div id="vendorStrip" class="light-text">
|
|
<ul>
|
|
<li><a href="/v1.1/guides">GUIDES</a></li>
|
|
<li><a href="/v1.1/reference">REFERENCE</a></li>
|
|
<li><a href="/v1.1/samples">SAMPLES</a></li>
|
|
<li><a href="/v1.1/support">SUPPORT</a></li>
|
|
</ul>
|
|
<div class="dropdown">
|
|
<div class="readout"></div>
|
|
<a href="/v1.1">Version 1.1</a>
|
|
<a href="/v1.0">Version 1.0</a>
|
|
</div>
|
|
<input type="text" id="search" placeholder="Search the docs">
|
|
</div>
|
|
</section>
|
|
|
|
<section id="encyclopedia">
|
|
<div id="docsToc">
|
|
<div class="pi-accordion">
|
|
|
|
|
|
|
|
</div> <!-- /pi-accordion -->
|
|
</div> <!-- /docsToc -->
|
|
<div id="docsContent">
|
|
<h1>Daemon Sets</h1>
|
|
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
<!-- END MUNGE: UNVERSIONED_WARNING -->
|
|
|
|
<h1 id="daemon-sets">Daemon Sets</h1>
|
|
|
|
<p><strong>Table of Contents</strong>
|
|
<!-- BEGIN MUNGE: GENERATED_TOC --></p>
|
|
|
|
<ul>
|
|
<li><a href="#daemon-sets">Daemon Sets</a>
|
|
<ul>
|
|
<li><a href="#what-is-a-daemon-set">What is a <em>Daemon Set</em>?</a></li>
|
|
<li><a href="#writing-a-daemonset-spec">Writing a DaemonSet Spec</a>
|
|
<ul>
|
|
<li><a href="#required-fields">Required Fields</a></li>
|
|
<li><a href="#pod-template">Pod Template</a></li>
|
|
<li><a href="#pod-selector">Pod Selector</a></li>
|
|
<li><a href="#running-pods-on-only-some-nodes">Running Pods on Only Some Nodes</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#how-daemon-pods-are-scheduled">How Daemon Pods are Scheduled</a></li>
|
|
<li><a href="#communicating-with-daemonset-pods">Communicating with DaemonSet Pods</a></li>
|
|
<li><a href="#updating-a-daemonset">Updating a DaemonSet</a></li>
|
|
<li><a href="#alternatives-to-daemon-set">Alternatives to Daemon Set</a>
|
|
<ul>
|
|
<li><a href="#init-scripts">Init Scripts</a></li>
|
|
<li><a href="#bare-pods">Bare Pods</a></li>
|
|
<li><a href="#static-pods">Static Pods</a></li>
|
|
<li><a href="#replication-controller">Replication Controller</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a href="#caveats">Caveats</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<!-- END MUNGE: GENERATED_TOC -->
|
|
|
|
<h2 id="what-is-a-daemon-set">What is a <em>Daemon Set</em>?</h2>
|
|
|
|
<p>A <em>Daemon Set</em> ensures that all (or some) nodes run a copy of a pod. As nodes are added to the
|
|
cluster, pods are added to them. As nodes are removed from the cluster, those pods are garbage
|
|
collected. Deleting a Daemon Set will clean up the pods it created.</p>
|
|
|
|
<p>Some typical uses of a Daemon Set are:</p>
|
|
|
|
<ul>
|
|
<li>running a cluster storage daemon, such as <code>glusterd</code>, <code>ceph</code>, on each node.</li>
|
|
<li>running a logs collection daemon on every node, such as <code>fluentd</code> or <code>logstash</code>.</li>
|
|
<li>running a node monitoring daemon on every node, such as <a href="https://github.com/prometheus/node_exporter">Prometheus Node Exporter</a>, <code>collectd</code>, New Relic agent, or Ganglia <code>gmond</code>.</li>
|
|
</ul>
|
|
|
|
<p>In a simple case, one Daemon Set, covering all nodes, would be used for each type of daemon.
|
|
A more complex setup might use multiple DaemonSets would be used for a single type of daemon,
|
|
but with different flags and/or different memory and cpu requests for different hardware types.</p>
|
|
|
|
<h2 id="writing-a-daemonset-spec">Writing a DaemonSet Spec</h2>
|
|
|
|
<h3 id="required-fields">Required Fields</h3>
|
|
|
|
<p>As with all other Kubernetes config, a DaemonSet needs <code>apiVersion</code>, <code>kind</code>, and <code>metadata</code> fields. For
|
|
general information about working with config files, see <a href="../user-guide/simple-yaml.html">here</a>,
|
|
<a href="../user-guide/configuring-containers.html">here</a>, and <a href="../user-guide/working-with-resources.html">here</a>.</p>
|
|
|
|
<p>A DaemonSet also needs a <a href="../devel/api-conventions.html#spec-and-status"><code>.spec</code></a> section.</p>
|
|
|
|
<h3 id="pod-template">Pod Template</h3>
|
|
|
|
<p>The <code>.spec.template</code> is the only required field of the <code>.spec</code>.</p>
|
|
|
|
<p>The <code>.spec.template</code> is a <a href="../user-guide/replication-controller.html#pod-template">pod template</a>.
|
|
It has exactly the same schema as a <a href="../user-guide/pods.html">pod</a>, except
|
|
it is nested and does not have an <code>apiVersion</code> or <code>kind</code>.</p>
|
|
|
|
<p>In addition to required fields for a pod, a pod template in a DaemonSet has to specify appropriate
|
|
labels (see <a href="#pod-selector">pod selector</a>).</p>
|
|
|
|
<p>A pod template in a DaemonSet must have a <a href="../user-guide/pod-states.html"><code>RestartPolicy</code></a>
|
|
equal to <code>Always</code>, or be unspecified, which defaults to <code>Always</code>.</p>
|
|
|
|
<h3 id="pod-selector">Pod Selector</h3>
|
|
|
|
<p>The <code>.spec.selector</code> field is a pod selector. It works the same as the <code>.spec.selector</code> of
|
|
a <a href="../user-guide/replication-controller.html">ReplicationController</a> or
|
|
<a href="../user-guide/jobs.html">Job</a>.</p>
|
|
|
|
<p>If the <code>.spec.selector</code> is specified, it must equal the <code>.spec.template.metadata.labels</code>. If not
|
|
specified, the are default to be equal. Config with these unequal will be rejected by the API.</p>
|
|
|
|
<p>Also you should not normally create any pods whose labels match this selector, either directly, via
|
|
another DaemonSet, or via other controller such as ReplicationController. Otherwise, the DaemonSet
|
|
controller will think that those pods were created by it. Kubernetes will not stop you from doing
|
|
this. Once case where you might want to do this is manually create a pod with a different value on
|
|
a node for testing.</p>
|
|
|
|
<h3 id="running-pods-on-only-some-nodes">Running Pods on Only Some Nodes</h3>
|
|
|
|
<p>If you specify a <code>.spec.template.spec.nodeSelector</code>, then the DaemonSet controller will
|
|
create pods on nodes which match that <a href="../user-guide/node-selection/README.html">node
|
|
selector</a>.</p>
|
|
|
|
<p>If you do not specify a <code>.spec.template.spec.nodeSelector</code>, then the DaemonSet controller will
|
|
create pods on all nodes.</p>
|
|
|
|
<h2 id="how-daemon-pods-are-scheduled">How Daemon Pods are Scheduled</h2>
|
|
|
|
<p>Normally, the machine that a pod runs on is selected by the Kubernetes scheduler. However, pods
|
|
created by the Daemon controller have the machine already selected (<code>.spec.nodeName</code> is specified
|
|
when the pod is created, so it is ignored by the scheduler). Therefore:</p>
|
|
|
|
<ul>
|
|
<li>the <a href="node.html#manual-node-administration"><code>unschedulable</code></a> field of a node is not respected
|
|
by the daemon set controller.</li>
|
|
<li>daemon set controller can make pods even when the scheduler has not been started, which can help cluster
|
|
bootstrap.</li>
|
|
</ul>
|
|
|
|
<h2 id="communicating-with-daemonset-pods">Communicating with DaemonSet Pods</h2>
|
|
|
|
<p>Some possible patterns for communicating with pods in a DaemonSet are:</p>
|
|
|
|
<ul>
|
|
<li><strong>Push</strong>: Pods in the Daemon Set are configured to send updates to another service, such
|
|
as a stats database. They do not have clients.</li>
|
|
<li><strong>NodeIP and Known Port</strong>: Pods in the Daemon Set use a <code>hostPort</code>, so that the pods are reachable
|
|
via the node IPs. Clients knows the the list of nodes ips somehow, and know the port by convention.</li>
|
|
<li><strong>DNS</strong>: Create a <a href="../user-guide/services.html#headless-services">headless service</a> with the same pod selector,
|
|
and then discover DaemonSets using the <code>endpoints</code> resource or retrieve multiple A records from
|
|
DNS.</li>
|
|
<li><strong>Service</strong>: Create a service with the same pod selector, and use the service to reach a
|
|
daemon on a random node. (No way to reach specific node.)</li>
|
|
</ul>
|
|
|
|
<h2 id="updating-a-daemonset">Updating a DaemonSet</h2>
|
|
|
|
<p>If node labels are changed, the DaemonSet will promptly add pods to newly matching nodes and delete
|
|
pods from newly not-matching nodes.</p>
|
|
|
|
<p>You can modify the pods that a DaemonSet creates. However, pods do not allow all
|
|
fields to be updated. Also, the DeamonSet controller will use the original template the next
|
|
time a node (even with the same name) is created.</p>
|
|
|
|
<p>You can delete a DeamonSet. If you specify <code>--cascade=false</code> with <code>kubectl</code>, then the pods
|
|
will be left on the nodes. You can then create a new DaemonSet with a different template.
|
|
the new DaemonSet with the different template will recognize all the existing pods as having
|
|
matching labels. It will not modify or delete them despite a mismatch in the pod template.
|
|
You will need to force new pod creation by deleting the pod or deleting the node.</p>
|
|
|
|
<p>You cannot update a DaemonSet.</p>
|
|
|
|
<p>Support for updating DaemonSets and controlled updating of nodes is planned.</p>
|
|
|
|
<h2 id="alternatives-to-daemon-set">Alternatives to Daemon Set</h2>
|
|
|
|
<h3 id="init-scripts">Init Scripts</h3>
|
|
|
|
<p>It is certainly possible to run daemon processes by directly starting them on a node (e.g using
|
|
<code>init</code>, <code>upstartd</code>, or <code>systemd</code>). This is perfectly fine. However, there are several advantages to
|
|
running such processes via a DaemonSet:</p>
|
|
|
|
<ul>
|
|
<li>Ability to monitor and manage logs for daemons in the same way as applications.</li>
|
|
<li>Same config language and tools (e.g. pod templates, <code>kubectl</code>) for daemons and applications.</li>
|
|
<li>Future versions of Kubernetes will likely support integration between DaemonSet-created
|
|
pods and node upgrade workflows.</li>
|
|
<li>Running daemons in containers with resource limits increases isolation between daemons from app
|
|
containers. However, this can also be accomplished by running the daemons in a container but not in a pod
|
|
(e.g. start directly via Docker).</li>
|
|
</ul>
|
|
|
|
<h3 id="bare-pods">Bare Pods</h3>
|
|
|
|
<p>It is possible to create pods directly which specify a particular node to run on. However,
|
|
a Daemon Set replaces pods that are deleted or terminated for any reason, such as in the case of
|
|
node failure or disruptive node maintenance, such as a kernel upgrade. For this reason, you should
|
|
use a Daemon Set rather than creating individual pods.</p>
|
|
|
|
<h3 id="static-pods">Static Pods</h3>
|
|
|
|
<p>It is possible to create pods by writing a file to a certain directory watched by Kubelet. These
|
|
are called <a href="static-pods.html">static pods</a>.
|
|
Unlike DaemonSet, static pods cannot be managed with kubectl
|
|
or other Kubernetes API clients. Static pods do not depend on the apiserver, making them useful
|
|
in cluster bootstrapping cases. Also, static pods may be deprecated in the future.</p>
|
|
|
|
<h3 id="replication-controller">Replication Controller</h3>
|
|
|
|
<p>Daemon Set are similar to <a href="../user-guide/replication-controller.html">Replication Controllers</a> in that
|
|
they both create pods, and those pods have processes which are not expected to terminate (e.g. web servers,
|
|
storage servers).</p>
|
|
|
|
<p>Use a replication controller for stateless services, like frontends, where scaling up and down the
|
|
number of replicas and rolling out updates are more important than controlling exactly which host
|
|
the pod runs on. Use a Daemon Controller when it is important that a copy of a pod always run on
|
|
all or certain hosts, and when it needs to start before other pods.</p>
|
|
|
|
<h2 id="caveats">Caveats</h2>
|
|
|
|
<p>DaemonSet objects are in the <a href="../api.html#api-groups"><code>extensions</code> API Group</a>.
|
|
DaemonSet is not enabled by default. Enable it by setting
|
|
<code>--runtime-config=extensions/v1beta1/daemonsets=true</code> on the api server. This can be
|
|
achieved by exporting ENABLE_DAEMONSETS=true before running kube-up.sh script
|
|
on GCE.</p>
|
|
|
|
<p>DaemonSet objects effectively have <a href="../api.html#api-versioning">API version <code>v1alpha1</code></a>.
|
|
Alpha objects may change or even be discontinued in future software releases.
|
|
However, due to to a known issue, they will appear as API version <code>v1beta1</code> if enabled.</p>
|
|
|
|
<!-- BEGIN MUNGE: IS_VERSIONED -->
|
|
<!-- TAG IS_VERSIONED -->
|
|
<!-- END MUNGE: IS_VERSIONED -->
|
|
|
|
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
|
<p><a href=""><img src="https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/admin/daemons.md?pixel" alt="Analytics" /></a>
|
|
<!-- END MUNGE: GENERATED_ANALYTICS --></p>
|
|
|
|
|
|
</div>
|
|
</section>
|
|
|
|
|
|
<footer>
|
|
<main class="light-text">
|
|
<nav>
|
|
<a href="/getting-started.html">Getting Started</a>
|
|
<a href="/docs.html">Documentation</a>
|
|
<a href="http://blog.kubernetes.io/">Blog</a>
|
|
<a href="/foobang.html">Community</a>
|
|
</nav>
|
|
<div class="social">
|
|
<a href="https://twitter.com/kubernetesio" class="twitter"><span>twitter</span></a>
|
|
<a href="https://github.com/kubernetes/kubernetes" class="github"><span>Github</span></a>
|
|
<a href="http://slack.k8s.io/" class="slack"><span>Slack</span></a>
|
|
<a href="http://stackoverflow.com/questions/tagged/kubernetes" class="stack-overflow"><span>stackoverflow</span></a>
|
|
<a href="https://groups.google.com/forum/#!forum/google-containers" class="mailing-list"><span>Mailing List</span></a>
|
|
<label for="wishField">I wish this page <input type="text" id="wishField" name="wishField" placeholder="made better textfield suggestions"></label>
|
|
</div>
|
|
<div class="center">© 2016 Kubernetes</div>
|
|
</main>
|
|
</footer>
|
|
|
|
</body>
|
|
</html>
|
|
|
|
|
|
|