Creating Kubernetes Cluster with kubeadm¶
For this activity, deploy minimum 2 AWS instances with the Security groups
All traffic is enabled between the instances
Node Name | Instance Details | Resources |
---|---|---|
Master Node | -t2.medium | 4GB Ram , 2 CPU |
Worker Node | -t2.micro | 1GB Ram , 1 CPU |
Preparing the Master and Worker nodes for kubeadm¶
Execute the below Commands on both Master & Worker Nodes
Change the hostname for nodes as master & worker
Installing Docker:¶
Add the Docker repository key and Docker repository.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \
"deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce
echo '{"exec-opts": ["native.cgroupdriver=systemd"]}' | sudo tee /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
systemctl enable docker
Installing kubeadm, kublet, and kubectl:¶
Add the Google repository key and Google repository
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
vim /etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io kubernetes-xenial main
apt-get update
apt-get install kubelet kubeadm kubectl -y
swapoff -a
Setup Master Node to Connect with Worker Nodes
sed -i '/ swap / s/^/#/' /etc/fstab
echo NODENAME=$(hostname -s)
kubeadm init --apiserver-advertise-address=172.31.85.246 --apiserver-cert-extra-sans=172.31.85.246 --pod-network-cidr=10.0.0.0/16
mkdir .kube
cp /etc/kubernetes/admin.conf .kube/config
After Executing kubeadm init command you will get one command as output that need to execute on worker nodes
kubeadm join 172.31.85.246:6443 --token n6v08z.53b057pfwnj8mq10 --discovery-token-ca-cert-hash sha256:9e8a38ddfc46c41ecb3317db9fc2145f70bddbdd2c6b8091fbdbab18e1dbcb19
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
kubectl get node
kubectl run pod --image=nginx
kubectl get pod
kubectl get pod -o wide