☑️Day 31: Creating Single Node Cluster in Kubernetes🚀

🔹Table of Contents :

  • Introduction to Single Node Cluster

  • Setting Up IP and Network Configurations

    • Viewing and Editing Network Configurations

    • Disabling Firewall

    • Restarting Network Services

  • Installing Prerequisites for Kubernetes

  • Initializing the Kubernetes Cluster

  • Conclusion


1. Introduction to Single Node Cluster

A single-node cluster in Kubernetes allows you to test and experiment with Kubernetes on just one machine. This node will act as both the Control Plane (Master) and the Worker Node, allowing for an all-in-one experience.


2. Setting Up IP and Network Configurations

Before you start setting up Kubernetes, it’s essential to configure your machine’s IP address, disable firewalls, and ensure your network settings are ready.

a) Viewing and Editing Network Configurations

The first step is to view the current network configurations. Most Linux systems store network configurations in /etc/sysconfig/network-scripts/.

Here’s how you can view and edit the configurations.

bashCopy codecat /etc/sysconfig/network-scripts/ifcfg-ens33
  • Explanation: This command shows the current network configuration for the interface ens33. If your interface name is different, replace ens33 with your actual interface name.

Once you open the file, you will see entries like this:

makefileCopy codeDEVICE=ens33
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=8.8.8.8

b) Modifying IP Address and Gateway

To change the IP address and gateway, simply modify the values for IPADDR, GATEWAY, and other necessary fields:

bashCopy codeIPADDR=192.168.1.101
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=8.8.8.8
  • IPADDR: This is the static IP address you assign to your machine.

  • GATEWAY: The gateway of your network.

  • NETMASK: Defines the network’s range. Usually 255.255.255.0 for a standard network.

  • DNS1: The DNS server, which can be set to something like Google’s DNS 8.8.8.8.

After making the changes, save the file.

c) Disabling Firewall

Firewalls can block certain ports and affect Kubernetes’ functionality. It’s better to turn off the firewall in a development environment (but not recommended in production).

bashCopy codesystemctl stop firewalld
systemctl disable firewalld
  • Explanation: These commands will stop the firewall service and disable it from starting on boot.

d) Restarting Network Services

Now, apply the changes by restarting your network service:

bashCopy codesystemctl restart network
  • Explanation: This command restarts your network service to apply the new IP address and settings.

3. Installing Prerequisites for Kubernetes

Before setting up Kubernetes, we need to install Docker and Kubeadm. Here's how you can do it step by step:

a) Installing Docker

Docker is the container runtime that Kubernetes uses to manage containers. First, we need to install Docker:

bashCopy codecurl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
  • Explanation: The curl command fetches the Docker installation script, and sh runs it. This will install Docker on your machine.

Start and enable Docker:

bashCopy codesystemctl start docker
systemctl enable docker

b) Installing Kubernetes Components

Next, install kubeadm, kubelet, and kubectl, which are the core components of Kubernetes.

bashCopy codecat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

Now, install the Kubernetes components:

bashCopy codesudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

Enable and start kubelet:

bashCopy codesystemctl enable --now kubelet

4. Initializing the Kubernetes Cluster

Once Docker and Kubernetes are installed, you can initialize the cluster using kubeadm. This will turn your machine into a Kubernetes master node.

bashCopy codekubeadm init --pod-network-cidr=192.168.0.0/16
  • Explanation: This command initializes the Kubernetes cluster with a specific pod network.

After initialization, you will see instructions to set up kubectl for your user. Run these commands:

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

Now, you can verify the cluster setup:

bashCopy codekubectl get nodes
  • Explanation: This command will show the node status. If it’s “Ready”, the cluster setup was successful.

5. Conclusion

In this newsletter, we covered how to set up a single-node Kubernetes cluster from scratch. We discussed how to configure network settings, disable firewalls, install prerequisites like Docker and Kubernetes, and initialize the cluster. By following these steps, you can easily set up your own development Kubernetes environment to test deployments, pods, and services.


Summary of Commands:

  1. Network Configuration:

    • cat /etc/sysconfig/network-scripts/ifcfg-ens33

    • Modify IP address and gateway in the file.

    • systemctl stop firewalld

    • systemctl restart network

  2. Docker Installation:

  3. Kubernetes Installation:

    • Create Kubernetes repo file: cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo

    • Install Kubernetes: sudo yum install -y kubelet kubeadm kubectl

    • Start kubelet: systemctl enable --now kubelet

  4. Cluster Initialization:

    • kubeadm init --pod-network-cidr=192.168.0.0/16

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

    • Verify cluster: kubectl get nodes


🚀Thanks for joining me on Day 31! Let’s keep learning and growing together!

Happy Learning! 😊

#90DaysOfDevOps

💡
Follow for more updates on LinkedIn , Github and Twitter(X)
0
Subscribe to my newsletter

Read articles from Kedar Pattanshetti directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kedar Pattanshetti
Kedar Pattanshetti