Skip to content

Commit

Permalink
Add convenience container-runtime flag for kubeadm
Browse files Browse the repository at this point in the history
To enable the cri-o runtime you may now just use

`minikube start --container-runtime=cri-o --bootstrapper=kubeadm`
or
`minikube start --container-runtiume=crio --bootstrapper=kubeadm`
or
`minikube start --extra-config=kubelet.container-runtime=remote
--extra-config=kubelet.container-runtime-endpoint=/var/run/crio.sock
--extra-config=image-service-endpoint=/var/run/crio.sock`
  • Loading branch information
r2d4 committed Oct 11, 2017
1 parent 967913b commit 16d2b7a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 11 deletions.
36 changes: 32 additions & 4 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/docker/machine/libmachine"
"github.com/docker/machine/libmachine/state"
"github.com/golang/glog"
download "github.com/jimmidyson/go-download"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -178,6 +179,30 @@ func (k *KubeadmBootstrapper) SetupCerts(k8s bootstrapper.KubernetesConfig) erro
return bootstrapper.SetupCerts(k.c, k8s)
}

// SetContainerRuntime possibly sets the container runtime, if it hasn't already
// been specified by the extra-config option. It has a set of defaults known to
// work for a particular runtime.
func SetContainerRuntime(cfg map[string]string, runtime string) map[string]string {
if _, ok := cfg["container-runtime"]; ok {
glog.Infoln("Container runtime already set through extra options, ignoring --container-runtime flag.")
return cfg
}

switch runtime {
case "crio", "cri-o":
cfg["container-runtime"] = "remote"
cfg["container-runtime-endpoint"] = "/var/run/crio.sock"
cfg["image-service-endpoint"] = "/var/run/crio.sock"
cfg["runtime-request-timeout"] = "15m"
default:
cfg["container-runtime"] = runtime
}

return cfg
}

// NewKubeletConfig generates a new systemd unit containing a configured kubelet
// based on the options present in the KubernetesConfig.
func NewKubeletConfig(k8s bootstrapper.KubernetesConfig) (string, error) {
version, err := ParseKubernetesVersion(k8s.KubernetesVersion)
if err != nil {
Expand All @@ -189,14 +214,17 @@ func NewKubeletConfig(k8s bootstrapper.KubernetesConfig) (string, error) {
return "", errors.Wrap(err, "generating extra configuration for kubelet")
}

extraOpts = SetContainerRuntime(extraOpts, k8s.ContainerRuntime)
extraFlags := convertToFlags(extraOpts)
b := bytes.Buffer{}
opts := struct {
ExtraOptions string
FeatureGates string
ExtraOptions string
FeatureGates string
ContainerRuntime string
}{
ExtraOptions: extraFlags,
FeatureGates: k8s.FeatureGates,
ExtraOptions: extraFlags,
FeatureGates: k8s.FeatureGates,
ContainerRuntime: k8s.ContainerRuntime,
}
if err := kubeletSystemdTemplate.Execute(&b, opts); err != nil {
return "", err
Expand Down
28 changes: 21 additions & 7 deletions pkg/minikube/bootstrapper/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,31 @@ nodeName: {{.NodeName}}
{{$val}}{{end}}
{{end}}`))

var kubeletSystemdTemplate = template.Must(template.New("kubeletSystemdTemplate").Parse(`
var kubeletSystemdTemplate = template.Must(template.New("kubeletSystemdTemplate").Funcs(template.FuncMap{
"installWants": installWants,
}).Parse(`
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.0.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0"
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_DNS_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS {{.ExtraOptions}} {{if .FeatureGates}}--feature-gates={{.FeatureGates}}{{end}}
ExecStart=/usr/bin/kubelet {{.ExtraOptions}} {{if .FeatureGates}}--feature-gates={{.FeatureGates}}{{end}}
[Install]
{{installWants .ContainerRuntime}}
`))

func installWants(containerRuntime string) string {
var wants string
switch containerRuntime {
case "":
wants = "docker.socket"
case "cri-o", "cri":
wants = "crio.service"
}
if wants != "" {
return fmt.Sprintf("Wants=%s", wants)
}
return ""
}

const kubeletService = `
[Unit]
Description=kubelet: The Kubernetes Node Agent
Expand Down
19 changes: 19 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ type VersionedExtraOption struct {
GreaterThanOrEqual semver.Version
}

// NewUnversionedOption returns a VersionedExtraOption that applies to all versions.
func NewUnversionedOption(component, k, v string) VersionedExtraOption {
return VersionedExtraOption{
Option: util.ExtraOption{
Component: component,
Key: k,
Value: v,
},
}
}

var versionSpecificOpts = []VersionedExtraOption{
{
Option: util.ExtraOption{
Expand All @@ -158,6 +169,14 @@ var versionSpecificOpts = []VersionedExtraOption{
},
GreaterThanOrEqual: semver.MustParse("1.8.0-alpha.0"),
},
NewUnversionedOption(Kubelet, "kubeconfig", "/etc/kubernetes/kubelet.conf"),
NewUnversionedOption(Kubelet, "require-kubeconfig", "true"),
NewUnversionedOption(Kubelet, "pod-manifest-path", "/etc/kubernetes/manifests"),
NewUnversionedOption(Kubelet, "allow-privileged", "true"),
NewUnversionedOption(Kubelet, "cluster-dns", "10.0.0.10"),
NewUnversionedOption(Kubelet, "cluster-domain", "cluster.local"),
NewUnversionedOption(Kubelet, "cadvisor-port", "0"),
NewUnversionedOption(Kubelet, "cgroup-driver", "cgroupfs"),
}

func VersionIsBetween(version, gte, lte semver.Version) bool {
Expand Down

0 comments on commit 16d2b7a

Please sign in to comment.