Kubernetes Cluster Setup on AWS EC2
Prerequisites
Section titled “Prerequisites”- AWS Account with appropriate permissions
- 3 EC2 instances running Ubuntu 18.04 or later
- Master node: t3.medium (minimum 2 CPUs, 2GB RAM)
- Worker nodes: t3.micro or larger (minimum 1 CPU, 1GB RAM)
Installation Steps
Section titled “Installation Steps”1. Update System Packages (All Nodes)
Section titled “1. Update System Packages (All Nodes)”sudo apt-get update2. Install Docker (All Nodes)
Section titled “2. Install Docker (All Nodes)”sudo apt-get install -y docker.iosudo systemctl enable dockersudo systemctl start docker3. Install Kubernetes Tools (All Nodes)
Section titled “3. Install Kubernetes Tools (All Nodes)”curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key addsudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"sudo apt-get updatesudo apt-get install -y kubeadm kubelet kubectlsudo apt-mark hold kubeadm kubelet kubectl4. Initialize Master Node
Section titled “4. Initialize Master Node”sudo kubeadm init --pod-network-cidr=10.244.0.0/165. Configure kubectl
Section titled “5. Configure kubectl”mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/config6. Deploy Pod Network
Section titled “6. Deploy Pod Network”kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml7. Join Worker Nodes
Section titled “7. Join Worker Nodes”On each worker node, run the kubeadm join command from step 4:
sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>Verification
Section titled “Verification”Check cluster status:
kubectl get nodeskubectl get pods --all-namespacesAll nodes should show Ready status and all system pods should be Running.