Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

How to join master node or control plane to


Kubernetes cluster
Amir Ad · Follow
5 min read · May 21, 2024

Listen Share More

add additional master node to Kubernetes

You might want to add a new master node to your new or existing Kubernetes
cluster or change a worker node role to master but do not know how it is done, in
this article, you will learn how to have multiple control plane nodes on your
Kubernetes cluster to prevent any failover on your operational cluster.

In this article, we are going to talk about two scenarios for your cluster, in the first
scenario you are about to initialize your cluster, and in the second scenario you
already have a cluster and want to add 2 or additional master nodes.

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 1/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Scenario 1 — Initialize cluster:


We assume you are installing kubeadm cluster for the first time and about to run
kubeadm init command but if you have already an existing cluster you can also use
kubeadm reset and reinitialize your cluster to use this approach but you should
know it does have consequences. First of all, we run the below command on your
target node as master or control plane:

kubeadm init --control-plane-endpoint <master-node-ip> \


--pod-network-cidr 11.0.0.0/16 \
--apiserver-advertise-address=<master-node-ip> \
--service-cidr 10.0.0.1/16 \
--upload-certs

- -upload certs: As you might know, the connection between master nodes is
mTLS, so both nodes must be authorized in this protocol. This flag helps you to
retrieve Kubernetes certificate modules on your master nodes so executing it is
necessary.

- -control-plan-endpoint: Another useful flag that comes in handy when you add
a new master to an existing cluster so the new master nodes would recognize
the first and primary master node.

- -service-cidr: You will allocate your desired Kubernetes service IP rang here.
try to avoid using the same IP rang pod network.

Open in
- -pod-network-cidr: As it mentioned app
before, pods IPs get allocated from the
range you define here.
Search
- -apiserver-advertise-address= The IP address the API Server will advertise it’s
listening on. If not set the default network interface will be used.

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 2/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

join kubernetes cluster

This is the result you are going to see on your terminal after initializing your cluster.
As you see the the first command is for joining the additional control plan and the
second one is for joining worker node.

Join master node:


To join a new master node on your existing cluster just copy and paste the first
command you see on the terminal:

kubeadm join <your-ip>:6443 --token <your-token> \


--discovery-token-ca-cert-hash <your-cert-hash> \
--control-plane \
--certificate-key <certificate-key>

- -certificate-key: Key used to encrypt the control-plane certificates in the


kubeadm-certs Secret. The certificate key is a hex encoded string that is an AES
key of size 32 bytes.

- -discovery-token-ca-cert-hash: is used to verify the authenticity of the cluster


you are joining
https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 3/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

When you see this page, the new master is joined. You might face the etcd error but
you can ignore it anyway and make your .kube file on your home directory by the
instruction that is shown.

Join worker node:

kubeadm join <master-ip>:6443 \


--token <your-token> \
--discovery-token-ca-cert-hash <your-cert-hash>

Joining worker node is easy, just copy and paste the above command which you saw
on the terminal.

After joining both nodes and installing your kubernetes network plugin, your
cluster with 2 master nodes and 1 worker node is ready.

Scenario 2 — Existing cluster:


https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 4/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

If you do not intend to reinitialize your existing and operational cluster, we have
another solution for you.

1. Make sure to have openssl installed and run the below command on your master
node:

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outfo

This command extracts the public key from the CA certificate, converts it to DER
format, and then calculates the SHA-256 hash of the public key. The resulting hash is
what you need for the --discovery-token-ca-cert-hash flag. You should also add
“sha256:” before the string you retrieved on your command.

2. If you have not run your kubeadm init command with - -upload-certs flag, you
should copy your cluster certificates manually to your additional master node. Copy
certificates from /etc/Kubernetes/pki directory.

These are the certificates you will need:

·ca.crt

· ca.key

· sa.key

· sa.pub

· front-proxy-ca.crt

· front-proxy-ca.key

This is the instruction you have to follow:

make necessary directories and copy to the destination:

sudo mkdir -p /etc/kubernetes/pki


