rivernews / iriversland2-kubernetes

Terraform provisioning K8 infra for iriversland2, my personal website, as well as other projects.
0 stars 1 forks source link

⭐️ K8 modularize: deploy microservices in different namespace #7

Closed rivernews closed 4 years ago

rivernews commented 5 years ago

Currently we are using one namespace for all microservices (specified a fixed namespace in our custom terraform module). It would be great if we can separate them into different microservices.

The challenge is we are using a single wildcard certificate that intends to serve all ingress of every microservices:

ClusterIssuer -->(cert-manager)-->(Ing annotation)--> Certificate == Ingress == Service
!! Certificate & ingress should be in same namespace (at least one cert per ingress)
!! Ingress & Service should be in same namespace

If we are using different namespace for each service, we will end up having several certificates, even if we only have one ClusterIssuer, and should only need one wildcard certificate that covers all domains services will deploy to.

Multiple certificate might work as well, it's just a concern if this will cause unnecessary api calls to letsencrypt, since letsencrypt has a pretty strict quota limit. Needs further investigation into this.

Relevant posts

rivernews commented 5 years ago

This is indeed a common problem. Wildcard certificate, different namespace. How?

https://itnext.io/using-wildcard-certificates-with-cert-manager-in-kubernetes-and-replicating-across-all-namespaces-5ed1ea30bb93

https://github.com/jetstack/cert-manager/issues/273

https://www.techdiction.com/2018/06/17/configuring-kubernetes-ingress-with-a-wildcard-dns-certificate-single-tls-secret-and-applications-in-multiple-namespaces/

rivernews commented 5 years ago

This isn’t probably a good start: https://scriptthe.net/2019/06/21/utilize-a-default-certificate-for-services-fronted-by-nginx-ingress/

  1. Set default ssl certificate in extra args in Nginx controller. Also for the cert secret specified, you have to use the one w/ tls.crt and tls.key, which is the letsencrypt prod or staging itself, not the one created by cert-manager.Like in this example.
  2. Ingress resources: remove annotations, remove secret name. So just the tls block with hosts.
rivernews commented 4 years ago

Implementation

rivernews commented 4 years ago

De-coupling the installation module

How should we approach this?

Imagine what the result should be like


rivernews commented 4 years ago

CI/CD through terraform

rivernews commented 4 years ago

Resolved K8 unauthorized error, see code comment in k8 provider block. Deployed module caller in each microservices repository.