In order to expose a service we will issue the expose command:

> kubectl expose deployment <service> --type=<type> --name=<exposed_service_name>


First, find the service you want to expose by getting a list of services

> kubectl get services


The output should look similar to:

$ kubectl get services
NAME           TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
cloudservice   ClusterIP      10.100.59.239    <none>        80/TCP           17h
isservice      ClusterIP      10.111.24.187    <none>        7080/TCP         17h
kubernetes     ClusterIP      10.96.0.1        <none>        443/TCP          228d
postgres       ClusterIP      10.105.23.38     <none>        5432/TCP         17h
redis          ClusterIP      10.98.242.175    <none>        6379/TCP         17h


In the above example, we want to expose our cloudservice, so we would issue the following command:


> kubectl expose deployment cloudservice --type=LoadBalancer --name=cloud


If we list our services again we should see our new exposed service 'cloud': 

$ kubectl get services
NAME           TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
cloud          LoadBalancer   10.111.127.172   <pending>     8080:30100/TCP   17h
cloudservice   ClusterIP      10.100.59.239    <none>        80/TCP           17h
isservice      ClusterIP      10.111.24.187    <none>        7080/TCP         17h
kubernetes     ClusterIP      10.96.0.1        <none>        443/TCP          228d
postgres       ClusterIP      10.105.23.38     <none>        5432/TCP         17h
redis          ClusterIP      10.98.242.175    <none>        6379/TCP         17h

We can now open our exposed service in a browser by issuing the following command:

> minikube service cloud

NOTE: A LoadBalancer type would refer to a load balancer running in a cloud provider's environment.

>> Should use in ingress.


  • No labels