forked from docs/doc-exports
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com> Co-authored-by: qiujiandong1 <qiujiandong1@huawei.com> Co-committed-by: qiujiandong1 <qiujiandong1@huawei.com>
133 lines
16 KiB
HTML
133 lines
16 KiB
HTML
<a name="cce_10_0232"></a><a name="cce_10_0232"></a>
|
|
|
|
<h1 class="topictitle1">Overview</h1>
|
|
<div id="body0000001860261862"><p id="cce_10_0232__p14784281034">Kubernetes schedules workloads based on pods. After you create a workload, the scheduler automatically assigns pods. For example, the scheduler distributes pods to nodes that have enough resources.</p>
|
|
<p id="cce_10_0232__p1661224512597">While the default scheduler behavior is sufficient for most needs, there may be situations where you require more precise control over where pods are deployed. To address this, Kubernetes enables you to configure scheduling policies when creating workloads. For example, you may need to:</p>
|
|
<ul id="cce_10_0232__ul1585552580"><li id="cce_10_0232__li14855515813">Deploy a frontend application and a backend application on the same node. This reduces latency because the pods of both applications can use the physical resources of the node.</li><li id="cce_10_0232__li7857545811">Deploy a certain type of applications on specific nodes to ensure that these critical applications always run on the best hardware or configuration.</li><li id="cce_10_0232__li198505135816">Deploy different applications on separate nodes to isolate them from each other. This prevents any issues with one application from affecting others.</li></ul>
|
|
<p id="cce_10_0232__p1431544814403">Use the methods listed in the following table to select a pod scheduling policy in Kubernetes.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="cce_10_0232__table10982142172417" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Workload scheduling policies</caption><thead align="left"><tr id="cce_10_0232__row198315425247"><th align="left" class="cellrowborder" valign="top" width="16.09%" id="mcps1.3.5.2.5.1.1"><p id="cce_10_0232__p10983942152420">Scheduling Policy</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="15.52%" id="mcps1.3.5.2.5.1.2"><p id="cce_10_0232__p1382125215531">YAML Field</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="48.4%" id="mcps1.3.5.2.5.1.3"><p id="cce_10_0232__p1998324282412">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="19.99%" id="mcps1.3.5.2.5.1.4"><p id="cce_10_0232__p139833428241">Reference</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="cce_10_0232__row513120229332"><td class="cellrowborder" valign="top" width="16.09%" headers="mcps1.3.5.2.5.1.1 "><p id="cce_10_0232__p13131172233310">Node selector</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.52%" headers="mcps1.3.5.2.5.1.2 "><p id="cce_10_0232__p318155910318">nodeSelector</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="48.4%" headers="mcps1.3.5.2.5.1.3 "><p id="cce_10_0232__p1131122133310">A basic scheduling mode, in which Kubernetes selects the target node according to node labels. This means that pods are only scheduled to the node that has the specific label.</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="19.99%" headers="mcps1.3.5.2.5.1.4 "><p id="cce_10_0232__p413112222336"><a href="cce_10_0891.html">Configuring Specified Node Scheduling (nodeSelector)</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="cce_10_0232__row169835423246"><td class="cellrowborder" valign="top" width="16.09%" headers="mcps1.3.5.2.5.1.1 "><p id="cce_10_0232__p119839425245">Node affinity</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.52%" headers="mcps1.3.5.2.5.1.2 "><p id="cce_10_0232__p20181155912315">nodeAffinity</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="48.4%" headers="mcps1.3.5.2.5.1.3 "><p id="cce_10_0232__p114225331615">Node affinity is more expressive than nodeSelector. It allows you to use <a href="#cce_10_0232__section188105862813">Label Selectors</a> to filter nodes that require affinity based on their labels and choose between <strong id="cce_10_0232__b1519152451516">Required</strong> and <strong id="cce_10_0232__b146242618156">Preferred</strong> for <a href="#cce_10_0232__section849843422810">Affinity Rules</a>.</p>
|
|
<div class="note" id="cce_10_0232__note181294518111"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="cce_10_0232__p24131953110">When both nodeSelector and nodeAffinity are specified, a pod can only be scheduled to a candidate node if both conditions are met.</p>
|
|
</div></div>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="19.99%" headers="mcps1.3.5.2.5.1.4 "><p id="cce_10_0232__p79831542192418"><a href="cce_10_0892.html">Configuring Node Affinity Scheduling (nodeAffinity)</a></p>
|
|
</td>
|
|
</tr>
|
|
<tr id="cce_10_0232__row198344262416"><td class="cellrowborder" valign="top" width="16.09%" headers="mcps1.3.5.2.5.1.1 "><p id="cce_10_0232__p4983144213247">Workload affinity or anti-affinity scheduling</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.52%" headers="mcps1.3.5.2.5.1.2 "><p id="cce_10_0232__p2018035914315">podAffinity/podAntiAffinity</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="48.4%" headers="mcps1.3.5.2.5.1.3 "><p id="cce_10_0232__p49837427244">You can use <a href="#cce_10_0232__section188105862813">Label Selectors</a> to filter pods that require affinity or anti-affinity based on workload labels. You can then determine whether to schedule new workload pods to the same node (or node group) as the target pod or not. Additionally, you can choose between <strong id="cce_10_0232__b4538114711178">Required</strong> and <strong id="cce_10_0232__b3538144711175">Preferred</strong> for <a href="#cce_10_0232__section849843422810">Affinity Rules</a>.</p>
|
|
<div class="note" id="cce_10_0232__note96621857163518"><span class="notetitle"> NOTE: </span><div class="notebody"><p id="cce_10_0232__p1866216576354">Workload affinity and anti-affinity require a certain amount of computing time, which significantly slows down scheduling in large-scale clusters. Do not enable workload affinity and anti-affinity in a cluster that contains hundreds of nodes.</p>
|
|
</div></div>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="19.99%" headers="mcps1.3.5.2.5.1.4 "><p id="cce_10_0232__p398364214246"><a href="cce_10_0893.html">Configuring Workload Affinity or Anti-affinity Scheduling (podAffinity or podAntiAffinity)</a></p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="section" id="cce_10_0232__section849843422810"><a name="cce_10_0232__section849843422810"></a><a name="section849843422810"></a><h4 class="sectiontitle">Affinity Rules</h4><p id="cce_10_0232__p225902183013">Scheduling policies that use node affinity or workload affinity/anti-affinity can include both hard and soft constraints to meet complex scheduling requirements. Hard constraints must be met, while soft constraints should be met as much as possible.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="cce_10_0232__table13604041103115" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Affinity rules</caption><thead align="left"><tr id="cce_10_0232__row1860434153116"><th align="left" class="cellrowborder" valign="top" width="14.42%" id="mcps1.3.6.3.2.5.1.1"><p id="cce_10_0232__p209912314349">Rule Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="30.990000000000002%" id="mcps1.3.6.3.2.5.1.2"><p id="cce_10_0232__p15604141113117">YAML Field</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="38.940000000000005%" id="mcps1.3.6.3.2.5.1.3"><p id="cce_10_0232__p56041941193118">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="15.65%" id="mcps1.3.6.3.2.5.1.4"><p id="cce_10_0232__p116541533185915">Example</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="cce_10_0232__row176043419314"><td class="cellrowborder" valign="top" width="14.42%" headers="mcps1.3.6.3.2.5.1.1 "><p id="cce_10_0232__p209917323417">Required</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="30.990000000000002%" headers="mcps1.3.6.3.2.5.1.2 "><p id="cce_10_0232__p1604114173115">requiredDuringSchedulingIgnoredDuringExecution</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="38.940000000000005%" headers="mcps1.3.6.3.2.5.1.3 "><p id="cce_10_0232__p132361949123118">Hard constraint that <strong id="cce_10_0232__b68704431731">must be met</strong>. The scheduler can perform scheduling only when the rule is met.</p>
|
|
</td>
|
|
<td class="cellrowborder" rowspan="2" valign="top" width="15.65%" headers="mcps1.3.6.3.2.5.1.4 "><ul id="cce_10_0232__ul1991454011013"><li id="cce_10_0232__li19141401303"><a href="cce_10_0892.html">Configuring Node Affinity Scheduling (nodeAffinity)</a></li><li id="cce_10_0232__li129144401603"><a href="cce_10_0893.html">Configuring Workload Affinity or Anti-affinity Scheduling (podAffinity or podAntiAffinity)</a></li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="cce_10_0232__row15604341113120"><td class="cellrowborder" valign="top" headers="mcps1.3.6.3.2.5.1.1 "><p id="cce_10_0232__p149912373413">Preferred</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.6.3.2.5.1.2 "><p id="cce_10_0232__p56042418316">preferredDuringSchedulingIgnoredDuringExecution</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.6.3.2.5.1.3 "><p id="cce_10_0232__p55721652193116">Soft constraint. The scheduler tries to locate the target object that satisfies the target rule. The scheduler will schedule the pod even if it cannot find a matching target object that satisfies the target rule.</p>
|
|
<p id="cce_10_0232__p106037852313">When using preferred affinity, you can set a weight field ranging from 1 to 100 for each pod. Assigning a higher weight to a pod will increase its priority in the scheduling process.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note" id="cce_10_0232__note327475655215"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="cce_10_0232__p17051425315">The YAML field <strong id="cce_10_0232__b4392141061920">requiredDuringScheduling</strong> or <strong id="cce_10_0232__b5188213181911">preferredDuringScheduling</strong> in the affinity rules above indicates that a label rule must be forcibly met or needs to be met as much as possible during scheduling. <strong id="cce_10_0232__b092111494196">IgnoredDuringExecution</strong> indicates that any changes to the node label after Kubernetes schedules the pod will not affect the pod's running or cause it to be rescheduled. However, if kubelet on the node is restarted, kubelet will recheck the node affinity rule, and the pod will still be scheduled to another node.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="cce_10_0232__section188105862813"><a name="cce_10_0232__section188105862813"></a><a name="section188105862813"></a><h4 class="sectiontitle">Label Selectors</h4><p id="cce_10_0232__p9913448111813">When creating a scheduling policy use the logical operators of a label selector to filter label values and identify the objects that need affinity or anti-affinity.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="cce_10_0232__table985595651810" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Label selectors</caption><thead align="left"><tr id="cce_10_0232__row485655631815"><th align="left" class="cellrowborder" valign="top" width="13.58%" id="mcps1.3.7.3.2.4.1.1"><p id="cce_10_0232__p1085619560189">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="55.37%" id="mcps1.3.7.3.2.4.1.2"><p id="cce_10_0232__p12856165611814">Description</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="31.05%" id="mcps1.3.7.3.2.4.1.3"><p id="cce_10_0232__p0657347122115">YAML Example</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="cce_10_0232__row785685619186"><td class="cellrowborder" valign="top" width="13.58%" headers="mcps1.3.7.3.2.4.1.1 "><p id="cce_10_0232__p1385611567186">key</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="55.37%" headers="mcps1.3.7.3.2.4.1.2 "><p id="cce_10_0232__p685610566182">Label key. The objects that meet the filter criteria must contain the label of the key, and the label value must meet the operation relationship between the label value list (<strong id="cce_10_0232__b989855373315">values</strong> field) and logical operators.</p>
|
|
</td>
|
|
<td class="cellrowborder" rowspan="3" valign="top" width="31.05%" headers="mcps1.3.7.3.2.4.1.3 "><p id="cce_10_0232__p20812165933219">In the example below, objects that meet the filter criteria must have a label with a key of <strong id="cce_10_0232__b9892192613117">topology.kubernetes.io/zone</strong> and a value of either <strong id="cce_10_0232__b116451631193118">az1</strong> or <strong id="cce_10_0232__b35001433163120">az2</strong>.</p>
|
|
<pre class="screen" id="cce_10_0232__screen1949315362304">matchExpressions:
|
|
- key: <strong id="cce_10_0232__b1354121115416">topology.kubernetes.io/zone</strong>
|
|
operator: <strong id="cce_10_0232__b123021344115">In</strong>
|
|
values:
|
|
- <strong id="cce_10_0232__b129238419419">az1</strong>
|
|
- <strong id="cce_10_0232__b8189664417">az2</strong></pre>
|
|
</td>
|
|
</tr>
|
|
<tr id="cce_10_0232__row88561756191812"><td class="cellrowborder" valign="top" headers="mcps1.3.7.3.2.4.1.1 "><p id="cce_10_0232__p18856155618188">operator</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.7.3.2.4.1.2 "><p id="cce_10_0232__p1862515719305">Logical operator that can be used to determine filtering rules for label values. Options:</p>
|
|
<ul id="cce_10_0232__ul10233151017145"><li id="cce_10_0232__en-us_topic_0000001244101079_li13393182416613"><strong id="cce_10_0232__b176774273411">In</strong>: The label of the affinity or anti-affinity object <strong id="cce_10_0232__b1443817113919">is</strong> in the label value list (<strong id="cce_10_0232__b9677172716411">values</strong> field).</li><li id="cce_10_0232__en-us_topic_0000001244101079_li186115112515"><strong id="cce_10_0232__b1411130545">NotIn</strong>: The label of the affinity or anti-affinity object is <strong id="cce_10_0232__b25993113394">not</strong> in the label value list (<strong id="cce_10_0232__b1511630246">values</strong> field).</li><li id="cce_10_0232__en-us_topic_0000001244101079_li961161112511"><strong id="cce_10_0232__b155224376348">Exists</strong>: The affinity or anti-affinity object <strong id="cce_10_0232__b5908191293911">has</strong> a specified label key. There is no need to configure the label value list (<strong id="cce_10_0232__b1550045213615">values</strong> field).</li><li id="cce_10_0232__en-us_topic_0000001244101079_li86111116256"><strong id="cce_10_0232__b173113271372">DoesNotExist</strong>: The affinity or anti-affinity object does <strong id="cce_10_0232__b3626324173915">not</strong> have a specified label key. There is no need to configure the label value list (<strong id="cce_10_0232__b53691012173820">values</strong> field).</li><li id="cce_10_0232__en-us_topic_0000001244101079_li86120115255"><strong id="cce_10_0232__b55061781531">Gt</strong>: (available only for node affinity) The label value of the scheduled node is <strong id="cce_10_0232__b13797944173818">greater</strong> than what is listed (string comparison).</li><li id="cce_10_0232__en-us_topic_0000001244101079_li18611018254"><strong id="cce_10_0232__b10801111212310">Lt</strong>: (available only for node affinity) The label value of the scheduled node is <strong id="cce_10_0232__b1940710469391">less</strong> than what is listed (string comparison).</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="cce_10_0232__row5241181242118"><td class="cellrowborder" valign="top" headers="mcps1.3.7.3.2.4.1.1 "><p id="cce_10_0232__p172413129218">values</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" headers="mcps1.3.7.3.2.4.1.2 "><p id="cce_10_0232__p92415123214">Label values</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="cce_10_0889.html">Scheduling a Workload</a></div>
|
|
</div>
|
|
</div>
|
|
|