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.