我创建了一个 yaml 档案,它唯一的作业是: It should immediately redirect to google.com
但它只是不起作用......
我localhost还回来了404-nginx
我在 docker-desktop 上,我的 clusterversion 是 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作业正常......
uj5u.com热心网友回复:
我猜你忘记了入口类名称。
spec:
  ingressClassName: nginx
  ...
除此之外,您还可以创建外部服务。
---
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如上所示的注释。

 
							 
										
										 
										
										 
										
										
										 
										
										 
										
										 
										
										
0 评论