mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #7277 from guenter/cgroup-parent
Add --cgroup_parent flag to Kubelet to set the parent cgroup for pods
This commit is contained in:
commit
cadfde0bd1
@ -99,6 +99,7 @@ type KubeletServer struct {
|
|||||||
CertDirectory string
|
CertDirectory string
|
||||||
NodeStatusUpdateFrequency time.Duration
|
NodeStatusUpdateFrequency time.Duration
|
||||||
ResourceContainer string
|
ResourceContainer string
|
||||||
|
CgroupRoot string
|
||||||
|
|
||||||
// Flags intended for testing
|
// Flags intended for testing
|
||||||
|
|
||||||
@ -151,6 +152,7 @@ func NewKubeletServer() *KubeletServer {
|
|||||||
CertDirectory: "/var/run/kubernetes",
|
CertDirectory: "/var/run/kubernetes",
|
||||||
NodeStatusUpdateFrequency: 10 * time.Second,
|
NodeStatusUpdateFrequency: 10 * time.Second,
|
||||||
ResourceContainer: "/kubelet",
|
ResourceContainer: "/kubelet",
|
||||||
|
CgroupRoot: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,6 +204,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
|
|||||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
|
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
|
||||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||||
fs.StringVar(&s.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).")
|
fs.StringVar(&s.ResourceContainer, "resource-container", s.ResourceContainer, "Absolute name of the resource-only container to create and run the Kubelet in (Default: /kubelet).")
|
||||||
|
fs.StringVar(&s.CgroupRoot, "cgroup_root", s.CgroupRoot, "Optional root cgroup to use for pods. This is handled by the container runtime on a best effort basis. Default: '', which means use the container runtime default.")
|
||||||
|
|
||||||
// Flags intended for testing, not recommended used in production environments.
|
// Flags intended for testing, not recommended used in production environments.
|
||||||
fs.BoolVar(&s.ReallyCrashForTesting, "really-crash-for-testing", s.ReallyCrashForTesting, "If true, when panics occur crash. Intended for testing.")
|
fs.BoolVar(&s.ReallyCrashForTesting, "really-crash-for-testing", s.ReallyCrashForTesting, "If true, when panics occur crash. Intended for testing.")
|
||||||
@ -301,6 +304,7 @@ func (s *KubeletServer) Run(_ []string) error {
|
|||||||
Cloud: cloud,
|
Cloud: cloud,
|
||||||
NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency,
|
NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency,
|
||||||
ResourceContainer: s.ResourceContainer,
|
ResourceContainer: s.ResourceContainer,
|
||||||
|
CgroupRoot: s.CgroupRoot,
|
||||||
}
|
}
|
||||||
|
|
||||||
RunKubelet(&kcfg, nil)
|
RunKubelet(&kcfg, nil)
|
||||||
@ -409,6 +413,7 @@ func SimpleKubelet(client *client.Client,
|
|||||||
NodeStatusUpdateFrequency: 10 * time.Second,
|
NodeStatusUpdateFrequency: 10 * time.Second,
|
||||||
ResourceContainer: "/kubelet",
|
ResourceContainer: "/kubelet",
|
||||||
OSInterface: osInterface,
|
OSInterface: osInterface,
|
||||||
|
CgroupRoot: "",
|
||||||
}
|
}
|
||||||
return &kcfg
|
return &kcfg
|
||||||
}
|
}
|
||||||
@ -536,6 +541,7 @@ type KubeletConfig struct {
|
|||||||
NodeStatusUpdateFrequency time.Duration
|
NodeStatusUpdateFrequency time.Duration
|
||||||
ResourceContainer string
|
ResourceContainer string
|
||||||
OSInterface kubecontainer.OSInterface
|
OSInterface kubecontainer.OSInterface
|
||||||
|
CgroupRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.PodConfig, err error) {
|
func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.PodConfig, err error) {
|
||||||
@ -580,7 +586,8 @@ func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
|
|||||||
kc.Cloud,
|
kc.Cloud,
|
||||||
kc.NodeStatusUpdateFrequency,
|
kc.NodeStatusUpdateFrequency,
|
||||||
kc.ResourceContainer,
|
kc.ResourceContainer,
|
||||||
kc.OSInterface)
|
kc.OSInterface,
|
||||||
|
kc.CgroupRoot)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -195,6 +195,8 @@ type RunContainerOptions struct {
|
|||||||
// into docker's container runtime.
|
// into docker's container runtime.
|
||||||
NetMode string
|
NetMode string
|
||||||
IpcMode string
|
IpcMode string
|
||||||
|
// The parent cgroup to pass to Docker
|
||||||
|
CgroupParent string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pods []*Pod
|
type Pods []*Pod
|
||||||
|
@ -556,6 +556,9 @@ func (dm *DockerManager) runContainer(pod *api.Pod, container *api.Container, op
|
|||||||
if len(opts.DNSSearch) > 0 {
|
if len(opts.DNSSearch) > 0 {
|
||||||
hc.DNSSearch = opts.DNSSearch
|
hc.DNSSearch = opts.DNSSearch
|
||||||
}
|
}
|
||||||
|
if len(opts.CgroupParent) > 0 {
|
||||||
|
hc.CgroupParent = opts.CgroupParent
|
||||||
|
}
|
||||||
|
|
||||||
if err = dm.client.StartContainer(dockerContainer.ID, hc); err != nil {
|
if err = dm.client.StartContainer(dockerContainer.ID, hc); err != nil {
|
||||||
if ref != nil {
|
if ref != nil {
|
||||||
|
@ -120,7 +120,8 @@ func NewMainKubelet(
|
|||||||
cloud cloudprovider.Interface,
|
cloud cloudprovider.Interface,
|
||||||
nodeStatusUpdateFrequency time.Duration,
|
nodeStatusUpdateFrequency time.Duration,
|
||||||
resourceContainer string,
|
resourceContainer string,
|
||||||
osInterface kubecontainer.OSInterface) (*Kubelet, error) {
|
osInterface kubecontainer.OSInterface,
|
||||||
|
cgroupRoot string) (*Kubelet, error) {
|
||||||
if rootDirectory == "" {
|
if rootDirectory == "" {
|
||||||
return nil, fmt.Errorf("invalid root directory %q", rootDirectory)
|
return nil, fmt.Errorf("invalid root directory %q", rootDirectory)
|
||||||
}
|
}
|
||||||
@ -233,6 +234,7 @@ func NewMainKubelet(
|
|||||||
os: osInterface,
|
os: osInterface,
|
||||||
oomWatcher: oomWatcher,
|
oomWatcher: oomWatcher,
|
||||||
runtimeHooks: newKubeletRuntimeHooks(recorder),
|
runtimeHooks: newKubeletRuntimeHooks(recorder),
|
||||||
|
cgroupRoot: cgroupRoot,
|
||||||
}
|
}
|
||||||
|
|
||||||
if plug, err := network.InitNetworkPlugin(networkPlugins, networkPluginName, &networkHost{klet}); err != nil {
|
if plug, err := network.InitNetworkPlugin(networkPlugins, networkPluginName, &networkHost{klet}); err != nil {
|
||||||
@ -404,6 +406,9 @@ type Kubelet struct {
|
|||||||
// TODO(vmarmol): Remove this when we only have to inject the hooks into the runtimes.
|
// TODO(vmarmol): Remove this when we only have to inject the hooks into the runtimes.
|
||||||
// Hooks injected into the container runtime.
|
// Hooks injected into the container runtime.
|
||||||
runtimeHooks kubecontainer.RuntimeHooks
|
runtimeHooks kubecontainer.RuntimeHooks
|
||||||
|
|
||||||
|
// If non-empty, pass this to the container runtime as the root cgroup.
|
||||||
|
cgroupRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRootDir returns the full path to the directory under which kubelet can
|
// getRootDir returns the full path to the directory under which kubelet can
|
||||||
@ -652,8 +657,9 @@ func makeBinds(container *api.Container, podVolumes volumeMap) (binds []string)
|
|||||||
func (kl *Kubelet) GenerateRunContainerOptions(pod *api.Pod, container *api.Container, netMode, ipcMode string) (*kubecontainer.RunContainerOptions, error) {
|
func (kl *Kubelet) GenerateRunContainerOptions(pod *api.Pod, container *api.Container, netMode, ipcMode string) (*kubecontainer.RunContainerOptions, error) {
|
||||||
var err error
|
var err error
|
||||||
opts := &kubecontainer.RunContainerOptions{
|
opts := &kubecontainer.RunContainerOptions{
|
||||||
NetMode: netMode,
|
NetMode: netMode,
|
||||||
IpcMode: ipcMode,
|
IpcMode: ipcMode,
|
||||||
|
CgroupParent: kl.cgroupRoot,
|
||||||
}
|
}
|
||||||
|
|
||||||
vol, ok := kl.volumeManager.GetVolumes(pod.UID)
|
vol, ok := kl.volumeManager.GetVolumes(pod.UID)
|
||||||
|
Loading…
Reference in New Issue
Block a user