Building Kubernetes Cluster

Kubernetes is an open-source platform for automating deployment, scaling, and operations of application containers across clusters of hosts, providing container-centric infrastructure.

With Kubernetes, you are able to quickly and efficiently respond to customer demand:

  • Deploy your applications quickly and predictably.
  • Scale your applications on the fly.
  • Seamlessly roll out new features.
  • Optimize use of your hardware by using only the resources you need.

Advantages:

  • portable: public, private, hybrid, multi-cloud
  • extensible: modular, pluggable, hookable, composable
  • self-healing: auto-placement, auto-restart, auto-replication, auto-scaling

Prerequisites for building a cluster:

Deploy 1 master and 3 nodes

For the sake of simplicity I will use KVM guests.

for VM in {kubemaster01,kubenode01,kubenode02,kubenode03}; do \
    lvcreate -V 150G --thin -n $VM raid_1/thin_pool_primary \
    virt-install --name $VM--ram 4096 --disk path=/dev/mapper/raid_1-$VM \
    --cdrom CentOS-7-x86_64-Minimal-1511.iso --connect=qemu:///system --noautoconsole \
    --graphics vnc,listen=0.0.0.0 --accelerate --network bridge:br0 
;done

Now make sure you have DNS records created for your new VMs.

 

Configure the nodes with Kubernetes

On each node run this sequence:

yum -y update

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
            https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

setenforce 0


sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/sysconfig/selinux

sysctl -w net.ipv4.ip_forward=1

sed -i '$a\net.ipv4.ip_forward=1' /etc/sysctl.conf


yum install -y docker kubelet kubeadm kubectl kubernetes-cni


yum install -y ntp


systemctl enable docker && systemctl start docker


systemctl enable kubelet && systemctl start kubelet


systemctl enable ntpd && systemctl start ntpd


reboot

 

 

Only to be run on kubemaster01:

kubeadm init

And you should expect to receive an output similar to the one below:

<master/tokens> generated token: “f0c861.753c505740ecde4c”
<master/pki> created keys and certificates in “/etc/kubernetes/pki”
<util/kubeconfig> created “/etc/kubernetes/kubelet.conf”
<util/kubeconfig> created “/etc/kubernetes/admin.conf”

<master/apiclient> created API client configuration
<master/apiclient> created API client, waiting for the control plane to become ready
<master/apiclient> all control plane components are healthy after 61.346626 seconds
<master/apiclient> waiting for at least one node to register and become ready <master/apiclient> first node is ready after 4.506807 seconds
<master/discovery> created essential addon: kube-discovery
<master/addons> created essential addon: kube-proxy
<master/addons> created essential addon: kube-dns Kubernetes master initialised successfully!
You can connect any number of nodes by running:
kubeadm join –token <token> <master-ip>

On the remaining nodes kubenode0{1..3} run this:

kubeadm join --token <token> kubemaster01

Configure networking

On kubemaster01 run:

kubectl apply -f https://git.io/weave-kube

Install Dashboard

On kubemaster01 run:

kubectl create -f https://rawgit.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml

Access the Dashboard

[root@kubemaster01 ~]# kubectl get pods --namespace=kube-system | grep dashboard

[root@kubemaster01 ~]# kubectl describe pods --namespace=kube-system kubernetes-dashboard-1655269645-k0jh7

[root@kubemaster01 ~]# kubectl edit svc/kubernetes-dashboard --namespace=kube-system 

And search for – nodePort:

You will now see that you can access the Dashboard by: http://kubenode01:31048/

Now you can enjoy you new Kubernetes Cluster and start deploy applications.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s