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:
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
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.
@dpalmaEdo See: https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#deployment on how this automation works.
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.
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
tls:
Would you use code tags next time, please :)
Most helpful comment
@dpalmaEdo See: https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/rewrite#deployment on how this automation works.