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: NodePorts and LoadBalancers.
kubectl get svc my-nginx
Output
Currently the Service does not have an External IP, so let’s now recreate the Service to use a cloud load balancer, just change the Type of my-nginx Service fromClusterIP
to LoadBalancer
:
kubectl edit svc my-nginx
Once edited, we can check for the changes:
kubectl get svc my-nginx
Output
Now, let’s try if it’s accesible. The ELB can take a couple of minutes in being available on the DNS.curl http://<EXTERNAL-IP> -k
Output
The IP address in the EXTERNAL-IP column is the one that is available on the public internet. The CLUSTER-IP is only available inside your cluster/private cloud network.
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 describe service my-nginx | grep Ingress
Output