Learning towards Kubernetes: Installation

I am not going to make the steps more complex in this blog as was just want copy the command, we need to follow the video made along with this.

Note: Always make sure what is the latest supported docker version for Kubernetes installation.

This is made on CentOS

Step 1: Install Dockers

(refer for more https://docs.docker.com/install/linux/docker-ce/centos/)

Uninstall old versions

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

Install Docker CE

  1.  Install the required package
$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

2.   Set up the stable repository

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

3.  Get list of docker versions

yum list docker-ce --showduplicates | sort -r

4. Install the required version

$ sudo yum install docker-ce-<VERSION STRING>

 

Step2: Make Pre-requisite ready

  1. Update DNS and update vim /etc/hosts
  2. Disable SELinux
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

3. Enable br_netfilter Kernel Module

modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

4. Disable SWAP

swapoff -a

And then edit the ‘/etc/fstab’ file.
vim /etc/fstab
Comment the swap line UUID

5. Kubernestes needs firewall:

Master node(s):

TCP     6443*       Kubernetes API Server
TCP     2379-2380   etcd server client API
TCP     10250       Kubelet API
TCP     10251       kube-scheduler
TCP     10252       kube-controller-manager
TCP     10255       Read-Only Kubelet API

Worker nodes (minions):

TCP     10250       Kubelet API
TCP     10255       Read-Only Kubelet API
TCP     30000-32767 NodePort Services

Full Firewall disable(not recommeded)

systemctl disable firewalld
systemctl stop firewalld

Step3: Install Kubernetes

  1. Add the kubernetes repository
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/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

2. Install the kubernetes packages kubeadm, kubelet, and kubectl

yum install -y kubelet kubeadm kubectl

3.  Start all the service

systemctl start docker && systemctl enable docker
systemctl start kubelet && systemctl enable kubelet

4. Check docker cgroup and change

docker info | grep -i cgroup

if output is cgroupfs, run the below to change

sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

5. Restart service again

systemctl daemon-reload
systemctl restart kubelet

Step4: Kubernetes Cluster Initialization

  1. kubeadm init –pod-network-cidr 10.244.0.0/16

2. After the Cluster initialization, you need to run the command generated on screen, or refer below

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Install Network for cluster

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get nodes
kubectl get pods --all-namespaces

 

Step5: Add other nodes

  1. Run below format command. Please use which was generated during the inial cluster configuration
kubeadm join 10.0.15.10:6443 --token vzau5v.vjiqyxq26lzsf28e --discovery-token-ca-cert-hash sha256:e6d046ba34ee03e7d55e1f5ac6d2de09fd6d7e6959d16782ef0778794b94c61e

 

kubectl get nodes
kubectl get pods --all-namespaces

Step5: Create First tomcat application

  1. Create yaml file and save the below as tomcat.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: tomcat-deployment
spec:
selector:
matchLabels:
app: tomcat
replicas: 1
template:
metadata:
labels:
app: tomcat
spec:
containers:
- name: tomcat
image: tomcat:9.0
ports:
- containerPort: 8080

2. Run the below command to create the pod

kubectl apply -f ./tomcat.yaml

3. Expose port

kubectl expose deployment tomcat-deployment --type=NodePort

4. Get Port no

kubectl get svc

 

Leave a comment