title: How to Use Sockets from Kubernetes Port Forwarding in Python
body: <p>Giving the port forward object</p>
  <pre><code>from kubernetes.stream import stream, portforward
  
  
      pf = portforward(
           k8s_client_v1.connect_get_namespaced_pod_portforward,
           pod_name,
           name_space,
           ports=port
      )
      
      pf.socket(port)
  </code></pre>
  <p><code>pf</code> is a socket object from <code>AF_UNIX</code> family.</p>
  <p>I need a better understating whether another <code>AF_INET</code> family socket has to be instantiated in oder to achieve the same functionality as <code>kubectl</code> client has, ex: <code>kubectl port-forward $pod_name $port</code></p>
  <p>I appreciate in advance if someone could share any snippets of this type of implementation.</p>
  <p>At this moment creating port forward object was inspired from <a href="https://github.com/kubernetes-client/python/blob/master/examples/pod_portforward.py#L176" rel="nofollow noreferrer">here</a></p>