DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Establishing a Highly Available Kubernetes Cluster on AWS With Kops
  • Azure, AWS, and GCP: A Multicloud Service Cheat Sheet
  • KIAM vs AWS IAM Roles for Service Accounts (IRSA)
  • Streamline Microservices Development With Dapr and Amazon EKS

Trending

  • Accelerating AI Inference With TensorRT
  • DGS GraphQL and Spring Boot
  • Scalable, Resilient Data Orchestration: The Power of Intelligent Systems
  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Setting up Kubernetes Master and Worker Node on Amazon Web Service (AWS)

Setting up Kubernetes Master and Worker Node on Amazon Web Service (AWS)

We want to create a Kubernetes cluster on AWS public cloud. We are going to create a master node and two worker nodes on AWS EC2 instances, as shown below.

By 
Saurav K Mehta user avatar
Saurav K Mehta
·
Feb. 09, 21 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
10.1K Views

Join the DZone community and get the full member experience.

Join For Free


We want to create a Kubernetes cluster on AWS public cloud. 

We are going to create a master node and two worker nodes on AWS EC2 instances, as shown below.


Figure 1: Kubernetes Master Node and Worker Node

Figure 1: Kubernetes Master Node and Worker Node
Sourced from https://m.yisu.com/.

Step 1: Create Instances and Install Docker

To begin with, I have created three EC2 Ubuntu instances, one of type t2.medium for master and of type t2.micro for worker nodes. Once we have all 3 instances available, the next step is to deploy kubeadm on all three instances.

Figure 2: AWS EC2 instances t2.medium for master and t2.micro for worker node

Figure 2: AWS EC2 instances t2.medium for master and t2.micro for worker node

First of all, for identification purpose, we gave three ubuntu ec2 instance a meaningful name i.e. k8-master, k8-worker-node1, and k8-worker-node2 using the below command:

  • sudo hostnamectl set-hostname "k8s-master"

Once names are set for all EC2, we need to update the /etc/hosts file to include IPs of master and worker nodes. Contents to be updated are:

34.204.176.6 k8s-master

54.82.35.243 k8s-worker-node1

54.235.235.212 k8s-worker-node2

The next step is to install docker on all three machines and verifying the same. To do that, we need to execute the below set of commands.

To update packages:

  • sudo apt-get update

To install Docker:

  • sudo apt-get install docker.io -y

To start docker on the node:

  • sudo systemctl start docker

To enable docker on the node:

  • sudo systemctl enable docker

To verify the docker installation:

  • docker --version

Figure 3: Verification of docker installation

Figure 3: Verification of docker installation

Step 2: Install Kubeadm

Once the docker is installed, the next step is to install kubeadm on all three machines.

Install transport HTTPS package:

  • sudo apt-get install apt-transport-https curl -y

Add Kubernetes package repository key:

  • wget https://packages.cloud.google.com/apt/doc/apt-key.gpg
  • sudo apt-key add apt-key.gpg

Figure 4: Screenshot of add apt-key

Figure 4: Screenshot of add apt-key

To disable swap temporary (as recommended):

  • sudo swapoff -a

To configure Kubernetes repository

  • sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"

Install Kubeadm package:

  • sudo apt-get install kubeadm -y

Verification of kubeadm installation:

  • kubeadm version

Figure 5: Verifying version of kubeadm

Figure 5: Verifying version of kubeadm

Step 3: Initialize Kubernetes

The next step of Kubernetes cluster configuration is to initialize Kubernetes on the master node using the kubeadm init command. It should be successful.

Note: Since I had created an EC2 instance with only 1 vCPU my kubeadm init failed as we need a minimum of 2 vCPU for the master node. I deleted the master node of ‘t2.micro’ and recreated it with ‘t2.medium.’

Figure 6: Error while initializing kubeadm on master as it was of type t2.micro which has only one vCPU

Figure 6: Error while initializing kubeadm on master as it was of type t2.micro which has only one vCPU

After successful execution of the kubeadm init command, we will get all the information to configure the Kubernetes client as well as how the worker node can join the master node. This is shown in the below figure.

Figure 7: Initializing kubeadm on master successful

Figure 7: Initializing kubeadm on master successful after changing EC2 instance type to t2.medium which has 2 CPU

Step 4: Set Up Kubeconfig

To set up the kubeconfig, I need to execute the below set of commands on the master as well as on the client machine.

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

On each worker node, we need to execute the kubeadm join command so that it can join the Kubernetes master. I faced a few issues in this step and spend a good bit of time to troubleshoot and fix the same. As shown below, my join command was hanging forever and the message on the console was not helpful.

Figure 8: Worker node is not able to join master node

Figure 8: Worker node is not able to join master node

I executed the command with the ‘-v=5’ option to get detail. I identified the root cause as port 6443, which was blocked in the security group of AWS.

Figure 9: Verbose error log to troubleshoot

Figure 9: Verbose error log to troubleshoot why the worker is not able to join the master

Once I change the security group, it will have an immediate effect on all EC2 instance which are using this security group and worker nodes were able to join the master node. In the below figure, we can see the success message printed on the console.

Figure 10: Confirmation of worker joining the master

Figure 10: Confirmation of worker joining the master

We need to execute the same command for worker2. After that, in my Kubernetes cluster, I have one master node and two worker nodes configured. I confirmed this by executing ‘kubectl get nodes’ whose output is shown below.

Figure 11: kubectl command to show master and worker

Figure 11: kubectl command to show master and worker

I list all the pods in my Kubernetes and many systems created pods were there. kube-proxy and weave-net were present on all nodes, including the master.

Figure 12: kubectl command to show all pods

Figure 12: kubectl command to show all pods

Conclusion

This completes the Kubernetes master node and worker node setup on EC2 of AWS cloud.


AWS master Kubernetes Web Service

Opinions expressed by DZone contributors are their own.

Related

  • Establishing a Highly Available Kubernetes Cluster on AWS With Kops
  • Azure, AWS, and GCP: A Multicloud Service Cheat Sheet
  • KIAM vs AWS IAM Roles for Service Accounts (IRSA)
  • Streamline Microservices Development With Dapr and Amazon EKS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!