K8S裸机Nginx入口控制器不起作用

时间:2019-12-15 09:33:11

标签: nginx kubernetes kubernetes-ingress

集成K8S nginx入口时遇到问题。我安装了nginx入口控制器,并根据文档中的说明建立了测试入口资源,但是我无法跳转到常规路径。测试服务正常,可以通过群集IP访问。我想念什么吗?

  

安装脚本

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

使用NodePort的裸机

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

入口控制器正常 enter image description here

  

测试入口资源

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

我们可以看到已测试的Nginx Pod凸起并可以正常工作,我可以按集群IP访问Nginx索引页面 enter image description here

但是我无法访问nginx1.beencoding.com enter image description here

无法通过浏览器访问 enter image description here

2 个答案:

答案 0 :(得分:1)

我已通过设置hostnetwork: true

解决了该问题

答案 1 :(得分:0)

无法解决

将域放入/etc/hosts/文件中,或按以下步骤进行卷曲:

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

应该工作。