Creating a single control-plane cluster with kubeadm with Calico Pod Network
The kubeadm
tool helps you bootstrap a minimum viable
Kubernetes cluster that conforms to best practices.
The kubeadm tool is good if you
need:
- A simple way for you to try out
Kubernetes, possibly for the first time.
- A way for existing users to
automate setting up a cluster and test their application.
- A building block in other ecosystem
and/or installer tools with a larger scope.
Before you begin
To follow this guide, you need:
- One or more
machines running a deb/rpm-compatible Linux OS; for example: Ubuntu or
CentOS.
- 2 GiB or more of
RAM per machine--any less leaves little room for your apps.
- At least 2 CPUs on
the machine that you use as a control-plane node.
- Full network
connectivity among all machines in the cluster. You can use either a
public or a private network.
Check required ports
Control-plane node(s)
Protocol |
Direction |
Port Range |
Purpose |
Used By |
TCP |
Inbound |
6443* |
Kubernetes
API server |
All |
TCP |
Inbound |
2379-2380 |
etcd
server client API |
kube-apiserver,
etcd |
TCP |
Inbound |
10250 |
Kubelet
API |
Self,
Control plane |
TCP |
Inbound |
10251 |
kube-scheduler |
Self |
TCP |
Inbound |
10252 |
kube-controller-manager |
Self |
Worker node(s)
Protocol |
Direction |
Port Range |
Purpose |
Used By |
TCP |
Inbound |
10250 |
Kubelet
API |
Self,
Control plane |
TCP |
Inbound |
30000-32767 |
NodePort
Services† |
All |
By default, Kubernetes uses the Container Runtime Interface (CRI)
to interface with your chosen container runtime.
If you don't
specify a runtime, kubeadm automatically tries to detect an installed container
runtime by scanning through a list of well known Unix domain sockets.
Runtime |
Path to Unix domain socket |
Docker |
/var/run/docker.sock |
containerd |
/run/containerd/containerd.sock |
CRI-O |
/var/run/crio/crio.sock |
If both Docker and containerd are detected, Docker takes precedence. This is
needed because Docker 18.09 ships with containerd and both are detectable even
if you only installed Docker. If any other two or more runtimes are detected,
kubeadm exits with an error.
Installing kubeadm, kubelet and kubectl
· kubeadm
: the command to bootstrap the
cluster.
· kubelet
: the component that runs on all
of the machines in your cluster and does things like starting pods and
containers.
· kubectl
: the command line util to talk
to your cluster.
Infrastructure
Lets
Create 3 VirtualMachines(VMs) (1 Master Node and 2 Worker node). There must be
network connectivity among these VMs
Installation
on Ubuntu (Both on Master and Worker Nodes)
sudo apt-get update && sudo apt-get install -y
apt-transport-https curl
curl -s
https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/
kubernetes-xenial main
EOF
sudo apt-get update
apt install -qq -y kubeadm=1.21.0-00
kubelet=1.21.0-00 kubectl=1.21.0-00
sudo apt-mark hold kubelet
kubeadm kubectl
OPTIONAL
So in particular case docker was using the groupfs which i
changed to systemd
Create the file as
[root@k8smaster ~]# vim /etc/docker/daemon.json
{
"exec-opts":
["native.cgroupdriver=systemd"]
}
[root@k8smaster ~]# systemctl restart docker
[root@k8smaster ~]# systemctl status docker
Installation
on RHEL/CentOS (Both on Master and Worker Nodes)
In case
if you are using CentOS/RHEL
cat
<<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
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
exclude=kubelet kubeadm kubectl
EOF
# Set SELinux in permissive mode (effectively disabling it)
sudo setenforce
0
sudo sed -i
's/^SELINUX=enforcing$/SELINUX=permissive/'
/etc/selinux/config
sudo yum install -y kubelet kubeadm kubectl --disableexcludes
=
kubernetes
sudo systemctl
enable
--now kubelet
Create Master Server
On master machine run the
below command
1. kubeadm
init --apiserver-advertise-address=<<Master ServerIP>>
--pod-network-cidr=192.168.0.0/16
2. mkdir -p
$HOME/.kube
3. sudo cp
-i /etc/kubernetes/admin.conf $HOME/.kube/config
4. sudo
chown $(id -u):$(id -g) $HOME/.kube/config
5. Run the join command on workernodes to connect these on kubernetes cluster.
Install Calico (run it only on master node)
kubectl create -f
https://docs.projectcalico.org/v3.18/manifests/calico.yaml
kubectl get nodes
Wait
for above command and run again it may take a minute or so to get all the nodes
in ready state.
OPTIONAL (Donot Run below commands if Calico is configured properly
by above step)
Incase Case
1.
Install the Tigera Calico operator and custom resource
definitions.
2.
kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
3.
Install Calico by creating the
necessary custom resource. For more information on configuration options
available in this manifest, see the installation reference.
4.
kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml
Note: Before creating this
manifest, read its contents and make sure its settings are correct for your
environment. For example, you may need to change the default IP pool CIDR to
match your pod network CIDR.
5.
Confirm that all of the pods are running with the following
command.
6.
watch kubectl get pods -n calico-system
Wait until each pod has the STATUS
of Running
.
Note: The Tigera operator
installs resources in the calico-system
namespace. Other
install methods may use the kube-system
namespace instead.
7.
Remove the taints on the master so that you can schedule pods on
it.
8.
kubectl taint nodes --all node-role.kubernetes.io/master-
It should return the following.
node/<your-hostname> untainted
9.
Confirm that you now have a node in your cluster with the
following command.
10.
kubectl get nodes -o wide
It should return something like
the following.
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
<your-hostname> Ready master 52m v1.12.2 10.128.0.28 <none> Ubuntu 18.
Comments
Post a Comment