Once a Kubernetes cluster is setup in a public cloud such as Amazon EC2 each Kubernetes host will get a private and public IP address pair. Once a container is spawned it will return the private IP address of the Kubernetes host that it resides, as the public IP address of the container. However private IP address of the Kubernetes host is not accessible from an external network.
Therefore we need to keep private and public IP addresses of each Kubernetes host in the Kubernetes cluster model and returnt he public IP address of the Kubernetes host as the public IP address of the container.
Thanks to Lakmal for identifying this issue!