Portainer CE on k3s (Kubernetes 1.24+) fails with x509 errors due to missing CA in auto-mounted token — full working fix #13189
Replies: 1 comment 1 reply
-
|
This is a common issue with k3s 1.24+ because Kubernetes stopped auto-mounting the service account token with the CA cert in the projected volume. The token is there but the CA bundle isn't where Portainer expects it. The fix is to either:
Which approach are you going with? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Ask a Question!
Summary
When running Portainer CE inside a k3s cluster (or any Kubernetes 1.24+ cluster), the UI fails to list namespaces, pods, services, ingresses, secrets, etc., and repeatedly shows TLS errors such as:
Warning
tls: failed to verify certificate: x509: certificate signed by unknown authority
This happens even when Portainer is running inside the cluster and using the default ServiceAccount.
After investigation, this appears to be a structural incompatibility between:
Below is the root cause and a solution.
Environment
Symptoms
Portainer CE UI shows errors such as:
Warning
Unable to retrieve namespaces: tls: failed to verify certificate: x509: certificate signed by unknown authority
Unable to list pods across the cluster: tls: failed to verify certificate
Unable to get dashboard stats
The Portainer container logs show the same TLS validation failures.
Root Cause
BoundServiceAccountTokens are:
It expects three files:
But with Kubernetes 1.24+:
These options exist in Portainer Business, but not in CE.
Solution Overview
This restores the legacy behavior Portainer CE expects.
Step-by-step
# portainer-sa-token.yaml apiVersion: v1 kind: Secret metadata: name: portainer-sa-token namespace: portainer annotations: kubernetes.io/service-account.name: portainer-sa type: kubernetes.io/service-account-tokenApply:
Extract the token:
Extract the k3s CA:
sudo cat /var/lib/rancher/k3s/server/tls/server-ca.crt | base64 -w0Edit the Secret:
Add or replace:
This ensures the Secret contains the full legacy ServiceAccount bundle.
The initial patch mounted only the token, which caused the TLS failure.
We must mount the entire Secret.
Result
After applying this fix:
Portainer CE successfully lists namespaces
Pods, services, ingresses, secrets, PVCs all load correctly
No more TLS errors
No need to disable TLS verification
No need for Portainer Business features
/Optional improvements for maintainers
A minimal enhancement would be:
This would make Portainer CE compatible with modern Kubernetes clusters without manual patching.
I hope this helps
Beta Was this translation helpful? Give feedback.
All reactions