{"id":2581,"date":"2022-02-08T20:26:15","date_gmt":"2025-05-17T18:21:46","guid":{"rendered":""},"modified":"2025-02-02T00:46:18","modified_gmt":"2025-02-01T23:46:18","slug":"setup-a-kubernetes-cluster-on-aws-ec2-instance-with-ubuntu-using-kubeadm","status":"publish","type":"post","link":"https:\/\/netcloud24.com\/knowledgebase\/setup-a-kubernetes-cluster-on-aws-ec2-instance-with-ubuntu-using-kubeadm\/","title":{"rendered":"Setup a Kubernetes Cluster on AWS EC2 Instance with Ubuntu using kubeadm"},"content":{"rendered":"<p>\u00a0<\/p>\n<\/p>\n<h1>\u00a0<\/h1>\n<p>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 <strong>kubeadm<\/strong> for cluster bootstrapping. Whether you&#8217;re hosting your cluster on a  or another VPS platform, this guide will help you get started with Kubernetes.<\/p>\n<h2>Prerequisites<\/h2>\n<p>Before getting started, ensure you have the following:<\/p>\n<ul>\n<li>An AWS account with EC2 instances running Ubuntu 20.04. You will need at least one master node and one or more worker nodes.<\/li>\n<li>Root or sudo access on each instance.<\/li>\n<li>Basic knowledge of Kubernetes and AWS EC2.<\/li>\n<\/ul>\n<h2>Step 1: Launch EC2 Instances<\/h2>\n<p>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).<\/p>\n<h2>Step 2: Update Your System<\/h2>\n<p>Once your instances are running, connect to them via SSH and update your system packages:<\/p>\n<pre><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n<h2>Step 3: Disable Swap<\/h2>\n<p>Kubernetes requires that swap be disabled. Disable swap by running the following commands:<\/p>\n<pre><code>sudo swapoff -a\r\nsudo sed -i '\/ swap \/ s\/^\/#\/' \/etc\/fstab<\/code><\/pre>\n<h2>Step 4: Install Docker<\/h2>\n<p>Kubernetes uses Docker as its container runtime. Install Docker on each instance by following these commands:<\/p>\n<pre><code>sudo apt install apt-transport-https ca-certificates curl software-properties-common\r\ncurl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -\r\nsudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu focal stable\"\r\nsudo apt update\r\nsudo apt install docker-ce -y<\/code><\/pre>\n<p>After installation, enable and start Docker:<\/p>\n<pre><code>sudo systemctl start docker\r\nsudo systemctl enable docker<\/code><\/pre>\n<h2>Step 5: Install kubeadm, kubelet, and kubectl<\/h2>\n<p>Next, install Kubernetes components on all nodes (master and workers):<\/p>\n<pre><code>sudo apt update\r\nsudo apt install -y apt-transport-https curl\r\ncurl -s https:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | sudo apt-key add -\r\nsudo add-apt-repository \"deb http:\/\/apt.kubernetes.io\/ kubernetes-xenial main\"\r\nsudo apt update\r\nsudo apt install -y kubelet kubeadm kubectl\r\nsudo apt-mark hold kubelet kubeadm kubectl<\/code><\/pre>\n<h2>Step 6: Initialize the Kubernetes Master<\/h2>\n<p>On the master node, initialize the cluster with <code>kubeadm<\/code>:<\/p>\n<pre><code>sudo kubeadm init --pod-network-cidr=10.244.0.0\/16<\/code><\/pre>\n<p>Once initialization is complete, you will see a command to join worker nodes to the cluster, which looks like this:<\/p>\n<pre><code>kubeadm join 192.168.0.100:6443 --token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:...<\/code><\/pre>\n<h2>Step 7: Set Up kubectl for the Master Node<\/h2>\n<p>To use <code>kubectl<\/code> on the master node, set up the kubeconfig file:<\/p>\n<pre><code>mkdir -p $HOME\/.kube\r\nsudo cp -i \/etc\/kubernetes\/admin.conf $HOME\/.kube\/config\r\nsudo chown $(id -u):$(id -g) $HOME\/.kube\/config<\/code><\/pre>\n<h2>Step 8: Install a Pod Network Add-on<\/h2>\n<p>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:<\/p>\n<pre><code>kubectl apply -f https:\/\/raw.githubusercontent.com\/coreos\/flannel\/master\/Documentation\/kube-flannel.yml<\/code><\/pre>\n<h2>Step 9: Join Worker Nodes to the Cluster<\/h2>\n<p>On each worker node, run the <code>kubeadm join<\/code> command that was generated during the master node initialization. For example:<\/p>\n<pre><code>sudo kubeadm join 192.168.0.100:6443 --token abcdef.1234567890abcdef --discovery-token-ca-cert-hash sha256:...<\/code><\/pre>\n<p>Once the worker nodes have joined, verify that they are connected by running the following command on the master node:<\/p>\n<pre><code>kubectl get nodes<\/code><\/pre>\n<p>You should see a list of all your nodes (master and workers) in the cluster.<\/p>\n<h2>Step 10: Verify the Cluster<\/h2>\n<p>To verify that your Kubernetes cluster is working, create a simple Nginx deployment:<\/p>\n<pre><code>kubectl create deployment nginx --image=nginx<\/code><\/pre>\n<p>Check the status of the deployment:<\/p>\n<pre><code>kubectl get pods<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>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  or another <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPS<\/a>, Kubernetes offers a scalable platform for automating your containerized applications.<\/p>\n<footer>\n<p>For more VPS hosting options, visit . They offer a range of <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPSVirtual Private Servers<\/a> and <a href=\"https:\/\/ie.netcloud24.com\" target=\"_blank\" rel=\"follow\">Windows VPS Hosting UK<\/a> tailored to your needs.<\/p>\n<\/footer>\n<div class=\"post-author-box\" style=\"border-top:1px solid #ddd;margin-top:20px;padding-top:15px;\">\n<p><strong>Author:<\/strong> \u0141ukasz Bodziony<\/p>\n<p><strong>Website:<\/strong> <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a><\/p>\n<p><em>\u0141ukasz Bodziony is the CEO and founder of <a href=\"https:\/\/netcloud24.com\" target=\"_blank\" rel=\"dofollow\">NETCLOUD24<\/a>, a global VPS hosting brand proudly originating from Poland. With extensive experience in cloud computing, virtualization, and server management, he delivers high-performance <strong>Windows VPS<\/strong> and <strong>Remote Desktop Services (RDS)<\/strong> solutions to clients across Europe, North America, and beyond.<\/em><\/p>\n<p><em>His expertise covers a wide range of technologies, including <strong>Microsoft Azure<\/strong>, <strong>Proxmox VE<\/strong>, <strong>Amazon Web Services (AWS)<\/strong>, and numerous other virtualization and cloud platforms.<\/em><\/p>\n<p><em>Beyond running his hosting business, \u0141ukasz also provides <strong>professional paid server configuration and optimization services<\/strong> for companies and individuals. Outside of work, he is dedicated to caring for his children and building a secure future for them.<\/em><\/p>\n<p><em>If you are interested in working with him or need expert assistance with your hosting, cloud environment, or server setup, feel free to reach out via <a href=\"https:\/\/ca.netcloud24.com\" target=\"_blank\" rel=\"dofollow\">Windows VPS<\/a>.<\/em><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0 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\u2026<\/p>\n","protected":false},"author":1,"featured_media":3421,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[],"tags":[14,12,11,23,20,21,22,17,7,8,6,10,18,19,15,24,16,5,13,9],"class_list":["post-2581","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-cheapvps","tag-cloudvps","tag-hostingvps","tag-rds","tag-rdscal","tag-remotedesktop","tag-remotedesktopvps","tag-servervps","tag-ukvps","tag-virtualserver","tag-vpshosting","tag-vpsserver","tag-vpssolutions","tag-vpswindows","tag-vpswithwindows","tag-windowsrds","tag-windowsserver","tag-windowsvps","tag-windowsvpshosting","tag-windowsvpsuk"],"jetpack_publicize_connections":[],"_links":{"self":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=2581"}],"version-history":[{"count":0,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/2581\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media\/3421"}],"wp:attachment":[{"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=2581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=2581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/netcloud24.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=2581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}