Setting up single node Kubernetes cluster using Minikube

Single Node Cluster with Minikube:

To run the Kubernetes locally, we can use command line tool called Minikube. For development and testing purpose, we can run a single node Kubernetes cluster on a Laptop.

Before setting up Kubernetes, first we will install the Docker engine.

Installation of Docker CE:

To install the Docker Community Edition, set up the repository as below,

[root@kube-master-1 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in

[root@kube-master-1 ~]# yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@kube-master-1 ~]#

[root@kube-master-1 ~]# yum install docker-ce
Loaded plugins: fastestmirror
docker-ce-stable | 2.9 kB 00:00:00
docker-ce-stable/x86_64/primary_db | 11 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: ftp.iitm.ac.in
* extras: ftp.iitm.ac.in
* updates: ftp.iitm.ac.in
Resolving Dependencies
.
.
.
Installed:
docker-ce.x86_64 0:17.12.0.ce-1.el7.centos

Dependency Installed:
audit-libs-python.x86_64 0:2.7.6-3.el7 checkpolicy.x86_64 0:2.5-4.el7 container-selinux.noarch 2:2.36-1.gitff95335.el7
libcgroup.x86_64 0:0.41-13.el7 libseccomp.x86_64 0:2.3.1-3.el7 libsemanage-python.x86_64 0:2.5-8.el7
libtool-ltdl.x86_64 0:2.4.2-22.el7_3 policycoreutils-python.x86_64 0:2.5-17.1.el7 python-IPy.noarch 0:0.75-6.el7
setools-libs.x86_64 0:3.3.8-1.1.el7

Complete!
[root@kube-master-1 ~]#

Start and Enable the Docker service as below,

[root@kube-master-1 ~]# systemctl start docker
[root@kube-master-1 ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@kube-master-1 ~]#

Verify that docker is installed correctly by running the hello-world image,

[root@kube-master-1 ~]# docker run hello-world
Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

[root@kube-master-1 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8a865336d2a hello-world “/hello” 32 seconds ago Exited (0) 32 seconds ago mystifying_davinci
[root@kube-master-1 ~]#

So the docker set up is completed, now we will proceed with Kubernetes,

Installation of kubectl:

Download the latest release with the command:

[root@kube-master-1 ~]# curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 64.2M 100 64.2M 0 0 3510k 0 0:00:18 0:00:18 –:–:– 3919k
[root@kube-master-1 ~]#

Make the kubectl binary executable.

chmod +x ./kubectl

Move the binary in to your PATH.

mv ./kubectl /usr/local/bin/kubectl

[root@kube-master-1 ~]# pwd
/root
[root@kube-master-1 ~]# ls -lrt
total 65816
-rw——-. 1 root root 1423 Feb 18 13:23 anaconda-ks.cfg
-rw-r–r–. 1 root root 67390456 Feb 18 14:22 kubectl
[root@kube-master-1 ~]# chmod +x ./kubectl
[root@kube-master-1 ~]# mv ./kubectl /usr/local/bin/kubectl

Check the kubectl version as below,

[root@kube-master-1 ~]# kubectl version
Client Version: version.Info{Major:”1″, Minor:”9″, GitVersion:”v1.9.3″, GitCommit:”d2835416544f298c919e2ead3be3d0864b52323b”, GitTreeState:”clean”, BuildDate:”2018-02-07T12:22:21Z”, GoVersion:”go1.9.2″, Compiler:”gc”, Platform:”linux/amd64″}
[root@kube-master-1 ~]#

Download and Install the Minitkube as below,

[root@kube-master-1 ~]# curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.25.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 41.4M 100 41.4M 0 0 2850k 0 0:00:14 0:00:14 –:–:– 3971k
[root@kube-master-1 ~]#

To check the minikube version, execute -> minikube version

[root@kube-master-1 ~]# minikube version
minikube version: v0.25.0
[root@kube-master-1 ~]#

Start the cluster, by running the minikube start command with VM-driver is none

[root@kube-master-1 ~]# minikube start –vm-driver none
Starting local Kubernetes v1.9.0 cluster…
Starting VM…
Getting VM IP address…
Moving files into cluster…
Downloading localkube binary
162.41 MB / 162.41 MB [============================================] 100.00% 0s
65 B / 65 B [======================================================] 100.00% 0s
Setting up certs…
Connecting to cluster…
Setting up kubeconfig…
Starting cluster components…
Kubectl is now configured to use the cluster.
===================
WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS
The ‘none’ driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks

When using the none driver, the kubectl config and credentials generated will be root owned and will appear in the root home directory.
You will need to move the files to the appropriate location and then set the correct permissions. An example of this is below:

sudo mv /root/.kube $HOME/.kube # this will write over any previous configuration
sudo chown -R $USER $HOME/.kube
sudo chgrp -R $USER $HOME/.kube

sudo mv /root/.minikube $HOME/.minikube # this will write over any previous configuration
sudo chown -R $USER $HOME/.minikube
sudo chgrp -R $USER $HOME/.minikube

This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
Loading cached images from config file.
[root@kube-master-1 ~]#

To get the minikube IP address, use the below command,

[root@kube-master-1 ~]# minikube ip
192.168.0.34
[root@kube-master-1 ~]#

To get the logs, we can use below command,

[root@kube-master-1 ~]# minikube logs
— Logs begin at Sun 2018-02-18 14:17:15 IST, end at Sun 2018-02-18 14:57:38 IST. —
Feb 18 14:53:37 kube-master-1 systemd[1]: Starting Localkube…
Feb 18 14:53:38 kube-master-1 localkube[1668]: listening for peers on http://localhost:2380
Feb 18 14:53:38 kube-master-1 localkube[1668]: listening for client requests on localhost:2379
Feb 18 14:53:38 kube-master-1 localkube[1668]: name = default
Feb 18 14:53:38 kube-master-1 localkube[1668]: data dir = /var/lib/localkube/etcd
Feb 18 14:53:38 kube-master-1 localkube[1668]: member dir = /var/lib/localkube/etcd/member
Feb 18 14:53:38 kube-master-1 localkube[1668]: heartbeat = 100ms
Feb 18 14:53:38 kube-master-1 localkube[1668]: election = 1000ms
Feb 18 14:53:38 kube-master-1 localkube[1668]: snapshot count = 10000

To get the Minikube status,

[root@kube-master-1 ~]# minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.0.34
[root@kube-master-1 ~]#

In the next article we will see minikube with virtualbox as VM-DRIVER.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: