Skip to content

Commit

Permalink
salt,docs: Allow to manage number of CoreDNS replica
Browse files Browse the repository at this point in the history
Refs: #3574
  • Loading branch information
TeddyAndrieux committed Nov 22, 2021
1 parent b2e8764 commit 3615bbb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
(PR[#3540](https://github.com/scality/metalk8s/pull/3540))

- [#3574](https://github.com/scality/metalk8s/issues/3574) - Allow to manage
soft and hard `podAntiAffinity` for `CoreDNS` from Bootstrap configuration
file, with a default soft anti-affinity on hostname, so that if it's
possible each `CoreDNS` pods will sit on different infra node
number of replicas and, soft and hard `podAntiAffinity` for `CoreDNS`
from Bootstrap configuration file, with a default soft anti-affinity on
hostname, so that if it's possible each `CoreDNS` pods will sit on different infra node
(PR[#3579](https://github.com/scality/metalk8s/pull/3579))

### Removals
Expand Down
14 changes: 8 additions & 6 deletions docs/installation/bootstrap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Configuration
featureGates:
<feature_gate_name>: True
coreDNS:
replicas: 2
podAntiAffinity:
hard: []
soft:
Expand Down Expand Up @@ -171,12 +172,13 @@ defaults kubernetes configuration.
configure the corresponding entries in the
``kubernetes.apiServer.featureGates`` mapping.

If you want to override the default ``coreDNS`` podAntiAffinity, by default
MetalK8s use soft podAntiAffinity on hostname so that if it's possible
``coreDNS`` pods will be spread on different infra nodes.
If you have more infra node than ``coreDNS`` replicas (default is 2), you
should set hard podAntiAffinity on hostname so that you are sure that
``coreDNS`` pods sit on different node, to do so:
If you want to override the default ``coreDNS`` podAntiAffinity or number of
replicas, by default MetalK8s deploy 2 replicas and use soft podAntiAffinity
on hostname so that if it's possible ``coreDNS`` pods will be spread on
different infra nodes.
If you have more infra node than ``coreDNS`` replicas, you should set hard
podAntiAffinity on hostname so that you are sure that ``coreDNS`` pods sit
on different node, to do so:

.. code-block:: yaml
Expand Down
6 changes: 5 additions & 1 deletion salt/metalk8s/kubernetes/coredns/deployed.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
{%- set cluster_dns_ip = salt.metalk8s_network.get_cluster_dns_ip() %}
{%- set pillar_coredns = pillar.kubernetes.get("coreDNS", {}) %}
{%- set replicas = pillar_coredns.get("replicas") or 2 %}
{%- set label_selector = {"k8s-app": "kube-dns"} %}
{%- set pillar_affinities = pillar.kubernetes.get("coreDNS", {}).get("podAntiAffinity", {}) %}
{%- set pillar_affinities = pillar_coredns.get("podAntiAffinity", {}) %}
{#- NOTE: The default podAntiAffinity is a soft anti-affinity on hostname #}
{%- set soft_affinities = pillar_affinities.get("soft") or [{"topologyKey": "kubernetes.io/hostname"}] %}
{%- set hard_affinities = pillar_affinities.get("hard") or [] %}
Expand Down Expand Up @@ -80,6 +83,7 @@ Create coredns deployment:
- name: salt://{{ slspath }}/files/coredns-deployment.yaml.j2
- template: jinja
- defaults:
replicas: {{ replicas }}
label_selector: {{ label_selector | tojson }}
affinity: {{ affinity | tojson }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ metadata:
app.kubernetes.io/part-of: metalk8s
app.kubernetes.io/managed-by: salt
spec:
replicas: 2
replicas: {{ replicas }}
strategy:
type: RollingUpdate
rollingUpdate:
Expand Down
1 change: 1 addition & 0 deletions salt/tests/unit/formulas/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ metalk8s:
_cases:
"From metalk8s.kubernetes.coredns.deployed":
extra_context:
replicas: 2
label_selector:
k8s-app: kube-dns
affinity:
Expand Down

0 comments on commit 3615bbb

Please sign in to comment.