How to Install Kubernetes on Centos 7

Kubernetes-logo

In this tutorial we will show you how to install kubernetes on centos 7. For you don’t know kubernetes, kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. Our tutorial is how to install kubernetes on your own baremetal or vm server.

Prerequisites

This article assumes you have at least basic knowledge of linux, know how to use the shell, root user or non-root user account with sudo privileges set up on your server. To create kubernetes cluster we need at least minimum 3 servers installed centos 7.

Master : 192.168.40.1
Minion1 : 192.168.40.2
Minion2 : 192.168.40.3

cluster Configuration

  • Server private subnet IP range: 192.168.40.0/24
  • Flannel subnet IP range: 172.30.0.0/16
  • Service Cluster IP range for Kubernetes: 10.254.0.0/16
  • Kubernetes Service IP: 10.254.0.1 (kubernetes always allocated first ip range for kubernetes service)
  • DNS service IP: 10.254.3.100 (For DNS you can use any IP from the service cluster IP range)

service installation (on all host)

Create repo on all host including master,minion1,minon2

put these line below

Install kubernetes and other service using yum

Configure kubernetes base component , still on all host

put these line below

Configure ETCD (on master host)

We will configure etcd service on kubernetes master hosts, etcd configuration are on /etc/etcd/etcd.conf

Edit like these line below

Configure API server (on master host)

We will configure API server service on master host,  API Server Configuration is stored at /etc/kubernetes/apiserver
Kubernetes uses certificates to authenticate API request, to configure api server, we need to generate certificates that will be used for authentication. Kubernetes provides ready made scripts for generating these certificates, you can download in here

Download script using curl

After script downloaded, find and update these line below

Run the script using parameter based on master host ip address in this tutorial is 192.168.40.1

Configure API server file configuration

Edit like these line below

Note : make sure service cluster IP range doesn’t overlap with your server subnet IP range.

 

Configure Controller Manager (On Master Host)

You can find controller manager file configuration at /etc/kubernetes/controller-manager

Edit using nano editor

Edit like these line below

 

Configure Kubelet Service (On Minions Hosts)

Kubelet service is a node/minion agent that runs pods and make sure that it is healthy. It also communicates pod details to Kubernetes Master. Kubelet configuration is stored at /etc/kubernetes/kubelet

(On Minion1 Host)

Edit and configure like below

(On Minion2 Host)

Edit and configure like below

Please take a look above, the different option from minion1 and minion2  was KUBELET_HOSTNAME

Before Configuring Flannel for Kubernetes cluster, we need to create network configuration for Flannel in etcd.

Start etcd node on the master using this command

Create new keyname in etcd to store Flannel configuration using this command

Configure network for flannel using command below

The above command allocates the 172.30.0.0/16 subnet to the Flannel network. A flannel subnet of CIDR 24 is allocated to each server in Kubernetes cluster.

Note: Please make sure Flannel subnet doesn’t overlap with your infrastructure subnet or service cluster IP range.

Configure Flannel (On All Nodes)

Flannel used for inter-pod communication by kubernetes. Flannel configuration are stored at /etc/sysconfig/flanneld

Configure your /etc/sysconfig/flanneld like the following below

Start services on Master and Minion

After all configuration above, we will begin to start service at master and minions node

On Master

On minions

Note: In each host, make sure that IP address allocated to Docker0 is the first IP address in the Flannel subnet, otherwise your cluster won’t work properly. You can check using “ifconfig” command.

 

Check Status of all Services

Check again your service has been run normally
On Master : etcd, kube-apiserver, kube-controller-manager, kube-scheduler, and flanneld
On Minions : kube-proxy, kubelet, flanneld, and docker

Deploying Addons in Kubernetes

Configuring DNS for Kubernetes Cluster

We need DNS service in our kubernetes cluster to enable service name discovery in our kubernetes clueter.SO we need to deploy DNS pod and service in our cluster and configure kubelet to resolve all DNS queries from this DNS service.

You can download DNS replication controller and service from this github repo.

Use this command below to create replication controller and service

Note: Make sure you have entered correct cluster IP for DNS service in skydns-svc.yaml

For this example tutorial we have used 10.254.3.100 as DNS service IP.

Configure Kubelet in all Minion to resolve all DNS queries from our local DNS service.

Restart kubelet on all Minions to load the new kubelet configuration

Configuring Dashboard for Kubernetes Cluster

Using kubernetes dashboard you can create, delete, or edit all kubernetes work using web user interface.

We will deploy kubernetes dashboard as a pod in kubernetes cluser. You can download kubernetes dashboard yaml from this github repo.

After downloading YAML, run the following commands from the master

Open http://master_public_ip:8080/ui on your browser to access kubernetes dashboard

kube-dashboard

Note: If you have public ip ,don’t forget to secure your Dashboard. You can install Nginx or Apache web server on your master that proxy pass to localhost: 8080 port and enable http_auth on it to secure your Dashboard.

Configuring Monitoring for Kubernetes Cluster

Kubernetes provides detail resource usage monitoring at the container, Pod, and cluster level. The user can monitor their application at all these levels. To do this we will deploy YAML config for our kubernetes cluster.
You can download updated YAML configs for monitoring stack in this github repo.

Launch this command below to deplay YAML file

Check Cluster Configuration

We will check if all the addons are working properly.
Run the following command on master node to check addons service running status

kube1

You may also like...

Leave a Reply

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