Ingress-nginx: Ingress doesn't redirect to https

Created on 12 Dec 2017  路  4Comments  路  Source: kubernetes/ingress-nginx

Hi all!

I read that ingress-nginx redirect traffic http ---> https at the moment you use ssl. Well, I tried many configurations and this never happens to me.

I give you info:
Architecture: Kubernetes cluster in GCP.

Ingress deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-ingress
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
app: nginx-ingress
spec:
containers:
- name: nginx-ingress
image: quay.io/aledbf/nginx-ingress-controller:0.130
imagePullPolicy: Always
readinessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
livenessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- containerPort: 80
hostPort: 80
protocol: TCP
args:
- /nginx-ingress-controller
- --default-backend-service=$(POD_NAMESPACE)/my-app
#- --configmap=default/nginx-config
- --default-ssl-certificate=default/ssl-cert

My nginx service:
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
labels:
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: nginx-ingress
#service.beta.kubernetes.io/force-ssl-redirect: "true"
app: nginx-ingress
namespace: default
spec:
type: LoadBalancer
#type: NodePort
ports:

  • name: http
    port: 80
    protocol: TCP
    targetPort: 80
  • name: https
    port: 443
    protocol: TCP
    targetPort: 443
    selector:
    app: nginx-ingress

When I go to my browser and write: https://servicePublicIP it solve but when I wirte http://servicePublicIIP solve too. Doesn't redirect to https.

Could someone help me?

Thanks

Most helpful comment

All 4 comments

Update:

If I wirte this rule in the nginx.conf pod:
if ($https = ""){
rewrite ^(.*)$ https://$host$request_uri permanent;
return 301;
}
I have my redirect. But this is a problem becuase I can't automatize this. Is this a normal behaviour?

Thanks again.

Hi! Thanks for the answer.

Actually, the real reason was in my ingress.yaml sintaxis. I don't know why but sintaxis was wrong but it worked.

The config for the ingress is:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
tls:

  • secretName: ssl-certificate
    rules:

    • host:

      http:

      paths:



      • path: /


        backend:


        serviceName: service


        servicePort: 3000



Would you use code tags next time, please :)

Was this page helpful?
0 / 5 - 0 ratings