My Kubernetes cluster is running in Vmware PKS.
I am having Ingress resource with spec.rules.host: test.domain.com for backend service "test-service". I understand that by adding an entry in DNS server will route traffic to my cluster when accessed from outside of the cluster(external). But without DNS entry in the server/cloud, I need to test the Ingress configuration locally by adding an entry to /etc/hosts or something like.
I found in a baremetal tutorial, adding the HA Proxy IP to /etc/hosts file redirects traffic to kubernetes cluster. Just like that, added the "ip_of_k8_cluster test.domain.com" to /etc/hosts the tried to access like "curl http://test.domain.com/" but the URL is not reachable.
How to verify(internal) the hostname in the Ingress resource without having actual DNS entry for host. I want to make sure my Ingress resource is perfectly working then I can request my company admin to add the name in DNS.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
namespace: ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: app-ingress
spec:
rules:
- host: test.domain.com
http:
paths:
- backend:
serviceName: test-service
servicePort: 80
path: /
The IP which you have to add to /etc/hosts
is not the IP of the Kubernetes-Cluster, it must be the External-IP of the Ingress-Service.
And the port
and targetPort
of the Ingress-Service must be also correct (in your case port
to 80
and targetPort
to the one on which your Ingress Service listens).
Use curl
with the --resolve
flag, example;
host=test.domain.com
adr=<your-external-or-loadbalancer-ip-for-the-nginx-service>
curl -D - --resolv $host:80:$adr http://$host/
Or with https;
curl -D - --resolv $host:443:$adr --insecure https://$host/