The error you're encountering indicates that the TLS certificate presented by the Kubernetes kubelet does not include the IP address 5.161.21.151 in its Subject Alternative Names (SANs). To establish a secure connection, the client verifies that the certificate includes the IP it's connecting to. Since 5.161.21.151 isn't listed, the verification fails.
Here's a step-by-step guide to resolve this issue:
1. Understand the Root Cause
-
Kubelet Certificates: The kubelet, which runs on each node, uses TLS certificates to secure communication. These certificates include SANs that specify which IPs or hostnames are valid for accessing the kubelet API (typically on port 10250).
-
Missing SAN Entry: Your certificate includes 178.156.142.121, 192.168.0.2, and 2a01:4ff:f0:c9e::1, but not 5.161.21.151. This absence causes TLS verification to fail when accessing the kubelet via 5.161.21.151.
2. Potential Solutions
You have a couple of options to address this issue:
Option A: Add the Public IP to the Kubelet’s Certificate SANs
Note: Modifying kubelet certificates can be intricate, especially with MicroK8s, which manages certificates internally. Proceed with caution and ensure you have backups.
-
Locate the Current Certificate:
- MicroK8s stores its certificates typically under
/var/snap/microk8s/current/certs/.
- Identify the kubelet certificate, usually named
kubelet-client-current.pem or similar.
-
Regenerate the Certificate with the New SAN:
- Using MicroK8s Commands:
- Unfortunately, MicroK8s doesn't provide a direct command to add SANs to the kubelet certificate.
- Manual Regeneration:
- Generate a new certificate signing request (CSR) that includes
5.161.21.151 in the SANs.
- Sign the CSR with your CA.
- Replace the existing kubelet certificate with the new one.
- Caution: This might disrupt your cluster temporarily. Ensure you understand the implications.
-
Restart the Kubelet:
-
Verify the Certificate:
Option B: Access the Kubelet via an Existing SAN IP
If modifying certificates is too complex or risky, consider accessing the kubelet using an IP already listed in the SANs:
-
Use a Private IP:
- Instead of
5.161.21.151, access the kubelet via 192.168.0.2 or another IP present in the certificate.
-
Update DNS or Hosts File:
- Map a hostname to one of the existing SAN IPs and use that hostname for access.
-
Set Up a Proxy:
- Use Traefik or another reverse proxy to route requests securely to the kubelet using an IP that's already trusted by the certificate.
3. Secure Your Setup
Important Considerations:
4. Verify the Fix
After implementing either option:
-
Attempt to Access the Logs Again:
kubectl logs backend-deployment-6c7476579d-pfpq9 -n backend-api
- Ensure you're using the correct context and that your kubeconfig points to the right API server.
-
Check for TLS Errors:
- If the connection is successful without TLS errors, the issue is resolved.
-
Monitor Cluster Health:
- Ensure that all cluster components are functioning correctly after making changes to certificates or access methods.
5. Reference Documentation
Conclusion
The core issue is the mismatch between the IP you're accessing (5.161.21.151) and the SANs listed in the kubelet's TLS certificate. By either updating the certificate to include the necessary IP or adjusting your access method to use an existing trusted IP, you can resolve the TLS verification error.
If you're not comfortable making these changes or if exposing the kubelet seems risky, consider leveraging Kubernetes’ API server for log access and management tasks, as it provides a more secure and centralized method for interacting with your cluster.
Please ensure you understand the security implications of exposing the kubelet and modifying certificates. Always back up current configurations before making significant changes.