I have configured an EKS cluster on AWS using terraform and it works totally fine. On that cluster, I created a simple nginx deployment exposed by a service which in turn, is exposed by an ingress. I can reach the landing page of that nginx server, i.e.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
by running curl <http://dns_name_of_eks_load_balancer>
where I retrieve the dns_name_of_eks_load_balancer
by running kubectl get svc -n nginx-ingress
and looking for the external IP of the service of type LoadBalancer
. By the way, nginx-ingress
is the namespace, into which I deployed an nginx ingress controller using the Helm provider of terraform.
Now, instead of using curl <http://dns_name_of_eks_load_balancer>
, I want to use curl http://trading-bot.kevinsuedmersen.org
to be redirected to the nginx server, where kevinsuedmersen.org
is the domain I registered on AWS route53 and trading-bot.kevinsuedmersen.org should be a subdomain created by terraform. Following is the corresponding terraform code which should achieve this:
resource "aws_route53_zone" "primary_hosted_zone" {
name = "kevinsuedmersen.org"
}
data "kubernetes_service" "load_balancer" {
metadata {
name = "nginx-ingress-controller"
namespace = "nginx-ingress"
}
}
data "aws_elb_hosted_zone_id" "hosted_zone_id" {}
resource "aws_route53_record" "trading_bot_record" {
zone_id = aws_route53_zone.primary_hosted_zone.zone_id
name = "trading-bot.kevinsuedmersen.org"
type = "A"
alias {
name = data.kubernetes_service.load_balancer.status[0].load_balancer[0].ingress[0].hostname
zone_id = data.aws_elb_hosted_zone_id.hosted_zone_id.id
evaluate_target_health = true
}
}
output "hosted_zone_name" {
value = aws_route53_zone.primary_hosted_zone.name
}
output "hosted_zone_id" {
value = aws_route53_zone.primary_hosted_zone.id
}
output "load_balancer_hostname" {
value = data.kubernetes_service.load_balancer.status[0].load_balancer[0].ingress[0].hostname
}
output "load_balancer_hosted_zone_id" {
value = data.aws_elb_hosted_zone_id.hosted_zone_id.id
}
However after running terraform apply
and then curl trading-bot.kevinsuedmersen.org
I always get the error
curl: (6) Could not resolve host: trading-bot.kevinsuedmersen.org
so I think there must be some sort of problem in the domain resolution.
I read through the corresponding terraform documentation and aws documentation, but I cannot find any errors, so any help is much appreciated!
PS: Just for completeness, here is the terraform code which provisions the nginx-ingress controller and the load balancer:
resource "helm_release" "nginx_ingress" {
name = "nginx-ingress-controller"
namespace = "nginx-ingress"
create_namespace = true
repository = "https://charts.bitnami.com/bitnami"
chart = "nginx-ingress-controller"
set {
name = "service.type"
value = "LoadBalancer"
}
depends_on = [module.eks]
}
output "nginx_ingress_manifest" {
value = helm_release.nginx_ingress.manifest
}
and here are the kubernetes configuration files for the simple nginx deployment, service and ingress
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: "2024-09-13T18:45:03Z"
generation: 1
labels:
app: nginx-deployment
name: nginx-deployment
namespace: default
resourceVersion: "1634842"
uid: c3918ec9-7281-467d-818a-b2b36b21c837
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: nginx-deployment
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: nginx-deployment
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: nginx-deployment
name: nginx-service
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx-deployment
status:
loadBalancer: {}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- # TODO: host: "trading-bot.kevinsuedmersen.org"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: nginx-service
port:
number: 80
6