<p>I have frontend container running with below php code;</p>

<pre><code>&lt;?php
$hn=file_get_contents('/var/secrets/hostname.txt');
$hn=str_replace("\n", "", $hn);
$pass=file_get_contents('/var/secrets/password.txt');
$pass=str_replace("\n", "", $pass);
$cname=$_POST['name'];
$email=$_POST['email'];
$hostname=$hn;
$username='root';
$password=$pass;
$dbname='test';
$usertable='testuser';
$con=mysqli_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysqli_select_db($con,$dbname);
$query = "select * from testuser";
$result = $con-&gt;query($query) or die("Not Updated!");
while($row = $result-&gt;fetch_assoc()) {
        echo "&lt;tr&gt;&lt;td&gt; " . $row["name"] . "&lt;td&gt; " . $row["email"] . "&lt;/tr&gt; ";
}
$con-&gt;close();
?&gt;
</code></pre>

<p>I have hostname name and password saved in text file as mentioned above on frontend container. I have metioned <strong>hostname as SeriveName</strong>. Please find below sample backend service,  here backend service name is "userdatabase-service". Same I have mentioned in hostname.txt on frontend container.</p>

<pre><code>    apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2018-11-13T12:01:25Z
  labels:
    app: userdatabase
  name: userdatabase-service
  namespace: default
  resourceVersion: "32448"
  selfLink: /api/v1/namespaces/default/services/userdatabase-service
  uid: d85cf471-e73b-11e8-8506-42010aa60fca
spec:
  clusterIP: 10.7.255.80
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30198
    port: 80
    protocol: TCP
    targetPort: 3306
  selector:
    app: userdatabase
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 35.228.105.176
</code></pre>

<p>But while accessing frontend service which pulls record from database gives message: Unable to connect to database! Please try again later.</p>

<p>I tried with Ingress Ip but still it gives same error. 
Can you please guide here?
Regards,
Vikas</p>

Vikas Banage
<p>This was solved in the comments by @<a href="https://stackoverflow.com/users/225016/matthew-l-daniel">Matthew L Daniel</a>. The connection string was being formed with 'userdatabase-service' but without any explicit port. It worked when the port 80 was added to the connection string. </p>
