Skip to content

Instantly share code, notes, and snippets.

@sayadi
Created July 21, 2021 09:34
Show Gist options
  • Save sayadi/7d705e408982d82509dcc83331f4dcc7 to your computer and use it in GitHub Desktop.
Save sayadi/7d705e408982d82509dcc83331f4dcc7 to your computer and use it in GitHub Desktop.
Running the EKS CoreDNS deployment on Fargate when using the Terraform EKS module
# By default, the AWS EKS API creates the coredns deployment template with an annotation
# `eks.amazonaws.com/compute-type` equal to `ec2`. This prevents coredns pods from running on Fargate.
# Removing this annotation fixes the issue.
# More on: https://github.com/hashicorp/terraform-provider-aws/issues/11327
resource "null_resource" "edit_coredns" {
provisioner "local-exec" {
environment = {
KUBECONFIG = module.eks.kubeconfig_filename
CLUSTER_NAME = local.cluster_name
}
command = <<EOF
sleep 60
aws eks update-kubeconfig --name $CLUSTER_NAME
kubectl -n kube-system patch deployment coredns \
--type json -p='[
{"op": "add", "path": "/spec/template/metadata/annotations", "value": {}},
{"op": "add", "path": "/spec/template/metadata/annotations/eks.amazonaws.com~1compute-type", "value": "to-be-removed"}
]'
kubectl -n kube-system patch deployment coredns \
--type json -p='[{"op": "remove", "path": "/spec/template/metadata/annotations/eks.amazonaws.com~1compute-type"}]'
kubectl -n kube-system rollout restart deployment coredns
kubectl -n kube-system rollout status deployment coredns
EOF
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment