diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 0128b1a8fdbd..695b5ccf89eb 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -20,6 +20,7 @@ import ( goflag "flag" "fmt" "os" + "path/filepath" "runtime" "strings" @@ -73,6 +74,11 @@ var RootCmd = &cobra.Command{ // Execute adds all child commands to the root command sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { + _, callingCmd := filepath.Split(os.Args[0]) + + if callingCmd == "kubectl" { + os.Args = append([]string{RootCmd.Use, callingCmd}, os.Args[1:]...) + } for _, c := range RootCmd.Commands() { c.Short = translate.T(c.Short) c.Long = translate.T(c.Long) diff --git a/site/content/en/docs/faq/_index.md b/site/content/en/docs/faq/_index.md index 0eb2a1b28837..0539c92f2873 100644 --- a/site/content/en/docs/faq/_index.md +++ b/site/content/en/docs/faq/_index.md @@ -29,3 +29,8 @@ minikube's bootstrapper, [Kubeadm](https://github.com/kubernetes/kubeadm) verifi Please allocate sufficient resources for Knative setup using minikube, especially when you run a minikube cluster on your local machine. We recommend allocating at least 6 CPUs and 8G memory. `minikube start --cpus 6 --memory 8000` + +## Do I need to install kubectl locally? + +No, minikube comes with built-in kubectl [see minikube's kubectl documentation]({{< ref "docs/handbook/kubectl.md" >}}). + diff --git a/site/content/en/docs/handbook/kubectl.md b/site/content/en/docs/handbook/kubectl.md index 5f21ff4f206a..21532287d37c 100644 --- a/site/content/en/docs/handbook/kubectl.md +++ b/site/content/en/docs/handbook/kubectl.md @@ -17,6 +17,10 @@ as well. You can also `alias kubectl="minikube kubectl --"` for easier usage. +Alternatively, you can create a symbolic link to minikube's binary named 'kubectl'. + +`ln -s $(which minikube) /usr/local/bin/kubectl` + Get pods `minikube kubectl -- get pods` diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index e2a82a726a0a..a85e1b4e1b0f 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -86,6 +86,7 @@ func TestFunctional(t *testing.T) { {"KubectlGetPods", validateKubectlGetPods}, // Make sure apiserver is up {"CacheCmd", validateCacheCmd}, // Caches images needed for subsequent tests because of proxy {"MinikubeKubectlCmd", validateMinikubeKubectl}, // Make sure `minikube kubectl` works + {"MinikubeKubectlCmdDirectly", validateMinikubeKubectlDirectCall}, } for _, tc := range tests { tc := tc @@ -307,6 +308,26 @@ func validateMinikubeKubectl(ctx context.Context, t *testing.T, profile string) } } +// validateMinikubeKubectlDirectCall validates that calling minikube's kubectl +func validateMinikubeKubectlDirectCall(ctx context.Context, t *testing.T, profile string) { + defer PostMortemLogs(t, profile) + dir := filepath.Dir(Target()) + dstfn := filepath.Join(dir, "kubectl") + err := os.Link(Target(), dstfn) + + if err != nil { + t.Fatal(err) + } + defer os.Remove(dstfn) // clean up + + kubectlArgs := []string{"get", "pods"} + rr, err := Run(t, exec.CommandContext(ctx, dstfn, kubectlArgs...)) + if err != nil { + t.Fatalf("failed to run kubectl directl. args %q: %v", rr.Command(), err) + } + +} + // validateComponentHealth asserts that all Kubernetes components are healthy func validateComponentHealth(ctx context.Context, t *testing.T, profile string) { defer PostMortemLogs(t, profile)