Skip to content

Commit a115db6

Browse files
author
priyawadhwa
authored
Merge pull request #8552 from priyawadhwa/coredns
Reduce coredns replicas from 2 to 1
2 parents d368674 + 1769750 commit a115db6

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

Diff for: pkg/addons/kubectl.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os/exec"
2222
"path"
2323

24+
"k8s.io/minikube/pkg/kapi"
2425
"k8s.io/minikube/pkg/minikube/config"
2526
"k8s.io/minikube/pkg/minikube/constants"
2627
"k8s.io/minikube/pkg/minikube/vmpath"
@@ -32,7 +33,7 @@ func kubectlCommand(cc *config.ClusterConfig, files []string, enable bool) *exec
3233
v = cc.KubernetesConfig.KubernetesVersion
3334
}
3435

35-
kubectlBinary := kubectlBinaryPath(v)
36+
kubectlBinary := kapi.KubectlBinaryPath(v)
3637

3738
kubectlAction := "apply"
3839
if !enable {
@@ -46,7 +47,3 @@ func kubectlCommand(cc *config.ClusterConfig, files []string, enable bool) *exec
4647

4748
return exec.Command("sudo", args...)
4849
}
49-
50-
func kubectlBinaryPath(version string) string {
51-
return path.Join(vmpath.GuestPersistentDir, "binaries", version, "kubectl")
52-
}

Diff for: pkg/kapi/kapi.go

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package kapi
1919
import (
2020
"context"
2121
"fmt"
22+
"path"
2223
"time"
2324

2425
"github.com/golang/glog"
@@ -37,6 +38,7 @@ import (
3738
watchtools "k8s.io/client-go/tools/watch"
3839
kconst "k8s.io/kubernetes/cmd/kubeadm/app/constants"
3940
"k8s.io/minikube/pkg/minikube/proxy"
41+
"k8s.io/minikube/pkg/minikube/vmpath"
4042
)
4143

4244
var (
@@ -205,3 +207,8 @@ func WaitForService(c kubernetes.Interface, namespace, name string, exist bool,
205207
func IsRetryableAPIError(err error) bool {
206208
return apierr.IsTimeout(err) || apierr.IsServerTimeout(err) || apierr.IsTooManyRequests(err) || apierr.IsInternalError(err)
207209
}
210+
211+
// KubectlBinaryPath returns the path to kubectl on the node
212+
func KubectlBinaryPath(version string) string {
213+
return path.Join(vmpath.GuestPersistentDir, "binaries", version, "kubectl")
214+
}

Diff for: pkg/minikube/node/start.go

+19
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
3737
"k8s.io/minikube/pkg/addons"
3838
"k8s.io/minikube/pkg/drivers/kic/oci"
39+
"k8s.io/minikube/pkg/kapi"
3940
"k8s.io/minikube/pkg/minikube/bootstrapper"
4041
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
4142
"k8s.io/minikube/pkg/minikube/cluster"
@@ -146,6 +147,12 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) {
146147
go addons.Start(&wg, starter.Cfg, starter.ExistingAddons, config.AddonList)
147148
}
148149

150+
wg.Add(1)
151+
go func() {
152+
rescaleCoreDNS(starter.Cfg, starter.Runner)
153+
wg.Done()
154+
}()
155+
149156
if apiServer {
150157
// special ops for none , like change minikube directory.
151158
// multinode super doesn't work on the none driver
@@ -507,3 +514,15 @@ func prepareNone() {
507514
exit.WithCodeT(exit.Permissions, "Failed to change permissions for {{.minikube_dir_path}}: {{.error}}", out.V{"minikube_dir_path": localpath.MiniPath(), "error": err})
508515
}
509516
}
517+
518+
// rescaleCoreDNS attempts to reduce coredns replicas from 2 to 1 to improve CPU overhead
519+
// no worries if this doesn't work
520+
func rescaleCoreDNS(cc *config.ClusterConfig, runner command.Runner) {
521+
kubectl := kapi.KubectlBinaryPath(cc.KubernetesConfig.KubernetesVersion)
522+
cmd := exec.Command("sudo", "KUBECONFIG=/var/lib/minikube/kubeconfig", kubectl, "scale", "deployment", "--replicas=1", "coredns", "-n=kube-system")
523+
if _, err := runner.RunCmd(cmd); err != nil {
524+
glog.Warningf("unable to scale coredns replicas to 1: %v", err)
525+
} else {
526+
glog.Infof("successfully scaled coredns replicas to 1")
527+
}
528+
}

0 commit comments

Comments
 (0)