<p>These are my first steps to the kubernetes world so excuse me if my terms are not used right etc.
I am running a single node kubernetes setup without external loadbalancer and I have deployed a pod with to containers. One mysql database and a powerdns.
Powerdns should expose port 53 to the internet while mysql should expose its port only in the cluster.
Therefore I set the following:</p>

<p>"hostNetwork: true" for the pod<br>
"hostPort" for the powerdns container and not for mysql</p>

<p>Service for port 3306 with "type: ClusterIP"</p>

<p>Now everything is running. Powerdns can connect to the mysql and is exposed on port 53 in the internet.
But contrary to my assumption the mysql database is exposed to the internet too. </p>

<p>Could anyone give me a hint to what I am doing wrong?</p>

Clark Nova
<p>Using <code>hostNetwork: true</code> allows your whole pod (all containers in it) to bind ports to the host, which you already identified as problematic.</p>

<p>First of all, you should consider to move the mysql container out of your pod. Using multiple containers is supposed to group containers working as one unit (e.g. an application and a background process closely communicating with each other).</p>

<p>Think in services. Your service PowerDNS is a service user itself as it requires a database, something the application PowerDNS doesn't provide. You want another service for MySQL. Take a look at the documentation (<a href="https://kubernetes.io/docs/tasks/run-application/run-single-instance-stateful-application/" rel="noreferrer">one</a>, <a href="https://kubernetes.io/docs/tasks/run-application/run-replicated-stateful-application/" rel="noreferrer">two</a>) for StatefulSets as it uses MySQL as an example (running databases on Kubernetes is one of the more complex tasks).
Create a <code>ClusterIP</code> service for this. <code>ClusterIP</code> services are only available from within the cluster (your database is an internal service, so that's what you want).</p>

<p>This way, your PowerDNS pod will only feature one container that you can bind to your host network. <strong>But</strong> using <code>hostNetwork: true</code> is not a good in general. You won't be able to create multiple instances of your application (in case PowerDNS scales), it's fine for first steps though. A load balancer in front of your setup would be better though. You can use <code>NodePort</code> services to make your service available on a high-values port which your load balancer proxies connections to.</p>
