Search code examples
kubernetesssl-certificategoogle-kubernetes-enginelets-encryptcert-manager

cert-mananger configuration on GKE with clouddns


So I am looking to set up cert-manager on GKE using google clouddns. It seems like a lot of the older questions on SO that have been asked are using http01 instead of dns01. I want to make sure everything is correct so I don't get rate limited.

here is my issuer.yaml

apiVersion: cert-manager.io/v1alpha2
kind: Issuer
metadata:
  name: letsencrypt-staging
spec:
  acme:
    server: https://acme-staging-v02.api.letsencrypt.org/directory
    email: engineering@company.com 
    privateKeySecretRef:
      name: letsencrypt-staging
    solvers:
    - dns01:
        clouddns:
          project: MY-GCP_PROJECT
          # This is the secret used to access the service account
          serviceAccountSecretRef:
            name: clouddns-dns01-solver-svc-acct
            key: key.json

here is my certificate.yaml

apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
  name: my-website
  namespace: default
spec:
  secretName: my-website-tls
  issuerRef:
    # The issuer created previously
    name: letsencrypt-staging
  dnsNames:
  - my.website.com 

I ran these commands to get everything configured:

kubectx my-cluster
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.15.1/cert-manager.yaml
kubectl get pods --namespace cert-manager
gcloud iam service-accounts create dns01-solver --display-name "dns01-solver"
gcloud projects add-iam-policy-binding $PROJECT_ID --member serviceAccount:dns01-solver@$PROJECT_ID.iam.gserviceaccount.com --role roles/dns.admin
gcloud iam service-accounts keys create key.json --iam-account dns01-solver@$PROJECT_ID.iam.gserviceaccount.com
kubectl create secret generic clouddns-dns01-solver-svc-acct --from-file=key.json
kubectl apply -f issuer.yaml
kubectl apply -f certificate.yaml

here is the output from kubectl describe certificaterequests

Name:         my-certificaterequests
Namespace:    default
Labels:       <none>
Annotations:  cert-manager.io/certificate-name: my-website
              cert-manager.io/private-key-secret-name: my-website-tls
              kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"cert-manager.io/v1alpha2","kind":"Certificate","metadata":{"annotations":{},"name":"my-cluster","namespace":"default...
API Version:  cert-manager.io/v1alpha3
Kind:         CertificateRequest
Metadata:
  Creation Timestamp:  2020-06-28T00:05:55Z
  Generation:          1
  Owner References:
    API Version:           cert-manager.io/v1alpha2
    Block Owner Deletion:  true
    Controller:            true
    Kind:                  Certificate
    Name:                  my-cluster
    UID:                   81efe2fd-5f58-4c84-ba25-dd9bc63b032a
  Resource Version:        192470614
  Self Link:               /apis/cert-manager.io/v1alpha3/namespaces/default/certificaterequests/my-certificaterequests
  UID:                     8a0c3e2d-c48e-4cda-9c70-b8dcfe94f14c
Spec:
  Csr:  ...
  Issuer Ref:
    Name:  letsencrypt-staging
Status:
  Certificate: ...
  Conditions:
    Last Transition Time:  2020-06-28T00:07:51Z
    Message:               Certificate fetched from issuer successfully
    Reason:                Issued
    Status:                True
    Type:                  Ready
Events:
  Type    Reason             Age   From          Message
  ----    ------             ----  ----          -------
  Normal  OrderCreated       16m   cert-manager  Created Order resource default/my-certificaterequests-484284207
  Normal  CertificateIssued  14m   cert-manager  Certificate fetched from issuer successfully

I see the secret kubectl get secret my-website-tls

NAME                    TYPE                DATA   AGE
my-website-tls   kubernetes.io/tls   3      18m

Does that means everything worked and I should try it in prod? What worries me is that I didn't see any DNS records change in my cloud console.

In addition I wanted to confirm:

  • How would I change the certificate to be for a wildcard *.company.com?
  • If in fact I am ready for prod and will get the cert, I just need to updated the secret name in my ingress deployment to redeploy?

Any insight would be greatly appreciated. Thanks


Solution

  • I answered you on Slack already. And you would change the name by changing the value in the dnsNames section of the Certificate or the spec.tls.*.hosts if using ingress-shim, you just include the wildcard name exactly as you showed it.