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

feat: add possibility to customize containerd with additional files #2604

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 16 additions & 0 deletions docs/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@ Finally, if you want to change CRI look into:
runtime = "runc"
```

### Alternative method

In case you don't want to change the original `/etc/k0s/containerd.toml` file, then you can easily add your customizations under the `/etc/k0s/containerd.d/` directory.

Files under this path must have a `.toml` extention in order to get read by containerd:

```shell
cat << EOF > /etc/k0s/containerd.d/debug.toml
[debug]
address = "/run/containerd/debug.sock"
uid = 0
gid = 0
level = "info"
EOF
```

## Using gVisor

[gVisor](https://gvisor.dev/docs/) is an application kernel, written in Go, that implements a substantial portion of the Linux system call interface. It provides an additional layer of isolation between running applications and the host operating system.
Expand Down
13 changes: 10 additions & 3 deletions pkg/component/worker/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ import (
"github.com/k0sproject/k0s/pkg/supervisor"
)

const confTmpl = `
const confPath = "/etc/k0s/containerd.toml"
const confPathContainerd = "/etc/k0s/containerd.d"

var confTmpl = fmt.Sprintf(`
# This is a placeholder configuration for k0s managed containerD.
# If you wish to customize the config replace this file with your custom configuration.
# For reference see https://github.com/containerd/containerd/blob/main/docs/man/containerd-config.toml.5.md
version = 2
`
const confPath = "/etc/k0s/containerd.toml"

imports = ["%s/*.toml"]
`, confPathContainerd)

// ContainerD implement the component interface to manage containerd as k0s component
type ContainerD struct {
Expand Down Expand Up @@ -98,6 +102,9 @@ func (c *ContainerD) setupConfig() error {
if err := dir.Init(filepath.Dir(confPath), 0755); err != nil {
return err
}
if err := dir.Init(confPathContainerd, 0755); err != nil {
return err
}
return file.WriteContentAtomically(confPath, []byte(confTmpl), 0644)
}

Expand Down