I'm new to kubernetes, actually I started 1 week ago and I'm trying to use Ingress to see the application using a domain name but no matter what I've done I haven't been able to get it to work. My yaml file has the following format and when I apply it, it runs normally and doesn't show me any errors.
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
namespace: my-namespace
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
namespace: my-namespace
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
nodePort: 32000
port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
namespace: my-namespace
spec:
ingressClassName: nginx
rules:
- host: xxxx.xxxxxx.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
When I try to browse the application using the nodePort http://??.??.??.??:32000/ I can view the contents of the application but when I use the domain name I get the error message "This site can’t be reached".
I have spent too many hours and I can't find what the problem is. Can someone tell me what is wrong with my configuration.
Thanks in advance
Based on the YAML configuration you've posted, there appears to be a mismatch between the service name specified in the Ingress resource and the actual name of the service defined earlier in your configuration. In my opinion, this is likely why your domain name is not resolving correctly to your application hosted on Kubernetes.
Your service is defined with the name my-app-service
, however, in your Ingress definition, you are referencing a service named nginx-service
.
To fix the issue, update the Ingress resource to match the correct service name:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
namespace: my-namespace
spec:
ingressClassName: nginx
rules:
- host: xxxx.xxxxxx.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service # Here
port:
number: 80
Make sure to apply the updated configuration with kubectl apply -f <filename>.yaml
. Also, ensure that your DNS settings for xxxx.xxxxxx.com
are correctly pointing to your Kubernetes cluster's external IP where the Ingress controller is running.