Kubernetes Cluster Setup
Kubernetes Cluster Setup
Kubernetes Cluster Setup
172.16.153.129 centos-master
172.16.153.133 node01
172.16.153.134 node02
setenforce 0
sed -i --follow-symlinks
's/SELINUX=enforcing/SELINUX=disabled/g'
/etc/sysconfig/selinux
The br_netfilter module is required for kubernetes installation. Enable this kernel
module so that the packets traversing the bridge are processed by iptables for
filtering and for port forwarding, and the kubernetes pods across the cluster can
communicate with each other.
Run the command below to enable the br_netfilter kernel module.
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
- Disable SWAP
swapoff -a
vim /etc/fstab
- Install Docker CE
Add the docker repository to the system and install docker-ce using the yum
command.
yum-config-manager --add-repo
https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce
- Install Kubernetes
Add the kubernetes repository to the centos 7 system by running the following
command.
Now install the kubernetes packages kubeadm, kubelet, and kubectl using the yum
command below.
sudo reboot
Log in again to the server and start the services, docker and kubelet.
We need to make sure the docker-ce and kubernetes are using same 'cgroup'.
Check docker cgroup using the docker info command.
sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g'
/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl daemon-reload
systemctl restart kubelet
Note:
--apiserver-advertise-address = determines which IP address Kubernetes should
advertise its API server on.
--pod-network-cidr = specify the range of IP addresses for the pod network. We're
using the 'flannel' virtual network. If you want to use another pod network such as
weave-net or calico, change the range IP address.
When the Kubernetes initialization is complete, you will get the result as below.
Note:
Copy the 'kubeadm join ... ... ...' command to your text editor. The command will
be used to register new nodes to the kubernetes cluster.
Now in order to use Kubernetes, we need to run some commands as on the result.
Create new '.kube' configuration directory and copy the configuration 'admin.conf'.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Next, deploy the flannel network to the kubernetes cluster using the kubectl
command.
kubectl apply -f
https://raw.githubusercontent.com/coreos/flannel/master/Docume
ntation/kube-flannel.yml
And you will get the 'centos-master' node is running as a 'master' cluster with status
'ready', and you will get all pods that are needed for the cluster, including the 'kube-
flannel-ds' for network pod configuration.
Make sure all kube-system pods status is 'running'.
Connect to the node02 server and run the kubeadm join command as we copied on
the top.
Now you will get node01 and node02 has been added to the cluster with status
'ready'.
To see details of the 'nginx' deployment sepcification, run the following command.
Make sure there is no error. Now check the nginx service nodeport and IP using the
kubectl command below.
Now you will get the nginx pod is now running under cluster IP address
'10.160.60.38' port 80, and the node main IP address '10.0.15.x' on port '30691'.
From the 'centos-master' server run the curl command below.
curl node01:30691
curl node02:30691
The Nginx Pod has now been deployed under the Kubernetes cluster and it's
accessible via the internet.
Now access from the web browser.
http://172.16.153.129:30691/
And you will get the Nginx default page.