<p>I have two containers in one pod and the Kubernetes services have a selector to the pod.</p>

<p>Container 1 is a UI, exposing the port 8080.
Container 2 is a service to sync with Git.</p>

<p>The issue I have is when the "Container 2" dies (because the Git is down for example) the Kubernetes Service removes the pod from the pool and the service is not routing traffic to the pod.</p>

<p>How can I set in the Kubernetes Service the selector to the container and not to the pod, or some workaround ?</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
      protocol: TCP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
  labels:
    app: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: git
          image: git:1.0

        - name: ui
          image: ui:1.0
          ports:
            - containerPort: 8080
</code></pre>

<p>Thanks!</p>

mrbit01
<p>Although POD can run more than one containers, The failure of those containers are managed together by Kubernetes. You can <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="nofollow noreferrer">refer</a> here.</p>
<p>When you have a pod running two containers, ideally the second container must be a helper container - similiar to a SideCar implementation, where it just does update or read of data to be used by the main container. <br></p>
<p>Pod life cycle doc from kubernetes clearly explains the same.</p>
<blockquote>
<p>Pod is running and has two Containers. <br>
Container 1 exits with failure:<br><br>
Log failure event. <br>
If restartPolicy is: <strong>Always</strong>: <br>
Restart Container; <br>
Pod phase stays Running. <br>
If restartPolicy is: <strong>OnFailure</strong>: <br>
Restart Container; <br>
Pod phase stays Running. <br>
If restartPolicy is: <strong>Never</strong>: <br>
Do not restart Container; <br>
Pod phase stays Running.</p>
<p>If Container 1 is not running, and Container 2 exits:
Log failure event. <br></p>
<p>If restartPolicy is: <strong>Always</strong>: <br>
Restart Container; <br>
Pod phase stays Running.<br>
If restartPolicy is:  <strong>OnFailure</strong>: <br>
Restart Container; <br>
Pod phase stays Running. <br>
If restartPolicy is: <strong>Never</strong>: <br>
Pod phase becomes Failed.</p>
</blockquote>
