Using Service's ClusterIP Address inside POD Using Service's ClusterIP Address inside POD kubernetes kubernetes

Using Service's ClusterIP Address inside POD


Yes, via the environment-level service discovery mechanism. Note, however that any service that you want to access like this must be created before the pod itself has been launched, otherwise the environment variables are not populated.


Within the containers/POD, you can use a dns name which refers to the service.Basically, the file /etc/hosts is populated with the kube-dns edress.You can just use it as like:

<svc-name>.<namespace>.svc.cluster.local

If you must need the IP, you can use ENV Variablse or just ping the DNS name.