Openshift Origin 1.5.1 Pod anti-affinity on DeploymentConfig not working

8/30/2018

I have a strange issue where I am trying to apply a PodAntiAffinity to make sure that no 2 pods of the specific deploymentConfig ever end up on the same node:

I attempt to edit the dc with:

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"

but on saving that, I get a :

"/tmp/oc-edit-34z56.yaml" 106L, 3001C written
deploymentconfig "server-config" skipped

and the changes dont stick. My openshift/Kubernetes versions are:

[root@master1 ~]# oc version
oc v1.5.1
kubernetes v1.5.2+43a9be4
features: Basic-Auth GSSAPI Kerberos SPNEGO

Thanks in advance.

-- Kim Attree
kubernetes
openshift

1 Answer

8/30/2018

This seems to work, the syntax is wildly different and the "scheduler.alpha.kubernetes.io/affinity" annotation needs to be added to work:

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"
              }]
            }
          }

Working as intended and spreading out properly between nodes:

[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
-- Kim Attree
Source: StackOverflow