top of page
Writer's picturevP

Setup Kubernetes - Lab

In this blog, we will look at the various options available in building a Kubernetes cluster from scratch. Kubernetes can be configured in a variety of ways. We can set it up locally on our laptops or virtual machines using tools such as Minikube and Kubeadmin.


Minikube is a tool used to setup a single instance of Kubernetes in an All-in-one setup and kubeadmin is a tool used to configure kubernetes in a multi-node setup. There are also hosted solutions for deploying Kubernetes in cloud environments like GCP and AWS. If you don't have the resources or don't want to go through the hassle of setting it all up yourself and just want to play with a kubernetes cluster right away, you can visit this page .


In this blog post, I'm going to use Minikube, which is the most straightforward way to get started with Kubernetes on a local system. Before we proceed further, let's first understand how Minikube works. We previously discussed the various Kubernetes components that comprise a Master and worker node, such as the api server, etcd key value store, controllers and scheduler on the master, and kubelets and container runtime on the worker nodes. It would take a significant amount of time and effort to configure and install all of these various components on various systems on our own.


Minikube combines all of these components into a single image, providing us with a pre-configured single node Kubernetes cluster that allows us to get started in minutes. The entire package is packaged into an ISO image and is available for download online. Also, we don't have to download it ourselves. Minikube includes an executable command-line utility that will automatically download the ISO and deploy it in a virtualization platform like Oracle Virtualbox or VMware Fusion.


Before installing minikube, we must install a Kubectl utility. We will use Kubectl command line tool, to manage our kubernetes resources and cluster once it is setup. Installing a Kubectl utility before installing minikube will allow minikube to configure the kubectl utility to work with the cluster when it's provisioned. Kubectl utility can work with multiple local or remote clusters at the same time.


Install and Set Up kubectl on Linux

I'm using CentOS system for this demo -


1. Download the latest release with the command

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

2. Validate the binary (optional)

Download the kubectl checksum file:

curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

3. Validate the kubectl binary against the checksum file:

echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

If valid, the output is:

kubectl: OK 

4. Install kubectl.

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

5. Test to ensure the version you installed is up-to-date:

kubectl version --client

Or use this for detailed view of version:

kubectl version --client --output=yaml

Install Docker

Once the Kubectl is installed, the next step is to install the Docker.

1. Set up the repository - Install the yum-utils package (which provides the yum-config-manager utility) and set up the repository.

$ sudo yum install -y yum-utils
$ sudo yum-config-manager \--add-repo \
    https://download.docker.com/linux/rhel/docker-ce.repo
    

2. Start Docker

 sudo systemctl start docker

Install Minikube

Now that we have finished the installation of Kubectl utility, let's proceed with installation of Minikube.


1. To install the latest minikube stable release on x86-64 Linux using RPM package -

$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
$ sudo rpm -Uvh minikube-latest.x86_64.rpm

2. Start Minikube

minikube start

Don't be worried if minikube fails to start with the following error.

* minikube v1.26.1 on Centos 7.6.1810
* Automatically selected the docker driver. Other choices: none, ssh
* The "docker" driver should not be used with root privileges. If you wish to continue as root, use --force.
* If you are running minikube within a VM, consider using --driver=none:
*   https://minikube.sigs.k8s.io/docs/reference/drivers/none/

X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.

This error is common while starting the Minikube internally which configured with the docker driver and can be solved the same in few steps.


1. Create a new user.

adduser minikube

2. Add User to the Docker Group.

usermod -aG docker minikube

3. Login to the newly created User.

su - minikube

4. Start the Minikube service.

minikube start --driver=docker

Once the minikube is started, you can check the minikube status by running below command.

minikube status

To check the nodes running, execute below command

kubectl get nodes

Now that we have minikube installed, lets see how we can interact with the cluster. Since we already have kubectl installed, we can now use it to access the new cluster.

kubectl get po -A

Let's try to create some deployments

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

To view all the deployments, use below command

kubectl get deployment

To Expose the deployment as service, we can use below command

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

It may take a moment, but the deployment will soon show up when we run below command

kubectl get services hello-minikube

To get the URL of the exposed service

minikube service hello-minikube --url

Copy the link and paste it in a browser and it should show details about the application.


To list the running pods, we can run below command

$ kubectl get pods

It will show output as below

NAME                              READY   STATUS    RESTARTS   AGE
hello-minikube-5c5f5cddb9-hl247   1/1     Running   0          25m

To delete the service

$ kubectl delete services hello-minikube

If deleted successfully, you will see

service "hello-minikube" deleted

To delete the deployment

$ kubectl delete deployment hello-minikube

If deleted successfully, you will see

deployment.apps "hello-minikube" deleted

That's all I've got for now.


Thank you for reading!


*** Explore | Share | Grow ***

57 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page