sudo chown -R root:root /etc/kubernetes/pki

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 5/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

sudo chmod -R 700 /etc/kubernetes/pki

scp /etc/kubernetes/admin.conf <user>@<new-master-node-ip>:/etc/kubernetes/

scp /etc/kubernetes/pki/ca.crt /etc/kubernetes/pki/ca.key /etc/kubernetes/pki/s

if you already have run --upload-certs flag on


kubeadm init before, you do not need to copy certs
manually but you have to use --certificate-key on
your join command and know the value from first
initialization.
Generate new join token:

kubeadm token generate

Now everything is ready to join your new control plane to kubeadm cluster with
below command, copy token and hash cert here:

kubeadm join <master-ip>:6443 \


--token <your-token> \
--discovery-token-ca-cert-hash sha256:<your-cert-hash> \
--control-plane \

With certificates copied manually, we do not need to set --certificate-key flag.


if you run “kubectl get nodes”you must see you your newly added master node.

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 6/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Kubernetes Control Plane Kubeadm Cluster Join

Follow

Written by Amir Ad
33 Followers

DevOps engineer and system administrator with more than 3 years experience in enterprise and startup
projects. linkedin: https://www.linkedin.com/in/amir-eydi/

More from Amir Ad

Amir Ad

How to set up nginx ingress controller in local server?


In this article you will learn how to set up nginx ingress controller in bare metal or local server.

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 7/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

5 min read · Jun 30, 2023

63 3

Amir Ad

Kubernetes authentication with keycloak oidc


Authentication or login in Kubernetes cluster can be done multiply, today we want to learn how
to authenticate in Kubernetes cluster and…

10 min read · Feb 5, 2024

61 1

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 8/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Amir Ad

Create a POST JavaScript REST API with MongoDB step by step


In this article, you will learn how to write a simple JavaScript REST API that works with POST
method. You will also learn how to dockerize…

10 min read · Oct 4, 2023

Amir Ad

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 9/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Build and deploy a web application example on AWS with external


domain
building and deploying a website or web application is not as tricky as before, thanks to AWS
service you can create and host your basic…

8 min read · Mar 31, 2024

19

See all from Amir Ad

Recommended from Medium

Ravi Patel

Understanding Kubernetes Namespaces


Kubernetes has revolutionized the way we deploy, scale, and manage containerized
applications. Among its many features, Namespaces stand…

3 min read · Mar 28, 2024

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 10/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Subham Pradhan

How to Install Kubernetes Cluster (kubeadm Setup) on Ubuntu 22.04


(Step-by-Step Guide)
This document provides a step-by-step guide to setting up a Kubernetes cluster using
kubeadm on multiple nodes. Kubernetes is an…

6 min read · Apr 4, 2024

4 1

Lists

Natural Language Processing


1499 stories · 1027 saves

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 11/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Lubomir Tobek

Kubernetes Multi-Master Node Cluster


Creating and operating a highly available Kubernetes cluster requires multiple Kubernetes
control plane nodes and “Master Nodes”. To…

10 min read · Dec 13, 2023

50

Mehmet kanus in Hedgus

Velero: Kubernetes Backup and Restore Solution


https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 12/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

Kubernetes is a powerful platform for managing and deploying applications. However,


managing Kubernetes environments requires a robust…

6 min read · Jun 2, 2024

24 1

Nidhi Ashtikar

Kubernetes Ingress
Project: Deploying a Web Application with Kubernetes Ingress

6 min read · Apr 27, 2024

51

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 13/14
6/11/24, 10:21 PM How to join master node or control plane to Kubernetes cluster | by Amir Ad | May, 2024 | Medium

@Harsh

🚀
Setting Up a Kubernetes Multi-Node Cluster on AWS: A Step-by-Step
Guide
INTRODUCTION

7 min read · Feb 10, 2024

9 1

See more recommendations

https://medium.com/@amirhosseineidy/how-to-join-master-node-or-control-plane-to-kubernetes-cluster-e16be68459bf 14/14

You might also like