<p>I have a chart in it two containers:</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: catalog
  labels:
    app: catalog
    chart: catalog-0.1.0
    heritage: Tiller
spec:
  replicas: 1
  selector:
    matchLabels:
      app: catalog
  template:
    metadata:
      labels:
        app: catalog
    spec:
      containers:
        - name: catalog
          image: catalog:v1
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
        - name: myproxy
          image: myproxy:v1
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 8008
              protocol: TCP
          env:
            - name: PROXY_PORT
              value: '8080'
---
apiVersion: v1
kind: Service
metadata:
  name: catalog
  labels:
    app: catalog
    chart: catalog-0.1.0
    heritage: Tiller
spec:
  type: NodePort
  ports:
    - port: 8008
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: catalog
</code></pre>

<p>I need to redirect all outbound traffic from the catalog container to myproxy container by localhost.</p>

<p>And already in the container to determine whether the catalog can send requests, log them, etc.</p>

<p>Prompt please whether it is possible to implement it using kubernetes.</p>

<p>Thanks.</p>

<hr>

<p><strong>Update:</strong></p>

<p>The problem is that I can not change the code in the catalg container and send queries to localhost</p>

<p>The container also does not have iptables to do something like this</p>

<pre><code>containers:
    - name: catalog
      image: catalog:v1
      imagePullPolicy: IfNotPresent
      command:
        - 'iptables -t nat -A OUTPUT -p tcp --dport 8080 -j DNAT --to-destination 127.0.0.1:8008'
      ports:
        - name: http
          containerPort: 8080
          protocol: TCP
</code></pre>

<p>Ideally done with kubernetes</p>

<p>If catalog application respects <code>http_proxy</code> environment variable, it it easy. Just add an environment variable to catalog container.</p>

<pre><code>    - name: catalog
      image: catalog:v1
      imagePullPolicy: IfNotPresent
      ports:
        - name: http
          containerPort: 8080
          protocol: TCP
      env:
      - name: HTTP_PROXY
        value: localhost:8008
</code></pre>
