<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>

Igor Ognichenko
<p>For your update, if you need to manipulate iptables, you can add another <code>initContainer</code>, for example:</p>

<pre><code>  initContainers:
  - image: centos
    imagePullPolicy: Always
    name: run-iptables
    securityContext:
      privileged: true
    command:
    - "sh"
    - "-c"
    - 'yum -y install iptables; iptables -t nat -A OUTPUT -p tcp --dport 8080 -j DNAT --to-destination 127.0.0.1:8008'
</code></pre>

<p>Since all containers in a pod share the same net namespace, it effects to catalog container as well.</p>
