Skip to content
LF Cert Trainer

Lesson 71 · Section 7: Security

Lesson 71: TLS introduction: why every connection in a cluster is encrypted

A first map of TLS before the details: the three promises it makes, the four words you need (key, certificate, CA, mutual TLS), where TLS sits in a Kubernetes cluster, and how to read the certificate errors you will meet in the exam. · 12 min read · 3 min video

1/10TLS introduction
0:00 / 3:30

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

What TLS is

TLS (Transport Layer Security) is the protocol that protects a network connection between two programs. It is the "S" in HTTPS. You will still hear people say "SSL", which is the name of its retired predecessor: tools such as openssl and error texts such as SSL certificate problem keep the old word, but what runs today is TLS 1.2 or TLS 1.3.

Kubernetes is a set of programs that talk to each other over the network all day: kubectl to the API server, the API server to etcd, the kubelet to the API server, and so on. Those requests carry Secrets, tokens and commands that can delete a whole cluster. So Kubernetes does not make TLS optional. Every one of these connections uses it.

This lesson is the map for the lessons that follow. It does not teach you to create a certificate yet. It tells you what TLS promises, which words you need, where TLS sits in a cluster, and how to recognise a TLS problem when you see one.

What TLS protects againstTLSTLSreadsrejectedkubectlyour laptopThe networknot trustedAPI serverport 6443Listenersees only noiseImpostorhas no valid certificate
What TLS protects against. The network between two programs is not trusted. TLS lets them talk across it anyway: a listener sees only noise, and an impostor cannot prove it is the real server.

Parts:

  • kubectl (your laptop)
  • The network (not trusted)
  • API server (port 6443)
  • Listener (sees only noise)
  • Impostor (has no valid certificate)

Connections:

  • kubectl to The network: TLS
  • The network to API server: TLS
  • Listener to The network: reads
  • Impostor to The network: rejected

Why a cluster needs it

Picture the API server without TLS. Everything would travel as plain text, and two attacks become easy:

  • Listening. Anyone on the path between you and the server (a shared network, a compromised node, a cloud router) reads every request and response. kubectl get secret -o yaml would hand them your passwords.
  • Impersonation. Someone answers on the server's address and pretends to be the API server. Your kubectl sends its credentials to them, and they can replay those credentials against the real cluster.

Encryption alone does not stop the second attack. An encrypted channel to an impostor is still a channel to an impostor. That is why TLS always combines encryption with a proof of identity, and why that proof, the certificate, takes up most of this section of the course.

There is a second reason that is specific to Kubernetes: certificates are also how the cluster's own components log in. The scheduler does not have a password. It presents a certificate, and the API server reads the name inside it to decide who is calling. So in a cluster, TLS is both the lock on the connection and the identity card of the caller.

The four words you need

The next lesson explains how the cryptography works. For now, four terms are enough to follow any conversation about TLS.

WordWhat it isTypical fileMay it be shared?
Private keyA secret number that only its owner holds. It proves "I am the owner of this certificate".apiserver.keyNever
CertificateA public document that ties a name to a public key, with an expiry date, signed by a CA.apiserver.crtYes, it is sent to every client
Certificate authority (CA)A party whose signature others have decided to trust. It has its own key and certificate.ca.crt, ca.keyca.crt yes, ca.key never
Mutual TLS (mTLS)A connection where the client presents a certificate as well as the server.a client .crt and .key

Three things follow from this table, and they are worth fixing in your mind now:

  • A key and a certificate come as a pair. A component that proves its identity always needs both files.
  • Trust is decided by the client. A certificate is not "valid" in the abstract; it is valid for a client that holds the CA certificate which signed it.
  • A certificate is made for certain names and a certain time. Outside those, it is refused even though it is genuine.

How a connection starts

Before any real data moves, the two sides run a short exchange called the handshake.

A TLS connection in four movessendsshownchecks signatureagreeprotectsClientkubectl, curlCertificatename + public keyServerholds the private keyca.crtthe CA you trustSession keyshared, temporaryEncrypted datarequests, responses
A TLS connection in four moves. The server proves who it is with a certificate, the client checks it against a CA it already trusts, and only then do both sides agree on a temporary key that encrypts the data.

Parts:

  • Client (kubectl, curl)
  • Certificate (name + public key)
  • Server (holds the private key)
  • ca.crt (the CA you trust)
  • Session key (shared, temporary)
  • Encrypted data (requests, responses)

