【问题标题】:Redirect everything with ingress-nginx使用 ingress-nginx 重定向所有内容
【发布时间】:2023-01-04 19:12:42
【问题描述】:

我创建了一个 YAML 文件,它唯一的工作是:It should immediately redirect to google.com

但它就是行不通......

我的localhost 仍然返回404-nginx

我在 docker-desktop 上,我的集群版本是v1.21.5

这是我的redirect.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-google
  annotations:
    nginx.ingress.kubernetes.io/permanent-redirect: https://www.google.com
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: doesntmatter
            port:
              number: 80

这是我的kubectl get ingress

NAME          CLASS    HOSTS                          ADDRESS     PORTS   AGE
cheddar       nginx    cheddar.127.0.0.1.nip.io       localhost   80      31m
my-google     <none>   *                                          80      26m
stilton       nginx    stilton.127.0.0.1.nip.io       localhost   80      31m
wensleydale   nginx    wensleydale.127.0.0.1.nip.io   localhost   80      31m

注意:其他入口服务,例如cheddar.127.0.0.1.nip.io 工作完美...

【问题讨论】:

    标签: kubernetes kubernetes-ingress kubectl nginx-ingress


    【解决方案1】:

    我猜你忘记了入口类名。

    spec:
      ingressClassName: nginx
      ...
    

    除此之外,您可以创建一个external service

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: google
    spec:
      type: ExternalName
      externalName: www.google.com
      ports:
        - name: https
          port: 443
          protocol: TCP
          targetPort: 443
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: google
      labels:
        name: google
      annotations:
        nginx.ingress.kubernetes.io/backend-protocol: HTTPS
        nginx.ingress.kubernetes.io/upstream-vhost: www.google.com
    spec:
      ingressClassName: nginx
      rules:
      - http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: google
                port:
                  name: https
    

    请注意,来自您的入口控制器的证书不是谷歌的证书。因此可能存在一些问题。一种可能有助于解决此类问题的设置是注释 nginx.ingress.kubernetes.io/upstream-vhost,如上所示。

    【讨论】:

      猜你喜欢
      • 2019-04-30
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2020-07-17
      • 1970-01-01
      • 2021-04-13
      • 2021-11-28
      • 1970-01-01
      相关资源
      最近更新 更多