Home > front end >  How to exclude HA backup pod from node group selector in kubernates?
How to exclude HA backup pod from node group selector in kubernates?

Time:03-09

I want to create nodegroup selector which contain only primary pod and exclude backup pod in kubernates. How to achieve that using helm chart ?

appVersion: version1
kind: StatefulSet
metadata: 
  name: statefulname
  label: 
    ....
    ....
    ....
spec:
  replica: 2

  .....
 container:
   .....
   ....
   nodeselecor:
    {{$nodegroup}}

here result is

 NAME                    READY   STATUS    STARTS   AGE
pod/zookeeper-np-0       1/1     Running   0        203s
pod/zookeeper-np-1       1/1     Running   0        137s

here replica create 2 instance of pod with suffix -0 and -1 and both have same node selector but i want to that for pod/zookeeper-np-0 for this node selector is node group ng1 pod/zookeeper-np-1 for this node selector is node group ng2

i tried with iterate also not getting error

Caused By: java.lang.IllegalStateException: Identified another participant with the same name for Space: newspace_container_newspace

CodePudding user response:

You have not shared the K8s version details however you can look for the using the Node affinity with statefulset or else topologySpreadConstraints

topologySpreadConstraints:
    - maxSkew: <integer>
      topologyKey: <string>
      whenUnsatisfiable: <string>
      labelSelector: <object>

Read more at : https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/

using the topologySpreadConstraints you can spread the PODs across the nodes.

Node Affinity

nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/e2e-az-name
            operator: In
            values:
            - e2e-az1
            - e2e-az2

Read more : https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/

You can also use the node affinity to do the same scheduling the PODs on different nodes.

CodePudding user response:

i want to that for pod/zookeeper-np-0 for this node selector is node group ng1 pod/zookeeper-np-1 for this node selector is node group ng2

Per StatefulSet you can only have one nodeSelector which apply to all pods under this StatefulSet control. If you need to place pod in specific node group, you need to run them in different StatefulSet with its own nodeSelector.

  • Related