Skip to content

Commit

Permalink
Add nodeName to pod node selection (kubernetes#12194)
Browse files Browse the repository at this point in the history
The "Assigning Pods to Nodes" page did not mention nodeName, which, if
specified, takes priority over the methods discussed in the page.  Add
description of nodeName and an example using it.

Address reviewer comments from @bsalamat and @liggitt, thanks!
  • Loading branch information
ddgenome authored and k8s-ci-robot committed Jan 24, 2019
1 parent a254339 commit 7b15bdd
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions content/en/docs/concepts/configuration/assign-pod-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ weight: 30
{{% capture overview %}}

You can constrain a [pod](/docs/concepts/workloads/pods/pod/) to only be able to run on particular [nodes](/docs/concepts/architecture/nodes/) or to prefer to
run on particular nodes. There are several ways to do this, and they all use
run on particular nodes. There are several ways to do this, and the recommended approaches all use
[label selectors](/docs/concepts/overview/working-with-objects/labels/) to make the selection.
Generally such constraints are unnecessary, as the scheduler will automatically do a reasonable placement
(e.g. spread your pods across nodes, not place the pod on a node with insufficient free resources, etc.)
Expand All @@ -29,7 +29,7 @@ repo here](https://github.com/kubernetes/website/tree/{{< param "docsbranch" >}}

## nodeSelector

`nodeSelector` is the simplest form of constraint.
`nodeSelector` is the simplest recommended form of node selection constraint.
`nodeSelector` is a field of PodSpec. It specifies a map of key-value pairs. For the pod to be eligible
to run on a node, the node must have each of the indicated key-value pairs as labels (it can have
additional labels as well). The most common usage is one key-value pair.
Expand Down Expand Up @@ -362,6 +362,41 @@ For more information on inter-pod affinity/anti-affinity, see the
You may want to check [Taints](/docs/concepts/configuration/taint-and-toleration/)
as well, which allow a *node* to *repel* a set of pods.
## nodeName
`nodeName` is the simplest form of node selection constraint, but due
to its limitations it is typically not used. `nodeName` is a field of
PodSpec. If it is non-empty, the scheduler ignores the pod and the
kubelet running on the named node tries to run the pod. Thus, if
`nodeName` is provided in the PodSpec, it takes precedence over the
above methods for node selection.
Some of the limitations of using `nodeName` to select nodes are:
- If the named node does not exist, the pod will not be run, and in
some cases may be automatically deleted.
- If the named node does not have the resources to accommodate the
pod, the pod will fail and its reason will indicate why,
e.g. OutOfmemory or OutOfcpu.
- Node names in cloud environments are not always predictable or
stable.
Here is an example of a pod config file using the `nodeName` field:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
nodeName: kube-01
```

The above pod will run on the node kube-01.

{{% /capture %}}

{{% capture whatsnext %}}
Expand Down

0 comments on commit 7b15bdd

Please sign in to comment.