<p>I'm building a K8 cluster for a school project.
It's bare metal and uses metallb as a loadbalancer.
Each service works in a separate pod:</p>
<ul>
<li>Nginx</li>
<li>Wordpress</li>
<li>Phpmyadmin</li>
<li>Mysql (mariadb)</li>
</ul>
<p>In the phpmyadmin file, I need to link my mysql server with something like this:</p>
<p><code>$cfg['Servers'][$i]['host'] = &quot;mysql-server-name&quot;;</code></p>
<p>I've tried to use the node's IP:</p>
<p><code>kubectl get node -o=custom-columns='DATA:status.addresses[0].address' | sed -n 2p</code></p>
<p>adding the port :3306 but I realised that none of my services could be reached through the browser with this method.
For instance the node's Ip:5050 should redirect me to my wordpress but it doesn't.
Is there any way to get a single IP that I can use to make my pods communicate between them ?
I must add that each service works appart when I use the svc IP instead of the nodes.</p>
<p>Here's the configmap I use for metallb:</p>
<pre><code>kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.99.100-192.168.99.200
</code></pre>

Ajvar
<p>The reason the node IP doesn't expose your application to other apps is that the pods in the kubernetes cluster don't listen to the requests coming to the node by default. In other words, the port on the pod is not connected to the port on the node.<br />
The <code>service</code> resource is what you need to make that connection.<br />
Services have different types. A service of type <code>cluster IP</code> will assign an IP internal to the cluster to the app. If you don't want to access your mysql database directly from the internet, this is what you would want.<br />
Here is an example service of type cluster IP for your project.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql-service
  namespace: metallb-system
spec:
  selector:
    app: Mysql
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3306
</code></pre>
<p><code>Selector</code> selects pods that carry the label <code>app=mysql</code>.<br />
<code>Port</code> is the port that the service will listen to.<br />
<code>TargetPort</code> is the port that mysql is listening to.<br />
When you create the service you can find it's IP by running this command</p>
<pre><code>kubectl get services -n metallb-system
</code></pre>
<p>Under CLUSTER-IP column note the IP of the service you created.<br />
So in this case, if mysql is listening to 3306, you can reach it through this service on the service IP on port 80.<br />
If you want to expose your wordpress app to the internet, use either the <code>NodePort</code> or <code>LoadBalancer</code> service types. <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">Here</a> is the reference for service types.</p>
