Reputation: 14790
I have two nodes
gke-1789571565414321321-a3ec9151-node-q0cz
gke-98798532417432432421-a3ec9151-node-q0cz
And I have two ReplicationController to deploy 2 pods, xxx & yyy.
What I want to: If xxx
is deployed on one of the node
, yyy
should go to the other.
I implement this by spec.nodeName
property.
Is there a generic way to avoid indicating the specific node?
xxx:
{
"apiVersion": "v1",
"kind": "ReplicationController",
"metadata": {
"name": "xxx",
"labels": { "name" : "xxx" }
},
"spec": {
"replicas": 1,
"selector": {
"name":"xxx"
},
"template": {
"metadata": {
"labels": {
"name":"xxx"
}
},
"spec": {
"containers": [
//...
],
"nodeName" : "gke-1789571565414321321-a3ec9151-node-q0cz"
}
}
}
}
yyy:
{
"apiVersion": "v1",
"kind": "ReplicationController",
"metadata": {
"name": "yyy",
"labels": { "name" : "yyy" }
},
"spec": {
"replicas": 1,
"selector": {
"name":"yyy"
},
"template": {
"metadata": {
"labels": {
"name":"yyy"
}
},
"spec": {
"containers": [
//...
],
"nodeName" : "gke-98798532417432432421-a3ec9151-node-q0cz"
}
}
}
}
Upvotes: 0
Views: 365
Reputation: 18200
The feature you are looking for is called "anti-affinity" and is not yet implemented (but is described in a design doc in github). Until then, you can force the pods to be spread by assigning a constraint that can only be met once per node, such as a host port (see Allow only one pod of a type on a node in Kubernetes).
Upvotes: 1