The software described in this documentation is either no longer supported or is in extended support.
Oracle recommends that you upgrade to a current supported release.
Typically, while many applications may only need to communicate internally within a pod, or even across pods, you may need to expose your application externally so that clients outside of the Kubernetes cluster can interface with the application. You can do this by creating a service definition for the deployment.
To expose a deployment using a service object, you must define
the service type that should be used. If you are not using a
cloud-based load balancing service, you can set the service type
to NodePort
. The NodePort
service exposes the application running within the cluster on a
dedicated port on the public IP address on all of the nodes
within the cluster. Use the kubectl expose
deployment to create a new service:
$ kubectl expose deployment hello-world
--port 80
--type=LoadBalancer
service/hello-world exposed
Use kubectl get services to list the different services that the cluster is running, and to obtain the port information required to access the service:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-world LoadBalancer 10.102.42.160 <pending> 80:31847/TCP 3s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 5h13m
In this example output, you can see that traffic to port 80
inside the cluster is mapped to the NodePort
31847. The external IP that can be used to access the service is
listed as <pending>
, meaning that if you
connect to the external IP address for any of the nodes within
the cluster on the port 31847, you are able access the service.
For the sake of the example in this guide, you can open a web
browser to point at any of the nodes in the cluster, such as
http://worker1.example.com:31847/
, and it
should display the NGINX demonstration application.