minikube // setup node ports for balancing

assuming a two k8s or minikube node cluster

kiss nodeport + replicas

kubectl create deploy web --image=gcr.io/google-samples/hello-app:1.0 --replicas=3
kubectl get deploy -o wide
kubectl get pods -o wide

==> here one pod on node1 and two pods on node2

kubectl expose deploy web --type=NodePort --port=8080
kubectl get svc -o wide

and check

curl -i http://192.168.49.2:30xxx
curl -i http://192.168.49.3:30xxx

==> goes to 3 different hostnames/pods whatever node you are talking to

note it will always go to the same pod if you use a web browser… (thanks to the keepalive feature that is enabled by default)

clean-up

kubectl delete svc web
kubectl delete deploy web

additional notes

type NodePort is already balancing across the cluster, not sure what type LoadBalancer is useful for

#kubectl expose deployment web --type=LoadBalancer --port=8080

resources

https://minikube.sigs.k8s.io/docs/start/

https://kubernetes.io/docs/tutorials/hello-minikube/

https://www.digitalocean.com/community/tutorials/how-to-use-minikube-for-local-kubernetes-development-and-testing

https://minikube.sigs.k8s.io/docs/tutorials/multi_node/

multi-node

https://minikube.sigs.k8s.io/docs/tutorials/multi_node/

https://pet2cattle.com/2021/01/multinode-minikube


https://www.cnblogs.com/zhangmingcheng/p/17640118.html


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun