Kubernetes ingress redirects http to https

拟墨画扇 提交于 2020-12-12 06:14:17

问题


I need some help from the community, I'm pretty new to kubernetes.

I need the URL of my host defined in the "deployment.yaml" file to redirect from http to https using whatever technique. Next I am going to leave the infrastructure as the code I have.

Deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: default
spec:
  selector:
    matchLabels:
      run: web
  template:
    metadata:
      labels:
        run: web
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:1.0
        imagePullPolicy: Always
        name: web
        ports:
        - containerPort: 8080
          protocol: TCP

service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: default
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
    name: web
  selector:
    run: web
  type: NodePort

I have also created an ssl certificate for https obviously. For this I have created a certificate managed by google with the file "managedcertificate.yaml":

apiVersion: networking.gke.io/v1beta2
kind: ManagedCertificate
metadata:
  name: certificate-test   
spec:
  domains:
    - test.host.com       

Finally, I have created a static ip to assign it later in the ingress. Command: "gcloud compute addresses create ip-test --global"

ingress.yaml:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: basic-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: ip-test        
    networking.gke.io/managed-certificates: certificate-test   
spec:
  rules:
  - host: test.host.com       
    http:
      paths:
      - backend:
          serviceName: web
          servicePort: 8080

That's it. The service works for the url "http://test.host.com" and "https://test.host.com", but what I want is that when I go to port 80 (that is to "http: //test.host.com ") automatically redirects me to 443 (with https).

I have tried to put the following configuration in the ingress: 'ingress.kubernetes.io/force-ssl-redirect:" true "', but it still doesn't work.

I hope someone who understands something more than me can help me please. Thanks in advance to the community, greetings.


回答1:


Unfortunately GKE Ingress implementation does not support HTTP to HTTPS redirection yet, although the feature is being implemented and should be available soon. See ingress-gce #1075.

For now you have the following options:

  • replacing GKE native Ingress with the ingress-nginx
  • implementing redirection yourself. See an example here.


来源:https://stackoverflow.com/questions/64159880/kubernetes-ingress-redirects-http-to-https

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!