@@ -2,20 +2,6 @@ provider "aws" {
2
2
region = local. region
3
3
}
4
4
5
- provider "helm" {
6
- kubernetes {
7
- host = module. eks . cluster_endpoint
8
- cluster_ca_certificate = base64decode (module. eks . cluster_certificate_authority_data )
9
-
10
- exec {
11
- api_version = " client.authentication.k8s.io/v1beta1"
12
- command = " aws"
13
- # This requires the awscli to be installed locally where Terraform is executed
14
- args = [" eks" , " get-token" , " --cluster-name" , module . eks . cluster_name ]
15
- }
16
- }
17
- }
18
-
19
5
data "aws_availability_zones" "available" {}
20
6
21
7
locals {
@@ -47,6 +33,11 @@ module "eks" {
47
33
cluster_addons = {
48
34
kube-proxy = {}
49
35
vpc-cni = {}
36
+ coredns = {
37
+ configuration_values = jsonencode ({
38
+ computeType = " Fargate"
39
+ })
40
+ }
50
41
}
51
42
52
43
vpc_id = module. vpc . vpc_id
@@ -105,129 +96,6 @@ module "eks" {
105
96
tags = local. tags
106
97
}
107
98
108
- # ###############################################################################
109
- # Modify EKS CoreDNS Deployment
110
- # ###############################################################################
111
-
112
- data "aws_eks_cluster_auth" "this" {
113
- name = module. eks . cluster_name
114
- }
115
-
116
- locals {
117
- kubeconfig = yamlencode ({
118
- apiVersion = " v1"
119
- kind = " Config"
120
- current-context = " terraform"
121
- clusters = [{
122
- name = module.eks.cluster_name
123
- cluster = {
124
- certificate-authority-data = module.eks.cluster_certificate_authority_data
125
- server = module.eks.cluster_endpoint
126
- }
127
- }]
128
- contexts = [{
129
- name = " terraform"
130
- context = {
131
- cluster = module.eks.cluster_name
132
- user = " terraform"
133
- }
134
- }]
135
- users = [{
136
- name = " terraform"
137
- user = {
138
- token = data.aws_eks_cluster_auth.this.token
139
- }
140
- }]
141
- })
142
- }
143
-
144
- # Separate resource so that this is only ever executed once
145
- resource "null_resource" "remove_default_coredns_deployment" {
146
- triggers = {}
147
-
148
- provisioner "local-exec" {
149
- interpreter = [" /bin/bash" , " -c" ]
150
- environment = {
151
- KUBECONFIG = base64encode (local. kubeconfig )
152
- }
153
-
154
- # We are removing the deployment provided by the EKS service and replacing it through the self-managed CoreDNS Helm addon
155
- # However, we are maintaining the existing kube-dns service and annotating it for Helm to assume control
156
- command = <<- EOT
157
- kubectl --namespace kube-system delete deployment coredns --kubeconfig <(echo $KUBECONFIG | base64 --decode)
158
- EOT
159
- }
160
- }
161
-
162
- resource "null_resource" "modify_kube_dns" {
163
- triggers = {}
164
-
165
- provisioner "local-exec" {
166
- interpreter = [" /bin/bash" , " -c" ]
167
- environment = {
168
- KUBECONFIG = base64encode (local. kubeconfig )
169
- }
170
-
171
- # We are maintaining the existing kube-dns service and annotating it for Helm to assume control
172
- command = <<- EOT
173
- echo "Setting implicit dependency on ${ module . eks . fargate_profiles [" kube_system" ]. fargate_profile_pod_execution_role_arn } "
174
- kubectl --namespace kube-system annotate --overwrite service kube-dns meta.helm.sh/release-name=coredns --kubeconfig <(echo $KUBECONFIG | base64 --decode)
175
- kubectl --namespace kube-system annotate --overwrite service kube-dns meta.helm.sh/release-namespace=kube-system --kubeconfig <(echo $KUBECONFIG | base64 --decode)
176
- kubectl --namespace kube-system label --overwrite service kube-dns app.kubernetes.io/managed-by=Helm --kubeconfig <(echo $KUBECONFIG | base64 --decode)
177
- EOT
178
- }
179
-
180
- depends_on = [
181
- null_resource. remove_default_coredns_deployment
182
- ]
183
- }
184
-
185
- # ###############################################################################
186
- # CoreDNS Helm Chart (self-managed)
187
- # ###############################################################################
188
-
189
- data "aws_eks_addon_version" "this" {
190
- for_each = toset ([" coredns" ])
191
-
192
- addon_name = each. value
193
- kubernetes_version = module. eks . cluster_version
194
- most_recent = true
195
- }
196
-
197
- resource "helm_release" "coredns" {
198
- name = " coredns"
199
- namespace = " kube-system"
200
- create_namespace = false
201
- description = " CoreDNS is a DNS server that chains plugins and provides Kubernetes DNS Services"
202
- chart = " coredns"
203
- version = " 1.19.4"
204
- repository = " https://coredns.github.io/helm"
205
-
206
- # For EKS image repositories https://docs.aws.amazon.com/eks/latest/userguide/add-ons-images.html
207
- values = [
208
- <<- EOT
209
- image:
210
- repository: 602401143452.dkr.ecr.eu-west-1.amazonaws.com/eks/coredns
211
- tag: ${ data . aws_eks_addon_version . this [" coredns" ]. version }
212
- deployment:
213
- name: coredns
214
- annotations:
215
- eks.amazonaws.com/compute-type: fargate
216
- service:
217
- name: kube-dns
218
- annotations:
219
- eks.amazonaws.com/compute-type: fargate
220
- podAnnotations:
221
- eks.amazonaws.com/compute-type: fargate
222
- EOT
223
- ]
224
-
225
- depends_on = [
226
- # Need to ensure the CoreDNS updates are performed before provisioning
227
- null_resource. modify_kube_dns
228
- ]
229
- }
230
-
231
99
# ###############################################################################
232
100
# Supporting Resources
233
101
# ###############################################################################
0 commit comments