【问题标题】:Minikube Ingress Does not resolve but minikube IP doesMinikube Ingress 无法解析,但 minikube IP 可以
【发布时间】:2020-11-18 18:35:07
【问题描述】:

我正在运行一个简单的 pod,其中包含来自 Windows 10 上 minikube 集群中本地映像注册表的映像。我还在运行一个简单的节点端口服务。当我尝试使用 :30080 从浏览器访问容器时,该容器可用。

但是,现在我想设置一个入口控制器,因为我想设置一个域而不是使用 IP 访问它。入口适用于基本 nginx pod 等简单的东西,但不适用于我正在尝试使用的这个 pod。我以前在 docker-compose 中使用 jwilder/nginx-proxy,它有一些需要附加到 conf.d 目录中的 conf 文件。但是,由于我要迁移到 Kubernetes,我想完全省略 conf 文件和反向代理图像。

现在hosts fie更新后,可以通过curl访问域,域也可以ping通,但是在浏览器上根本无法访问。

pod-yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: api
  name: api
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: api
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        io.kompose.service: api
    spec:
      containers:
      - env:
        - name: DEV_PORT
          value: "80"
        image: localhost:5000/api:2.3
        imagePullPolicy: "IfNotPresent"
        name: api
        resources: {}
      restartPolicy: Always
      serviceAccountName: ""
status: {}

Service.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: C:\Users\***kompose.exe
      convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: api
  name: api
spec:
  selector:
    io.kompose.service: api
  type: NodePort
  ports:
  - name: "http"
    port: 80
    targetPort: 80
    nodePort: 30080

Ingress.yaml

 apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
 kind: Ingress
 metadata:
   name: tls-ingress
 spec:
   tls:
     - secretName: oaky-tls
       hosts: 
         - api.localhost
   rules:
   - host: api.localhost
     http:
       paths:
       - path: /
         backend:
           serviceName: api
           servicePort: 80

我已经检查并且 TLS 密码可用,我不明白这里的问题,非常感谢一些帮助。

【问题讨论】:

  • 这是hello world ingress,我已经完成了所有这些,并且通过curl进行了测试,根据问题,我没有curl的问题,只是浏览器的问题
  • Ingress 不需要指向 NodePort 后端。请问可以把服务类型改成 ClusterIP 吗?您还可以验证您是如何到达入口的吗?它有带有外部 IP 的服务吗?你部署了什么入口控制器?
  • 我使用的是 nginx 入口控制器,默认情况下它是一个 minikube 插件。我现在已将类型更改为 clusterIP。当我在 ingress-controller pod 上执行日志时,它会为我提供 curl 请求的结果,而不是浏览器请求的结果。

标签: nginx kubernetes kubernetes-ingress nginx-reverse-proxy


【解决方案1】:

已解决: Chrome 忽略了 etc hosts 文件,所以我做了以下操作:

  • 切换到 Firefox,URL 立即可用。
  • 添加了注释来表示类:

kubernetes.io/ingress.class: nginx

  • 添加注释以确保将请求重定向到 ssl

nginx.ingress.kubernetes.io/ssl-redirect: "true"

【讨论】:

    猜你喜欢
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 2023-03-09
    • 2020-03-18
    • 2020-12-04
    • 2021-12-17
    相关资源
    最近更新 更多