Skip to content

How to setup Kubernetes cluster with kubeadm on AWS EC2

sonyafenge edited this page Jan 25, 2023 · 2 revisions

Prepare AWS ENV

1. Create Security Group for Master and add inbound rule

1. TCP 6443      → For Kubernetes API server
2. TCP 2379–2380 → For etcd server client API
3. TCP 10250     → For Kubelet API
4. TCP 10259     → For kube-scheduler
5. TCP 10257     → For kube-controller-manager
6. TCP 22        → For remote access with ssh
7. UDP 8472      → Cluster-Wide Network Comm. — Flannel VXLAN
8. TCP 32443     -> for karmada

2. Create Security Group for worker nodes and add inbound rule

1. TCP 10250       → For Kubelet API
2. TCP 30000–32767 → NodePort Services†
3. TCP 22          → For remote access with ssh
4. UDP 8472        → Cluster-Wide Network Comm. — Flannel VXLAN

3. Create EC2 Instances for master and nodes

Image: ubuntu 20.4
Instance Type: t2.medium and above
Security Group: created in steps #1 and #2
Disk: 50GB
Security Key: use your own aws key for ssh

Setup kubernetes on ec2

For master

1. Login to master and install Kubernetes related components

export HOST_NAME=[your own host name]
bash https://github.com/sonyafenge/arktos-tool/blob/master/k8s/install-onubuntu.sh

2. Kubeadm init, download init-template.yaml and change to related config

sudo kubeadm init --config https://github.com/sonyafenge/arktos-tool/blob/master/k8s/kubeadm-init-template.yaml

If cross region, external ip is necessary in kubeconifg, using the command below:

 IP_ADDRESS=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo $IP_ADDRESS
sudo kubeadm init --control-plane-endpoint=$IP_ADDRESS --pod-network-cidr=10.244.0.0/16

3. Run kubeconfig related setup per kubeadm init instruction

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

4. Activate pod networking

kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/v0.20.2/Documentation/kube-flannel.yml

5. Check cluster status

kubectl get pods -A
Kubectl get nodes

For worker nodes

1. Login to worker nodes and install kubernetes related components

export HOST_NAME=[your own host name]
bash https://github.com/sonyafenge/arktos-tool/blob/master/k8s/install-onubuntu.sh

2. Kubeadm join based on kubeadm init instructions with master ip and token information

sudo kubeadm join 172.31.22.203:6443 --token bt4b0d.lcdvksfbmqsb190d --discovery-token-ca-cert-hash sha256:6f36c83c341381bb9d0bc3d8ab5873b1cc1bfba3caca89e92ea3cc7dfd864b1a