Once you have deployed an application into Kubernetes, it will not be available to the outside world.
For this to be possible, you need to expose it via a Service.
Services can be exposed in 4 different ways:
- ClusterIP (default) – Exposes the Service via an internal IP to the cluster (only available internally)
- NodePort – Exposes the Service via the same port on all Nodes
- LoadBalancer – Creates an external LoadBalancer in the current cloud
- ExternalName – Maps the Service to the
externalName, and returns a CNAME record with it’s value
How to Expose your App via a Service in Kubernetes
kubectl get pods to list your available pods.
kubectl get services to list your existing Services.
kubectl get deployments to list your active deployments.
Once you have this information, you can run the following command:
This will expose your deployment on port 8080.
Verify that the App has been exposed
We can verify that the deployment has been exposed by running the following:
kubectl get services
This will show the new exposed Service we requested.