For some parts of your applications you may want to expose a Service onto an external IP address. Kubernetes supports two ways of doing this: NodePort
and LoadBalancer
.
kubectl -n my-nginx get svc my-nginx
Output
Currently the Service does not have an External IP, so let’s now patch the Service to use a cloud load balancer, by updating the type of the my-nginx Service from ClusterIP
to LoadBalancer
:
kubectl -n my-nginx patch svc my-nginx -p '{"spec": {"type": "LoadBalancer"}}'
We can check for the changes:
kubectl -n my-nginx get svc my-nginx
Output
The Load Balancer can take a couple of minutes in being available on the DNS.
Now, let’s try if it’s accessible.
export loadbalancer=$(kubectl -n my-nginx get svc my-nginx -o jsonpath='{.status.loadBalancer.ingress[*].hostname}')
curl -k -s http://${loadbalancer} | grep title
Output
If the Load Balancer name is too long to fit in the standard kubectl get svc output, you’ll need to do kubectl describe service my-nginx to see it. You’ll see something like this:
kubectl -n my-nginx describe service my-nginx | grep Ingress
Output