Asking for help? Comment out what you need so we can get more information to help you!
Cluster information:
Kubernetes version: v1.18.3
Cloud being used: (put bare-metal if not on a public cloud) : Bare-metal
Installation method: Kubeadm
Host OS: Ubuntu 20.04 LTS Server
CNI and version: Calico / latest
CRI and version: Docker / 19.03.8
You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.
I have installed NGINX ingress controller in Kubernetes cluster using the following command,
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/deploy.yaml
namespace/ingress-nginx created
serviceaccount/ingress-nginx created
configmap/ingress-nginx-controller created
clusterrole.rbac.authorization.k8s.io/ingress-nginx created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx created
role.rbac.authorization.k8s.io/ingress-nginx created
rolebinding.rbac.authorization.k8s.io/ingress-nginx created
service/ingress-nginx-controller-admission created
service/ingress-nginx-controller created
deployment.apps/ingress-nginx-controller created
validatingwebhookconfiguration.admissionregistration.k8s.io/ingress-nginx-admission created
clusterrole.rbac.authorization.k8s.io/ingress-nginx-admission created
clusterrolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
job.batch/ingress-nginx-admission-create created
job.batch/ingress-nginx-admission-patch created
role.rbac.authorization.k8s.io/ingress-nginx-admission created
rolebinding.rbac.authorization.k8s.io/ingress-nginx-admission created
serviceaccount/ingress-nginx-admission created
pkumar@k8s-master:~$
But the issue is that When i try to access my application , say nginx web server using hostname, then it is not accessible and if i append nodeport along with host-name in browser then it is working. But i want to access the application only via DNS name / hostname. To implement this demo i have followed following steps:
pkumar@k8s-master:~$ kubectl get pods --all-namespaces | grep -i ingress
ingress-nginx ingress-nginx-admission-create-dkjtm 0/1 Completed 0 4m53s
ingress-nginx ingress-nginx-admission-patch-zgdth 0/1 Completed 2 4m52s
ingress-nginx ingress-nginx-controller-75f84dfcd7-9sjqd 1/1 Running 0 5m3s
pkumar@k8s-master:~$
pkumar@k8s-master:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 24d v1.18.3
k8s-node-0 Ready <none> 24d v1.18.3
k8s-node-1 Ready <none> 24d v1.18.3
pkumar@k8s-master:~$
Created a deployment named “web-server”
pkumar@k8s-master:~$ kubectl create deployment web-server --image=nginx
deployment.apps/web-server created
pkumar@k8s-master:~$
Expose the deployment using service named “web-service”
pkumar@k8s-master:~$ kubectl expose deployment web-server --name=web-service --type=NodePort --port=80 --target-port=80
service/web-service exposed
pkumar@k8s-master:~$
pkumar@k8s-master:~$ kubectl get deployments.apps web-server
NAME READY UP-TO-DATE AVAILABLE AGE
web-server 1/1 1 1 2m37s
pkumar@k8s-master:~$ kubectl get service web-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
web-service NodePort 10.109.191.153 <none> 80:30397/TCP 42s
pkumar@k8s-master:~$
Create an ingress resource using the following yaml file,
pkumar@k8s-master:~$ cat ingress-web.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: name-virtual-host-ingress
spec:
rules:
- host: web.example.com
http:
paths:
- backend:
serviceName: web-service
servicePort: 80
pkumar@k8s-master:~$ kubectl create -f ingress-web.yaml
ingress.networking.k8s.io/name-virtual-host-ingress created
pkumar@k8s-master:~$
pkumar@k8s-master:~$ kubectl get ingress name-virtual-host-ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
name-virtual-host-ingress <none> web.example.com 192.168.1.41 80 57s
pkumar@k8s-master:~$
pkumar@k8s-master:~$ kubectl describe ingress name-virtual-host-ingress
Name: name-virtual-host-ingress
Namespace: default
Address: 192.168.1.41
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
web.example.com
web-service:80 (172.16.109.75:80)
Annotations: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 79s nginx-ingress-controller Ingress default/name-virtual-host-ingress
Normal UPDATE 41s nginx-ingress-controller Ingress default/name-virtual-host-ingress
pkumar@k8s-master:~$
I have added the entry of web.example.com in hosts file of my laptop,
192.168.1.41 web.example.com
In my laptop’s web browser, if I type “http://web.example.com” then i am getting an error “Unable to connect” and if I specify the NodePort then i can see nginx home page.
I have attached both images for the same.
I am expecting web server should be accessible via hostname without NodePort.
Can you please suggest what i am doing wrong here ?
Thanks in advance !!!