Kubernetes Multi-Node Cluster

Photo by Jan Meeus on Unsplash

Kubernetes Multi-Node Cluster

ยท

3 min read

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.