mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #92863 from AkihiroSuda/rootless-pr
kubelet & kube-proxy: ignore sysctl errors and rlimit errors when running in UserNS (for rootless)
This commit is contained in:
commit
ebbe63f116
@ -762,6 +762,14 @@ const (
|
|||||||
//
|
//
|
||||||
// Allows clients to request a duration for certificates issued via the Kubernetes CSR API.
|
// Allows clients to request a duration for certificates issued via the Kubernetes CSR API.
|
||||||
CSRDuration featuregate.Feature = "CSRDuration"
|
CSRDuration featuregate.Feature = "CSRDuration"
|
||||||
|
|
||||||
|
// owner: @AkihiroSuda
|
||||||
|
// alpha: v1.22
|
||||||
|
//
|
||||||
|
// Enables support for running kubelet in a user namespace.
|
||||||
|
// The user namespace has to be created before running kubelet.
|
||||||
|
// All the node components such as CRI need to be running in the same user namespace.
|
||||||
|
KubeletInUserNamespace featuregate.Feature = "KubeletInUserNamespace"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -876,6 +884,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
|
|||||||
ReadWriteOncePod: {Default: false, PreRelease: featuregate.Alpha},
|
ReadWriteOncePod: {Default: false, PreRelease: featuregate.Alpha},
|
||||||
CSRDuration: {Default: true, PreRelease: featuregate.Beta},
|
CSRDuration: {Default: true, PreRelease: featuregate.Beta},
|
||||||
DelegateFSGroupToCSIDriver: {Default: false, PreRelease: featuregate.Alpha},
|
DelegateFSGroupToCSIDriver: {Default: false, PreRelease: featuregate.Alpha},
|
||||||
|
KubeletInUserNamespace: {Default: false, PreRelease: featuregate.Alpha},
|
||||||
|
|
||||||
// inherited features from generic apiserver, relisted here to get a conflict if it is changed
|
// inherited features from generic apiserver, relisted here to get a conflict if it is changed
|
||||||
// unintentionally on either side:
|
// unintentionally on either side:
|
||||||
|
@ -39,6 +39,7 @@ import (
|
|||||||
utilpath "k8s.io/utils/path"
|
utilpath "k8s.io/utils/path"
|
||||||
|
|
||||||
libcontainerdevices "github.com/opencontainers/runc/libcontainer/devices"
|
libcontainerdevices "github.com/opencontainers/runc/libcontainer/devices"
|
||||||
|
libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
@ -455,6 +456,13 @@ func setupKernelTunables(option KernelTunableBehavior) error {
|
|||||||
klog.V(2).InfoS("Updating kernel flag", "flag", flag, "expectedValue", expectedValue, "actualValue", val)
|
klog.V(2).InfoS("Updating kernel flag", "flag", flag, "expectedValue", expectedValue, "actualValue", val)
|
||||||
err = sysctl.SetSysctl(flag, expectedValue)
|
err = sysctl.SetSysctl(flag, expectedValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if libcontaineruserns.RunningInUserNS() {
|
||||||
|
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.KubeletInUserNamespace) {
|
||||||
|
klog.V(2).InfoS("Updating kernel flag failed (running in UserNS, ignoring)", "flag", flag, "err", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
klog.ErrorS(err, "Updating kernel flag failed (Hint: enable KubeletInUserNamespace feature flag to ignore the error)", "flag", flag)
|
||||||
|
}
|
||||||
errList = append(errList, err)
|
errList = append(errList, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
|
|
||||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||||
|
libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns"
|
||||||
"k8s.io/mount-utils"
|
"k8s.io/mount-utils"
|
||||||
"k8s.io/utils/integer"
|
"k8s.io/utils/integer"
|
||||||
|
|
||||||
@ -481,7 +482,19 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
|
|||||||
|
|
||||||
oomWatcher, err := oomwatcher.NewWatcher(kubeDeps.Recorder)
|
oomWatcher, err := oomwatcher.NewWatcher(kubeDeps.Recorder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
if libcontaineruserns.RunningInUserNS() {
|
||||||
|
if utilfeature.DefaultFeatureGate.Enabled(features.KubeletInUserNamespace) {
|
||||||
|
// oomwatcher.NewWatcher returns "open /dev/kmsg: operation not permitted" error,
|
||||||
|
// when running in a user namespace with sysctl value `kernel.dmesg_restrict=1`.
|
||||||
|
klog.V(2).InfoS("Failed to create an oomWatcher (running in UserNS, ignoring)", "err", err)
|
||||||
|
oomWatcher = nil
|
||||||
|
} else {
|
||||||
|
klog.ErrorS(err, "Failed to create an oomWatcher (running in UserNS, Hint: enable KubeletInUserNamespace feature flag to ignore the error)")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterDNS := make([]net.IP, 0, len(kubeCfg.ClusterDNS))
|
clusterDNS := make([]net.IP, 0, len(kubeCfg.ClusterDNS))
|
||||||
@ -1360,8 +1373,10 @@ func (kl *Kubelet) initializeModules() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start out of memory watcher.
|
// Start out of memory watcher.
|
||||||
if err := kl.oomWatcher.Start(kl.nodeRef); err != nil {
|
if kl.oomWatcher != nil {
|
||||||
return fmt.Errorf("failed to start OOM watcher %v", err)
|
if err := kl.oomWatcher.Start(kl.nodeRef); err != nil {
|
||||||
|
return fmt.Errorf("failed to start OOM watcher: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start resource analyzer
|
// Start resource analyzer
|
||||||
|
@ -26,14 +26,17 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
libcontaineruserns "github.com/opencontainers/runc/libcontainer/userns"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
"k8s.io/apimachinery/pkg/util/runtime"
|
"k8s.io/apimachinery/pkg/util/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||||
servicehelper "k8s.io/cloud-provider/service/helpers"
|
servicehelper "k8s.io/cloud-provider/service/helpers"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
kubefeatures "k8s.io/kubernetes/pkg/features"
|
||||||
"k8s.io/kubernetes/pkg/proxy"
|
"k8s.io/kubernetes/pkg/proxy"
|
||||||
"k8s.io/kubernetes/pkg/proxy/config"
|
"k8s.io/kubernetes/pkg/proxy/config"
|
||||||
utilproxy "k8s.io/kubernetes/pkg/proxy/util"
|
utilproxy "k8s.io/kubernetes/pkg/proxy/util"
|
||||||
@ -231,7 +234,11 @@ func NewCustomProxier(loadBalancer LoadBalancer, listenIP net.IP, iptables iptab
|
|||||||
|
|
||||||
err = setRLimit(64 * 1000)
|
err = setRLimit(64 * 1000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to set open file handler limit: %v", err)
|
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.KubeletInUserNamespace) && libcontaineruserns.RunningInUserNS() {
|
||||||
|
klog.V(2).InfoS("Failed to set open file handler limit to 64000 (running in UserNS, ignoring)", "err", err)
|
||||||
|
} else {
|
||||||
|
return nil, fmt.Errorf("failed to set open file handler limit to 64000: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
proxyPorts := newPortAllocator(pr)
|
proxyPorts := newPortAllocator(pr)
|
||||||
|
Loading…
Reference in New Issue
Block a user