I whole wholeheartedly agree with the answer provided by @guillaume blaquiere.
You should use following guide to have the HTTPS
connection to your Django.
I would also like to add some additional information/resources to the whole question.
Addressing the following statement:
I apply it and all work done on my cluster except for the fact that kubernetes create a Load balancer using http.
In fact you are creating a network load balancer (layer 4), (TCP
/UDP
):
When you create a Service of type LoadBalancer, a Google Cloud controller wakes up and configures a network load balancer in your project. The load balancer has a stable IP address that is accessible from outside of your project.
-- Cloud.google.com: Kubernetes Engine: Docs: Concepts: Service: Service of type LoadBalancer
This type of a load balancer will forward the packets to its destination but it won't be able to accomplish things like path based routing or SSL termination.
To have the ability to connect to your Django app with HTTPS you can:
In the whole process you will be using an Ingress
resource to forward the traffic to the specific backend. Your Ingress
controller will also be responsible for handling SSL
.
A side note!
I'd reckon you could change the Service
of type LoadBalancer
to a Service
of type NodePort
.
You final Ingress
definition will look similar to the one below:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: INGRESS_NAME
namespace: test1
annotations:
kubernetes.io/ingress.global-static-ip-name: ADDRESS_NAME
networking.gke.io/managed-certificates: CERTIFICATE_NAME
kubernetes.io/ingress.class: "gce"
spec:
defaultBackend:
service:
name: mydjango
port:
number: 8080
Alternatively you can:
- Use different
Ingress
controller like nginx-ingress
and add the certificate to handle the HTTPS
either by (this will not use Google managed certificate):
Additional resources:
I'd reckon you could also take a look on this answer (on how the communication is happening with nginx-ingress
):