Aaron Shivers

Follow

Aaron Shivers

Follow
Kubernetes Multi-Node Cluster

Photo by Jan Meeus on Unsplash

Kubernetes Multi-Node Cluster

Aaron Shivers's photo
Aaron Shivers
·Apr 10, 2022·

3 min read

Table of contents

  • Multi-Node Cluster
  • Setup
  • Start the Cluster
  • View the Nodes
  • Deploy the Application
  • Access the Service
  • Summary

Multi-Node Cluster

Deploy a service locally on a multi-node cluster.

Setup

This article assumes you have Minikube and Kubectl installed.

Create these files in your project directory.

# simple-web-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: simple-web-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: simple-web
  template:
    metadata:
      labels:
        app: simple-web
    spec:
      containers:
        - name: simple-web-container
          image: aaronshivers/simple-web
# simple-web-service.yml
apiVersion: v1
kind: Service
metadata:
  name: simple-web-service
spec:
  selector:
    app: simple-web
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000
  type: NodePort

Start the Cluster

Start a cluster with three nodes.

minikube start -n 3
😄  minikube v1.25.2 on Ubuntu 20.04
✨  Automatically selected the docker driver
👍  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
🔥  Creating docker container (CPUs=2, Memory=2200MB) ...
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ kubelet.housekeeping-interval=5m
    ▪ kubelet.cni-conf-dir=/etc/cni/net.mk
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔗  Configuring CNI (Container Networking Interface) ...
🔎  Verifying Kubernetes components...
    ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass

👍  Starting worker node minikube-m02 in cluster minikube
🚜  Pulling base image ...
🔥  Creating docker container (CPUs=2, Memory=2200MB) ...
🌐  Found network options:
    ▪ NO_PROXY=192.168.49.2
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ env NO_PROXY=192.168.49.2
🔎  Verifying Kubernetes components...

👍  Starting worker node minikube-m03 in cluster minikube
🚜  Pulling base image ...
🔥  Creating docker container (CPUs=2, Memory=2200MB) ...
🌐  Found network options:
    ▪ NO_PROXY=192.168.49.2,192.168.49.3
🐳  Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
    ▪ env NO_PROXY=192.168.49.2
    ▪ env NO_PROXY=192.168.49.2,192.168.49.3
🔎  Verifying Kubernetes components...
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

View the Nodes

Get a list of nodes.

kubectl get nodes
NAME           STATUS   ROLES                  AGE     VERSION
minikube       Ready    control-plane,master   2m50s   v1.23.3
minikube-m02   Ready    <none>                 2m15s   v1.23.3
minikube-m03   Ready    <none>                 104s    v1.23.3

Get the status of the nodes.

minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

minikube-m02
type: Worker
host: Running
kubelet: Running

minikube-m03
type: Worker
host: Running
kubelet: Running

Deploy the Application

Deploy the deployment.

kubectl apply -f simple-web-deployment.yml
deployment.apps/simple-web-deployment created
kubectl rollout status deployment simple-web-deployment
deployment "simple-web-deployment" successfully rolled out

Deploy the service.

kubectl apply -f simple-web-service.yml
service/simple-web-service created

View the IP addresses of the pods.

kubectl get pods -o wide
NAME                                    READY   STATUS    RESTARTS   AGE     IP           NODE           NOMINATED NODE   READINESS GATES
simple-web-deployment-f464cd66f-bs7ld   1/1     Running   0          2m52s   10.244.1.2   minikube-m02   <none>           <none>
simple-web-deployment-f464cd66f-q5k52   1/1     Running   0          2m52s   10.244.0.3   minikube       <none>           <none>
simple-web-deployment-f464cd66f-wdvqq   1/1     Running   0          2m52s   10.244.2.2   minikube-m03   <none>           <none>

Get the URL of the service

minikube service list
|-------------|--------------------|--------------|---------------------------|
|  NAMESPACE  |        NAME        | TARGET PORT  |            URL            |
|-------------|--------------------|--------------|---------------------------|
| default     | kubernetes         | No node port |
| default     | simple-web-service |           80 | http://192.168.49.2:32766 |
| kube-system | kube-dns           | No node port |
|-------------|--------------------|--------------|---------------------------|

Access the Service

Go to the URL from the service list a few times to see which node is accessed.

curl http://192.168.49.2:30563
➜ multinode curl http://192.168.49.2:32766
Hello from simple-web-deployment-f464cd66f-bs7ld on 10.244.1.2!!%
➜ multinode curl http://192.168.49.2:32766
Hello from simple-web-deployment-f464cd66f-q5k52 on 10.244.0.3!!%
➜ multinode curl http://192.168.49.2:32766
Hello from simple-web-deployment-f464cd66f-wdvqq on 10.244.2.2!!%

Summary

The service is spread across multiple nodes.

 
Share this