Kubernetes Setup

Learning about Kubernetes basics

Kubernetes is orchestraton layer of various Docker and/or containerization manager. Let see in this artcile how to setup a Kubernetes cluster or in short K8s cluster.

Steps involed in setting up Kubernetes Cluster

  1. Create VMs which are part of K8s cluster (master and worker nodes).
  2. Disable SELinux and SWAP on all nodes.
  3. Install kubeadm, kubelet, kubectl and docker in all nodes.
    • start and enable docker and kubelet in all nodes.
  4. Initialize the master node.
  5. Configure Pod network in master node.
  6. Join all worker nodes in cluster.
  7. Verify the congigurations

Create VMs

In this example I show four VMs (1 Master and 3 Worker nodes) created in Google Cloud Platform.

Disable SELinux and SWAP in all nodes

Disable SWAP in all nodes: [email protected]:$ swapoff -a

Repeat the above step in all nodes.

Disable SELinux in all nodes:

[email protected]:$ setenforce 0
[email protected]:$ sed -i 's/enforcing/disabled/g' /etc/selinux/config
[email protected]:$ grep disabled /etc/selinux/config | grep -v '#'
SELINUX=disabled

Repeat the above step in all nodes.

Reboot all nodes

Install kubeadm, kubelet, kubectl and docker

  • Docker Installation

Install Docker:

[email protected]:$ yum install -y
[email protected]:$ yum install -y docker

Start and enable docker:

[email protected]:$ systemctl start docker
[email protected]:$ systemctl enable docker

Repeat the above step in all worker nodes as well. Docker runnning status in all nodes (master and worker) can be verified by [email protected]:$ systemctl status docker

  • Install kubeadm, kubectl and kubelet

Add kubernetes repo:

[email protected]:$  cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-e17-x86_64
enabled=1
gpgcheck=1
repo_gpgchek=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-packages-key.gpg
exclude=kube*
EOF

Install kublet, kubeadm, kubectl and start docker:

[email protected]:$ yum install -y kubeadm kubelet kubectl --disableexludes=kubernetes
[email protected]:$ systemctl enable kubelet && systemctl start kubelet

Repeat the above step in all worker nodes as well. Kubectl and Kubelet runnning status in all nodes (master and worker) can be verified by

[email protected]:$ systemctl status kubectl
[email protected]:$ systemctl status kubelet

If you are in RHEL or Centos7, perform the below steps as well

[email protected]:$ cat <<EOF > /etc/sysctl.d/k8s.conf
net.brige.bridge-nf-call-ip6tables=1
net.brige.bridge-nf-call-iptables=1
EOF
	
[email protected]:$ sysctl --system

Initialize the master node

only on master node: [email protected]: $ kubeadm init --pod-network-cidr=10.240.0.0/16

Configure the Pod network

only on master node: [email protected]:$ kubectl apply -f \ https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube.flannel.yml

Join worker nodes to the cluster

Only on worker nodes:

[email protected]:$ kubeadm join --token <token id> 10.240.0.1:6443 --discovery-token-ca-cert-hash <sha256>
[email protected]:$ kubeadm token create --print-join-command

Verifications

[email protected]:$ kubectl get no
[email protected]:$ kubectl run kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080
[email protected]:$ kubectl get po


See also