This tutorial assumers that minikube kubernetes is already installed. Steps to create a deployment with 3 replicas and load balancer:
- Start a cluster with 2 nodes (1 node also ok):
minikube start --nodes 2
- create minikube tunnel to support external access
minikube tunnel
- create deployment with 3 replicas
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0 --replicas=3
- Expose deployment (type loadBalancer)
kubectl expose deployment hello-minikube --type=LoadBalancer --port=8080
- View the service detail
kubectl get services hello-minikube
- Get yaml file of deployment
kubectl get deploy hello-minikube -o yaml
- Print the external service url and port
kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-minikube LoadBalancer 10.106.211.74 127.0.0.1 8080:31806/TCP 6m36s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9m50s
- access the service
curl http://127.0.0.1:8080/Request served by hello-minikube-7ddcbc9b8b-b94pq HTTP/1.1 GET / Host: 127.0.0.1:8080 Accept: */* User-Agent: curl/7.84.0
You can run above multiple time and you should get different pods in response. - One alternative to using tunnel above it exposing service url using service command
minikube service hello-minikube --url
😿 service default/kubernetes has no node port http://127.0.0.1:61762 ❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
You can run curl on above url multiple time and you should get different pods in response.