提交 800be7ed 编写于 作者: M Matt Rickard

Add convenience container-runtime flag for kubeadm

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`
上级 967913b9
......@@ -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"
......@@ -178,6 +179,35 @@ 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
}
if runtime == "" {
glog.Infoln("Container runtime flag provided with no value, using defaults.")
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 {
......@@ -189,14 +219,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
......
......@@ -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
......
......@@ -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{
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册