How to fix Nginx ingress controller "certificate signed by unknown authority" error?
"Internal error occurred: failed calling webhook \"validate.nginx.ingress.kubernetes.io\": failed to call webhook: Post \"https://nginx-ingress-ingress-nginx-controller-admission.default.svc:443/networking/v1/ingresses?timeout=10s\": x509: certificate signed by unknown authority"
-
Compare the CA stored in
ValidatingWebhookConfiguration
vs in the secret where the*nginx-controller*
pods are runningIn this case, the
*nginx-controller*
pods are indefault
namespace - yours may be in different namespace$ k get ValidatingWebhookConfiguration nginx-ingress-ingress-nginx-admission -o jsonpath='{.webhooks[0].clientConfig.caBundle}' | md5 d41d8cd98f00b204e9800998ecf8427e $ k -n default get secret nginx-ingress-ingress-nginx-admission -o jsonpath='{.data.ca}' | md5 bbf6ef16566994f9f65facc7e8f07b16
-
It's clear that they are not same because the MD5 hashes are different. Let's fix this...
-
Copy the CA from the secret where the
*nginx-controller*
pods are runningIn this case, the
*nginx-controller*
pods are indefault
namespace - yours may be in different namespace$ CA=$(kubectl -n default get secret nginx-ingress-ingress-nginx-admission -o jsonpath='{.data.ca}')
-
Patch the
ValidatingWebhookConfiguration
$ kubectl patch validatingwebhookconfigurations nginx-ingress-ingress-nginx-admission --type='json' -p='[{"op": "add", "path": "/webhooks/0/clientConfig/caBundle", "value":"'$CA'"}]'
-
Repeat step 1 and make sure both MD5 hashes are same
$ k get ValidatingWebhookConfiguration nginx-ingress-ingress-nginx-admission -o jsonpath='{.webhooks[0].clientConfig.caBundle}' | md5 bbf6ef16566994f9f65facc7e8f07b16 $ k -n default get secret nginx-ingress-ingress-nginx-admission -o jsonpath='{.data.ca}' | md5 bbf6ef16566994f9f65facc7e8f07b16
Thank you for saving me half an hour of reading through
nginx-ingress
code! Please accept this humble gift of half a year of free ChatGPT Plus (if I guessed your email right).P.S. You can factor out the namespace and ingress name into variables for ease of copy-paste.