Lab Exercise: Installing a Kubernetes Cluster
Follow these steps to install Kubernetes on Amazon Linux:
Prerequisites:
An Amazon Linux instance (e.g., EC2 instance)
Basic knowledge of Linux commands
Steps:
Disable SELinux:
Edit the SELinux configuration file:
vi /etc/selinux/config
Change
SELINUX
topermissive
andpolicy
totargeted
:SELINUX=permissive
Verify SELinux Status:
If SELinux is disabled, edit the configuration and reboot the server.
Otherwise, execute the command. This will change it from enforcing to permissive.
setenforce permissive
Load Kernel Modules:
Execute the following commands:
modprobe overlay modprobe br_netfilter
Make Kernel Modules Permanent:
Edit the file
/etc/modules-load.d/containerd.conf
and add the following lines:overlay br_netfilter
Configure sysctl Settings:
Create or edit the file
/etc/sysctl.d/99-kubernetes-cri.conf
:
vi /etc/sysctl.d/99-kubernetes-cri.conf
- Add the following lines: ```ini net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1
Apply the sysctl settings:
sysctl --system
Disable Swap and Remove Fstab Entry:
Disable swap:
swapoff -a
Remove the swap entry from
/etc/fstab
.
Add Kubernetes Repository:
Create or edit the file
/etc/yum.repos.d/kubernetes.repo
:
vi /etc/yum.repos.d/kubernetes.repo
- Add the following content: ```ini [kubernetes] name=Kubernetes baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/ enabled=1 gpgcheck=1 gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
Install Kubernetes Components:
Install
kubelet
,kubeadm
, andkubectl
:yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
Enable the kubelet service:
systemctl enable kubelet systemctl start kubelet
Install
containerd
:yum install -y containerd
Create Containerd Configuration:
Run the following command:
containerd config default | sudo tee /etc/containerd/config.toml
Edit
/etc/containerd/config.toml
: search for the below string and modifiy it to true.SystemdCgroup = true
Start containerd service :
systemctl status containerd systemctl start containerd systemctl enable containerd
Configure Node IP:
Edit
/etc/default/kubelet
:KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}
Initialize the Kubernetes Cluster:
Run the following command (replace
{IP address of the server}
with your server's IP):sudo kubeadm init --apiserver-advertise-address="{IP address of the server}" --apiserver-cert-extra-sans="{IP address of the server}" --node-name master --pod-network-cidr=192.168.0.0/24
References
Last updated