Are 2 OpenShift pods replicas deployed on two different nodes (when #nodes > 2)?

1/25/2019

Assume I have a cluster with 2 nodes and a POD with 2 replicas. Can I have the guarantee that my 2 replicas are deployed in 2 differents nodes. So that when a node is down, the application keeps running. By default does the scheduler work on best effort mode to assign the 2 replicas in distinct nodes?

-- scoulomb
kubernetes
openshift

3 Answers

1/27/2019

Daemonset is not a good option. It will schedule one pod on every node. In future if you scale your cluster and then pods get scaled as many as nodes. Instead Use pod affinity to schedule no more than one pod on any node

-- P Ekambaram
Source: StackOverflow

1/25/2019

You can use kind: DeamonSet . Here is a link to Kubernetes DeamonSet documentation.

A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created.

Here is a link to documentation about DeamonSets in OpenShift Example might look like the following:

This is available on Openshift >= 3.2 version of openshift This use case is to run a specific docker container (veermuchandi/welcome) on all nodes (or a set nodes with specific label

Enable HostPorts expose on Openshift

$ oc edit scc restricted #as system:admin user

change allowHostPorts: true and save

apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: welcome
spec:
  template:
    metadata:
      name: welcome
      labels:
        daemon: welcome
    spec:
      containers:
      - name: c
        image: veermuchandi/welcome
        ports:
        - containerPort: 8080
          hostPort: 8080
          name: serverport

$ oc create -f myDaemonset.yaml #with system:admin user

Source available here

-- Crou
Source: StackOverflow

1/29/2019

Pod AntiAffinity

Pod anti-affinity can also to repel the pod from each other. so no two pods can be scheduled on same node.

Use following configurations.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - nginx
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: nginx
        image: nginx

This will use the anti-affinity feature so if you are having more than 2 nodes the there will be guarantee that no two pod will be scheduled on same node.

-- Vishal Ghule
Source: StackOverflow