gpt4 book ai didi

nginx - Kubernetes/Minikube Ingress 错误(301 永久移动)

转载 作者:行者123 更新时间:2023-12-05 00:15:35 27 4
gpt4 key购买 nike

我正在关注 Kubernetes 教程,并在我的 MacBook 上使用 Minikube 作为我的 Kubernetes 环境。本教程中的所有步骤都运行良好,除了让 Ingress 正常工作(我正在关注的 Ingress 教程位于:https://cloud.google.com/container-engine/docs/tutorials/http-balancer)。通过 Ingress 访问时,我收到“301 Moved Permanently”错误。

我的环境:

  • MacBook(macOS Sierra,版本:10.12.5 (16F73))
  • 推荐用于 Minikube 的 xhyve 驱动程序
  • minikube 版本:v0.19.0

  • 我正在使用默认的 Ingress Controller (用于 minikube 的 nginx)并且有
    成功启用入口:
    minikube addons enable ingress

    然后我按照教程中的步骤进行操作:

    第 1 步:部署 nginx 服务器(成功)
    kubectl run nginx --image=nginx --port=80

    步骤 2a:在内部将您的 nginx 部署公开为服务(成功)
    kubectl expose deployment nginx --target-port=80  --type=NodePort

    步骤 2b:验证服务是否可用:
    kubectl get service nginx

    输出:
    NAME      CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
    nginx 10.0.0.170 <nodes> 80:31635/TCP 7s

    从上面,我知道该服务已正确创建...

    第 3 步:创建 Ingress 资源(成功)

    入口配置 YAML (basic-ingress.yaml):
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
    name: basic-ingress
    spec:
    backend:
    serviceName: nginx
    servicePort: 80

    现在应用 YAML:
    kubectl apply -f basic-ingress.yaml

    步骤 4a:验证 Ingress
    kubectl get ingress basic-ingress

    输出:
    NAME            HOSTS     ADDRESS         PORTS     AGE
    basic-ingress * 192.168.64.37 80 16s

    步骤 4b:访问应用程序 ( * 不成功 * )

    该教程指出我应该“将我的浏览器指向应用程序的外部 IP 地址,然后查看标题为“欢迎使用 nginx!”的网页。

    当我将浏览器指向该站点时( http://192.168.64.37 )尝试转换为 https ,这会给出错误“安全连接失败”(来自 Firefox,但来自 Chrome 的类似错误)

    但是,当我 curl 网站时,我收到“301”错误:
    curl 192.168.64.37

    输出:
    <html>
    <head><title>301 Moved Permanently</title></head>
    <body bgcolor="white">
    <center><h1>301 Moved Permanently</h1></center>
    <hr><center>nginx/1.11.12</center>
    </body>
    </html>

    我一直在尝试调试它,但到目前为止没有运气,但是,我在下面提供了更多信息......也许它对诊断问题很有用:

    完整入口描述:
    kubectl describe ingress

    输出:
    Name:           basic-ingress
    Namespace: default
    Address: 192.168.64.38
    Default backend: nginx:80 (172.17.0.3:80)
    Rules:
    Host Path Backends
    ---- ---- --------
    * * nginx:80 (172.17.0.3:80)
    Annotations:
    Events:
    FirstSeen LastSeen Count From SubObjectPath Type Reason Message
    --------- -------- ----- ---- ------------- -------- ------ -------
    3m 3m 1 {ingress-controller } Normal CREATE Ingress default/basic-ingress
    3m 3m 1 {ingress-controller } Normal UPDATE Ingress default/basic-ingress

    以下是 nginx Ingress pod 日志:
    2017-05-26T16:08:27.142309346Z I0526 16:08:27.142156       1 launch.go:101] &{NGINX 0.9.0-beta.4 git-72bb2222 git@github.com:ixdy/kubernetes-ingress.git}
    2017-05-26T16:08:27.142345769Z I0526 16:08:27.142218 1 launch.go:104] Watching for ingress class: nginx
    2017-05-26T16:08:27.142350322Z I0526 16:08:27.141160 1 nginx.go:180] starting NGINX process...
    2017-05-26T16:08:27.142834005Z I0526 16:08:27.142764 1 launch.go:257] Creating API server client for https://10.0.0.1:443
    2017-05-26T16:08:27.166946862Z I0526 16:08:27.166808 1 launch.go:120] validated kube-system/default-http-backend as the default backend
    2017-05-26T16:08:27.174640373Z I0526 16:08:27.174527 1 controller.go:1184] starting Ingress controller
    2017-05-26T16:08:27.175954273Z I0526 16:08:27.175092 1 leaderelection.go:203] attempting to acquire leader lease...
    2017-05-26T16:08:27.183187824Z I0526 16:08:27.183085 1 leaderelection.go:213] successfully acquired lease kube-system/ingress-controller-leader-nginx
    2017-05-26T16:08:28.175881543Z W0526 16:08:28.175472 1 backend_ssl.go:42] deferring sync till endpoints controller has synced
    2017-05-26T16:08:28.179906454Z W0526 16:08:28.179769 1 queue.go:94] requeuing kube-system/default-http-backend, err deferring sync till endpoints controller has synced
    2017-05-26T16:08:31.207329775Z I0526 16:08:31.206860 1 event.go:217] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"basic-ingress", UID:"8fd367b9-422d-11e7-9dd4-d68827e778d4", APIVersion:"extensions", ResourceVersion:"278", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/basic-ingress
    2017-05-26T16:08:37.353651374Z I0526 16:08:37.353525 1 metrics.go:34] changing prometheus collector from to default
    2017-05-26T16:08:37.416440774Z I0526 16:08:37.416333 1 controller.go:421] ingress backend successfully reloaded...
    2017-05-26T16:08:57.183350506Z I0526 16:08:57.183046 1 status.go:302] updating Ingress default/basic-ingress status to [{192.168.64.38 }]
    2017-05-26T16:08:57.186454653Z I0526 16:08:57.186366 1 event.go:217] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"basic-ingress", UID:"8fd367b9-422d-11e7-9dd4-d68827e778d4", APIVersion:"extensions", ResourceVersion:"327", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress default/basic-ingress
    2017-05-26T16:08:57.471160018Z W0526 16:08:57.471017 1 queue.go:94] requeuing kube-system/ingress-controller-leader-nginx, err
    2017-05-26T16:08:57.471182113Z -------------------------------------------------------------------------------
    2017-05-26T16:08:57.471185648Z Error: exit status 1
    2017-05-26T16:08:57.471188375Z nginx: the configuration file /tmp/nginx-cfg585054790 syntax is ok
    2017-05-26T16:08:57.47119123Z 2017/05/26 16:08:57 [emerg] 164#164: no "events" section in configuration
    2017-05-26T16:08:57.471194521Z nginx: [emerg] no "events" section in configuration
    2017-05-26T16:08:57.471197512Z nginx: configuration file /tmp/nginx-cfg585054790 test failed
    2017-05-26T16:08:57.471200655Z
    2017-05-26T16:08:57.471203144Z -------------------------------------------------------------------------------
    2017-05-26T16:09:37.260238379Z E0526 16:09:37.260068 1 controller.go:417] unexpected failure restarting the backend:
    2017-05-26T16:09:37.260266173Z 2017/05/26 16:09:37 [emerg] 182#182: no "events" section in configuration
    2017-05-26T16:09:37.260271749Z nginx: [emerg] no "events" section in configuration
    2017-05-26T16:09:37.260276045Z W0526 16:09:37.260095 1 queue.go:94] requeuing kube-system/kube-dns, err exit status 1
    2017-05-26T16:09:47.20646199Z I0526 16:09:47.206349 1 controller.go:421] ingress backend successfully reloaded...
    2017-05-26T16:10:22.518854138Z 192.168.64.1 - [192.168.64.1] - - [26/May/2017:16:10:22 +0000] "GET / HTTP/1.1" 404 21 "-" "curl/7.51.0" 77 0.001 [upstream-default-backend] 172.17.0.4:8080 21 0.001 404
    2017-05-26T16:10:30.797507654Z 192.168.64.1 - [192.168.64.1] - - [26/May/2017:16:10:30 +0000] "GET / HTTP/1.1" 404 21 "-" "curl/7.51.0" 77 0.000 [upstream-default-backend] 172.17.0.4:8080 21 0.000 404

    最后一点...当我在 basic-ingress.yaml 文件中添加“host:”标签,并将 basic-ingress.yaml 文件中使用的主机名映射到/etc/中的 IP 地址(192.168.64.37)时主机,然后我能够使它工作。不知道为什么 Minikube 需要一个“主机”标签,其中几乎相同的教程在没有主机标签的 GCE 上运行。

    最佳答案

    经过一些实验,似乎 nginx 入口插件错误地尝试重定向到 https 协议(protocol)(端口 443),但如果未配置(这是我的情况),则会出现“301 Moved Permanently”错误......所以为了解决这个问题,我将 ssl-redirect 标志设置如下
    (请参阅新的注释标签 ingress.kubernetes.io/ssl-redirect 其中
    设置为“false”),这似乎解决了这个问题。

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
    name: basic-ingress
    annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
    spec:
    backend:
    serviceName: nginx
    servicePort: 80

    关于nginx - Kubernetes/Minikube Ingress 错误(301 永久移动),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44205593/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com