Skip to content

Affinity

Gregory Nickonov edited this page Mar 11, 2019 · 3 revisions

Quick Start

R.deployment :backend do
  pod_spec.affinity.node_affinity.required.add_term do
    preference.match_expressions.exists 'backend-log-collector'
  end
end

Schedule backend deployment pods to nodes that are labeled with backend-log-collector label.

Affinity

Kubernetes Documentation

Sunstone property Kubernetes property Type
node_affinity nodeAffinity NodeAffinity
pod_affinity podAffinity PodAffinity
pod_anti_affinity podAntiAffinity PodAntiAffinity

NodeAffinity

Kubernetes Documentation

Sunstone property Kubernetes property Type
preferred preferredDuringSchedulingIgnoredDuringExecution Array of PreferredSchedulingTerm
required requiredDuringSchedulingIgnoredDuringExecution NodeSelector

add_preferred_term

Creates an instance of PreferredSchedulingTerm, calls optional block to initialize the term and then adds that term to the preferred array:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    # Setup newly created term
  end
end

PreferredSchedulingTerm

Kubernetes Documentation

Sunstone property Kubernetes property Type
preference preference NodeSelectorTerm
weight weight Integer

NodeSelectorTerm

Kubernetes Documentation

Sunstone property Kubernetes property Type
match_expressions matchExpressions NodeSelectorRequirementArray
match_fields matchFields NodeSelectorRequirementArray

NodeSelectorRequirementArray

An array with helper methods to add NodeSelectorRequirement instances.

exists

Adds a NodeSelectorRequirement with specified key and operator Exists:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    preference.match_expressions.exists 'backend-log-collector'
  end
end

does_not_exists

Adds a NodeSelectorRequirement with specified key and operator DoesNotExists:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    preference.match_expressions.does_not_exists 'node-for-frontends'
  end
end

in

Adds a NodeSelectorRequirement with specified key and values and operator In:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    preference.match_expressions.in :kind, 'php-backends', 'ruby-backends', 'dotnet-backends'
  end
end

not_in

Adds a NodeSelectorRequirement with specified key and values and operator NotIn:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    preference.match_expressions.not_in :kind, 'frontends', 'service-workers'
  end
end

lt

Adds a NodeSelectorRequirement with specified key and integer value and operator Lt:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    preference.match_expressions.lt :volume, 42
  end
end

Helper lt has an alias less_than for aesthetic purposes.

gt

Adds a NodeSelectorRequirement with specified key and integer value and operator Gt:

R.deployment :backend do
  pod_spec.affinity.node_affinity.add_preffered_term do
    preference.match_expressions.gt :volume, 42
  end
end

Helper gt has an alias greater_than for aesthetic purposes.

NodeSelectorRequirement

Kubernetes Documentation

Sunstone property Kubernetes property Type
key key String
operator operator String
values values Array of String

NodeSelector

Kubernetes Documentation

Sunstone property Kubernetes property Type
node_selector_terms nodeSelectorTerms Array of NodeSelectorTerm

add_term

Helper to add and initialize term to the node_selector_terms array:

R.deployment :backend do
  pod_spec.affinity.node_affinity.required.add_term do
    preference.match_expressions.exists 'backend-log-collector'
  end
end

PodAffinity

Kubernetes Documentation

Sunstone property Kubernetes property Type
preferred preferredDuringSchedulingIgnoredDuringExecution Array of WeightedPodAffinityTerm
required requiredDuringSchedulingIgnoredDuringExecution Array of PodAffinityTerm

add_preferred_term

Helper to create, initialize and add an item to the preferred array:

R.deployment :backend do
  pod_spec.affinity.pod_affinity.add_preferred_term do
    # Initialize newly created item
  end
end

add_required_term

Helper to create, initialize and add an item to the required array:

R.deployment :backend do
  pod_spec.affinity.pod_affinity.add_required_term do
    # Initialize newly created item
  end
end

WeightedPodAffinityTerm

Kubernetes Documentation

Sunstone property Kubernetes property Type
pod_affinity_term podAffinityTerm PodAffinityTerm
weight weight Integer

PodAffinityTerm

Kubernetes Documentation

Sunstone property Kubernetes property Type
label_selector labelSelector LabelSelector
namespaces namespaces Array of String
topology_key topologyKey String

namespaces

Without arguments namespaces helper returns current list of namespaces. If one or more values is passed to the helper they are added to the list of namespaces:

R.deployment :backend do
  pod_spec.affinity.pod_affinity.add_required_term do
    pod_affinity_term do
      namespaces 'master', 'production'
    end
  end
end

For aesthetic purposes an alias namespace is provided.

PodAntiAffinity

Kubernetes Documentation

Sunstone property Kubernetes property Type
preferred preferredDuringSchedulingIgnoredDuringExecution Array of WeightedPodAffinityTerm
required requiredDuringSchedulingIgnoredDuringExecution Array of PodAffinityTerm

add_preferred_term

Helper to create, initialize and add an item to the preferred array:

R.deployment :backend do
  pod_spec.affinity.pod_affinity.add_preferred_term do
    # Initialize newly created item
  end
end

add_required_term

Helper to create, initialize and add an item to the required array:

R.deployment :backend do
  pod_spec.affinity.pod_affinity.add_required_term do
    # Initialize newly created item
  end
end