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

Support CRI-O runtime with Rootless Docker driver (--driver=docker --container-runtime=cri-o) #12900

Merged
merged 1 commit into from
Nov 12, 2021
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
5 changes: 2 additions & 3 deletions cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,8 @@ func generateNewConfigFromFlags(cmd *cobra.Command, k8sVersion string, drvName s
exit.Message(reason.Usage, "Ensure your {{.driver_name}} is running and is healthy.", out.V{"driver_name": driver.FullName(drvName)})
}
if si.Rootless {
if cc.KubernetesConfig.ContainerRuntime != "containerd" {
exit.Message(reason.Usage, "Container runtime must be set to \"containerd\" for rootless")
// TODO: support cri-o (https://kubernetes.io/docs/tasks/administer-cluster/kubelet-in-userns/#configuring-cri)
if cc.KubernetesConfig.ContainerRuntime == "docker" {
exit.Message(reason.Usage, "--container-runtime must be set to \"containerd\" or \"cri-o\" for rootless")
}
// KubeletInUserNamespace feature gate is essential for rootless driver.
// See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-in-userns/
Expand Down
52 changes: 49 additions & 3 deletions pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -147,11 +148,50 @@ func enableIPForwarding(cr CommandRunner) error {
return nil
}

// enableRootless enables configurations for running CRI-O in Rootless Docker.
//
// 1. Create /etc/systemd/system/crio.service.d/10-rootless.conf to set _CRIO_ROOTLESS=1
// 2. Create /etc/crio/crio.conf.d/10-fuse-overlayfs.conf to enable fuse-overlayfs
// 3. Reload systemd
//
// See https://kubernetes.io/docs/tasks/administer-cluster/kubelet-in-userns/#configuring-cri
func (r *CRIO) enableRootless() error {
files := map[string]string{
"/etc/systemd/system/crio.service.d/10-rootless.conf": `[Service]
Environment="_CRIO_ROOTLESS=1"
`,
"/etc/crio/crio.conf.d/10-fuse-overlayfs.conf": `[crio]
storage_driver = "overlay"
storage_option = ["overlay.mount_program=/usr/local/bin/fuse-overlayfs"]
`,
}
for target, content := range files {
targetDir := filepath.Dir(target)
c := exec.Command("sudo", "mkdir", "-p", targetDir)
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrapf(err, "failed to create directory %q", targetDir)
}
asset := assets.NewMemoryAssetTarget([]byte(content), target, "0644")
err := r.Runner.Copy(asset)
asset.Close()
if err != nil {
return errors.Wrapf(err, "failed to create %q", target)
}
}
// reload systemd to apply our changes on /etc/systemd
if err := r.Init.Reload("crio"); err != nil {
return err
}
if r.Init.Active("crio") {
if err := r.Init.Restart("crio"); err != nil {
return err
}
}
return nil
}

// Enable idempotently enables CRIO on a host
func (r *CRIO) Enable(disOthers, forceSystemd, inUserNamespace bool) error {
if inUserNamespace {
return errors.New("inUserNamespace must not be true for cri-o (yet)")
}
if disOthers {
if err := disableOthers(r, r.Runner); err != nil {
klog.Warningf("disableOthers: %v", err)
Expand All @@ -171,6 +211,12 @@ func (r *CRIO) Enable(disOthers, forceSystemd, inUserNamespace bool) error {
return err
}
}
if inUserNamespace {
if err := r.enableRootless(); err != nil {
return err
}
}
// NOTE: before we start crio explicitly here, crio might be already started automatically
return r.Init.Start("crio")
}

Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/drivers/includes/docker_usage.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker context use rootless
minikube start --driver=docker --container-runtime=containerd
```

The `--container-runtime` flag must be currently set to "containerd".
The `--container-runtime` flag must be set to "containerd" or "cri-o".

The restrictions of rootless `kind` apply to minikube with rootless docker as well.

Expand Down