bimals.net
Getting familiar with Kubernetes using minikube
Overview
This post follows the Hello Minikube tutorial from official kubernetes documentation. It is a very basic starting guide and I included it here to have it as a starting point for K8s related posts.
Installation
I used Homebrew to install the required packages minikube and kubectl: brew install minikube kubectl. Both of these could be downloaded and installed using curl.
After installation, I created a minikube cluster using minikube start command. This command pulls the base minikube image using docker which creates a cluster with a control-plane node and starts a container named minikube. After the installation is complete, the created node can be accessed using kubectl get command.
kubectl get nodes
Output:
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 5m34s v1.30.0
First Deployment
To run the first deployment, i ran kubectl create deployment command that runs a container based on provided image, which in this case is the kicbase/echo-server:1.0 .
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
Output:
deployment.apps/hello-minikube created
The deployed container/s can be viewed as follows:
kubectl get deployments
Output:
NAME READY UP-TO-DATE AVAILABLE AGE
hello-minikube 1/1 1 1 10s
Similarly, the pod/s inside the container can be viewed as follows:
kubectl get pods
Output:
NAME READY STATUS RESTARTS AGE
hello-minikube-5c898d8489-76pms 1/1 Running 0 4m57s
The pod inside the container can only be accessed from outside the kubernetes network by exposing it’s port.
First Service
A kubernetes service is required to expose it outside the virtual network which I have done as follows:
kubectl expose deployment hello-minikube --type=NodePort --port=8080
Output:
service/hello-minikube exposed
As above with deployments, the services can be viewed with the get command.
kubectl get services
Output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.98.7.247 <none> 8080:31513/TCP 5m28s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 53m
The —type=Nodeport —port=8080 flags indicates the service should be exposed in the TCP port 8080, which is the port the application inside the hello-minikube pod listens to.
Finally, I used the minikube service hello-minikube command to open the application in the browser. This command opened a browser window and showed the app response.
minikube service hello-minikube
|-----------|----------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|---------------------------|
| default | hello-minikube | 8080 | http://192.168.49.2:31513 |
|-----------|----------------|-------------|---------------------------|
🏃 Starting tunnel for service hello-minikube.
|-----------|----------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|------------------------|
| default | hello-minikube | | http://127.0.0.1:65013 |
|-----------|----------------|-------------|------------------------|
🎉 Opening service default/hello-minikube in default browser...
Additional basic commands
To remove the service: kubectl delete service hello-minikube
To remove the deployment: kubectl delete deployment hello-minikube
To stop the minikube cluster: minikube stop
To delete the minikube cluster: minikube delete