0

Currently, to generate certificates with Let's encrypt have to add these annotations

kubernetes.io/ingress.class=nginx
certmanager.k8s.io/cluster-issuer=letsencrypt-prod ### your cluster issuer name
kubernetes.io/tls-acme="true"

Unfortunately, with a larger HA system, this is a bit pain adding manually when creating a new ingress.

This can be done with single command applying annotation to all ingress which also requires after work.

Dipak Parmar
  • 11
  • 1
  • 2

2 Answers2

2

You could use the following script to do a mass update all ingresses across all namespaces.

for namespace in `kubectl get ns -o name | awk -F '/' '{print $2}'`
do
  for ingress in 'kubectl get ingress -o name | awk -F '/' '{print $2}'`
  do
    echo "Working on $ingress in $namespace"
    kubectl -n $namespace annotate ingress $ingress kubernetes.io/ingress.class=nginx
    kubectl -n $namespace annotate ingress $ingress certmanager.k8s.io/cluster-issuer=letsencrypt-prod
    kubectl -n $namespace annotate ingress $ingress kubernetes.io/tls-acme="true"
  done
done
  • Thanks, @matthew. Unfortunately, my question is more on setting default values to ingress. For eg. In Cluster A, for node A all the ingress I create onwards should have these annotations by default. – Dipak Parmar Aug 10 '20 at 18:21
  • @DipakParmar I don't know of any settings that let you customize the default annotations for an ingress. You might be able to use sidecar to inject the annotations are creating. Please see https://github.com/tumblr/k8s-sidecar-injector – Matthew Mattox Aug 12 '20 at 15:26
  • sidecar injector seems a good solution. Thank you. :) – Dipak Parmar Oct 23 '20 at 05:11
1

you probably want to do

kubectl annotate ingress kubernetes.io/ingress.class=nginx --all

this way you don't need to know the name of the ingress service since its apply to all of them.

Erwan A. R. Riou
  • 403
  • 5
  • 15
  • Thanks @erwan-a-r-riou this helps after the creation of ingress. My question was more when you create the ingress, controller or operator watches the changes and add it automatically apply that annotations – Dipak Parmar Sep 05 '21 at 01:04