尽管未配置TLS,minikube ingress仍坚持使用HTTPS

时间:2019-10-06 11:27:14

标签: kubernetes https minikube kubernetes-ingress

我想使用minikube在本地测试我的(Helm打包的)Kubernetes应用程序,并使用Kubernetes入口将HTTP代理到我的应用程序提供的HTTP服务。但这不起作用,因为尽管我未请求TLS,但入口(或入口控制器)坚持认为连接是HTTPS。如何确保入口允许HTTP?

kubectl get --output=yaml ingress显示存在用于HTTP且没有TLS的入口资源:

apiVersion: v1
items:
- apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    creationTimestamp: "2019-10-06T10:54:38Z"
    generation: 1
    labels:
      app.kubernetes.io/instance: quarreling-shrimp
      app.kubernetes.io/managed-by: Tiller
      app.kubernetes.io/name: mc
      app.kubernetes.io/version: 2.3.1-SNAPSHOT
      helm.sh/chart: mc-2.3.1
    name: quarreling-shrimp-mc
    namespace: default
    resourceVersion: "126597"
    selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/quarreling-shrimp-mc
    uid: 296f8d69-8f40-49c5-b352-acbc6ec1cc19
  spec:
    rules:
    - http:
        paths:
        - backend:
            serviceName: quarreling-shrimp-mc-be-svc
            servicePort: 8080
          path: /api
        - backend:
            serviceName: quarreling-shrimp-mc-fe
            servicePort: 80
          path: /
  status:
    loadBalancer:
      ingress:
      - ip: 192.168.122.66
kind: List
metadata:
  resourceVersion: ""
  selfLink: ""

但是当我尝试使用HTTP访问应用程序时,响应尝试重定向以使用HTTPS。这是curl -i 192.168.122.66的输出:

HTTP/1.1 308 Permanent Redirect
Server: openresty/1.15.8.1
Date: Sun, 06 Oct 2019 11:22:40 GMT
Content-Type: text/html
Content-Length: 177
Connection: keep-alive
Location: https://192.168.122.66/

<html>
<head><title>308 Permanent Redirect</title></head>
<body>
<center><h1>308 Permanent Redirect</h1></center>
<hr><center>openresty/1.15.8.1</center>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

minikube使用 Nginx Ingress controller 。该控制器does a permanent redirect (HTTP status code 308) from initial HTTP to HTTPS

  

默认情况下,如果该入口启用了TLS,则控制器会将(308)重定向到HTTPS

但是,正如您所指出的那样,文档表明它不应针对您的情况进行重定向,因为您尚未启用TLS。

我观察到,一旦我将host:字段添加到未启用TLS的特定Ingress资源中,生成的curl命令将返回HTTP/1.1 200且没有重定向操作:

  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: some-svc
          servicePort: 80
        path: /

$ curl -v http://$(kubectl get svc -l component=controller -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}') -H 'Host: example.com'

> GET / HTTP/1.1
> Host: example.com
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200

但是没有匹配主机的HTTP GET会导致重定向:

$ curl -v http://$(kubectl get svc -l component=controller -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}')

> GET / HTTP/1.1
> Host: XX.XX.XX.XX
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 308 Permanent Redirect

因此,我假设尽管host:字段是可选的,但如果您未在目标Ingress资源中指定它,则Ingress控制器将无法正确识别与TLS相关的设置。