From dbedffbd0763a9c0f0303171dff44c10c2d5f248 Mon Sep 17 00:00:00 2001 From: lobiyed mohammed karim Date: Wed, 25 Oct 2023 14:52:12 +0200 Subject: [PATCH] Fix PR --- roles/kubernetes-apps/ansible/defaults/main.yml | 7 +++++++ roles/kubernetes-apps/ansible/tasks/coredns.yml | 2 ++ .../templates/coredns-poddisruptionbudget.yml.j2 | 11 +++++++++++ 3 files changed, 20 insertions(+) create mode 100644 roles/kubernetes-apps/ansible/templates/coredns-poddisruptionbudget.yml.j2 diff --git a/roles/kubernetes-apps/ansible/defaults/main.yml b/roles/kubernetes-apps/ansible/defaults/main.yml index fb26bd3eb3a..c42d2becf98 100644 --- a/roles/kubernetes-apps/ansible/defaults/main.yml +++ b/roles/kubernetes-apps/ansible/defaults/main.yml @@ -16,8 +16,15 @@ coredns_ordinal_suffix: "" coredns_deployment_nodeselector: "kubernetes.io/os: linux" coredns_default_zone_cache_block: | cache 30 + coredns_host_network: false coredns_port: 53 + +coredns_pod_disruption_budget: false + +# value for coredns pdb +# coredns_pod_disruption_budget_max_unavailable: 1 + # coredns_additional_configs adds any extra configuration to coredns # coredns_additional_configs: | # whoami diff --git a/roles/kubernetes-apps/ansible/tasks/coredns.yml b/roles/kubernetes-apps/ansible/tasks/coredns.yml index d8f85477486..e37375c6d64 100644 --- a/roles/kubernetes-apps/ansible/tasks/coredns.yml +++ b/roles/kubernetes-apps/ansible/tasks/coredns.yml @@ -33,6 +33,7 @@ - { name: coredns, src: coredns-deployment.yml, file: coredns-deployment-secondary.yml, type: deployment } - { name: coredns, src: coredns-svc.yml, file: coredns-svc-secondary.yml, type: svc } - { name: dns-autoscaler, src: dns-autoscaler.yml, file: coredns-autoscaler-secondary.yml, type: deployment } + - { name: coredns, file: coredns-poddisruptionbudget.yml, type: poddisruptionbudget, when: "{{ coredns_pod_disruption_budget }}"} register: coredns_secondary_manifests vars: clusterIP: "{{ skydns_server_secondary }}" @@ -40,5 +41,6 @@ when: - dns_mode == 'coredns_dual' - inventory_hostname == groups['kube_control_plane'][0] + - item.when | default(True) | bool tags: - coredns diff --git a/roles/kubernetes-apps/ansible/templates/coredns-poddisruptionbudget.yml.j2 b/roles/kubernetes-apps/ansible/templates/coredns-poddisruptionbudget.yml.j2 new file mode 100644 index 00000000000..5990391e996 --- /dev/null +++ b/roles/kubernetes-apps/ansible/templates/coredns-poddisruptionbudget.yml.j2 @@ -0,0 +1,11 @@ +{%- if coredns_pod_disruption_budget -%} +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: coredns{{ coredns_ordinal_suffix }} +spec: + maxUnavailable: {{ coredns_max_unavailable }} + selector: + matchLabels: + k8s-app: kube-dns{{ coredns_ordinal_suffix }} +{% endif %}