How to use Kubernetes locally?
A few words about Kubectl and Minikube
We use Kubernetes to make our life easier when we have a real product and cloud. There are a lot of reasons to use Kubernetes with clouds like AWS, GCP, or Azure. This is not the topic of this article.
The question is how to test your work before using a cloud you’ve chosen. And here Kubectl and minilube come. This stack permits to test everything on your PC.
Install Minikube and Kubectl
Install on Mac OS X
Installed both with brew throw the terminal
brew install minikube
brew install kubectl
Error I had
If you will install kubectl before minikube and check kubectl version, you’ll see the error :
error: Missing or incomplete configuration info. Please point to an existing, complete config file
kubectl version
After the installation and start of minikube, the issue disappears
minikube start
Kubectl works.
Kubectl configs
Kubectl configs saved in $HOME/.kube/config.
cd
cat .kube/config
Example of my configs after the installation.
Useful commands
Minikube commands
minikube version
minikube start
minikube stop
minikube start --driver=virtualbox
minikube start --driver=hyperkit
minikube delete
Minikube dashboard
minikube dashboard
Kubectl commands
kubectl version
kubectl get nodes
kubectl --namespace=mystuff #to change a namespace
kubectl --all-namespaces
kubectl config set-context my-context --namespace=mystuff #create context
kubectl config use-context my-context # start using context
kubectl get <resource> #get resouce from kubernetes from the current namespace, -o, -o json, -o yaml
kubectl describe <resource-name> <obj-name>
kubectl get pods my-pod -o jsonpath --template={.status.podIP} #get ip
kubectl apply -f obj.yaml
kubectl label pods bar color=red #add labal
kubectl label pods bar color- #remove label
kubectl logs <pod-name>
kubectl exec -it <pod-name> -- bash
kubectl top nodes
kubectl top pods
minikube service <service_name> --url
Deploy simple hello minikube with Kubectl
https://kubernetes.io/fr/docs/tutorials/hello-minikube/
Map Kubectl to different contexts
kubectl config get-contexts
kubectl config use-context docker-desktop
kubectl config get-contexts
On the desktop docker app, it’s possible to change it directly in menu
Command Autocompletion
kubectl supports integration with your shell to enable tab completion for both commands and resources
# macOS
brew install bash-completion# CentOS/Red Hat
yum install bash-completion# Debian/Ubuntu
apt-get install bash-completions
Done
Now you are ready to work on your machine, play with K8 commands and learn everything you need without any cloud platform.
Other articles
You can also be interested in Kubernetes main terms article.
Thanks
Thank you for your attention.
Do Need professional help in web or mobile development?
Recommendation for planning or estimation of your project?
Feel free to contact me here.
P.S. I really appreciate your like or share 🙏.