LAB02b: Deep Dive into Kubeconfig, Client Certificate & Server Certificate

LAB OBJECTIVE

You will learn:

✔ Where kubeconfig files are stored

✔ How to view kubeconfig structure

✔ How to extract client cert & private key

✔ How to decode the client certificate

✔ How to check Kubernetes API server certificate

✔ How to find Subject, Issuer, SAN

✔ How Kubernetes verifies TLS connections

This is essential knowledge for:

  • troubleshooting kubectl

  • integrating Lens

  • adding remote clusters

  • fixing TLS errors

  • understanding Kubernetes authentication

LAB 1 — Locate and View Kubeconfig

Step 1: Check where kubectl is reading kubeconfig from

Step 2: Show path

If empty, default is:

Step 3: View cluster info in kubeconfig

LAB 2 — View the Entire Kubeconfig File

Look for:

  • clusters:

  • users:

  • contexts:

  • current-context:

LAB 3 — Extract the Client Certificate from kubeconfig

Your kubeconfig contains:

Step 1: Extract client certificate

Step 2: Extract client private key

LAB 4 — Decode Client Certificate and Inspect Identity

Step 1: View certificate info

Output will show:

  • Subject CN (user name)

  • O (group)

  • Issuer (Kubernetes CA)

  • Validity (expiry date)

  • Public Key

  • Extensions

Expected Example:

Meaning:

  • CN = user identity inside Kubernetes

  • O = group, e.g., system:masters → full admin

LAB 5 — Verify Client Key Matches the Certificate

Both must match.

This validates the cert-key pair.

LAB 6 — Extract the Kubernetes Cluster CA Certificate

Your kubeconfig has:

Extract it:

View it:

Look for:

This is the Kubernetes CA.

LAB 7 — Check Kubernetes API Server Certificate (Server Cert)

The Kubernetes API server certificate is located at:

View full certificate:

Important fields:

✔ Subject CN

✔ SAN (Subject Alternative Names)

These SAN entries must include:

  • cluster IP

  • internal DNS names

  • external hostname (if used)

If SAN is missing → kubectl/Lens will give x509 unknown certificate or tls server name errors.

LAB 8 — Compare Client → Server → CA trust chain

Check if server certificate is signed by CA:

Expected result:

If failed → certificate mismatch → cluster broken.

LAB 9 — Verify kubectl Connectivity using TLS Debug Mode

Use curl to test API server:

You should see:

This means TLS OK, but no token/cert provided.

LAB 10 — Check Who You Are Inside the Cluster

Expected:

LAB 11 — Check RBAC Permissions Based on Certificate Identity

Example:

As system:masters:

BONUS LAB — Export kubeconfig for Lens

Verify kubeconfig is valid:

Lens uses:

  • cluster.server

  • certificate-authority-data

  • client-certificate-data

  • client-key-data

This lab helps troubleshoot Lens issues like:

Last updated