<p>I didn't expose any port in kubernetes/docker but i'm still able to connect to python app from another pod.</p>
<p>Here is the Dockerfile</p>
<pre><code>FROM python:3.6.8
.
.
.
.

RUN chmod u+x /app/entrypoint.sh
ENTRYPOINT /app/entrypoint.sh $WORKERS $FLASK_APP
</code></pre>
<p>This is the entrypoint</p>
<pre><code>flask db upgrade -d abc/migration
gunicorn -w $1 -k gevent -b 0.0.0.0:7103 $2
</code></pre>
<p>This is deployment.yaml</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 labels:
   app: nw-microservice  
 name: nw-microservice  
 namespace: nw-microservice-stg 
spec:
 replicas: 1
 strategy:
   rollingUpdate:
     maxSurge: 20%
     maxUnavailable: 0
   type: RollingUpdate
 template:
   metadata:
     labels:
       app: nw-microservice  
   spec:
     containers:
       - env:
           - name: &quot;PYTHONPATH&quot;
             value: &quot;/app&quot;
         image: imageurl
         imagePullPolicy: IfNotPresent
         name: nw-microservice-api  
         terminationMessagePath: /dev/termination-log
         terminationMessagePolicy: File
     dnsPolicy: ClusterFirst
     imagePullSecrets:
       - name: shared-account-ecr
     restartPolicy: Always
</code></pre>
<p>This is the service</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
 name: service  
 namespace: namespace  
spec:
 ports:
   - name: http
     port: 7103  
     protocol: TCP
     targetPort: 7103
 selector:
   app: nw-microservice  
 type: ClusterIP
</code></pre>
<p>So i can connect the pod through <a href="http://service.namespace:7103" rel="nofollow noreferrer">http://service.namespace:7103</a> but i don't understand why.</p>

mgg
<p>The ports defined in a container are purely informational:</p>
<blockquote>
<p>Exposing a port here gives the system additional information about the network connections a container uses, but is primarily <strong>informational</strong>. <strong>Not specifying a port here DOES NOT prevent that port from being exposed</strong>. Any port which is listening on the default &quot;0.0.0.0&quot; address inside a container will be accessible from the network.</p>
</blockquote>
<p>You can have a look <a href="https://kubernetes.io/docs/reference/kubernetes-api/workloads-resources/container/#ports" rel="nofollow noreferrer">here</a></p>
