Run kubernetes locally using Minikube
Kubernetes is an open source orchestration system for docker conatiners or you can say a platform for microservices container management. It manages computing, networking, and storage infrastructure on the basis of user workloads.
Minikube is a tool which provides a way to run kubernetes on your local machine. It simply takes a docker image ( an immutable file, created using build command) and run it using kubectl (kubectl is a command line interface for running commands against Kubernetes clusters).
It is aimed for users who just want to test it or use it for development. It cannot be used on production cluster, it’s a single node machine with no high availability. A good news is that it works on Mac, Linux and windows.
- Installation and setup of minikube
- Run an image on kubernetes locally using minikube. (For image I will be using google echoserver image, you can use your own docker image).
- linux environment.
- You will need visaulization software installed to run minikube. For instance, you can use Virtual box, which can be downloaded from:(https://www.virtualbox.org/wiki/Downloads)
- minikube installation ( https://github.com/kubernetes/minikube )
- kubectl installation (https://kubernetes.io/docs/tasks/tools/install-kubectl/)
To launch your cluster you need to follow these steps:
- First download Minikube on your system :
2. To start minikube cluster, which will boot up your virtual machine, type: minikube start
So, I am starting a local kubernetes cluster. This will take some time, because it needs to boot up the virtual machine.
3. It says “kubectl” is now configured to use the cluster.
So the “config” is now created. So, that “kubectl” can connect to our newly created vm with Kubernetes.
If you don’t have the “kubectl” tool yet, have a look at requirements section point 4.
4. Now type kubectl, if you’ll see all the commands available that means “kubectl” is working.
5. Now first let’s run “kubectl” with a command run, we use the existing image echoserver, which is a simple HTTP server that responds with the http headers it receives. First, you need to create a managed set of pods:
$ kubectl run hello-minikube \
deployment "hello-minikube" created
The above command created a new deployment, which contains a single container, created using the specified image. The option ‘–port=8080’ specifies the container’s port number to be exposed. The option ‘–replicas=2’ specifies that the deployment will maintain two replicas of the pod using a new replica set.
6. To access our echoserver, we need to expose the pods through a service:
$ kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
The above command created a new service using parameters such as port and label from the specified deployment. The option ‘–type=NodePort’ specifies a type of the service.
- For a NodePort service, Kubernetes allocates a port from a configured range (default is 30000–32767), and each node forwards that port, which is the same on each node, to the service. It is possible to define a specific port number, but you should take care to avoid potential port conflicts.
7. Now, we need to get the exposed port:
$ kubectl describe services/echoserver
NodePort: <unset> 30115/TCP
Or we can get the URL of exposed service using:
$ minikube service hello-minikube — url
And this can take some time, because it needs to download this image, this echo server. And this image is quite big, because every time you are pulling an image it’s a fully contained image, so it includes operating system, all the dependencies with this echo server.
8. Now let’s go to the browser :
Tadaaa, here is our first running service using minikube :
And here, you can see this is an echo service.
You can do “test”, then you will see the real path for the “test”. So, our cluster is working.
We can schedule containers on Kubenetes. And it just pulled a container for us with this application on.
9. Kubectl commands:
To list deployments : kubectl get deployments
To delete a particular deployment : kubectl delete deployment hello-minikube
To get information of the deployment: kubectl describe deployment hello-minikube
If you have any insight, respond here! Otherwise, I hope this article helped you in running your application on kubernetes cluster locally. Soon, I will post an article of a node application running using minikube as an example. Stay Tuned!