The issue opens pre-filled with this page title and URL.
A Kubernetes node is first of all a Linux machine: if an attacker takes it, RBAC, admission and NetworkPolicies no longer matter, as the Securing the infrastructure under the cluster lesson explains. This lesson shows the practical steps: reduce what the node contains, limit who can connect to it, check what its credentials allow and close the ports Kubernetes does not use. It is for anyone who administers kubeadm nodes and prepares the "System Hardening" domain of the CKS. The commands target an Ubuntu 24.04 node of a kubeadm cluster running Kubernetes 1.37.
What you will learn
List the services, packages and listening ports of a node, and remove what is not needed
Have the kubelet check kernel settings with protectKernelDefaults
Limit access to the node: accounts, sudo, SSH keys
Read what the kubelet credentials allow, and what the control plane credential allows
Reduce the cloud role attached to the node and block the metadata service from Pods
Open only the Kubernetes ports with nftables, then prove it from another machine
Prerequisites
A kubeadm cluster on virtual machines, like the one in kubeadm, and sudo access over SSH on each node: a kind cluster has no firewall or SSH of its own on its nodes
Generic Linux hardening is covered by reference guides of the hardening course, which this lesson does not repeat and does not assume you have read: ANSSI-BP-028 (in French), the CIS Benchmarks (in French), SSH (in French), sudo (in French) and sysctl. What is specific to Kubernetes is knowing what a node must keep.
Which paths lead to a node?
A node is taken through four paths: an SSH connection, the kubelet API, a port exposed to the network, or a compromised Pod that queries the cloud metadata service. Each section of this lesson closes one of these paths.
The diagram places them around the node. Look at the red Pod: it does not come in through the external network, it goes through the metadata service to fetch the node's cloud role, which opens the provider's API.
A node only needs the minimal system, a container runtime, the kubelet and administrator access. Every other service that listens is one more door: remove it, or keep it knowing why.
Which services and packages should you remove?
Start by measuring. The two commands show what listens on the network and what starts at boot:
Look at the port and process column of the first one. On worker k8s-w1 of a kubeadm cluster running Kubernetes v1.37.2 on Ubuntu 24.04.5 (measured on 2026-11-16), the ports open on all interfaces are 22 (sshd), 179 (bird, Calico's BGP), 10250 (kubelet), 10256 (kube-proxy) and UDP 4789 (Calico's VXLAN tunnel). The other sockets listen only on the loopback: 10249 (kube-proxy), 10248 (kubelet), 9099 (calico-node), a containerd port and the local DNS on 53. The system DHCP client (UDP 68) is bound to the node's address. On a healthy node, you should find these processes and nothing else.
The same node carries, in the same measurement, 682 installed packages and 19 running services. Several are useless on a Kubernetes node: ModemManager (modem management), udisks2 (removable disk management) and multipathd (multipath storage, useless without that kind of storage). unattended-upgrades, the automatic updates, is a judgment call and is handled below. For each of the first three, check that none of your components uses it, then stop it and prevent it from starting:
The apt-get purge --simulate command removes nothing: it lists the packages that would go, including those that depend on the three targets. Read this list before running the real purge, and stop if it contains a package the node needs.
The exact list depends on your image: remove what you have identified, not a copied list. For packages, apt list --installed shows everything, and a node needs no compiler, web server or database client. The reference guide ANSSI-BP-028 (in French) details the baseline recommendations (services, accounts, packages), for those who want to go further.
For a port you do not recognize, trace it back to the package that opened it. ss -tulpn gives the PID of the process, and systemctl status <PID> shows the unit that started it. Then sudo readlink /proc/<PID>/exe gives the path of the binary, and dpkg -S <binary-path> the name of the package that installed it. The Install and remove software lesson details dpkg and apt.
Once the package is identified, stopping the service is not always enough. Some services are woken up by a .socket unit: this is the case of rpcbind, whose rpcbind.socket unit keeps port 111 open, with systemd listening in place of the stopped service. The measurement of 2026-11-17 (Ubuntu 24.04.5, systemd 255) shows the trap: sudo systemctl disable --now rpcbind.service also disables rpcbind.socket for the next boot, thanks to the Also=rpcbind.socket directive of the unit, but it does not stop the socket. systemctl says so itself: Stopping 'rpcbind.service', but its triggering units are still active: rpcbind.socket. Port 111 stays open and systemctl is-active rpcbind.socket answers active. So name both units, sudo systemctl disable --now rpcbind.socket rpcbind.service, or purge the package. The same warning still appears with this command, even though the socket is indeed stopped: do not judge by the message, run ss -tulpn again and check that nothing listens on port 111 any more (measurement of 2026-11-17, systemctl is-active then answers inactive for both units).
What should you never remove from a node?
Three elements are removed by mistake and break the node: the runtime and the kubelet, clock synchronization, and the overlay and br_netfilter kernel modules loaded at installation. Swap disabled and the sysctl settings from kubeadm are also part of the minimum.
A fourth tool does not break the node, but you should keep it: iptables. kube-proxy and Calico do not depend on it, because they embed their own iptables binaries in their container. The diagram shows the difference: only the kubelet calls the host's one.
The kubelet uses it to set two protections: the KUBE-IPTABLES-HINT chain, which tells the kube-proxy and Calico containers which iptables variant to use (legacy or nft), and the KUBE-FIREWALL rule, which drops invalid packets addressed to the loopback. Without iptables on the host, the kubelet keeps running and logs No iptables support on this system, but it no longer sets these two protections.
Two other tools are more nuanced: conntrack and nft. The kubelet 1.37 package does not depend on conntrack, and kube-proxy in iptables mode talks to the kernel through netlink and iptables-restore, with the tools it embeds in its container. nft is only used by kube-proxy in nftables mode. These two binaries are therefore diagnostic tools (conntrack -L lists the tracked connections, nft list ruleset reads the rules) rather than Kubernetes dependencies. Keep them anyway: nft loads the firewall of this lesson, and you will need them the day a Service stops answering. This lesson does not measure what your network plugin calls on the host: check its documentation before purging a network tool.
Two habits prevent drift after hardening. Automatic security updates of the system remain useful, but Kubernetes packages are held with sudo apt-mark hold kubelet kubeadm kubectl, because a kubelet version upgrade is planned together with the control plane. And the protectKernelDefaults: true field of the KubeletConfiguration makes the kubelet refuse to start if a kernel setting differs from what it expects, which makes a sysctl drift visible instead of letting it through. The next subsection shows how to enable it without breaking the node.
How do you have the kubelet check the kernel settings?
Without protectKernelDefaults, the kubelet sets six kernel settings itself at startup. With protectKernelDefaults: true, it no longer changes them: it checks them, and refuses to start if one differs. You must therefore write these values before enabling the field. The six values are those from the kubelet 1.37 code:
The sysctl --system command rereads all the files in /etc/sysctl.d/ and applies the values immediately; the file also makes them permanent across reboots. Then add the line protectKernelDefaults: true to /var/lib/kubelet/config.yaml, restart the kubelet and check that it runs:
Terminal window
sudosystemctlrestartkubelet
sleep20
systemctlis-activekubelet
The output must be active. On a node where vm.overcommit_memory was 0 at restart time, the measurement of 2026-11-16 (worker k8s-w2.lab, Kubernetes v1.37.2) shows the failure: systemctl is-active answers activating, with Active: activating (auto-restart) in systemctl status, and the journal contains:
kubelet[6826]: E1116 20:52:52.572096 6826 kubelet.go:1850] "Failed to start ContainerManager" err="invalid kernel flag: vm/overcommit_memory, expected value: 1, actual value: 0"
Read the message: it names the faulty setting, the expected value and the value found.
Do not rely on kubectl get nodes to detect this failure. Systemd restarts the kubelet every 10 seconds (Restart=always, RestartSec=10), and each restart renews the node's lease before failing. The measurement of 2026-11-17 recorded it: for 6 minutes and 35 restarts, the node stayed Ready. It only goes to Ready=Unknown (message "Kubelet stopped posting node status.") when the kubelet stops renewing its lease, for example after systemctl stop kubelet: about 50 seconds after the last renewal. Ready therefore does not prove that the kubelet is running: look at systemctl status kubelet and journalctl -u kubelet.
To fix it, put the right value back (sudo sysctl -w vm.overcommit_memory=1): systemd restarts the kubelet by itself, and it was active 6 seconds later in the measurement. The node itself had stayed Ready during the whole failure.
Who can connect to a node, and with which rights?
Access to the node gives read access to the files of all the containers running on it. It is reduced by limiting accounts, requiring SSH keys and knowing the reach of the credentials the kubelet keeps there.
How do you limit accounts, sudo and SSH?
First list who can open a session and who can become root:
Read the three results together: every account in the sudo group is an administrator of the node, a file in /etc/sudoers.d/ grants extra rights, and sshd -T shows the configuration that sshd reads from disk, include files too, but not that of the processes already running. The goal is a short, named list, with no shared account.
A dedicated configuration file sets the rule. The values below are explained further down; the reference guide Hardening SSH access (in French) justifies them in detail.
Warning: a mistake in AllowGroups locks you out of the node. Keep the current session open for the whole procedure, and close it only after you have managed to connect in a second session. Order matters: the k8s-admins group must exist and contain your account before the rule applies.
The sshd -t command checks the syntax: if it fails, the reload does not happen. Then check the applied configuration:
Terminal window
sudosshd-T|grep-E'allowgroups|permitrootlogin'
pgrep-asshd
The first command must show allowgroups k8s-admins and permitrootlogin no. On Ubuntu 24.04.5 (measured on 2026-11-17), the 10-noeud.conf file wins over 50-cloud-init.conf, because sshd keeps the first value it reads. An account outside the group gets Permission denied (publickey)., and the sshd journal notes User ... not allowed because none of user's groups are listed in AllowGroups.
But sshd -Treads the configuration from disk, not that of the running processes. The second command answers the other question: pgrep -a sshd must show a single linesshd -D [listener]. On a freshly built Ubuntu 24.04.5 VM (measured on 2026-11-17), the service had started twice at first boot. The old process, which systemctl reload ssh does not reload, kept the old configuration, and 12 connections out of 20 from an account outside the group still got through. If you see two listeners, stop the extra process (or reboot the machine), then reload.
Then open a second SSH session with your account: if it succeeds, you can close the first one. Also try several times with an account outside the group: every attempt must be refused, because a single refused attempt does not rule out a second process that would accept some of them. Add the other authorized accounts to the group with the same usermod command. On the sudo side, the sudo reference guide (in French) shows how to limit the permitted commands and log sessions.
An on-call account, like stagiaire in the lab below, must not become an administrator of the node. Give it instead a sudoers rule limited to a single command, with no password so that the command also runs in a script. The file goes in /etc/sudoers.d/. As with sshd -t above, it is checked before being installed: the rule is first written to a temporary file, visudo -cf checks its syntax, and install copies it only afterwards, with the right permissions.
Terminal window
f=$(mktemp)
echo'stagiaire ALL=(root) NOPASSWD: /usr/bin/systemctl status kubelet'>"$f" &&
mktemp creates a file with an unpredictable name, in mode 0600 and owned by your account (measured: -rw------- 1 ansible ansible 0 … /tmp/tmp.x5XDcrZh0Q). With a fixed name in /tmp, another account on the node could prepare the file in advance and take advantage of the installation to raise its privileges. The three commands are chained with &&: if the write or the check fails, nothing is installed.
The rule reads as follows: the user stagiaire, on any machine (ALL), can act as root ((root)), with no password (NOPASSWD:), for this exact command with its arguments. visudo -cf must answer <temporary file>: parsed OK, for example /tmp/tmp.x5XDcrZh0Q: parsed OK (the name changes every time; measured on 2026-11-17 on Ubuntu 24.04.5, sudo 1.9.15p5; visudo -cf on a file in /tmp does not need sudo). The installed file is checked with sudo ls -l /etc/sudoers.d/stagiaire, because the directory is 750: the measurement gives -r--r----- 1 root root 65 … /etc/sudoers.d/stagiaire. You can also create the file directly with sudo visudo -f /etc/sudoers.d/stagiaire, which checks the syntax before saving. The /usr/bin/systemctl path is that of Ubuntu 24.04.5; on another distribution, check it with command -v systemctl. The syntax is that of man sudoers.
Adding this rule removes nothing: if the account is already an administrator, it keeps its full rights. Remove it from the sudo group with sudo gpasswd -d stagiaire sudo, which answers Removing user stagiaire from group sudo, then delete or reduce any file in /etc/sudoers.d/ that gives it NOPASSWD: ALL. Check the result with sudo -l -U stagiaire: only the authorized command must appear.
What do the kubelet credentials allow?
The kubelet authenticates to the API server with a client certificate, referenced by /etc/kubernetes/kubelet.conf. Its identity is system:node:<node-name>, in the system:nodes group. Anyone who is root on the node can use this file, so you must know what the Node authorization lets it do.
Replace <node-name> with the name of the node you are on, as kubectl get nodes displays it from the administration workstation. The first command must show files readable by root only, with one apparent exception: in /var/lib/kubelet/pki/, kubelet-client-current.pem shows as 777, because it is a symbolic link. The permissions that matter are those of its target, a kubelet-client-<date>.pem file at 600 (measured on 2026-11-16 with stat -c '%a %n': 600 for the keys, 644 for kubelet.crt, which is a public certificate). The second command must be refused (Forbidden): according to the Node authorization documentation, it only gives read access to a Secret to the Pods scheduled on this node, and does not allow listing those of the whole cluster. The third must answer, because a kubelet reads its own Node object. The measurement of 2026-11-16, on worker k8s-w2.lab, gives:
NAME STATUS ROLES AGE VERSION
k8s-w2.lab Ready <none> 2m11s v1.37.2
The get node command without a name, which asks for the list, is refused: cannot read all nodes, only its own Node object. A kubelet reads its node, not the others.
The official Node authorization documentation sets this limit: a node reads a Secret only by name, in a namespace, and only if it is bound to one of its Pods. The Restricting access to the API server lesson shows the exact kubectl auth can-i messages for these refusals, and how the NodeRestriction admission plugin also bounds what the kubelet can write. The control plane node is a special case: /etc/kubernetes/admin.conf gives cluster administrator rights there, and /etc/kubernetes/super-admin.conf (created by kubeadm 1.29 and later, group system:masters) even bypasses RBAC. So SSH access to a control plane node is equivalent to cluster-admin. Reserve it for very few people.
Which cloud role should you attach to a node?
On a cloud, the virtual machine often receives an identity from the provider (an instance profile on AWS, a service account on GCP, a managed identity on Azure). A compromised Pod that queries the metadata inherits it. The role of a node must be limited to what the node does itself: pull an image from the private registry, read-only, and nothing else. The rights to create volumes or load balancers belong to the component that uses them (the cloud controller manager, the storage driver), with its own identity.
In practice, list the permissions of the attached role and remove every write action, IAM management action or secret-reading action. The reference guide Least privilege in practice (in French) shows how to write and predict a minimal policy, and the IAM in the cloud lesson lays out the identity model. A machine's short-lived credentials are described in A machine's short-lived credentials (in French). For a Pod to have a cloud identity of its own, instead of borrowing the node's, see Machine identity and workload identity.
How do you stop a Pod from reaching the metadata?
The network countermeasure is an egress NetworkPolicy that excludes 169.254.169.254/32, already shown in the Protect the node metadata endpoint section of the NetworkPolicies lesson: it is not written twice here. Three points are specific to node hardening.
A standard NetworkPolicy is attached to one namespace: you must create it in every namespace that runs workloads, or use the cluster-wide policy that the network plugin offers. Pods with hostNetwork: true most often escape its filtering, because they share the node's address and most network plugins treat their traffic like the node's: the baseline security standard forbids them. Finally, the metadata service can also be restricted on the provider side (IMDS version 2 and the hop limit on AWS), as the infrastructure lesson describes.
To check the rule, run wget -T 3 -qO- http://169.254.169.254/ from a Pod of the protected namespace and read the result: it must time out. But the 169.254.169.254 address only exists at a cloud provider, which serves it from its hypervisor. On the measurement cluster, KVM machines, a busybox Pod that calls it (measured on 2026-11-16) gets wget: download timed out and exit code 1, even before any rule exists: no service answers. A timeout alone therefore proves nothing outside a cloud. A test server placed on the node itself does not work either: the NetworkPolicy documentation states that traffic between a Pod and the node that hosts it is always allowed, whatever the policy. The proof is therefore made on a cluster hosted at a cloud provider, where the metadata service answers before the policy and times out after it.
Which ports should you open on a node?
Kubernetes needs a few ports, and only between its own machines. They are listed in the official Ports and Protocols documentation.
Machine
Protocol and port
Role
Who must reach it
Control plane
TCP 6443
API server
the nodes, the administrators, the Pods that call the API
Control plane
TCP 2379-2380
etcd
the API server and the other etcd members
Control plane
TCP 10250
kubelet API
the nodes (control plane included) and the Pods, so that metrics-server can read the kubelet
Control plane
TCP 10259 and 10257
scheduler and controller manager
the node itself
Worker
TCP 10250
kubelet API
the nodes (control plane included) and the Pods, so that metrics-server can read the kubelet
Worker
TCP 10256
kube-proxy (health)
the node, and the load balancers if there are any
Worker
TCP and UDP 30000-32767
NodePort Services
depending on the published Services
Swipe to see more
The ports and their roles are those of the official documentation. The table does not contain the ports of your network plugin, which come on top: Cilium's VXLAN tunnel uses UDP 8472 and Calico's uses UDP 4789, for example, and Calico's BGP uses TCP 179. Look up yours in the documentation of the plugin you chose, otherwise the Pods of one node no longer reach those of another. And on top of that comes port 22 for SSH, restricted to the administration network. The table mentions metrics-server, the component that feeds kubectl top: it runs in a Pod and reads the kubelet on port 10250, hence the mention of Pods.
Which ports really listen on a kubeadm node?
The measurement of a real node shows what the official table does not say: not everything that listens is Kubernetes, and not everything is closed the same way. The following table reproduces ss -tulpn on the control plane k8s-cp (address 10.10.50.11) of the measurement cluster, with Calico, on 2026-11-16. The last column says who to leave access to: it is the list of sources to allow in the firewall.
Port
Process
What it is for
Who to leave it open to
TCP 22
sshd
administration
the administration network
TCP 179
bird
Calico's BGP, between nodes
the nodes
TCP 5473
calico-typha
information relay for the calico-node Pods (control plane only)
the nodes
TCP 6443
kube-apiserver
cluster API
the nodes, the administrators, the Pods
TCP 10250
kubelet
kubelet API
the nodes and the Pods
TCP 10256
kube-proxy
kube-proxy health
the node, the load balancers
UDP 4789
(kernel)
Calico's VXLAN tunnel
the nodes
TCP 2379 and 2380
etcd
cluster database, bound to 10.10.50.11
the API server and the other etcd members, nobody else
Swipe to see more
The port to restrict first is etcd's. It listens on the node's address and not on the loopback, so the network reaches it, even though it contains all the cluster's Secrets. The same etcd also listens on 127.0.0.1 (2379 and 2381), which is not a problem. The other listening ports are bound to the loopback, so they are unreachable from the network and need no rule: 10257 and 10259 (the controller manager and the scheduler), 10249 and 10248 (kube-proxy and the kubelet), 9098 and 9099 (calico-typha and calico-node) and the local DNS on 53. Worker k8s-w1 has no 5473, no 6443 and no etcd: only 22, 179, 10250, 10256 and UDP 4789 listen on all interfaces there.
The measurement also gives a useful figure before you write rules: nftables v1.0.9 is installed on both nodes, its service is disabled and inactive, and yet the current ruleset has 813 lines on k8s-cp and 528 on k8s-w1. These rules are those of kube-proxy and Calico, written directly into the kernel. A flush ruleset would therefore erase all of that, which the file in the next section avoids.
How do you close the rest with nftables?
The method is to define a dedicated table with an input chain whose policy is drop, then allow the flows from the table above. The reference guides Linux firewalls and nftables detail the principles and the syntax, but nothing here assumes you have read them; here is the application to a worker of the measurement cluster. The values at the top of the file are those of this cluster, to be replaced with yours: reseau_noeuds is the subnet where your nodes live (the one in the addresses of kubectl get nodes -o wide), reseau_admin is the only source allowed for SSH, that is the administration workstation or network, reseau_pods is the Pod network (the podSubnet field of the kubeadm configuration, 10.244.0.0/16 here), and 10.10.50.11 is the control plane address.
In this example, reseau_admin equals the node subnet, for simplicity: any node can then open an SSH session on another one. Do not copy this value as is. Whenever possible, choose for reseau_admin a network distinct from the node network, or reduce it to the addresses that really administer: a define accepts a set, for example define reseau_admin = { <administration-workstation-address>, 10.10.50.11 }, which adds the control plane address if it must also reach SSH.
The file deliberately does not contain flush ruleset: this command would also erase the rules that kube-proxy and the network plugin install, and cut the Pods' traffic. After the define lines, the first line declares the table and the second deletes it, which makes it replayable without error. The last two rules are Calico's (BGP and VXLAN); replace them with those of your plugin. The kube-proxy port 10256 has no rule here: add one if a load balancer queries the node's health.
The port 10250 rule names both networks, the node network and the Pod network. The control plane is included, because its address is part of the node network, and kubectl logs and kubectl exec work in every case: it is the API server that opens the connection to the kubelet. Opening 10250 to the Pod network widens the surface: any Pod can then reach the kubelet, which only its authentication and authorization protect.
Both networks serve metrics-server, because the kubelet does not see the same source depending on where it runs. From another node, the kubelet sees the source node's address, with Calico in this measurement. From the filtered node itself, it sees the Pod's address. The measurement of 2026-11-16 shows it with metrics-server placed in turn on another worker and on the filtered node: the rule limited to the control plane fails in both places, the node network alone only works from another node, the Pod network alone only from the node itself, and the two networks together work everywhere.
The diagram shows the two placements facing the filtered node's kubelet. Read each arrow from left to right: depending on the node where the metrics-server Pod runs, the source the kubelet sees changes, and it is this source that the 10250 rule must accept.
Two placements of metrics-server facing the kubelet of k8s-w2 on port 10250. From a Pod placed on k8s-w1, the kubelet sees the address of node k8s-w1, which the node network rule accepts. From a Pod placed on k8s-w2 itself, it sees the Pod's address, which only the Pod network rule accepts.metrics-server Podon k8s-w1 k8s-w2 kubelet port 10250 source seen: k8s-w1node addressrule: node network metrics-server Podon k8s-w2 source seen:Pod addressrule: Pod network metrics-serveron another nodemetrics-server onthe filtered node
If your monitoring (Prometheus for example) reads the kubelet from another network, add its source to this rule. Traffic from a ClusterIP Service to a Pod on the node is not affected by this rule: the measurement of 2026-11-16 shows a Pod on another node reaching an nginx Pod on the filtered node through its Service, with the firewall loaded.
On the control plane, add these three rules to the entree chain (the plan_de_controle set, declared in the file, contains the address of each control plane node and is only used here):
The 6443 rule names the administration network (so that administrators reach the API server with kubectl), the node network and the Pod network. The measurement of 2026-11-16 shows it: with only the node network, a Pod placed on the control plane no longer reaches the API server (curl times out, code 28), because its traffic leaves with an address from the Pod network. A Pod placed on a worker still reaches the API, because its traffic leaves with its node's address. With both networks, everything works, and etcd stays closed: from a worker, nc on port 2379 times out. Port 5473 is calico-typha's. Never open 2379 to the whole network: etcd contains all the cluster's Secrets.
The measurement of 2026-11-17 played the example file, with the values above, on a worker and on the control plane (Ubuntu 24.04.5, Kubernetes v1.37.2): nft -c then nft -f return code 0, a ClusterIP Service answers, a control plane Pod reaches the API server (code 200), kubectl logs and kubectl exec work, etcd stays closed from a worker (timeout) and metrics-server answers from both workers.
The 6443 rule with $reseau_admin was played with the strictest form of the recommendation above: define reseau_admin = 10.10.50.1 (the administration workstation alone) and define reseau_noeuds = { 10.10.50.11, 10.10.50.12, 10.10.50.17 }. Without $reseau_admin in the 6443 rule, kubectl from this workstation fails (Unable to connect to the server: dial tcp 10.10.50.11:6443: i/o timeout); with it, it answers, and the rest of the measurement is unchanged.
Save the content above in /etc/nftables.d/noeud.nft, then apply it with a safety net. Check the syntax, load the rules, and schedule their automatic removal until you have confirmed that access works:
If your session survives and the cluster stays healthy (kubectl get nodes from the administration workstation), cancel the removal with systemctl list-timers then sudo systemctl stop <timer-name>. Persistence across reboots depends on the distribution's nftables service. On the nodes of the measurement cluster, this service is disabled and inactive: until it is enabled, no file reloads rules at boot. The /etc/nftables.conf file provided by Ubuntu starts with a flush ruleset, which would erase the Kubernetes rules: remove this line before enabling the service, then add include "/etc/nftables.d/noeud.nft" to it to reload your file at boot.
Once this service is active, never restart it and never stop it on a Kubernetes node. Ubuntu's nftables unit carries ExecStop=/usr/sbin/nft flush ruleset: systemctl restart nftables and systemctl stop nftables play this flush ruleset and empty all the rules, those of kube-proxy and Calico as well as those of this lesson. The measurement of 2026-11-17 shows 31 lines of rules left after a restart (against 764 before), Services failing from the node, then kube-proxy rewriting its rules in about 10 seconds and Calico in about 30 seconds. After a stop, nothing is left, the node's firewall included.
To reload the file, use sudo systemctl reload nftables or sudo nft -f /etc/nftables.conf: these two actions break nothing. When the machine boots, only ExecStart runs, with no flush ruleset with this lesson's file. Removing the ExecStop through a systemd override file is another option, not measured here.
NodePort traffic is translated by kube-proxy before reaching the node itself, and so does not always go through the input chain: closing 30000-32767 in this chain may block nothing depending on the kube-proxy mode and the network plugin. The reliable way not to expose a NodePort is not to create a Service of this type, or to filter at the network firewall (the cloud's security group), then to test it from the outside.
How do you check from the outside?
A firewall is checked from another machine, not from the node itself. From a workstation of the administration network, then from a machine outside this network, test the ports:
Terminal window
nc-zv-w210.10.50.1222
nc-zv-w210.10.50.1210250
nmap-Pn-p1-1000010.10.50.12
Read the result port by port: 22 and 10250 answer from a workstation of the authorized networks, and do not answer from an outside machine. nmap must list no open port beyond those your rules allow for this workstation. With the values of the lesson, where the administration network is also the node network, the rules lead you to expect that a workstation of this network sees 22 and 179 open, and that an outside machine sees none. The scan shows neither 10250, which the 1-10000 range does not reach and which nc has just tested, nor UDP 4789, which only a UDP scan would see. This result is deduced from the file: compare it with what your scan displays. A "filtered" port means the packet is dropped with no answer, which a drop chain produces; a "closed" port means no service listens. Then check that the cluster works: kubectl get nodes must show all the nodes Ready, and a Pod must reach a Pod on another node.
If metrics-server is installed, restart it before concluding. A connection already open before the firewall keeps passing thanks to the ct state established,related accept rule: a kubectl top nodes run right after loading still shows fresh numbers and makes you believe nothing changed. Only the first new connection fails.
Wait about a minute after the restart before the last kubectl top nodes. The measurement of 2026-11-16 (metrics-server 0.9.0 with --kubelet-insecure-tls, firewall loaded on k8s-w2.lab only, metrics-server placed on k8s-w1.lab) compares two 10250 rules. With a rule limited to the control plane (tcp dport 10250 ip saddr 10.10.50.11 accept), it gives:
Read the last line: the filtered node has no more metrics, although it stays Ready. The Pod's logs confirm it (kubectl -n kube-system logs deploy/metrics-server):
E1116 21:35:05.539878 1 scraper.go:147] "Failed to scrape node, timeout to access kubelet" err="Get \"https://10.10.50.17:10250/metrics/resource\": context deadline exceeded" node="k8s-w2.lab" timeout="10s"
With the lesson's rule ({ $reseau_noeuds, $reseau_pods }), the same test gives three nodes with data, and metrics-server placed on k8s-w2.lab as well:
NAME CPU(cores) CPU(%) MEMORY(bytes) MEMORY(%)
k8s-cp.lab 135m 6% 1943Mi 51%
k8s-w1.lab 48m 2% 970Mi 41%
k8s-w2.lab 40m 2% 473Mi 20%
This time, the filtered node reports its metrics. nft list ruleset shows the loaded rule in the form { 10.10.50.0/24, 10.244.0.0/16 }.
Troubleshooting
After hardening, failures almost always come from three places: the SSH rule, the nftables firewall and the sysctl settings that the kubelet checks. The table starts from what you see (a connection that fails, a kubectl logs that times out, a kubelet that restarts) and goes back to the rule at fault. Look for your symptom in the first column, check the cause, then apply the fix in the third.
Symptom
Likely cause
What to do
No more SSH connection after the rule
AllowGroups without your account, or port 22 not allowed from your network
Cancel through the timer, then fix the rule or the group from the console
AllowGroups set and reloaded, sshd -T correct, but an account outside the group still gets in, intermittently
A second sshd process keeps the old configuration: sshd -T reads the disk, not the processes
pgrep -a sshd: stop the extra process (or reboot the machine), then reload and retest several times with the refused account
The Pods of one node no longer reach those of another
The network plugin's tunnel port is closed
Look up the port in the plugin's documentation and open it between the nodes
kubectl logs times out after 30 s: Error from server: Get "https://<node>:10250/containerLogs/...": dial tcp <node>:10250: i/o timeout. kubectl exec times out after 60 s: error: unable to upgrade connection: error dialing backend: dial tcp <node>:10250: i/o timeout. The node stays Ready
The control plane no longer reaches the kubelet's port 10250
Allow the node network, control plane included, on tcp dport 10250
kubectl top nodes shows <unknown> for a node, metrics-server journal: Failed to scrape node, timeout to access kubelet
The firewall's 10250 rule does not let the source of metrics-server in (node address or Pod address, depending on where it runs)
Allow the node network and the Pod network on tcp dport 10250, then restart metrics-server to test with a new connection
A Pod placed on the control plane no longer reaches the API server, while the workers do
The 6443 rule only names the node network
Add the Pod network to the 6443 rule
The kubelet stays in activating (auto-restart) after protectKernelDefaults: true, journal invalid kernel flag: vm/overcommit_memory, expected value: 1, actual value: 0
A sysctl setting differs from the value the kubelet expects
Write the six values in /etc/sysctl.d/, run sudo sysctl --system, check with systemctl is-active kubelet
The Services no longer answer after a reboot
The nftables service erased the kube-proxy rules with flush ruleset
Remove flush ruleset from the file loaded at boot
The Services fail from a node right after systemctl restart nftables or stop
The nftables unit runs nft flush ruleset on stop, which empties the kube-proxy and Calico rules
Wait for kube-proxy (about 10 s) and Calico (about 30 s) to rewrite their rules. After a restart, the lesson's file is already reloaded; after a stop, start the service again with systemctl start nftables (a reload refuses a stopped unit). Stop using restart and stop on a node
journalctl -u kubelet contains No iptables support on this system, although the kubelet is running
The iptables package was purged from the host: the kubelet no longer sets the KUBE-IPTABLES-HINT chain or the KUBE-FIREWALL rule
Reinstall iptables with sudo apt-get install iptables, then restart the kubelet
Swipe to see more
Hands-on practice
A hardening is proved by what can no longer be done from the outside, and by what the cluster keeps doing. The three labs replay three steps of the lesson on a real worker, on a virtual machine: a kind node is a container that shares the host's kernel and has no SSH server or firewall of its own to harden, and these three steps are precisely about those elements of a real machine. They measure neither protectKernelDefaults, nor the kubelet credentials, nor the cloud metadata: these three points remain to be practiced from the lesson.
The first one removes from a worker what listens without serving Kubernetes. Three ports (111, 21 and 8000) are opened by rpcbind, vsftpd and a debugging tool. You purge the rpcbind and vsftpd packages, you stop and disable the debugging tool, then nothing must listen beyond what a worker uses. The lab also checks that the three ports refuse connections, that kubelet, containerd and sshd are running, and that the node is Ready and accepts a Pod.
The second one limits who connects to the worker. You reserve SSH for the k8s-admins group, by key only and with no root login. The stagiaire account, an on-call account, is not deleted: it keeps its account and can read the kubelet status with sudo, nothing more. The scenario requires this command to run without a password: a sudoers rule with NOPASSWD, limited to this command, like the one shown above. In the lab, stagiaire initially has full rights through two paths: the sudo group and a file in /etc/sudoers.d/ with NOPASSWD: ALL. Adding the limited rule is therefore not enough, you must also close these two paths. To go further on sudo, rely on the sudo reference guide (in French).
The third one closes the worker to the network with an nftables input chain whose policy is drop. Here, another node must reach neither SSH nor port 10256. The SSH source is therefore reduced to the address of the administration workstation and that of the control plane, and not to the whole node network, as the lesson recommends above. The nodes do reach the kubelet, however, and the control plane reaches SSH. The Pods keep talking to each other through the filtered node, via a Service. The nftables service is enabled so that the rules come back at boot, and the file does not contain flush ruleset, which would erase the kube-proxy and Calico rules.
Key takeaways
A node is taken by SSH, by the kubelet API, by an exposed port or by the cloud metadata from a Pod: each path is closed separately.
ss -tulpn and systemctl list-unit-files --state=enabled measure what a node exposes and starts; you remove what is identified, never a copied list. For an unknown port, you trace it from the PID to the package with systemctl status <PID> and dpkg -S, and a .socket unit such as rpcbind.socket keeps the port open until it is stopped.
The runtime, the kubelet, the clock and the overlay and br_netfilter modules are not removed, and iptables stays for the kubelet's protections; conntrack and nft serve diagnosis, and nft loads the firewall of this lesson.
With protectKernelDefaults: true, the kubelet checks six kernel settings instead of setting them: write them in /etc/sysctl.d/ before enabling the field, otherwise it refuses to start, and the node nevertheless stays Ready while systemd restarts the kubelet in a loop: look at systemctl status kubelet.
sshd -T shows the SSH configuration written on disk, not that of the running processes: pgrep -a sshd must show a single sshd -D [listener], and the test is repeated several times with a refused account. Connection is by key, with no password and no root, for a named group, and an on-call account receives a sudoers rule limited to one command, checked with visudo -cf.
The kubelet credentials are limited by the Node authorization; access to a control plane node, however, is equivalent to cluster-admin, because of admin.conf.
The cloud role of a node is reduced to what the node does itself; the Pods that need the cloud receive their own identity.
An egress NetworkPolicy that excludes 169.254.169.254/32 protects the metadata, namespace by namespace, and most often does not filter hostNetwork Pods.
Port 10250 is opened to the node network and the Pod network: the kubelet sees the source node's address from another node, and the Pod's address from the node itself, and metrics-server needs both cases.
The Kubernetes ports are those of the Ports and Protocols documentation, completed by those of the network plugin and SSH; etcd (2379-2380) is only opened to the API server and the other etcd members.
The rest is closed with nftables, without flush ruleset, and checked with nc or nmap from another machine, after restarting metrics-server to test with new connections.
Knowledge check
Check that you have the essentials of this guide. The questions cover only
what has just been explained here.
Knowledge check
Check what you have learned with this interactive quiz
8 questions
8 min
70% to pass
How it works
The timer starts when you click Start
Multiple choice, true/false and short answer questions
You can move between questions
Detailed results are shown at the end
Starts the quiz and the timer
⏱️--:--
0 / 8
Review
(0/0)
--:--
0%
Result saved on this device. It will be sent to your account at the next sync. Sync now
0Correct
0To review
0:00Time
-Level
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.