Connections:

  • Server to Certificate: sends
  • Certificate to Client: shown
  • ca.crt to Client: checks signature
  • Client to Session key: agree
  • Session key to Encrypted data: protects
  1. The client connects and the server sends its certificate.
  2. The client checks it: is it signed by a CA I trust, is today inside its validity dates, and does it list the name or IP address I connected to?
  3. The server proves it holds the matching private key, and both sides agree on a temporary session key.
  4. Everything after that is encrypted with the session key.

If step 2 fails, the client closes the connection and prints an error. No request was sent, so nothing leaked. This is the moment that produces the x509: messages you will learn to read below.

With mutual TLS there is one more move: the server asks the client for a certificate and checks it the same way, against a CA the server trusts. Browsers rarely do this. Kubernetes components do it all the time.

Under the hood · Why agree on a new key instead of using the certificate's key?

The key pair behind a certificate can do something special: prove identity to a stranger. But that kind of cryptography is slow, and the same key pair lives for a year or more. So TLS uses it only during the handshake, to prove identity and to agree safely on a fresh, random session key. The session key uses fast, ordinary encryption and is thrown away when the connection ends.

One benefit: with TLS 1.3, someone who records your traffic today and steals the server's private key next year still cannot decrypt the recording, because the session keys were never stored anywhere. The next lesson, TLS Basics, covers the two kinds of encryption properly.

Where TLS sits in a cluster

Where TLS sits in a clusterTLSTLSTLS, both waysTLStrusted by allkubectladmins, usersScheduler, controllerscontrol plane clientskubeletevery node, port 10250Cluster CAsigns the certificatesAPI serverport 6443etcdport 2379
Where TLS sits in a cluster. Every arrow is a TLS connection. The API server is in the middle of almost all of them, and one cluster CA signs the certificates that make the parts trust each other.

Parts:

  • kubectl (admins, users)
  • Scheduler, controllers (control plane clients)
  • kubelet (every node, port 10250)
  • Cluster CA (signs the certificates)
  • API server (port 6443)
  • etcd (port 2379)

Connections:

  • kubectl to API server: TLS
  • Scheduler, controllers to API server: TLS
  • kubelet and API server: TLS, both ways
  • API server to etcd: TLS
  • Cluster CA to API server: trusted by all

Almost every connection has the API server at one end:

ConnectionWho is the serverWhy it matters
kubectl → API serverAPI server, port 6443Your commands and everything you read
Scheduler, controller manager → API serverAPI serverThey watch and change cluster state
kubelet → API serverAPI serverNode and Pod status, reading Secrets for Pods
API server → kubeletkubelet, port 10250kubectl logs, kubectl exec, metrics
API server → etcdetcd, port 2379All cluster data, including Secrets
etcd member ↔ etcd memberetcd, port 2380Replication between control plane nodes

Notice two patterns. First, the same program can be a server in one connection and a client in another: the API server serves kubectl and is a client of etcd and of the kubelet. So one component can hold several certificates. Second, the connections are mutual: both ends show a certificate.

On a cluster built with kubeadm, all of this is created for you when you run kubeadm init, and stored in one place on the control plane node:

/etc/kubernetes/pki/
├── ca.crt, ca.key                        the cluster CA
├── apiserver.crt, apiserver.key          the API server's serving certificate
├── apiserver-kubelet-client.crt, .key    the API server as a client of kubelets
├── apiserver-etcd-client.crt, .key       the API server as a client of etcd
├── front-proxy-ca.crt, ...               a separate CA for API extensions
└── etcd/                                 etcd's own CA and certificates

You do not have to memorise this list today. The lesson "TLS in Kubernetes" walks through every file. What you should take away now is the shape: a CA at the top, and one key and certificate pair for every role a component plays.

The road ahead

This section of the course takes TLS in small steps. Knowing the order helps you place each detail:

LessonQuestion it answers
TLS BasicsHow do keys, certificates and CAs work, and why can a stranger verify them?
TLS in KubernetesWhich component has which certificate, and which CA signed it?
Certificate CreationHow do I generate a key, a signing request and a signed certificate with openssl?
View Certificate DetailsHow do I read a certificate's names, issuer and dates, and find a broken one?
Certificates APIHow do I let Kubernetes sign a certificate for a new user?
KubeConfigWhere does kubectl keep the CA, the client certificate and the key?

Seeing it for yourself

Example · Watch a client refuse an unknown CA, then accept it

On a control plane node, ask the API server for its version with curl. curl knows the public CAs of the internet, but not your cluster's private CA:

curl https://controlplane:6443/version
curl: (60) SSL certificate problem: unable to get local issuer certificate

The certificate is genuine. The client simply has no reason to trust whoever signed it. Hand it the cluster CA and the same request succeeds:

