<p>I have docker-compose.yml</p>

<pre><code>version: '3.5'
services:
  container-name:
    image: container-image
    ports:
      - 80:80
      - 443:443
</code></pre>

<p>And it creates the container with port forwarding to host machine.
docker inspect container-name</p>

<pre><code>[...]
NetworkSettings: {
  [...]
  Ports: {
    443/tcp: [{ HostIp: 0.0.0.0, HostPort: 443 }]
    80/tcp: [{ HostIp: 0.0.0.0, HostPort: 80 }]
  }
  [...]
}
[...]
</code></pre>

<p>But in the kubernetes next pod.yml, create container without ports.</p>

<pre><code>kind: Pod
matadata:
  name: pod-name
spec:
  containers:
  - image: container-image
    name: container-name
    ports:
    - containerPort: 80
      protocol: TCP
    - containerPort: 443
      protocol: TCP
    [...]
</code></pre>

<p>In short, I need forward container(pod) port to host machine(node).</p>

<p>I found out that better to expose. But it doesn't work for me.</p>

Sviat Safr
<p>The kubernetes way" to prefer would be to expose your pod through a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service" rel="noreferrer">service</a> and control it with a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment" rel="noreferrer">deployment</a>.</p>

<p>If you want for some reason use the port-forwarding this is how you do:</p>

<pre><code>kubectl port-forward pod/pod-name 8080:80 8443:443 -n default
</code></pre>

<p>This is going to bind on your host ports <code>8080</code> and <code>8443</code>, forwarding the traffic to the ports <code>80</code> and <code>443</code> respectively for the pod with the name <code>pod-name</code>. I have not omitted the namespace (<code>default</code>), by default <code>kubectl</code> will use your <a href="https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#define-clusters-users-and-contexts" rel="noreferrer">current-context</a> </p>
