Files
doc-exports/docs/cce/umn/cce_10_0891.html
qiujiandong1 71d5c814e7 CCE UMN 20250311 version
Reviewed-by: Eotvos, Oliver <oliver.eotvos@t-systems.com>
Co-authored-by: qiujiandong1 <qiujiandong1@huawei.com>
Co-committed-by: qiujiandong1 <qiujiandong1@huawei.com>
2025-06-16 14:58:53 +00:00

46 lines
3.6 KiB
HTML

<a name="cce_10_0891"></a><a name="cce_10_0891"></a>
<h1 class="topictitle1">Configuring Specified Node Scheduling (nodeSelector)</h1>
<div id="body0000001910802569"><p id="cce_10_0891__p8060118">To select a node for scheduling in Kubernetes, simply configure the <strong id="cce_10_0891__b22814326539">nodeSelector</strong> field in the workload. This field allows you to configure the label of the desired node to be scheduled. Kubernetes schedules pods only to nodes with specified labels.</p>
<div class="section" id="cce_10_0891__section39217236524"><h4 class="sectiontitle">Prerequisites</h4><p id="cce_10_0891__p1871815210446">A custom label has been added to the target node so that workload pods can be scheduled based on the node label. For details, see <a href="cce_10_0004.html#cce_10_0004__section33951611481">Adding or Deleting a Node Label</a>.</p>
</div>
<div class="section" id="cce_10_0891__section1652711330565"><h4 class="sectiontitle">Creating a Workload Scheduled to a Specified Node</h4><ol id="cce_10_0891__ol129221949874"><li id="cce_10_0891__li367719515229"><span>Use kubectl to access the cluster. For details, see <a href="cce_10_0107.html">Accessing a Cluster Using kubectl</a>.</span></li><li id="cce_10_0891__li767713516221"><span>Create a YAML file named <strong id="cce_10_0891__b16565171545817">nginx.yaml</strong>. The file name can be customized.</span><p><div class="p" id="cce_10_0891__p28578015812">Configure nodeSelector for the workload. For example, if the key is <strong id="cce_10_0891__b10936103142315">deploy_qa</strong> and the value is <strong id="cce_10_0891__b19936131152317">true</strong>, the pod will be scheduled to the node with the <strong id="cce_10_0891__b2936173116234">deploy_qa=true</strong> label. Example:<pre class="screen" id="cce_10_0891__screen191412225599">apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
<strong id="cce_10_0891__b1624117278578"> nodeSelector: </strong>
<strong id="cce_10_0891__b1424312745717"> deploy_qa: "true"</strong>
containers:
- image: nginx:latest
imagePullPolicy: IfNotPresent
name: nginx
imagePullSecrets:
- name: default-secret</pre>
</div>
</p></li><li id="cce_10_0891__li586915442817"><span>Create a workload.</span><p><pre class="screen" id="cce_10_0891__screen74492541889">kubectl apply -f nginx.yaml</pre>
</p></li><li id="cce_10_0891__li1527319734716"><span>Verify that all pods run on the target node.</span><p><pre class="screen" id="cce_10_0891__screen17848748125316">kubectl get pod -o wide</pre>
<p id="cce_10_0891__p10354173325315">In the following command output, node 192.168.0.103 is labeled with <strong id="cce_10_0891__b187741817112510">deploy_qa=true</strong>:</p>
<pre class="screen" id="cce_10_0891__screen19265144016532">NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-66859f4f48-xgp2g 1/1 Running 0 6h57m 172.16.3.0 192.168.0.103 &lt;none&gt; &lt;none&gt;
nginx-66859f4f48-t9gqj 1/1 Running 0 6h57m 172.16.3.1 192.168.0.103 &lt;none&gt; &lt;none&gt;
nginx-66859f4f48-2grhq 1/1 Running 0 6h57m 172.16.3.2 192.168.0.103 &lt;none&gt; &lt;none&gt;</pre>
</p></li></ol>
</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>