Search code examples
kuberneteswebhookskubectlkubernetes-pod

Kubernetes certificate always disappear after few hours


I am new to kubernetes. I created a certificate in kubernetes for my validation webhook. After approving the certificate, and checking if it is still there after few hours, by running

kubectl -n mynamespace get csr

However, it shows no resources found in the namespace. But if the certificate is newly created and run the same command above it shows the certificate.

Is this an expected behavior? where does the certificate go?

Please help. :(


Solution

  • This is an expected behavior for security reasons. You should download the certificate using below command and keep it safe.

    kubectl get csr my-svc.my-namespace -o jsonpath='{.status.certificate}' \
        | base64 --decode > server.crt
    

    https://kubernetes.io/docs/tasks/tls/managing-tls-in-a-cluster/#download-the-certificate-and-use-it