Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --cgroup_parent flag to Kubelet to set the parent cgroup for pods #7277

Merged
merged 1 commit into from
May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type KubeletServer struct {
CertDirectory string
NodeStatusUpdateFrequency time.Duration
ResourceContainer string
CgroupRoot string

// Flags intended for testing

Expand Down Expand Up @@ -151,6 +152,7 @@ func NewKubeletServer() *KubeletServer {
CertDirectory: "/var/run/kubernetes",
NodeStatusUpdateFrequency: 10 * time.Second,
ResourceContainer: "/kubelet",
CgroupRoot: "",
}
}

Expand Down Expand Up @@ -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.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.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.
fs.BoolVar(&s.ReallyCrashForTesting, "really-crash-for-testing", s.ReallyCrashForTesting, "If true, when panics occur crash. Intended for testing.")
Expand Down Expand Up @@ -301,6 +304,7 @@ func (s *KubeletServer) Run(_ []string) error {
Cloud: cloud,
NodeStatusUpdateFrequency: s.NodeStatusUpdateFrequency,
ResourceContainer: s.ResourceContainer,
CgroupRoot: s.CgroupRoot,
}

RunKubelet(&kcfg, nil)
Expand Down Expand Up @@ -409,6 +413,7 @@ func SimpleKubelet(client *client.Client,
NodeStatusUpdateFrequency: 10 * time.Second,
ResourceContainer: "/kubelet",
OSInterface: osInterface,
CgroupRoot: "",
}
return &kcfg
}
Expand Down Expand Up @@ -536,6 +541,7 @@ type KubeletConfig struct {
NodeStatusUpdateFrequency time.Duration
ResourceContainer string
OSInterface kubecontainer.OSInterface
CgroupRoot string
}

func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.PodConfig, err error) {
Expand Down Expand Up @@ -580,7 +586,8 @@ func createAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
kc.Cloud,
kc.NodeStatusUpdateFrequency,
kc.ResourceContainer,
kc.OSInterface)
kc.OSInterface,
kc.CgroupRoot)

if err != nil {
return nil, nil, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubelet/container/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ type RunContainerOptions struct {
// into docker's container runtime.
NetMode string
IpcMode string
// The parent cgroup to pass to Docker
CgroupParent string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK with this. But seems we need to change the comment to remove 'Docker'. My understanding is you don't want other container runtime to escape the cgroup as well, right? @guenter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Yifan! :) Sounds good, let's make this runtime-agnostic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Tobi! :) SGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmarmol @vishh updated!

}

type Pods []*Pod
Expand Down
3 changes: 3 additions & 0 deletions pkg/kubelet/dockertools/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ func (dm *DockerManager) runContainer(pod *api.Pod, container *api.Container, op
if len(opts.DNSSearch) > 0 {
hc.DNSSearch = opts.DNSSearch
}
if len(opts.CgroupParent) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this option will be silently ignored with older versions of docker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I tested with Docker 1.4.1. Containers just launch under the default /docker cgroup.

hc.CgroupParent = opts.CgroupParent
}

if err = dm.client.StartContainer(dockerContainer.ID, hc); err != nil {
if ref != nil {
Expand Down
12 changes: 9 additions & 3 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func NewMainKubelet(
cloud cloudprovider.Interface,
nodeStatusUpdateFrequency time.Duration,
resourceContainer string,
osInterface kubecontainer.OSInterface) (*Kubelet, error) {
osInterface kubecontainer.OSInterface,
cgroupRoot string) (*Kubelet, error) {
if rootDirectory == "" {
return nil, fmt.Errorf("invalid root directory %q", rootDirectory)
}
Expand Down Expand Up @@ -236,6 +237,7 @@ func NewMainKubelet(
os: osInterface,
oomWatcher: oomWatcher,
runtimeHooks: newKubeletRuntimeHooks(recorder),
cgroupRoot: cgroupRoot,
}

if plug, err := network.InitNetworkPlugin(networkPlugins, networkPluginName, &networkHost{klet}); err != nil {
Expand Down Expand Up @@ -411,6 +413,9 @@ type Kubelet struct {
// TODO(vmarmol): Remove this when we only have to inject the hooks into the runtimes.
// Hooks injected into the container runtime.
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
Expand Down Expand Up @@ -659,8 +664,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) {
var err error
opts := &kubecontainer.RunContainerOptions{
NetMode: netMode,
IpcMode: ipcMode,
NetMode: netMode,
IpcMode: ipcMode,
CgroupParent: kl.cgroupRoot,
}

vol, ok := kl.volumeManager.GetVolumes(pod.UID)
Expand Down