curl --cacert /etc/kubernetes/pki/ca.crt https://controlplane:6443/version
{
  "major": "1",
  "minor": "34",
  "gitVersion": "v1.34.2",
  "platform": "linux/amd64"
}

That is the whole idea of a CA in two commands: trust is something the client is configured with.

Example · Look at the certificate a server presents

openssl s_client opens a TLS connection and prints what the server sent. Pipe it into openssl x509 to read the three facts that matter: who it is for, who signed it, and until when it is valid.

openssl s_client -connect controlplane:6443 </dev/null 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates
subject=CN = kube-apiserver
issuer=CN = kubernetes
notBefore=Nov 30 09:14:02 2026 GMT
notAfter=Nov 30 09:14:02 2027 GMT

The certificate belongs to kube-apiserver, it was signed by the CA named kubernetes, and it lasts one year. The lesson "View Certificate Details" goes through the rest of the output.

Example · Find the TLS settings kubectl uses

kubectl does not ask you for a CA on every command because its kubeconfig file already holds one. Three fields do the work:

kubectl config view
clusters:
  - name: kubernetes
    cluster:
      server: https://controlplane:6443
      certificate-authority-data: DATA+OMITTED     # the CA kubectl trusts for this server
users:
  - name: kubernetes-admin
    user:
      client-certificate-data: DATA+OMITTED        # who you are
      client-key-data: DATA+OMITTED                # proof that the certificate is yours

The first field verifies the server. The other two are your half of mutual TLS: the API server reads your name out of the client certificate. Add --raw to see the real, base64-encoded values.

Example · Check every expiry date at once

kubeadm certs check-expiration
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Nov 30, 2027 09:14 UTC   364d            ca                      no
apiserver                  Nov 30, 2027 09:14 UTC   364d            ca                      no
apiserver-etcd-client      Nov 30, 2027 09:14 UTC   364d            etcd-ca                 no
apiserver-kubelet-client   Nov 30, 2027 09:14 UTC   364d            ca                      no
...

CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Nov 28, 2036 09:14 UTC   9y              no
etcd-ca                 Nov 28, 2036 09:14 UTC   9y              no
front-proxy-ca          Nov 28, 2036 09:14 UTC   9y              no

One command, every certificate, and which CA signed each one.

Reading TLS errors

You will meet certificate errors long before you create a certificate. Each one points at one of the three checks from the handshake, or at the step after it.

Message containsWhich check failedUsual cause
x509: certificate signed by unknown authorityIs it signed by a CA I trust?The client has the wrong CA file, or the certificate was signed by a different CA
x509: certificate has expired or is not yet validIs today inside the dates?The certificate is past its notAfter date, or a clock is wrong
x509: certificate is valid for 10.96.0.1, 192.168.56.10, not 203.0.113.5Does it list the address I used?You reached the server by a name or IP address that is not in the certificate
remote error: tls: bad certificateThe other side rejected your certificateYour client certificate is expired or signed by a CA the server does not trust
error: You must be logged in to the server (Unauthorized)None: TLS succeededThe server could not identify you: a missing or rejected client certificate or token
Error from server (Forbidden)None: TLS and login succeededYou are identified but not allowed. This is authorization, not TLS

The last two rows matter as much as the first four. They tell you to stop looking at certificates on the server side and look at credentials or RBAC instead.

Tricks

Common mistakes

  • "Fixing" an error with --insecure-skip-tls-verify or curl -k. These switch off the identity check, so you would now talk happily to an impostor. They are acceptable for a ten-second test, never as the answer to a task.
  • Sharing or copying a private key casually. Whoever has ca.key can create a valid certificate for any user, including a cluster administrator. Certificates are public; keys are not.
  • Thinking HTTPS means "trusted". Encryption without a verified certificate only tells you that nobody else is listening, not who is on the other end.
  • Treating Unauthorized or Forbidden as a TLS problem. By the time you see either, the TLS handshake has already succeeded.
  • Forgetting that certificates are bound to names. A valid API server certificate is refused if you connect by an IP address or hostname that it does not list.
  • Assuming certificates last for ever. kubeadm certificates last one year. Clusters do break on that date.

Recap

  • TLS protects a connection with encryption, identity and integrity. Certificates provide identity.
  • A certificate ties a name to a public key and is signed by a CA. The matching private key stays secret.
  • A client trusts a server only if it holds the CA certificate that signed the server's certificate.
  • In Kubernetes every component connection uses TLS, and most are mutual: the client's certificate is also its login.
  • kubeadm keeps the cluster's certificates in /etc/kubernetes/pki; they last one year, the CAs ten.
  • Read the text after x509: to find the failed check: unknown authority, expired, or wrong name.

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.

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.