我遇到一个奇怪的问题,我试图应用PodAntiAffinity来确保特定DeploymentConfig的2个pod永远不会出现在同一节点上:
我尝试使用以下命令编辑DC
spec:
replicas: 1
selector:
app: server-config
deploymentconfig: server-config
strategy:
activeDeadlineSeconds: 21600
resources: {}
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailable: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
type: Rolling
template:
metadata:
creationTimestamp: null
labels:
app: server-config
deploymentconfig: server-config
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- server-config
topologyKey: "kubernetes.io/hostname"
但是保存下来,我得到了一个:
"/tmp/oc-edit-34z56.yaml" 106L, 3001C written
deploymentconfig "server-config" skipped
并且更改不保留。我的openshift / Kubernetes版本是:
[root@master1 ~]# oc version
oc v1.5.1
kubernetes v1.5.2+43a9be4
features: Basic-Auth GSSAPI Kerberos SPNEGO
谢谢。
答案 0 :(得分:1)
这似乎可行,语法千差万别,需要添加“ scheduler.alpha.kubernetes.io/affinity”注释才能使用:
spec:
replicas: 1
selector:
app: server-config
deploymentconfig: server-config
strategy:
activeDeadlineSeconds: 21600
resources: {}
rollingParams:
intervalSeconds: 1
maxSurge: 25%
maxUnavailable: 25%
timeoutSeconds: 600
updatePeriodSeconds: 1
type: Rolling
template:
metadata:
annotations:
scheduler.alpha.kubernetes.io/affinity: |
{
"podAntiAffinity": {
"requiredDuringSchedulingIgnoredDuringExecution": [{
"labelSelector": {
"matchExpressions": [{
"key": "app",
"operator": "In",
"values":["server-config"]
}]
},
"topologyKey": "kubernetes.io/hostname"
}]
}
}
按预期工作并在节点之间正确分布:
[root@master1 ~]# oc get pods -o wide |grep server-config
server-config-22-4ktvf 1/1 Running 0 3h 10.1.1.73 10.0.4.101
server-config-22-fz31j 1/1 Running 0 3h 10.1.0.3 10.0.4.100
server-config-22-mrw09 1/1 Running 0 3h 10.1.2.64 10.0.4.102