K8S baremetal nginx ingress controller not works

12/15/2019

I encountered a problem when integrating K8S nginx ingress. I installed the nginx ingress controller and established the testing ingress resources according to the instructions on the document, but I was not able to jump to the normal path. The test serive was normal and Accessible via cluster IP. Am I missing something?

Install script

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

Bare-metal Using NodePort

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml

Ingress controller is OK enter image description here

Testing ingress resource

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      app: my-nginx
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    app: my-nginx
spec:
  ports:
  - port: 80
    protocol: TCP
    name: http
  selector:
    app: my-nginx
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-nginx
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: nginx1.beencoding.com
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx-1
          servicePort: 80

We can see the test nginx pod raised and works fine, I can access the nginx index page by cluster IP enter image description here

But I can't access nginx1.beencoding.com enter image description here

Can't access via browser enter image description here

-- Aezio
kubernetes
kubernetes-ingress
nginx

2 Answers

12/15/2019

It says can't resolve.

Either put the domain in /etc/hosts/ file, or do the curl as follows:

curl -H "Host: nginx1.beecoding.com" IP_ADDRESS

Should work.

-- suren
Source: StackOverflow

12/17/2019

I have solved the problem by setting hostnetwork: true

-- Aezio
Source: StackOverflow