<p>In my project I have to create a kubernetes cluster on my GCP with an External Load Balancer service for my django app. I create it with this <code>yaml</code> file:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mydjango
  namespace: test1
  labels:
    app: mydjango
spec:
  ports:
  - name: http
    port: 8000
    targetPort: 8000
  selector:
    app: mydjango
  type: LoadBalancer
</code></pre>
<p>I apply it and all work is done on my cluster except for the fact that kubernetes create a Load balancer using <code>http</code>.</p>
<p>How can I modify my <code>yaml</code> to create the same Load Balancer using <code>https</code> instead <code>http</code> using my google managed certs?</p>
<p>So many thanks in advance
Manuel</p>

Manuel Santi
<p>I whole wholeheartedly agree with the answer provided by @guillaume blaquiere.</p>
<p>You should use following guide to have the <code>HTTPS</code> connection to your Django.</p>
<p>I would also like to add some additional information/resources to the whole question.</p>
<hr />
<p>Addressing the following statement:</p>
<blockquote>
<p>I apply it and all work done on my cluster except for the fact that kubernetes create a Load balancer using http.</p>
</blockquote>
<p><strong>In fact you are creating a network load balancer</strong> (layer 4), (<strong><code>TCP</code></strong>/<code>UDP</code>):</p>
<blockquote>
<p>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.</p>
<p>-- <em><a href="https://cloud.google.com/kubernetes-engine/docs/concepts/service#services_of_type_loadbalancer" rel="nofollow noreferrer">Cloud.google.com: Kubernetes Engine: Docs: Concepts: Service: Service of type LoadBalancer</a></em></p>
</blockquote>
<p>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.</p>
<p>To have the ability to connect to your Django app with HTTPS you can:</p>
<ul>
<li>Use <a href="https://cloud.google.com/kubernetes-engine/docs/concepts/ingress" rel="nofollow noreferrer">GKE Ingress for HTTP(S) Load Balancing</a> (as pointed by guillaume blaquiere)</li>
</ul>
<p>In the whole process you will be using an <code>Ingress</code> resource to forward the traffic to the specific backend. Your <code>Ingress</code> controller will also be responsible for handling <code>SSL</code>.</p>
<blockquote>
<p>A side note!</p>
<p>I'd reckon you could change the <code>Service</code> of type <code>LoadBalancer</code> to a <code>Service</code> of type <code>NodePort</code>.</p>
</blockquote>
<p>You final <code>Ingress</code> definition will look similar to the one below:</p>
<pre class="lang-yaml prettyprint-override"><code>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: &quot;gce&quot;
spec:
  defaultBackend:
    service:
      name: mydjango
      port:
        number: 8080
</code></pre>
<p><strong>Alternatively</strong> you can:</p>
<ul>
<li>Use different <code>Ingress</code> controller like <code>nginx-ingress</code> and add the certificate to handle the <code>HTTPS</code> either by (this will not use Google managed certificate):
<ul>
<li><a href="https://kubernetes.github.io/ingress-nginx/user-guide/tls/" rel="nofollow noreferrer">Kubernetes.github.io: Ingress nginx: User guide: TLS</a></li>
<li><a href="https://cert-manager.io/docs/installation/kubernetes/" rel="nofollow noreferrer">Cert-manager.io: Docs: Installation: Kubernetes</a></li>
</ul>
</li>
</ul>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Services networking: Ingress</a></em></li>
</ul>
<p>I'd reckon you could also take a look on this answer (on how the communication is happening with <code>nginx-ingress</code>):</p>
<ul>
<li><em><a href="https://stackoverflow.com/questions/64647258/how-nginx-ingress-controller-back-end-protocol-annotation-works-in-path-based-ro/64662822#64662822">Stackoverflow.com: Questions: How NGINX Ingress controller back-end protocol annotation works in path based routing?</a></em></li>
</ul>
