Lesson 73 · Section 7: Security
Lesson 73: TLS in Kubernetes: which certificate secures which connection
A map of every certificate in a kubeadm cluster: who is the server and who is the client on each connection, which of the three CAs signed what, where the files live, how a certificate's name becomes a Kubernetes identity, and how to read an x509 error. · 20 min read · 5 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
What this lesson is
The previous lesson explained TLS in general: a server proves its identity with a certificate, a certificate authority (CA) signs that certificate, and a client that trusts the CA can check it. This lesson applies those ideas to a cluster. It is a map: which certificates exist, which connection each one secures, and where to find it.
A cluster needs many certificates because it is not one program. It is a handful of programs on several machines, and each pair that talks must be sure of the other. If any program could connect to etcd, it could read every Secret. If any program could claim to be a kubelet, it could ask for the Secrets of every Pod on "its" node. So every connection is encrypted, and nearly every connection is authenticated in both directions.
The next lessons build on this map: how to create these certificates, how to read their contents with openssl,
how to request new ones through the Certificates API, and how a kubeconfig file carries a client certificate.
How it works
Three kinds of certificate
Every certificate in the cluster is one of three kinds, and each one is a pair of files.
| Kind | What it proves | Who holds the private key | Example |
|---|---|---|---|
| CA (root) certificate | "Certificates signed by me can be trusted" | Only the party that signs new certificates | ca.crt + ca.key |
| Server certificate | "I really am the server you dialled" | The server | apiserver.crt + apiserver.key |
| Client certificate | "I really am this user or component" | The client | apiserver-etcd-client.crt + .key |
The naming convention is steady: the public certificate ends in .crt (sometimes .pem), the private key ends in
.key. The .crt can be shown to anybody. The .key must never leave its owner.
Who is the server on each connection
Parts:
- kubectl (admin.conf)
- kube-scheduler (scheduler.conf)
- controller-manager (controller-manager.conf)
- kube-apiserver (serves apiserver.crt)
- etcd (serves etcd/server.crt)
- kubelet (serves kubelet.crt)
- Pods, kube-proxy (token + ca.crt)
Connections:
- kubectl to kube-apiserver: client cert
- kube-scheduler to kube-apiserver: client
- controller-manager to kube-apiserver: client cert
- kube-apiserver to etcd: etcd client cert
- kube-apiserver and kubelet: 2-way
- Pods, kube-proxy to kube-apiserver: token, no cert
Seen from the middle, the API server plays both roles:
| Connection | Server (presents) | Client (presents) |
|---|---|---|
| kubectl → API server | apiserver.crt | The client certificate in admin.conf |
| Scheduler → API server | apiserver.crt | The client certificate in scheduler.conf |
| Controller manager → API server | apiserver.crt | The client certificate in controller-manager.conf |
| Kubelet → API server | apiserver.crt | The kubelet's client certificate (kubelet-client-current.pem) |
| API server → etcd | etcd/server.crt | apiserver-etcd-client.crt |
| API server → kubelet (logs, exec, port-forward) | The kubelet's serving certificate (kubelet.crt) | apiserver-kubelet-client.crt |
| etcd member → etcd member | etcd/peer.crt | etcd/peer.crt (same file, both roles) |
Liveness probe and etcdctl → etcd | etcd/server.crt | etcd/healthcheck-client.crt |
| API server → aggregated API (metrics-server) | The extension server's certificate | front-proxy-client.crt |
| Pod or kube-proxy → API server | apiserver.crt | No certificate: a ServiceAccount token |
Three things in this table surprise people:
- The API server is a client too. It has one server certificate and three client certificates: one for etcd, one for the kubelets, one for the front proxy.
- The kubelet is a server too.
kubectl logsandkubectl execwork because the API server opens a connection to the kubelet on port 10250. So each kubelet has a client certificate (to call the API server) and a serving certificate (to be called). - Pods do not use client certificates. A Pod, including kube-proxy and CoreDNS, gets a ServiceAccount token
and a copy of the cluster CA certificate. It uses
ca.crtto check the API server, and the token to say who it is.
Three CAs, three circles of trust
Parts:
- apiserver.crt (server)
- kubernetes-ca (pki/ca.crt)
- Client certs (users, components)
- etcd server, peer (pki/etcd/*.crt)
- etcd-ca (pki/etcd/ca.crt)
- etcd clients (apiserver, healthcheck)
- front-proxy-ca (front-proxy-ca.crt)
- front-proxy-client (aggregated APIs)
Connections:
- kubernetes-ca to apiserver.crt: signs
- kubernetes-ca to Client certs: signs
- etcd-ca to etcd server, peer: signs
- etcd-ca to etcd clients: signs
- front-proxy-ca to front-proxy-client: signs
A kubeadm cluster does not have one CA. It has three, and they do not trust each other.
| CA | Files | Signs | Trusted by |
|---|---|---|---|
kubernetes-ca | pki/ca.crt, pki/ca.key | apiserver.crt, and every client certificate the API server accepts: admins, scheduler, controller manager, kubelets, apiserver-kubelet-client | API server (--client-ca-file), every kubeconfig, every Pod |
etcd-ca | pki/etcd/ca.crt, pki/etcd/ca.key | etcd/server.crt, etcd/peer.crt, etcd/healthcheck-client.crt, apiserver-etcd-client.crt | etcd (--trusted-ca-file, --peer-trusted-ca-file), API server (--etcd-cafile) |
front-proxy-ca | pki/front-proxy-ca.crt, .key | front-proxy-client.crt | API server (--requestheader-client-ca-file), extension API servers |
The separation is deliberate. etcd accepts any client certificate signed by its CA and gives that client full
access to all data; it has no RBAC in this setup. If etcd shared the main CA, then every kubelet and every user
with a client certificate could read the whole database directly. With a separate etcd-ca, only the handful of
certificates signed by it can open a connection.
Note where one file sits: apiserver-etcd-client.crt lives in pki/, next to the API server's other files, but
it is signed by etcd-ca. The location tells you who uses a file, not who signed it.
Where everything lives on a kubeadm node
/etc/kubernetes/
├── admin.conf kubeconfig: CN=kubernetes-admin, O=kubeadm:cluster-admins
├── super-admin.conf kubeconfig: O=system:masters (first control plane node only)
├── controller-manager.conf kubeconfig: CN=system:kube-controller-manager
├── scheduler.conf kubeconfig: CN=system:kube-scheduler
├── kubelet.conf kubeconfig: points at the kubelet's rotating client certificate
├── manifests/ static Pod manifests: the flags that name the files below
└── pki/
├── ca.crt, ca.key kubernetes-ca
├── apiserver.crt, .key API server's server certificate
├── apiserver-kubelet-client.crt, .key API server as client of kubelets
├── apiserver-etcd-client.crt, .key API server as client of etcd (signed by etcd-ca)
├── front-proxy-ca.crt, .key front-proxy-ca
├── front-proxy-client.crt, .key API server as client of aggregated APIs
├── sa.key, sa.pub signs and verifies ServiceAccount tokens (not a certificate)
└── etcd/
├── ca.crt, ca.key etcd-ca
├── server.crt, .key etcd's server certificate
├── peer.crt, .key etcd member to etcd member
└── healthcheck-client.crt, .key probes and etcdctl
/var/lib/kubelet/pki/ on every node, workers included
├── kubelet-client-current.pem kubelet's client certificate and key (link to the newest one)
└── kubelet.crt, kubelet.key kubelet's serving certificate
The scheduler and the controller manager have no .crt file in pki/. Their client certificate and key are
embedded in their kubeconfig files, as base64 text in the fields client-certificate-data and client-key-data.
The kubeconfig lesson covers that format.
The flags that connect a component to its files
A file on disk does nothing by itself. A component uses it only because a flag points at it, and kubeadm writes
those flags into the static Pod manifests in /etc/kubernetes/manifests/.
kube-apiserver
| Flag | File | Role |
|---|---|---|
--tls-cert-file, --tls-private-key-file | apiserver.crt, apiserver.key | Its server certificate |
--client-ca-file | ca.crt | Which client certificates it accepts |
--etcd-cafile | etcd/ca.crt | How it checks etcd's server certificate |
--etcd-certfile, --etcd-keyfile | apiserver-etcd-client.crt, .key | What it presents to etcd |
--kubelet-client-certificate, --kubelet-client-key | apiserver-kubelet-client.crt, .key | What it presents to kubelets |
--proxy-client-cert-file, --proxy-client-key-file | front-proxy-client.crt, .key | What it presents to aggregated APIs |
--requestheader-client-ca-file | front-proxy-ca.crt | The front proxy CA |
--service-account-key-file, --service-account-signing-key-file | sa.pub, sa.key | Verifying and signing tokens |
etcd
| Flag | File | Role |
|---|---|---|
--cert-file, --key-file | etcd/server.crt, .key | Its server certificate |
--trusted-ca-file with --client-cert-auth=true | etcd/ca.crt | Clients must present a certificate signed by this CA |
--peer-cert-file, --peer-key-file | etcd/peer.crt, .key | Member to member |
--peer-trusted-ca-file with --peer-client-cert-auth=true | etcd/ca.crt | Which peers it accepts |
kube-controller-manager
| Flag | File | Role |
|---|---|---|
--kubeconfig | controller-manager.conf | Its client certificate for the API server |
--cluster-signing-cert-file, --cluster-signing-key-file | ca.crt, ca.key | Signs new certificates (kubelets, approved requests) |
--root-ca-file | ca.crt | The CA copy that is handed to every Pod |
--service-account-private-key-file | sa.key | Signs ServiceAccount tokens |
The controller manager is the only running component that needs ca.key. It is the cluster's signer: when a
new kubelet asks for a certificate, this is the process that signs it.
Mutual TLS: two checks on every request
Parts:
- kubectl (reads kubeconfig)
- apiserver.crt (SAN: names and IPs)
- kube-apiserver (port 6443)
- CA in kubeconfig (certificate-authority)
- Client cert (CN=kubernetes-admin)
- Client CA (--client-ca-file)
- User and groups (from CN and O)
Connections:
- kube-apiserver to apiserver.crt: shows
- apiserver.crt to kubectl: sent to
- kubectl to CA in kubeconfig: verifies with
- kubectl to Client cert: presents
- Client cert to kube-apiserver: sent to
- kube-apiserver to Client CA: verifies with
- Client CA to User and groups: then RBAC
When kubectl calls the API server, two independent checks happen before any Kubernetes logic runs.
- The client checks the server. The API server presents
apiserver.crt. kubectl verifies the signature with the CA in its kubeconfig (certificate-authority-data), and then checks that the address it dialled appears in the certificate's Subject Alternative Names (SAN). - The server checks the client. kubectl presents its client certificate. The API server verifies the
signature with
--client-ca-file.
Both checks also look at the validity dates. Either side refuses a certificate that has expired.
The SAN list is why the API server certificate is the most detailed one in the cluster. It must name every address that anyone uses to reach the API server:
X509v3 Subject Alternative Name:
DNS:controlplane, DNS:kubernetes, DNS:kubernetes.default, DNS:kubernetes.default.svc,
DNS:kubernetes.default.svc.cluster.local, IP Address:10.96.0.1, IP Address:10.0.0.10
Pods reach it as kubernetes.default.svc or 10.96.0.1, nodes reach it by its IP address or host name, and a load
balancer in front of several control plane nodes adds one more name. An address that is missing from the list
produces an error even though the certificate is otherwise perfect.
The name in the certificate is the identity
Once a client certificate is accepted, the API server reads two fields from its subject:
- CN (common name) becomes the user name.
- Each O (organization) becomes a group.
Kubernetes has no user database. These names exist only inside certificates, and RBAC bindings refer to them.
| Credential | CN (user) | O (group) | Why it matters |
|---|---|---|---|
admin.conf | kubernetes-admin | kubeadm:cluster-admins | The group is bound to the cluster-admin ClusterRole |
super-admin.conf | kubernetes-super-admin | system:masters | This group bypasses authorization completely |
scheduler.conf | system:kube-scheduler | Matches the built-in role for the scheduler | |
controller-manager.conf | system:kube-controller-manager | Matches the built-in role for the controller manager | |
kubelet.conf | system:node:<nodeName> | system:nodes | Required by the Node authorizer, which limits a kubelet to its own node's objects |
So a certificate can be valid and still useless. A kubelet certificate with the CN node01 instead of
system:node:node01 passes the TLS check, and then every request is refused with Forbidden, because no rule
gives anything to a user called node01.
The kubelet's two certificates
The kubelet's certificates are not in /etc/kubernetes/pki. They are in /var/lib/kubelet/pki on every node, and
they are created differently from the rest.
- Client certificate. When a node joins, the kubelet uses a bootstrap token to ask the cluster for a
certificate. The controller manager signs it with
kubernetes-ca, and the kubelet stores it askubelet-client-<date>.pem. The linkkubelet-client-current.pemalways points to the newest file, and/etc/kubernetes/kubelet.confrefers to that link. The kubelet renews this certificate by itself before it expires. - Serving certificate. By default the kubelet creates
kubelet.crtitself, self-signed. No CA in the cluster vouches for it, so the API server does not verify it (it would need--kubelet-certificate-authorityto do so). This is also why metrics-server on a kubeadm cluster needs--kubelet-insecure-tlsunless you turn on signed serving certificates withserverTLSBootstrap: trueand approve the requests.
How long certificates last
| Certificate | Lifetime with kubeadm defaults | How it is renewed |
|---|---|---|
| The three CAs | 10 years | By hand; replacing a CA is a major operation |
Everything else in pki/ and the .conf files | 1 year | kubeadm certs renew all, and automatically during kubeadm upgrade |
| Kubelet client certificate | 1 year | Automatically, by the kubelet |
A cluster that is upgraded at least once a year never notices. A cluster that is left alone for a year stops
working on the anniversary of its installation, with certificate has expired in every log.
Under the hood · What sa.key is, and how Pods come to trust the API server
sa.key and sa.pub are a plain key pair with no certificate around them. The API server signs each
ServiceAccount token with the private key (--service-account-signing-key-file) and verifies incoming tokens with
the public key (--service-account-key-file). No CA is involved, because the only party that has to trust a token
is the API server itself.
The other half of the Pod story is the CA. The controller manager takes the file named by --root-ca-file and
publishes it as a ConfigMap called kube-root-ca.crt in every namespace. The kubelet mounts that ConfigMap,
together with the token, into each Pod:
/var/run/secrets/kubernetes.io/serviceaccount/
├── ca.crt the cluster CA, to verify the API server
├── namespace
└── token the Pod's identity
So a Pod performs only half of mutual TLS: it checks the server with ca.crt, and identifies itself with a
token instead of a client certificate.
Under the hood · What the front proxy is for
The API server can pass requests for some API groups to an extension server. kubectl top works this way: the
request for metrics.k8s.io is forwarded to metrics-server. The API server has already authenticated the user, so
it forwards the user name and groups in HTTP headers (X-Remote-User, X-Remote-Group).
The extension server must be sure those headers come from the real API server, and not from somebody who simply
typed them. So the API server connects with front-proxy-client.crt, and the extension server only believes the
headers if that certificate is signed by front-proxy-ca. A separate CA is essential here: if the main CA were
used, any holder of an ordinary client certificate could connect to an extension server and claim to be any user.
Using it
Example · Find every certificate a component uses
Do not rely on memory. The manifest lists the exact paths, and one grep shows all of them:
grep -E "\.(crt|key|pub)" /etc/kubernetes/manifests/kube-apiserver.yaml
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
- --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt
- --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key
- --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
- --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
- --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
- --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
- --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
- --service-account-key-file=/etc/kubernetes/pki/sa.pub
- --service-account-signing-key-file=/etc/kubernetes/pki/sa.key
- --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
- --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
The same command works for etcd.yaml and kube-controller-manager.yaml. When a task asks "which certificate
does the API server use to talk to etcd?", the answer is one line of this output.
Example · See all certificates, their expiry and their CA at once
On a control plane node, kubeadm prints the whole inventory:
kubeadm certs check-expiration
CERTIFICATE EXPIRES RESIDUAL TIME CERTIFICATE AUTHORITY EXTERNALLY MANAGED
admin.conf Nov 30, 2027 09:12 UTC 364d ca no
apiserver Nov 30, 2027 09:12 UTC 364d ca no
apiserver-etcd-client Nov 30, 2027 09:12 UTC 364d etcd-ca no
apiserver-kubelet-client Nov 30, 2027 09:12 UTC 364d ca no
controller-manager.conf Nov 30, 2027 09:12 UTC 364d ca no
etcd-healthcheck-client Nov 30, 2027 09:12 UTC 364d etcd-ca no
etcd-peer Nov 30, 2027 09:12 UTC 364d etcd-ca no
etcd-server Nov 30, 2027 09:12 UTC 364d etcd-ca no
front-proxy-client Nov 30, 2027 09:12 UTC 364d front-proxy-ca no
scheduler.conf Nov 30, 2027 09:12 UTC 364d ca no
super-admin.conf Nov 30, 2027 09:12 UTC 364d ca no
CERTIFICATE AUTHORITY EXPIRES RESIDUAL TIME EXTERNALLY MANAGED
ca Nov 28, 2036 09:12 UTC 9y no
etcd-ca Nov 28, 2036 09:12 UTC 9y no
front-proxy-ca Nov 28, 2036 09:12 UTC 9y no
The CERTIFICATE AUTHORITY column is the three-CA picture in table form. The kubelet's certificates are not listed:
the kubelet manages those itself. Check them with ls -l /var/lib/kubelet/pki on the node.
Example · Talk to etcd with the right three files
etcd demands a client certificate, so etcdctl needs the same three things as any TLS client: the CA to check the
server, and a certificate and key to present.
ETCDCTL_API=3 etcdctl \
--endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
endpoint health
https://127.0.0.1:2379 is healthy: successfully committed proposal: took = 9.6ms
Any pair signed by etcd-ca is accepted: server, peer, healthcheck-client or apiserver-etcd-client. Use
pki/ca.crt for --cacert by mistake and the answer is x509: certificate signed by unknown authority, because
the main CA never signed etcd's server certificate.
Example · Repair an API server that points at the wrong CA
After a change, kubectl answers connection refused. The API server is down, so work on the node:
crictl ps -a --name kube-apiserver # Exited, and the ATTEMPT number keeps growing
crictl logs <container-id> 2>&1 | tail -n 5
... "transport: authentication handshake failed: tls: failed to verify certificate:
x509: certificate signed by unknown authority" ... Addr: "127.0.0.1:2379"
Read the message as a sentence. Somebody could not verify a certificate: this is the client's complaint, and the
log belongs to the API server, so the API server is the client. Port 2379: the server is etcd. The file the API
server uses to check etcd is --etcd-cafile:
grep etcd /etc/kubernetes/manifests/kube-apiserver.yaml
- --etcd-cafile=/etc/kubernetes/pki/ca.crt
- --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt
- --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key
- --etcd-servers=https://127.0.0.1:2379
The first line names the main CA instead of the etcd CA. Change it to /etc/kubernetes/pki/etcd/ca.crt, save, and
the kubelet restarts the static Pod by itself. Wait about a minute, then kubectl get nodes answers again.
Reading x509 errors
The error text tells you which of the two checks failed and which file to look at.
| Message | What it means | Look at |
|---|---|---|
x509: certificate signed by unknown authority | The side that logs this does not trust the CA that signed the other side's certificate | The CA file of the complaining side: --etcd-cafile, --client-ca-file, or certificate-authority-data in a kubeconfig |
x509: certificate has expired or is not yet valid | The dates do not include now | kubeadm certs check-expiration; also the node's clock |
x509: certificate is valid for 10.96.0.1, 10.0.0.10, not 10.0.0.99 | The address dialled is not in the server certificate's SAN list | The server certificate's SANs, or the address in the kubeconfig |
remote error: tls: bad certificate or tls: unknown certificate authority | The other side rejected the certificate this side presented | The client certificate and key of the side that logs it, and the CA file of the other side |
Unauthorized (HTTP 401) from kubectl | TLS worked, but the client certificate was not accepted as a login, for example because it has expired or was signed by a CA other than --client-ca-file | The client certificate in the kubeconfig |
Forbidden (HTTP 403) | The certificate is fine and names a user; that user lacks permission | The CN and O of the certificate, then RBAC |
open /etc/kubernetes/pki/...: no such file or directory | A flag names a file that does not exist | The path in the manifest, and the volumeMounts of the static Pod |
Tricks
Common mistakes
- Assuming one CA signs everything. There are three. etcd files are checked with
pki/etcd/ca.crt, never withpki/ca.crt. - Looking for certificate problems in the wrong component's log. "Signed by unknown authority" is logged by the side that received the certificate. "Bad certificate" is logged by the side that sent it.
- Forgetting that the API server is a client. It needs three client certificates of its own, and a failure in any of them looks like "the API server is broken".
- Treating
sa.keyas a certificate. It is a bare key pair for ServiceAccount tokens. It has no expiry date and does not appear inkubeadm certs check-expiration. - Searching
/etc/kubernetes/pkifor the kubelet's certificates. They are in/var/lib/kubelet/pki, on every node. - Thinking a valid certificate means access. TLS only establishes who you are. The CN and O must also match what RBAC and the Node authorizer expect.
- Editing a manifest and waiting only a few seconds. The kubelet needs time to notice the change and restart
the static Pod. Watch
crictl psuntil the new container isRunningbefore you judge the fix.
Recap
- Every connection in a cluster uses TLS, and nearly all are checked in both directions (mutual TLS).
- Ask who dials whom. The API server is the server for kubectl, the scheduler, the controller manager, kubelets and Pods, and it is a client of etcd, of the kubelets and of aggregated APIs.
- Three CAs:
kubernetes-ca(pki/ca.crt),etcd-ca(pki/etcd/ca.crt) andfront-proxy-ca. A certificate only counts where its CA is trusted. - kubeadm keeps control plane certificates in
/etc/kubernetes/pki, component kubeconfigs in/etc/kubernetes, and kubelet certificates in/var/lib/kubelet/pki. The flags in the static Pod manifests name the exact files. - A client certificate's CN is the user and its O values are the groups. Component names such as
system:kube-schedulerandsystem:node:<name>are what give components their permissions. - Pods use a token plus
ca.crt, not a client certificate.sa.keysigns those tokens. - Leaf certificates last 1 year and CAs 10 years.
kubeadm certs check-expirationlists them with their CA. - To debug, read the component's log with
crictl logs, identify the pair from the port, and compare the flags with the files on disk.
Official docs
Quiz: check what you learned
5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.
Sign in to take the quiz and keep your score.
Practise: try it on a real cluster
A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.
Use kubeadm on a running cluster: read the configuration it was built with, print a join command that works, and renew the API server's certificate and prove that the new one is served.
Build · Level 2 · standard · target 20 min
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.