<p>I would like to expose a port on an <code>initContainer</code> in a Kubernetes <code>Job</code> I am working on. So far I have been unsuccessful in doing so, and when reading through <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#detailed-behavior" rel="nofollow noreferrer">the docs</a> it says:</p>

<blockquote>
  <p>The ports on an Init Container are not aggregated under a service.</p>
</blockquote>

<p>What does aggregated in this context mean?</p>

<p>As of right now I think the answer is no as the experiment I am running will not allow me to expose a port. However, I am fairly new to Kubernetes, so I don't know if I am making a mistake somewhere else. Figured I would ask here to see if what I am doing is even possible before I attempt to debug any further.</p>

Randy
<p>It is an ambiguous choice of words but the upshot is you cannot access the initContainer through a Service. </p>

<p>Kubernetes Services provide access to a set of Pods by matching to their labels. In this sense a service is an aggregator. I think this is the intended meaning. </p>

<p>There can also be multiple containers in a Pod, each using a different port. If the Pod is matched by a Service that service can be configured to provide access to both on different ports. So a service can also make multiple ports available, though I wouldn't call that aggregation. </p>

<p>Pods aren't exposed by a Service until their readiness probes pass and the Pod status is ready. An initContainer runs before the probes when the Pod status is initialising. So it is logical that it cannot be reached by a Service. It would also be odd to want to expose an initContainer externally as it is temporary by nature. </p>

<p>Is your aim in order to debug (<a href="https://unofficial-kubernetes.readthedocs.io/en/latest/tasks/debug-application-cluster/debug-init-containers/" rel="nofollow noreferrer">https://unofficial-kubernetes.readthedocs.io/en/latest/tasks/debug-application-cluster/debug-init-containers/</a>) or to allow other Pods/Containers to access? I believe the Pod would at init have an IP address but not one which would be guaranteed to be stable so I don't know whether you might be able to port-forward for debugging <a href="https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/</a></p>

<p>I notice you say you are looking to expose the initContainer in a Job. Servicing traffic in a Job would be an unusual aim. If the aim is to monitor the Job then see <a href="https://stackoverflow.com/questions/39146436/monitoring-a-kubernetes-job">Monitoring a kubernetes job</a></p>
