Deploying an HTTPS Website with Kubernetes, Istio, and cert-manager: Part 2

In this tutorial I’ll be walking you through you how to deploy an HTTPS microservice website using Kubernetes, Istio and Kubernetes cert-manager.

This is part 2 of a two-part series. The first part takes you through the Kubernetes cluster setup, installing and configuring Istio on that cluster, and deploying your first application on the cluster. In part 2 we’ll learn how to use Istio gateways, routes, and how to secure your website with Kubernetes cert-manager.

Cert-Manager

In order for our website to use HTTPS, we need to configure our Kubernetes cluster to use the cert-manager plugin. This plugin allows you to generate SSL certificates for your website automatically. To install cert-manager we'll use our Kubernetes package manager and friend Helm. Run the following 3 commands:

When successful you’ll see a message:

Issuer

The cert-manager relies on a new Kubernetes api-resource called an Issuer to... well... issue certificates. It will then store the certificate inside of a Kubernetes Secret, defined in the YAML of the issuer (called my-certificate-key in this example). Be sure to update your email address

Save the YAML and apply it:

You can verify the certificate was created by listing the secrets in the istio-system namespace. You should see an entry for my-certificate-key:

Certificates

We’ve finally made it to where we can get our SSL certificate. To do this, we’ll create a new Certificate Kubernetes API resource. This certificate resource will, in this example, be called my-cert and live in the istio-system namespace. It will save it's certificate's .key and .crt files in a Kubernetes secret named my-ingress-cert. The issuerRef name must match the Issuer we created above, and the certificate must live in the same namespace as the istio-ingressgateway. Also don't forget to update your dnsNames.

Before applying your certificate YAML, double check that your domain is resolvable to your Istio Ingress Gateway IP address

Once confirmed, apply your certificate:

Listing the secrets of istio-system namespace should now include the my-ingress-cert secret:

Gateways

With our SSL certificate in place, the last thing we need to do is route the incoming traffic to our pods. This is all done by Istio Gateways and VirtualServices. Let’s create our first Istio gateway. We’ll create a new Gateway named bookinfo-gateway-https which will reside in the default Kubernetes namespace. The gateway will listen on port 80 for YOURDOMAIN.COM and redirect traffic to HTTPS Port 443. The gateway will also be listening on HTTPS/443 for YOURDOMAIN.COM and use the certificate we created in the previous step, my-ingress-cert

Apply the gateway YAML file:

Virtual Services

The last component of this that we need to set up are the Virtual Services. Similar to those in NGINX or Apache, we need to configure the routes that Istio will direct traffic that comes in on YOURDOMAIN.COM to. These routes are called "Virtual Services" and are defined by yet another YAML file. The virtual service will route all requests to /productpage, /static, /login, /logout, and /api/v1/products through the bookinfo-gateway-https gateway we created above and route it to the productpage service of the application. This productpage service was created when we deployed the bookinfo application in part 1 of this tutorial.

Apply your virtual services:

Hooray! You’ve done it! You should be able to go to https://YOURDOMAIN.COM/productpage and see the beautiful bookinfo example application deployed!

Web Developer, Marathon Runner, Coffee Drinker.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store