Search code examples
kubernetesgoogle-cloud-platformlets-encrypt

How do I present letsencrypt certificates to Kubernetes nginx (GKE)?


I am learning the Google Cloud platform, trying to implement my first project and am getting lost in the tutorials. I am stuck at the trying to implement an nginx ingress. My ingress is stuck in CrashLoopBackoff and the logs show the following error.

I know how to do this task with DockerCompose, but not here.

Where do I start?

1#1: cannot load certificate "/etc/letsencrypt/live/blah.com/fullchain.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/blah.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/blah.com/fullchain.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/blah.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)

I am not yet certain this is helpful, but I have set up the Certificate Authority Service (https://cloud.google.com/certificate-authority-service/docs/best-practices).


Solution

  • Instead of using that and following setup of GCP CA setup i would suggest using cert-manager with the ingress.

    Cert-manager will get the TLS cert from let's-encrypt CA , cert-manager will create the secret into k8s and store verified certificate into a secret.

    You can attach secret with the ingress, as per host and use it.

    Cert-manager installation

    YAML example :

    apiVersion: cert-manager.io/v1alpha2
    kind: ClusterIssuer
    metadata:
      name: cluster-issuer-name
    spec:
      acme:
        server: https://acme-v02.api.letsencrypt.org/directory
        email: [email protected]
        privateKeySecretRef:
          name: secret-name
        solvers:
        - http01:
            ingress:
              class: nginx-class-name
    ---
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        kubernetes.io/ingress.class: nginx-class-name
        cert-manager.io/cluster-issuer: cluster-issuer-name
        nginx.ingress.kubernetes.io/rewrite-target: /
      name: example-ingress
    spec:
      rules:
      - host: sub.example.com
        http:
          paths:
          - path: /api
            backend:
              serviceName: service-name
              servicePort: 80
      tls:
      - hosts:
        - sub.example.com
        secretName: secret-name
    

    You can read this blog for ref : https://medium.com/@harsh.manvar111/kubernetes-nginx-ingress-and-cert-manager-ssl-setup-c82313703d0d