I have a problem with Kubernetes deployment. My service works perfectly when accessing "example.com" or "https://example.com" but it does not work when accessing over "www.example.com" or "http://example.com" the default nginx backend shows up with a 404.
Here is my ingress implementation:
# Ingress
apiVersion: networking.k8s.io/v1
# make a new cert
kind: Ingress
metadata:
name: ${APP_NAME}
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/from-to-www-redirect: 'true'
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: example.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: ${APP_NAME}
port:
number: 80
tls:
- secretName: ${APP_NAME}
hosts:
- example.com
- www.example.com
Here is my certificate configuration:
# Certificate
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: ${APP_NAME}
spec:
secretName: ${APP_NAME}
dnsNames:
- example.com
- www.example.com
issuerRef:
name: letsencrypt-production
# We can reference ClusterIssuers by changing the kind here.
# The default value is Issuer (i.e. a locally namespaced Issuer)
kind: ClusterIssuer
group: cert-manager.io
I configured the following DNS records:
example.com A 300 xx.xxx.xx.xx
*.example.com A 300 xx.xxx.xx.xx
www.example.com CNAME 300 example.com
Does anyone knows what could be the issue here? Every help is appreciated a lot!
2
Answers
the 404 was coming from Nginx. I'm not sure what went wrong but after reinstalling Nginx on my cluster it works now. I recommend everyone having this problem runing a curl -v and see if it is a redirect header or not.
You need to map your ingress controller external IP to your domain as a DNS record:
it’s present under your services
Add a DNS record in your DNS zone
example.com
==>$EXTERNAL-IP