vSphere Tanzu Supervisor Namespace Stuck Terminating Due to Expired imageregistry Webhook Certificate
search cancel

vSphere Tanzu Supervisor Namespace Stuck Terminating Due to Expired imageregistry Webhook Certificate

book

Article ID: 439557

calendar_today

Updated On:

Products

VMware vSphere Kubernetes Service

Issue/Introduction

A Supervisor Namespace is stuck in Terminating state because deletion of a ContentLibrary custom resource fails against the VMware Image Registry validating webhook due to an expired TLS certificate.

The namespace remains indefinitely in Terminating.

Running below command:

kubectl describe namespace <namespace-name>


Show below:

NamespaceDeletionContentFailure=True
NamespaceContentRemaining=True
NamespaceFinalizersRemaining=True


The failing condition is:

failed calling webhook "default.validating.contentlibraryitem.imageregistry.vmware.com"

 

with error below:

tls: failed to verify certificate: x509: certificate has expired or is not yet valid


The certificate expiry shown in the error is before the current timestamp of deletion attempts.

The namespace contains a remaining CR - contentlibraries.imageregistry.vmware.com/cl-#################

The CR object has a finalizer:

finalizers:
- ContentLibrary.imageregistry.vmware.com


Deletion of the CR will repeatedly fail because the validating webhook certificate is expired.

Error for the delete is as below:

message: Failed to delete library items:
failed calling webhook "default.validating.contentlibraryitem.imageregistry.vmware.com":
tls: failed to verify certificate:
x509: certificate has expired or is not yet valid


Current imageregistry components will appear healthy from pod status perspective:

vmware-system-imageregistry-controller-manager-#########-#####   Running
vmware-system-imageregistry-controller-manager-#########-#####   Running


However the webhook TLS certificate will appear not to have rotated correctly.

Cause

The TLS certificate for the VMware Image Registry validating webhook (imageregistry.vmware.com) expired and failed to auto-rotate.
This expired certificate prevents the webhook from authenticating and processing the deletion of the ContentLibrary custom resource, leaving the namespace termination blocked by the ContentLibrary.imageregistry.vmware.com finalizer.

The custom resource Contentlibraries.imageregistry.vmware.com/cl-################# status explicitly logged the failure: tls: failed to verify certificate: x509: certificate has expired or is not yet valid.
Logged timestamps should confirm the certificate expired at a time that predates the deletion attempt timestamp.

 

Resolution

The solutions is to force the rotation of the expired certificates by scaling the cert-manager and vmware-system-imageregistry-controller-manager deployments to zero (0) replicas, and then scaling them back to their original desired replica count.

Check the namespace stuck in terminating state

kubectl get namespace <namespace>

-- where <namespace> is the namespace of the stuck terminating namespace.

# expect output
# <namespace>   Terminating   24d


Scale the deployment in the vmware-system-cert-manager to zero replicas.

kubectl -n vmware-system-cert-manager scale deployment --all --replicas=0

# expected output
# deployment.apps/cert-manager scaled
# deployment.apps/cert-manager-cainjector scaled
# deployment.apps/cert-manager-webhook scaled
 
Scale the deployment.apps in the vmware-system-cert-manager back to original count.
kubectl -n vmware-system-cert-manager scale deployment --all --replicas=1

# expected output
# deployment.apps/cert-manager scaled
# deployment.apps/cert-manager-cainjector scaled
# deployment.apps/cert-manager-webhook scaled


Check the cert-manager pods for the namespace vmware-system-cert-manager

kubectl get pods -n vmware-system-cert-manager

# expected output

# NAME                                       READY   STATUS    RESTARTS   AGE
# cert-manager-##########-#####              1/1     Running   0          14s
# cert-manager-cainjector-##########-#####   1/1     Running   0          14s
# cert-manager-webhook-##########-#####       1/1     Running   0          14s

-- output per below

NAME                                       READY   STATUS    RESTARTS   AGE
cert-manager-##########-#####              1/1     Running   0          14s
cert-manager-cainjector-##########-#####   1/1     Running   0          14s
cert-manager-webhook-##########-#####       1/1     Running   0          14s


Scale vmware-system-imageregistry-controller-manager to zero replicas.

kubectl scale -n vmware-system-imageregistry deployment/vmware-system-imageregistry-controller-manager --replicas=0

# expected output
# deployment.apps/vmware-system-imageregistry-controller-manager scaled

Scale the deployment in the vmware-system-imageregistry-controller-manager back to original count.

kubectl scale -n vmware-system-imageregistry deployment/vmware-system-imageregistry-controller-manager --replicas=2

# expected output
# deployment.apps/vmware-system-imageregistry-controller-manager scaled


Check the namespace has been removed

kubectl get namespace <namespace>
-- where <namespace> is the namespace of the stuck terminating namespace.

It is expected the namespace will no longer exist.

Scaling the deployments to zero and back up restarts the respective pods, forcing cert-manager to issue a new, valid TLS certificate and the imageregistry-controller-manager to mount it. With a valid TLS certificate active, the validating webhook successfully processes the custom resource deletion, clearing the finalizer and allowing the namespace termination to complete.