Kubernetes is a powerful platform for automating the deployment, scaling, and operation of application containers. In this guide, we will show you how to set up a Kubernetes cluster on AWS EC2 instances running Ubuntu, using kubeadm for cluster bootstrapping. Whether you're hosting your cluster on a Windows VPS UK or another VPS platform, this guide will help you get started with Kubernetes.

Prerequisites

Before getting started, ensure you have the following:

  • An AWS account with EC2 instances running Ubuntu 20.04. You will need at least one master node and one or more worker nodes.
  • Root or sudo access on each instance.
  • Basic knowledge of Kubernetes and AWS EC2.

Step 1: Launch EC2 Instances

Log in to your AWS Management Console and launch EC2 instances with Ubuntu 20.04. You will need at least one instance for the master node and one or more for worker nodes. Ensure that the instances have security groups that allow communication on ports 6443 (Kubernetes API), 2379-2380 (etcd), 10250-10255 (Kubelet), and 30000-32767 (NodePort services).

Step 2: Update Your System

Once your instances are running, connect to them via SSH and update your system packages:

sudo apt update && sudo apt upgrade -y

Step 3: Disable Swap

Kubernetes requires that swap be disabled. Disable swap by running the following commands:

sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab

Step 4: Install Docker

Kubernetes uses Docker as its container runtime. Install Docker on each instance by following these commands:

sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt install docker-ce -y

After installation, enable and start Docker:

sudo systemctl start docker
sudo systemctl enable docker

Step 5: Install kubeadm, kubelet, and kubectl

Next, install Kubernetes components on all nodes (master and workers):

sudo apt update
sudo apt install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo add-apt-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Step 6: Initialize the Kubernetes Master

On the master node, initialize the cluster with kubeadm:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Once initialization is complete, you will see a command to join worker nodes to the cluster, which looks like this:

kubeadm join 192.168.0.100:6443 --token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:...

Step 7: Set Up kubectl for the Master Node

To use kubectl on the master node, set up the kubeconfig file:

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

Step 8: Install a Pod Network Add-on

Install a pod network add-on so that your pods can communicate across nodes. For this guide, we will use the Flannel network add-on:

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Step 9: Join Worker Nodes to the Cluster

On each worker node, run the kubeadm join command that was generated during the master node initialization. For example:

sudo kubeadm join 192.168.0.100:6443 --token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:...

Once the worker nodes have joined, verify that they are connected by running the following command on the master node:

kubectl get nodes

You should see a list of all your nodes (master and workers) in the cluster.

Step 10: Verify the Cluster

To verify that your Kubernetes cluster is working, create a simple Nginx deployment:

kubectl create deployment nginx --image=nginx

Check the status of the deployment:

kubectl get pods

Conclusion

By following these steps, you have successfully set up a Kubernetes cluster on AWS EC2 instances with Ubuntu using kubeadm. Whether you are hosting on Windows VPS UK or another Windows Virtual Dedicated Server Hosting, Kubernetes offers a scalable platform for automating your containerized applications.

War diese Antwort hilfreich? 0 Benutzer fanden dies hilfreich (0 Stimmen)