<p>I have developed a spring boot based REST API service and enabled https on it by using a self signed cert keystore (to test locally), and it works well.</p>

<pre><code>server.ssl.key-store=classpath:certs/keystore.jks
server.ssl.key-store-password=keystore
server.ssl.key-store-type=PKCS12
server.ssl.key-alias=tomcat
</code></pre>

<p>Now, I want to package a docker image and deploy this service in a kubernetes cluster. I know I can expose the service as a NodePort and access it externally. </p>

<p>What I want to know is, I doubt that my self signed cert generated in local machine will work when deployed in kubernetes cluster. I researched and found a couple of solutions using kubernetes ingress, kubernetes secrets, etc. I am confused as to what will be the best way to go about doing this, so that I can access my service running in kubernetes through https. What changes will I need to do to my REST API code?</p>

<p><strong>UPDATED NOTE</strong> : Though I have used a self signed cert for testing purposes, I can obtain a CA signed cert from my company and use it for production. My question is more on the lines of, For a REST API service which already uses a SSL/TLS based connection, what are some of the better ways to deploy and access the cert in kubernetes cluster , eg: package in the application itself, use Secrets, or scrap the application's SSL configuration and use Ingres instead, etc. Hope my question makes sense :)</p>

<p>Thanks for any suggestions.</p>

abisheksampath
<p>Well it depends on the way you want to expose your service. Basically you have either an ingress, an external load balancer (only in certain cloud evironments available) or a Service thats routed to a Port (either via NodePort or HostPort) as options. </p>

<p><strong>Attention:</strong> Our K8S Cluster is self hosted so I have no reliable information about external load balancers in K8S and will therefore omit that option.</p>

<p>If you want to expose your service directly behind one of your domains on port 80 (e.g. <a href="https://app.myorg.org" rel="nofollow noreferrer">https://app.myorg.org</a>) you'll want to use ingress. But if you don't need that and you can live with a specific port the NodePort approach should do the trick (e.g. <a href="https://one.ofyourcluster.servers:30000/" rel="nofollow noreferrer">https://one.ofyourcluster.servers:30000/</a>).</p>

<p>Let's assume you want to try the ingress approach than you need to add the certificates to the ingress definition in K8S instead of the spring boot application or you must additionally specify that the service is reachable via https itself in the ingress. The way to do it may differ from ingress controller to ingress controller.</p>

<p>For the NodePort/HostPort you just need to enable SSL in your application.</p>

<p>Despite that you also need a valid certificate e.g. issued by <a href="https://letsencrypt.org/" rel="nofollow noreferrer">https://letsencrypt.org/</a>
Actually for K8S there are some projects that can fetch you a letsencrypt certificate automatically if you to use ingresses. (e.g. <a href="https://github.com/jetstack/cert-manager/" rel="nofollow noreferrer">https://github.com/jetstack/cert-manager/</a>)</p>
