• 80跳转443

在这里插入图片描述

阿里云的方式

cat <<END>gitea-ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: gitea-ingress
  namespace: dbs
  annotations:
    nginx.ingress.kubernetes.io/service-weight: ""
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
  generation: 2
spec:
  rules:
  - host: git.more.cn 
    http:
      paths:
      - path: /
        backend:
          serviceName: gitea
          servicePort: 3000
END

自定义yaml方式

自签证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=jbjb/O=tls.test-ingress.com"

kubectl create secret tls tls-test-ingress --key tls.key --cert tls.crt
cat <<END>ingress-test.yaml 
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-test-ingress
  annotations:
    nginx.ingress.kubernetes.io/service-weight: ""
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
  - hosts:
    - tls.test-ingress.com
    secretName: tls-test-ingress
  rules:
  - host: tls.test-ingress.com
    http:
      paths:
      - path: /
        backend:
          serviceName: encry
          servicePort: 8080
END
  • 跨域

cat<<END>com.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress 
metadata:
  name: iguoxiaodi
  namespace: dev
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/enable-cors: "true"
    nginx.ingress.kubernetes.io/cors-allow-credentials: "false"
    nginx.ingress.kubernetes.io/cors-max-age: "3600"
    nginx.ingress.kubernetes.io/cors-allow-methods: "*"
    nginx.ingress.kubernetes.io/cors-allow-headers: "*"
    nginx.ingress.kubernetes.io/cors-expose-headers: '*' 
    nginx.ingress.kubernetes.io/proxy-body-size: '1024m'
    #nginx.ingress.kubernetes.io/connection-proxy-header: 'upgrade'
    nginx.ingress.kubernetes.io/proxy-read-timeout: "500"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    #ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/cors-allow-origin:  '*'
    #nginx.org/location-snippets: |
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
spec:
  rules: 
  - host: tadmin.JB.com
    http:
      paths: 
      - path: /  
        backend: 
          serviceName: admin-h5
          servicePort: 80

      - path: /admin
        backend: 
          serviceName: gateway
          servicePort: 16000
END
  • 对应以上
     location / {
      proxy_ignore_client_abort on;
      client_max_body_size    100m;
      proxy_pass http://172.16.0.30:30019;
      proxy_set_header HOST $proxy_host;
      proxy_set_header X-Real-IP $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_read_timeout 3600s;
      proxy_send_timeout 60s; 
      add_header 'Access-Control-Allow-Origin' '*';
      add_header 'Access-Control-Allow-Headers' '*';
      add_header 'Access-Control-Allow-Methods' '*';
      add_header 'Access-Control-Expose-Headers' '*';

        }

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