Skip to content

Commit 1ad6422

Browse files
Fix kubelet detection on MicroK8s with nftables backend (#58314)
* Fix kubelet detection on MicroK8s with nftables backend When Ambient mode is used with the nftables backend, this PR fixes kubelet UID detection so that it works in MicroK8s, where kubelet runs inside the unified “kubelite” daemon rather than as a standalone process. Fixes: istio/istio#58185 Signed-off-by: Sridhar Gaddam <[email protected]> * Add release notes Signed-off-by: Sridhar Gaddam <[email protected]> --------- Signed-off-by: Sridhar Gaddam <[email protected]>
1 parent 3463a6d commit 1ad6422

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

cni/pkg/nftables/kubeletuid_linux.go

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"github.com/prometheus/procfs"
2323
)
2424

25-
// getKubeletUIDFromPath finds the kubelet process UID by inspecting the proc filesystem path.
25+
// getKubeletUIDFromPath finds the kubelet or kubelite process UID by inspecting the proc filesystem path.
26+
// In standard Kubernetes distributions, it looks for the "kubelet" process.
27+
// On some platforms like MicroK8s, where multiple k8s components are consolidated, it looks for the "kubelite" process.
2628
func getKubeletUIDFromPath(procPath string) (string, error) {
2729
fs, err := procfs.NewFS(procPath)
2830
if err != nil {
@@ -34,44 +36,53 @@ func getKubeletUIDFromPath(procPath string) (string, error) {
3436
return "", fmt.Errorf("failed to read processes from %s: %v", procPath, err)
3537
}
3638

37-
// Find kubelet process
39+
// List of process names to search for, in order of preference
40+
processNames := []string{"kubelet", "kubelite"}
41+
3842
for _, proc := range procs {
3943
comm, err := proc.Comm()
4044
if err != nil {
4145
// Process might have exited, skip
4246
continue
4347
}
4448

45-
if comm == "kubelet" {
46-
// Lets check the command line to ensure it's really kubelet
47-
cmdline, err := proc.CmdLine()
48-
if err != nil {
49-
continue
50-
}
49+
for _, targetName := range processNames {
50+
if comm == targetName {
51+
// Lets check the command line to ensure it's really the target process
52+
cmdline, err := proc.CmdLine()
53+
if err != nil {
54+
continue
55+
}
5156

52-
kubeletFound := false
53-
for _, arg := range cmdline {
54-
if strings.Contains(strings.ToLower(arg), "kubelet") {
55-
kubeletFound = true
56-
break
57+
// Verify that this process is actually related to kubelet by checking
58+
// if "kubelet" appears in any of the command line arguments.
59+
// This works for both:
60+
// - Standard kubelet: /usr/bin/kubelet [args...]
61+
// - MicroK8s kubelite: /snap/microk8s/.../kubelite --kubelet-args-file=...
62+
processFound := false
63+
for _, arg := range cmdline {
64+
if strings.Contains(strings.ToLower(arg), "kubelet") {
65+
processFound = true
66+
break
67+
}
68+
}
69+
if !processFound {
70+
continue
5771
}
58-
}
59-
if !kubeletFound {
60-
continue
61-
}
6272

63-
// Get process status with UIDs
64-
status, err := proc.NewStatus()
65-
if err != nil {
66-
continue
67-
}
73+
// Get process status with UIDs
74+
status, err := proc.NewStatus()
75+
if err != nil {
76+
continue
77+
}
6878

69-
realUID := status.UIDs[0]
70-
realUIDStr := strconv.FormatUint(realUID, 10)
79+
realUID := status.UIDs[0]
80+
realUIDStr := strconv.FormatUint(realUID, 10)
7181

72-
return realUIDStr, nil
82+
return realUIDStr, nil
83+
}
7384
}
7485
}
7586

76-
return "", fmt.Errorf("kubelet process not found in %s", procPath)
87+
return "", fmt.Errorf("kubelet or kubelite process not found in %s", procPath)
7788
}

cni/pkg/nftables/nftables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func (cfg *NftablesConfigurator) CreateHostRulesForHealthChecks() error {
443443
//
444444
// Challenge: In nftables, there is no direct equivalent to "--socket-exists", so we explored multiple alternatives
445445
// - Option-1 (UID-based matching): Since kubelet runs as a specific process with a known UID, we can use
446-
// meta skuid to identify traffic originating from kubelet.
446+
// meta skuid to identify traffic originating from kubelet (or kubelite in MicroK8s).
447447
//
448448
// - Option-2: Match on kubelet’s source IP (node IP). This works in theory but is a bit unsafe as
449449
// other host processes can also send traffic from the node IP, and nodes can have multiple IPs making the

releasenotes/notes/58185.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: release-notes/v2
2+
kind: bug-fix
3+
area: traffic-management
4+
issue:
5+
- 58185
6+
releaseNotes:
7+
- |
8+
**Fixed** Istio CNI node agent startup failure in MicroK8s environments when using ambient mode with nftables backend.

0 commit comments

Comments
 (0)