Kubectl

Use kubectl inside minikube

By default, kubectl gets configured to access the kubernetes cluster control plane inside minikube when the minikube start command is executed.

However if kubectl is not installed locally, minikube already includes kubectl which can be used like this:

  1. minikube kubectl -- <kubectl commands>

You can also alias kubectl for easier usage.

  1. alias kubectl="minikube kubectl --"

Alternatively, you can create a symbolic link to minikube’s binary named ‘kubectl’.

  1. ln -s $(which minikube) /usr/local/bin/kubectl

You can also alias kubectl for easier usage.

  1. alias kubectl="minikube kubectl --"

Alternatively, you can create a symbolic link to minikube’s binary named ‘kubectl’.

  1. ln -s $(which minikube) /usr/local/bin/kubectl

You can also alias kubectl for easier usage.

  1. function kubectl { minikube kubectl -- $args }

Get pods

  1. minikube kubectl -- get pods

Creating a deployment inside kubernetes cluster

  1. minikube kubectl -- create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4

Exposing the deployment with a NodePort service

  1. minikube kubectl -- expose deployment hello-minikube --type=NodePort --port=8080

For more help

  1. minikube kubectl -- --help

Shell autocompletion

After applying the alias or the symbolic link you can follow https://kubernetes.io/docs/tasks/tools/included/optional-kubectl-configs-bash-linux/ to enable shell-autocompletion.

Last modified November 17, 2021: Fix Alias issue in kubectl page (b0ce8ae34)